Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: components/domain_reliability/monitor.cc

Issue 691053003: Domain Reliability: Mark beacons from previous networks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/monitor.h" 5 #include "components/domain_reliability/monitor.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/task_runner.h" 10 #include "base/task_runner.h"
(...skipping 15 matching lines...) Expand all
26 upload_reporter_string_(upload_reporter_string), 26 upload_reporter_string_(upload_reporter_string),
27 scheduler_params_( 27 scheduler_params_(
28 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()), 28 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()),
29 dispatcher_(time_.get()), 29 dispatcher_(time_.get()),
30 pref_task_runner_(pref_thread), 30 pref_task_runner_(pref_thread),
31 network_task_runner_(network_thread), 31 network_task_runner_(network_thread),
32 moved_to_network_thread_(false), 32 moved_to_network_thread_(false),
33 discard_uploads_set_(false), 33 discard_uploads_set_(false),
34 weak_factory_(this) { 34 weak_factory_(this) {
35 DCHECK(OnPrefThread()); 35 DCHECK(OnPrefThread());
36 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
36 } 37 }
37 38
38 DomainReliabilityMonitor::DomainReliabilityMonitor( 39 DomainReliabilityMonitor::DomainReliabilityMonitor(
39 const std::string& upload_reporter_string, 40 const std::string& upload_reporter_string,
40 scoped_refptr<base::SingleThreadTaskRunner> pref_thread, 41 scoped_refptr<base::SingleThreadTaskRunner> pref_thread,
41 scoped_refptr<base::SingleThreadTaskRunner> network_thread, 42 scoped_refptr<base::SingleThreadTaskRunner> network_thread,
42 scoped_ptr<MockableTime> time) 43 scoped_ptr<MockableTime> time)
43 : time_(time.Pass()), 44 : time_(time.Pass()),
44 upload_reporter_string_(upload_reporter_string), 45 upload_reporter_string_(upload_reporter_string),
45 scheduler_params_( 46 scheduler_params_(
46 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()), 47 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()),
47 dispatcher_(time_.get()), 48 dispatcher_(time_.get()),
48 pref_task_runner_(pref_thread), 49 pref_task_runner_(pref_thread),
49 network_task_runner_(network_thread), 50 network_task_runner_(network_thread),
50 moved_to_network_thread_(false), 51 moved_to_network_thread_(false),
51 discard_uploads_set_(false), 52 discard_uploads_set_(false),
52 weak_factory_(this) { 53 weak_factory_(this) {
53 DCHECK(OnPrefThread()); 54 DCHECK(OnPrefThread());
55 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
54 } 56 }
55 57
56 DomainReliabilityMonitor::~DomainReliabilityMonitor() { 58 DomainReliabilityMonitor::~DomainReliabilityMonitor() {
57 if (moved_to_network_thread_) 59 if (moved_to_network_thread_)
58 DCHECK(OnNetworkThread()); 60 DCHECK(OnNetworkThread());
59 else 61 else
60 DCHECK(OnPrefThread()); 62 DCHECK(OnPrefThread());
61 63
62 ClearContexts(); 64 ClearContexts();
65 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
63 } 66 }
64 67
65 void DomainReliabilityMonitor::MoveToNetworkThread() { 68 void DomainReliabilityMonitor::MoveToNetworkThread() {
66 DCHECK(OnPrefThread()); 69 DCHECK(OnPrefThread());
67 DCHECK(!moved_to_network_thread_); 70 DCHECK(!moved_to_network_thread_);
68 71
69 moved_to_network_thread_ = true; 72 moved_to_network_thread_ = true;
70 } 73 }
71 74
72 void DomainReliabilityMonitor::InitURLRequestContext( 75 void DomainReliabilityMonitor::InitURLRequestContext(
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 return; 140 return;
138 RequestInfo request_info(*request); 141 RequestInfo request_info(*request);
139 if (request_info.AccessedNetwork()) { 142 if (request_info.AccessedNetwork()) {
140 OnRequestLegComplete(request_info); 143 OnRequestLegComplete(request_info);
141 // A request was just using the network, so now is a good time to run any 144 // A request was just using the network, so now is a good time to run any
142 // pending and eligible uploads. 145 // pending and eligible uploads.
143 dispatcher_.RunEligibleTasks(); 146 dispatcher_.RunEligibleTasks();
144 } 147 }
145 } 148 }
146 149
150 void DomainReliabilityMonitor::OnNetworkChanged(
151 net::NetworkChangeNotifier::ConnectionType type) {
152 last_network_change_time_ = time_->NowTicks();
davidben 2014/11/03 19:25:34 Perhaps a test in monitor_unittest.cc to provide c
Deprecated (see juliatuttle) 2014/11/04 17:56:52 Hmm. I don't have an easy way to test the effects
davidben 2014/11/04 19:12:35 Mm. I dunno, it seems worth having an integration
153 }
154
147 void DomainReliabilityMonitor::ClearBrowsingData( 155 void DomainReliabilityMonitor::ClearBrowsingData(
148 DomainReliabilityClearMode mode) { 156 DomainReliabilityClearMode mode) {
149 DCHECK(OnNetworkThread()); 157 DCHECK(OnNetworkThread());
150 158
151 switch (mode) { 159 switch (mode) {
152 case CLEAR_BEACONS: { 160 case CLEAR_BEACONS: {
153 ContextMap::const_iterator it; 161 ContextMap::const_iterator it;
154 for (it = contexts_.begin(); it != contexts_.end(); ++it) 162 for (it = contexts_.begin(); it != contexts_.end(); ++it)
155 it->second->ClearBeacons(); 163 it->second->ClearBeacons();
156 break; 164 break;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 DCHECK(config); 219 DCHECK(config);
212 DCHECK(config->IsValid()); 220 DCHECK(config->IsValid());
213 221
214 // Grab a copy of the domain before transferring ownership of |config|. 222 // Grab a copy of the domain before transferring ownership of |config|.
215 std::string domain = config->domain; 223 std::string domain = config->domain;
216 224
217 DomainReliabilityContext* context = 225 DomainReliabilityContext* context =
218 new DomainReliabilityContext(time_.get(), 226 new DomainReliabilityContext(time_.get(),
219 scheduler_params_, 227 scheduler_params_,
220 upload_reporter_string_, 228 upload_reporter_string_,
229 &last_network_change_time_,
221 &dispatcher_, 230 &dispatcher_,
222 uploader_.get(), 231 uploader_.get(),
223 config.Pass()); 232 config.Pass());
224 233
225 std::pair<ContextMap::iterator, bool> map_it = 234 std::pair<ContextMap::iterator, bool> map_it =
226 contexts_.insert(make_pair(domain, context)); 235 contexts_.insert(make_pair(domain, context));
227 // Make sure the domain wasn't already in the map. 236 // Make sure the domain wasn't already in the map.
228 DCHECK(map_it.second); 237 DCHECK(map_it.second);
229 238
230 return map_it.first->second; 239 return map_it.first->second;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 328
320 return NULL; 329 return NULL;
321 } 330 }
322 331
323 base::WeakPtr<DomainReliabilityMonitor> 332 base::WeakPtr<DomainReliabilityMonitor>
324 DomainReliabilityMonitor::MakeWeakPtr() { 333 DomainReliabilityMonitor::MakeWeakPtr() {
325 return weak_factory_.GetWeakPtr(); 334 return weak_factory_.GetWeakPtr();
326 } 335 }
327 336
328 } // namespace domain_reliability 337 } // namespace domain_reliability
OLDNEW
« components/domain_reliability/context.h ('K') | « components/domain_reliability/monitor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698