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.
5 #include "components/domain_reliability/service.h"
8 #include "base/callback.h"
9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/task_runner_util.h"
12 #include "components/domain_reliability/monitor.h"
13 #include "net/url_request/url_request_context_getter.h"
15 namespace domain_reliability
{
19 scoped_ptr
<base::Value
> GetWebUIDataOnNetworkTaskRunner(
20 base::WeakPtr
<DomainReliabilityMonitor
> monitor
) {
22 base::DictionaryValue
* dict
= new base::DictionaryValue();
23 dict
->SetString("error", "no_monitor");
24 return scoped_ptr
<base::Value
>(dict
);
27 return monitor
->GetWebUIData();
32 class DomainReliabilityServiceImpl
: public DomainReliabilityService
{
34 explicit DomainReliabilityServiceImpl(
35 const std::string
& upload_reporter_string
)
36 : upload_reporter_string_(upload_reporter_string
) {}
38 ~DomainReliabilityServiceImpl() override
{}
40 // DomainReliabilityService implementation:
42 scoped_ptr
<DomainReliabilityMonitor
> CreateMonitor(
43 scoped_refptr
<base::SingleThreadTaskRunner
> network_task_runner
)
45 DCHECK(!network_task_runner_
.get());
47 scoped_ptr
<DomainReliabilityMonitor
> monitor(
48 new DomainReliabilityMonitor(upload_reporter_string_
,
49 base::MessageLoopProxy::current(),
50 network_task_runner
));
52 monitor_
= monitor
->MakeWeakPtr();
53 network_task_runner_
= network_task_runner
;
55 return monitor
.Pass();
58 void ClearBrowsingData(DomainReliabilityClearMode clear_mode
,
59 const base::Closure
& callback
) override
{
60 DCHECK(network_task_runner_
.get());
62 network_task_runner_
->PostTaskAndReply(
64 base::Bind(&DomainReliabilityMonitor::ClearBrowsingData
,
70 void GetWebUIData(const base::Callback
<void(scoped_ptr
<base::Value
>)>&
71 callback
) const override
{
72 DCHECK(network_task_runner_
.get());
74 PostTaskAndReplyWithResult(
75 network_task_runner_
.get(),
77 base::Bind(&GetWebUIDataOnNetworkTaskRunner
, monitor_
),
82 std::string upload_reporter_string_
;
83 base::WeakPtr
<DomainReliabilityMonitor
> monitor_
;
84 scoped_refptr
<base::SingleThreadTaskRunner
> network_task_runner_
;
88 DomainReliabilityService
* DomainReliabilityService::Create(
89 const std::string
& upload_reporter_string
) {
90 return new DomainReliabilityServiceImpl(upload_reporter_string
);
93 DomainReliabilityService::~DomainReliabilityService() {}
95 DomainReliabilityService::DomainReliabilityService() {}
97 } // namespace domain_reliability