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

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

Issue 2627523003: Observe network changes from network thread in DomainReliabilityMonitor. (Closed)
Patch Set: Created 3 years, 11 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h"
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
12 #include "base/profiler/scoped_tracker.h" 13 #include "base/profiler/scoped_tracker.h"
13 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
14 #include "base/task_runner.h" 15 #include "base/task_runner.h"
15 #include "components/domain_reliability/baked_in_configs.h" 16 #include "components/domain_reliability/baked_in_configs.h"
16 #include "components/domain_reliability/google_configs.h" 17 #include "components/domain_reliability/google_configs.h"
17 #include "components/domain_reliability/header.h" 18 #include "components/domain_reliability/header.h"
18 #include "components/domain_reliability/quic_error_mapping.h" 19 #include "components/domain_reliability/quic_error_mapping.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 scheduler_params_( 84 scheduler_params_(
84 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()), 85 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()),
85 dispatcher_(time_.get()), 86 dispatcher_(time_.get()),
86 context_manager_(this), 87 context_manager_(this),
87 pref_task_runner_(pref_thread), 88 pref_task_runner_(pref_thread),
88 network_task_runner_(network_thread), 89 network_task_runner_(network_thread),
89 moved_to_network_thread_(false), 90 moved_to_network_thread_(false),
90 discard_uploads_set_(false), 91 discard_uploads_set_(false),
91 weak_factory_(this) { 92 weak_factory_(this) {
92 DCHECK(OnPrefThread()); 93 DCHECK(OnPrefThread());
93 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
94 } 94 }
95 95
96 DomainReliabilityMonitor::DomainReliabilityMonitor( 96 DomainReliabilityMonitor::DomainReliabilityMonitor(
97 const std::string& upload_reporter_string, 97 const std::string& upload_reporter_string,
98 const scoped_refptr<base::SingleThreadTaskRunner>& pref_thread, 98 const scoped_refptr<base::SingleThreadTaskRunner>& pref_thread,
99 const scoped_refptr<base::SingleThreadTaskRunner>& network_thread, 99 const scoped_refptr<base::SingleThreadTaskRunner>& network_thread,
100 std::unique_ptr<MockableTime> time) 100 std::unique_ptr<MockableTime> time)
101 : time_(std::move(time)), 101 : time_(std::move(time)),
102 upload_reporter_string_(upload_reporter_string), 102 upload_reporter_string_(upload_reporter_string),
103 scheduler_params_( 103 scheduler_params_(
104 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()), 104 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()),
105 dispatcher_(time_.get()), 105 dispatcher_(time_.get()),
106 context_manager_(this), 106 context_manager_(this),
107 pref_task_runner_(pref_thread), 107 pref_task_runner_(pref_thread),
108 network_task_runner_(network_thread), 108 network_task_runner_(network_thread),
109 moved_to_network_thread_(false), 109 moved_to_network_thread_(false),
110 discard_uploads_set_(false), 110 discard_uploads_set_(false),
111 weak_factory_(this) { 111 weak_factory_(this) {
112 DCHECK(OnPrefThread()); 112 DCHECK(OnPrefThread());
113 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
114 } 113 }
115 114
116 DomainReliabilityMonitor::~DomainReliabilityMonitor() { 115 DomainReliabilityMonitor::~DomainReliabilityMonitor() {
117 if (moved_to_network_thread_) 116 if (moved_to_network_thread_) {
117 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
118 DCHECK(OnNetworkThread()); 118 DCHECK(OnNetworkThread());
119 else 119 } else {
120 DCHECK(OnPrefThread()); 120 DCHECK(OnPrefThread());
121 121 }
122 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
123 } 122 }
124 123
125 void DomainReliabilityMonitor::MoveToNetworkThread() { 124 void DomainReliabilityMonitor::MoveToNetworkThread() {
126 DCHECK(OnPrefThread()); 125 DCHECK(OnPrefThread());
127 DCHECK(!moved_to_network_thread_); 126 DCHECK(!moved_to_network_thread_);
128 127
128 network_task_runner_->PostTask(
129 FROM_HERE,
130 base::Bind(&net::NetworkChangeNotifier::AddNetworkChangeObserver,
131 base::Unretained(this)));
129 moved_to_network_thread_ = true; 132 moved_to_network_thread_ = true;
130 } 133 }
131 134
132 void DomainReliabilityMonitor::InitURLRequestContext( 135 void DomainReliabilityMonitor::InitURLRequestContext(
133 net::URLRequestContext* url_request_context) { 136 net::URLRequestContext* url_request_context) {
134 DCHECK(OnNetworkThread()); 137 DCHECK(OnNetworkThread());
135 DCHECK(moved_to_network_thread_); 138 DCHECK(moved_to_network_thread_);
136 139
137 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = 140 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter =
138 new net::TrivialURLRequestContextGetter(url_request_context, 141 new net::TrivialURLRequestContextGetter(url_request_context,
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 break; 430 break;
428 } 431 }
429 } 432 }
430 433
431 base::WeakPtr<DomainReliabilityMonitor> 434 base::WeakPtr<DomainReliabilityMonitor>
432 DomainReliabilityMonitor::MakeWeakPtr() { 435 DomainReliabilityMonitor::MakeWeakPtr() {
433 return weak_factory_.GetWeakPtr(); 436 return weak_factory_.GetWeakPtr();
434 } 437 }
435 438
436 } // namespace domain_reliability 439 } // namespace domain_reliability
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698