OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/domain_reliability/service.h" | 5 #include "components/domain_reliability/service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/task_runner_util.h" |
10 #include "components/domain_reliability/monitor.h" | 11 #include "components/domain_reliability/monitor.h" |
11 #include "net/url_request/url_request_context_getter.h" | 12 #include "net/url_request/url_request_context_getter.h" |
12 | 13 |
13 namespace domain_reliability { | 14 namespace domain_reliability { |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 void GetWebUIDataOnNetworkTaskRunner( | 18 scoped_ptr<const base::Value> MaybeGetWebUIData( |
18 base::WeakPtr<DomainReliabilityMonitor> monitor, | 19 base::WeakPtr<DomainReliabilityMonitor> monitor) { |
19 scoped_ptr<const base::Value>* data_out) { | 20 if (!monitor) |
20 if (monitor) | 21 return scoped_ptr<const base::Value>(); |
21 *data_out = monitor->GetWebUIData(); | |
22 } | |
23 | 22 |
24 void CallGetWebUIDataCallbackAndDeleteDataPointer( | 23 return monitor->GetWebUIData(); |
25 const base::Callback<void(scoped_ptr<const base::Value>)>& callback, | |
26 scoped_ptr<const base::Value>* data_in) { | |
27 callback.Run(data_in->Pass()); | |
28 delete data_in; | |
29 } | 24 } |
30 | 25 |
31 } // namespace | 26 } // namespace |
32 | 27 |
33 class DomainReliabilityServiceImpl : public DomainReliabilityService { | 28 class DomainReliabilityServiceImpl : public DomainReliabilityService { |
34 public: | 29 public: |
35 explicit DomainReliabilityServiceImpl( | 30 explicit DomainReliabilityServiceImpl( |
36 const std::string& upload_reporter_string) | 31 const std::string& upload_reporter_string) |
37 : upload_reporter_string_(upload_reporter_string) {} | 32 : upload_reporter_string_(upload_reporter_string) {} |
38 | 33 |
(...skipping 24 matching lines...) Expand all Loading... |
63 monitor_, | 58 monitor_, |
64 clear_mode), | 59 clear_mode), |
65 callback); | 60 callback); |
66 } | 61 } |
67 | 62 |
68 virtual void GetWebUIData( | 63 virtual void GetWebUIData( |
69 const base::Callback<void(scoped_ptr<const base::Value>)>& callback) | 64 const base::Callback<void(scoped_ptr<const base::Value>)>& callback) |
70 const OVERRIDE { | 65 const OVERRIDE { |
71 DCHECK(network_task_runner_); | 66 DCHECK(network_task_runner_); |
72 | 67 |
73 scoped_ptr<const base::Value>* data = | 68 base::PostTaskAndReplyWithResult( |
74 new scoped_ptr<const base::Value>(new base::DictionaryValue()); | 69 network_task_runner_, |
75 network_task_runner_->PostTaskAndReply(FROM_HERE, | 70 FROM_HERE, |
76 base::Bind(&GetWebUIDataOnNetworkTaskRunner, | 71 base::Bind(&MaybeGetWebUIData, |
77 monitor_, | 72 monitor_), |
78 data), | 73 callback); |
79 base::Bind(&CallGetWebUIDataCallbackAndDeleteDataPointer, | |
80 callback, | |
81 data)); | |
82 } | 74 } |
83 | 75 |
84 private: | 76 private: |
85 std::string upload_reporter_string_; | 77 std::string upload_reporter_string_; |
86 base::WeakPtr<DomainReliabilityMonitor> monitor_; | 78 base::WeakPtr<DomainReliabilityMonitor> monitor_; |
87 scoped_refptr<base::SequencedTaskRunner> network_task_runner_; | 79 scoped_refptr<base::SequencedTaskRunner> network_task_runner_; |
88 }; | 80 }; |
89 | 81 |
90 // static | 82 // static |
91 DomainReliabilityService* DomainReliabilityService::Create( | 83 DomainReliabilityService* DomainReliabilityService::Create( |
92 const std::string& upload_reporter_string) { | 84 const std::string& upload_reporter_string) { |
93 return new DomainReliabilityServiceImpl(upload_reporter_string); | 85 return new DomainReliabilityServiceImpl(upload_reporter_string); |
94 } | 86 } |
95 | 87 |
96 DomainReliabilityService::~DomainReliabilityService() {} | 88 DomainReliabilityService::~DomainReliabilityService() {} |
97 | 89 |
98 DomainReliabilityService::DomainReliabilityService() {} | 90 DomainReliabilityService::DomainReliabilityService() {} |
99 | 91 |
100 } // namespace domain_reliability | 92 } // namespace domain_reliability |
OLD | NEW |