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

Side by Side Diff: chromecast/net/connectivity_checker.cc

Issue 1037693005: Don't check connectivity if network is offline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chromecast/net/connectivity_checker.h" 5 #include "chromecast/net/connectivity_checker.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/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "chromecast/net/net_switches.h" 10 #include "chromecast/net/net_switches.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 98 }
99 99
100 void ConnectivityChecker::Check() { 100 void ConnectivityChecker::Check() {
101 if (!loop_proxy_->BelongsToCurrentThread()) { 101 if (!loop_proxy_->BelongsToCurrentThread()) {
102 loop_proxy_->PostTask(FROM_HERE, 102 loop_proxy_->PostTask(FROM_HERE,
103 base::Bind(&ConnectivityChecker::Check, this)); 103 base::Bind(&ConnectivityChecker::Check, this));
104 return; 104 return;
105 } 105 }
106 DCHECK(url_request_context_.get()); 106 DCHECK(url_request_context_.get());
107 107
108 // Don't check connectivity if network is offline, because internet could be
109 // accessible via netifs ignored.
110 if (net::NetworkChangeNotifier::IsOffline())
derekjchow1 2015/03/25 22:37:26 I don't think we should check here. What happens f
byungchul 2015/03/25 22:44:39 SetConnectivity(false) is called by OnConnectionTy
111 return;
112
108 // If url_request_ is non-null, there is already a check going on. Don't 113 // If url_request_ is non-null, there is already a check going on. Don't
109 // start another. 114 // start another.
110 if (url_request_.get()) 115 if (url_request_.get())
111 return; 116 return;
112 117
113 VLOG(1) << "Connectivity check: url=" << *connectivity_check_url_; 118 VLOG(1) << "Connectivity check: url=" << *connectivity_check_url_;
114 url_request_ = url_request_context_->CreateRequest( 119 url_request_ = url_request_context_->CreateRequest(
115 *connectivity_check_url_, net::MAXIMUM_PRIORITY, this); 120 *connectivity_check_url_, net::MAXIMUM_PRIORITY, this);
116 url_request_->set_method("HEAD"); 121 url_request_->set_method("HEAD");
117 url_request_->Start(); 122 url_request_->Start();
(...skipping 19 matching lines...) Expand all
137 void ConnectivityChecker::OnResponseStarted(net::URLRequest* request) { 142 void ConnectivityChecker::OnResponseStarted(net::URLRequest* request) {
138 int http_response_code = 143 int http_response_code =
139 (request->status().is_success() && 144 (request->status().is_success() &&
140 request->response_info().headers.get() != NULL) 145 request->response_info().headers.get() != NULL)
141 ? request->response_info().headers->response_code() 146 ? request->response_info().headers->response_code()
142 : net::HTTP_BAD_REQUEST; 147 : net::HTTP_BAD_REQUEST;
143 148
144 // Clears resources. 149 // Clears resources.
145 url_request_.reset(NULL); // URLRequest::Cancel() is called in destructor. 150 url_request_.reset(NULL); // URLRequest::Cancel() is called in destructor.
146 151
147 if (http_response_code < 400) { 152 if (http_response_code < 400) {
derekjchow1 2015/03/25 22:37:26 Perhaps we should check (http_response_code < 400
148 VLOG(1) << "Connectivity check succeeded"; 153 VLOG(1) << "Connectivity check succeeded";
149 bad_responses_ = 0; 154 bad_responses_ = 0;
150 SetConnectivity(true); 155 SetConnectivity(true);
151 return; 156 return;
152 } 157 }
153 158
154 VLOG(1) << "Connectivity check failed: " << http_response_code; 159 VLOG(1) << "Connectivity check failed: " << http_response_code;
155 ++bad_responses_; 160 ++bad_responses_;
156 if (bad_responses_ > kNumBadResponses) { 161 if (bad_responses_ > kNumBadResponses) {
157 bad_responses_ = kNumBadResponses; 162 bad_responses_ = kNumBadResponses;
(...skipping 12 matching lines...) Expand all
170 } 175 }
171 176
172 void ConnectivityChecker::Cancel() { 177 void ConnectivityChecker::Cancel() {
173 if (url_request_.get()) { 178 if (url_request_.get()) {
174 VLOG(2) << "Cancel connectivity check in progress"; 179 VLOG(2) << "Cancel connectivity check in progress";
175 url_request_.reset(NULL); // URLRequest::Cancel() is called in destructor. 180 url_request_.reset(NULL); // URLRequest::Cancel() is called in destructor.
176 } 181 }
177 } 182 }
178 183
179 } // namespace chromecast 184 } // namespace chromecast
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