1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef COMPONENTS_DOMAIN_RELIABILITY_SERVICE_H_
6#define COMPONENTS_DOMAIN_RELIABILITY_SERVICE_H_
7
8#include <string>
9
10#include "base/callback_forward.h"
11#include "base/macros.h"
12#include "base/memory/ref_counted.h"
13#include "base/memory/scoped_ptr.h"
14#include "base/single_thread_task_runner.h"
15#include "components/domain_reliability/clear_mode.h"
16#include "components/domain_reliability/domain_reliability_export.h"
17#include "components/keyed_service/core/keyed_service.h"
18
19class PrefService;
20
21namespace base {
22class Value;
23}  // namespace base
24
25namespace net {
26class URLRequestContextGetter;
27}  // namespace net
28
29namespace domain_reliability {
30
31class DomainReliabilityMonitor;
32
33// DomainReliabilityService is a KeyedService that manages a Monitor that lives
34// on another thread (as provided by the URLRequestContextGetter's task runner)
35// and proxies (selected) method calls to it. Destruction of the Monitor (on
36// that thread) is the responsibility of the caller.
37class DOMAIN_RELIABILITY_EXPORT DomainReliabilityService
38    : public KeyedService {
39 public:
40  // Creates a DomainReliabilityService that will contain a Monitor with the
41  // given upload reporter string.
42  static DomainReliabilityService* Create(
43      const std::string& upload_reporter_string);
44
45  virtual ~DomainReliabilityService();
46
47  // Initializes the Service: given the task runner on which Monitor methods
48  // should be called, creates the Monitor and returns it. Can be called at
49  // most once, and must be called before any of the below methods can be
50  // called. The caller is responsible for destroying the Monitor on the given
51  // task runner when it is no longer needed.
52  virtual scoped_ptr<DomainReliabilityMonitor> CreateMonitor(
53      scoped_refptr<base::SingleThreadTaskRunner> network_task_runner) = 0;
54
55  // Clears browsing data on the associated Monitor. |Init()| must have been
56  // called first.
57  virtual void ClearBrowsingData(DomainReliabilityClearMode clear_mode,
58                                 const base::Closure& callback) = 0;
59
60  virtual void GetWebUIData(
61      const base::Callback<void(scoped_ptr<base::Value>)>& callback)
62      const = 0;
63
64 protected:
65  DomainReliabilityService();
66
67 private:
68  DISALLOW_COPY_AND_ASSIGN(DomainReliabilityService);
69};
70
71}  // namespace domain_reliability
72
73#endif  // COMPONENTS_DOMAIN_RELIABILITY_SERVICE_H_
74