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/location.h"
10 #include "base/single_thread_task_runner.h"
11 #include "base/task_runner_util.h"
12 #include "base/thread_task_runner_handle.h"
13 #include "components/domain_reliability/monitor.h"
14 #include "net/url_request/url_request_context_getter.h"
16 namespace domain_reliability
{
20 scoped_ptr
<base::Value
> GetWebUIDataOnNetworkTaskRunner(
21 base::WeakPtr
<DomainReliabilityMonitor
> monitor
) {
23 base::DictionaryValue
* dict
= new base::DictionaryValue();
24 dict
->SetString("error", "no_monitor");
25 return scoped_ptr
<base::Value
>(dict
);
28 return monitor
->GetWebUIData();
33 class DomainReliabilityServiceImpl
: public DomainReliabilityService
{
35 explicit DomainReliabilityServiceImpl(
36 const std::string
& upload_reporter_string
)
37 : upload_reporter_string_(upload_reporter_string
) {}
39 ~DomainReliabilityServiceImpl() override
{}
41 // DomainReliabilityService implementation:
43 scoped_ptr
<DomainReliabilityMonitor
> CreateMonitor(
44 scoped_refptr
<base::SingleThreadTaskRunner
> network_task_runner
)
46 DCHECK(!network_task_runner_
.get());
48 scoped_ptr
<DomainReliabilityMonitor
> monitor(new DomainReliabilityMonitor(
49 upload_reporter_string_
, base::ThreadTaskRunnerHandle::Get(),
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