1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/domain_reliability/service.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/single_thread_task_runner.h"
#include "base/task_runner_util.h"
#include "components/domain_reliability/monitor.h"
#include "net/url_request/url_request_context_getter.h"
namespace domain_reliability {
namespace {
scoped_ptr<base::Value> GetWebUIDataOnNetworkTaskRunner(
base::WeakPtr<DomainReliabilityMonitor> monitor) {
if (!monitor) {
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetString("error", "no_monitor");
return scoped_ptr<base::Value>(dict);
}
return monitor->GetWebUIData();
}
} // namespace
class DomainReliabilityServiceImpl : public DomainReliabilityService {
public:
explicit DomainReliabilityServiceImpl(
const std::string& upload_reporter_string)
: upload_reporter_string_(upload_reporter_string) {}
~DomainReliabilityServiceImpl() override {}
// DomainReliabilityService implementation:
scoped_ptr<DomainReliabilityMonitor> CreateMonitor(
scoped_refptr<base::SingleThreadTaskRunner> network_task_runner)
override {
DCHECK(!network_task_runner_.get());
scoped_ptr<DomainReliabilityMonitor> monitor(
new DomainReliabilityMonitor(upload_reporter_string_,
base::MessageLoopProxy::current(),
network_task_runner));
monitor_ = monitor->MakeWeakPtr();
network_task_runner_ = network_task_runner;
return monitor.Pass();
}
void ClearBrowsingData(DomainReliabilityClearMode clear_mode,
const base::Closure& callback) override {
DCHECK(network_task_runner_.get());
network_task_runner_->PostTaskAndReply(
FROM_HERE,
base::Bind(&DomainReliabilityMonitor::ClearBrowsingData,
monitor_,
clear_mode),
callback);
}
void GetWebUIData(const base::Callback<void(scoped_ptr<base::Value>)>&
callback) const override {
DCHECK(network_task_runner_.get());
PostTaskAndReplyWithResult(
network_task_runner_.get(),
FROM_HERE,
base::Bind(&GetWebUIDataOnNetworkTaskRunner, monitor_),
callback);
}
private:
std::string upload_reporter_string_;
base::WeakPtr<DomainReliabilityMonitor> monitor_;
scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
};
// static
DomainReliabilityService* DomainReliabilityService::Create(
const std::string& upload_reporter_string) {
return new DomainReliabilityServiceImpl(upload_reporter_string);
}
DomainReliabilityService::~DomainReliabilityService() {}
DomainReliabilityService::DomainReliabilityService() {}
} // namespace domain_reliability
|