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

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

Issue 960693002: Remove NetworkChangeNotifierCast. (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 | « chromecast/chromecast.gyp ('k') | chromecast/net/network_change_notifier_cast.h » ('j') | 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 62 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
63 if (!net::NetworkChangeNotifier::IsOffline()) { 63 if (!net::NetworkChangeNotifier::IsOffline()) {
64 loop_proxy_->PostTask(FROM_HERE, 64 loop_proxy_->PostTask(FROM_HERE,
65 base::Bind(&ConnectivityChecker::Check, this)); 65 base::Bind(&ConnectivityChecker::Check, this));
66 } 66 }
67 } 67 }
68 68
69 ConnectivityChecker::~ConnectivityChecker() { 69 ConnectivityChecker::~ConnectivityChecker() {
70 DCHECK(loop_proxy_.get()); 70 DCHECK(loop_proxy_.get());
71 loop_proxy_->DeleteSoon(FROM_HERE, url_request_context_.release()); 71 loop_proxy_->DeleteSoon(FROM_HERE, url_request_context_.release());
72 loop_proxy_->DeleteSoon(FROM_HERE, url_request_.release());
72 } 73 }
73 74
74 void ConnectivityChecker::AddConnectivityObserver( 75 void ConnectivityChecker::AddConnectivityObserver(
75 ConnectivityObserver* observer) { 76 ConnectivityObserver* observer) {
76 connectivity_observer_list_->AddObserver(observer); 77 connectivity_observer_list_->AddObserver(observer);
77 } 78 }
78 79
79 void ConnectivityChecker::RemoveConnectivityObserver( 80 void ConnectivityChecker::RemoveConnectivityObserver(
80 ConnectivityObserver* observer) { 81 ConnectivityObserver* observer) {
81 connectivity_observer_list_->RemoveObserver(observer); 82 connectivity_observer_list_->RemoveObserver(observer);
(...skipping 19 matching lines...) Expand all
101 base::Bind(&ConnectivityChecker::Check, this)); 102 base::Bind(&ConnectivityChecker::Check, this));
102 return; 103 return;
103 } 104 }
104 DCHECK(url_request_context_.get()); 105 DCHECK(url_request_context_.get());
105 106
106 // If url_request_ is non-null, there is already a check going on. Don't 107 // If url_request_ is non-null, there is already a check going on. Don't
107 // start another. 108 // start another.
108 if (url_request_.get()) 109 if (url_request_.get())
109 return; 110 return;
110 111
111 VLOG(2) << "Connectivity check: url=" << *connectivity_check_url_; 112 VLOG(1) << "Connectivity check: url=" << *connectivity_check_url_;
112 url_request_ = url_request_context_->CreateRequest( 113 url_request_ = url_request_context_->CreateRequest(
113 *connectivity_check_url_, net::MAXIMUM_PRIORITY, this, NULL); 114 *connectivity_check_url_, net::MAXIMUM_PRIORITY, this, NULL);
114 url_request_->set_method("HEAD"); 115 url_request_->set_method("HEAD");
115 url_request_->Start(); 116 url_request_->Start();
116 } 117 }
117 118
118 void ConnectivityChecker::OnConnectionTypeChanged( 119 void ConnectivityChecker::OnConnectionTypeChanged(
119 net::NetworkChangeNotifier::ConnectionType type) { 120 net::NetworkChangeNotifier::ConnectionType type) {
120 Cancel(); 121 Cancel();
121 122
(...skipping 10 matching lines...) Expand all
132 int http_response_code = 133 int http_response_code =
133 (request->status().is_success() && 134 (request->status().is_success() &&
134 request->response_info().headers.get() != NULL) 135 request->response_info().headers.get() != NULL)
135 ? request->response_info().headers->response_code() 136 ? request->response_info().headers->response_code()
136 : net::HTTP_BAD_REQUEST; 137 : net::HTTP_BAD_REQUEST;
137 138
138 // Clears resources. 139 // Clears resources.
139 url_request_.reset(NULL); // URLRequest::Cancel() is called in destructor. 140 url_request_.reset(NULL); // URLRequest::Cancel() is called in destructor.
140 141
141 if (http_response_code < 400) { 142 if (http_response_code < 400) {
143 VLOG(1) << "Connectivity check succeeded";
142 bad_responses_ = 0; 144 bad_responses_ = 0;
143 SetConnectivity(true); 145 SetConnectivity(true);
144 return; 146 return;
145 } 147 }
146 148
149 VLOG(1) << "Connectivity check failed: " << http_response_code;
147 ++bad_responses_; 150 ++bad_responses_;
148 if (bad_responses_ > kNumBadResponses) { 151 if (bad_responses_ > kNumBadResponses) {
149 bad_responses_ = kNumBadResponses; 152 bad_responses_ = kNumBadResponses;
150 SetConnectivity(false); 153 SetConnectivity(false);
151 } 154 }
152 155
153 // Check again 156 // Check again
154 if (!net::NetworkChangeNotifier::IsOffline()) { 157 if (!net::NetworkChangeNotifier::IsOffline()) {
155 loop_proxy_->PostDelayedTask( 158 loop_proxy_->PostDelayedTask(
156 FROM_HERE, base::Bind(&ConnectivityChecker::Check, this), 159 FROM_HERE, base::Bind(&ConnectivityChecker::Check, this),
157 base::TimeDelta::FromSeconds(kConnectivityPeriodSeconds)); 160 base::TimeDelta::FromSeconds(kConnectivityPeriodSeconds));
158 } 161 }
159 } 162 }
160 163
161 void ConnectivityChecker::OnReadCompleted(net::URLRequest* request, 164 void ConnectivityChecker::OnReadCompleted(net::URLRequest* request,
162 int bytes_read) { 165 int bytes_read) {
163 NOTREACHED(); 166 NOTREACHED();
164 } 167 }
165 168
166 void ConnectivityChecker::Cancel() { 169 void ConnectivityChecker::Cancel() {
167 if (url_request_.get()) { 170 if (url_request_.get()) {
168 VLOG(2) << "Cancel connectivity check in progress"; 171 VLOG(2) << "Cancel connectivity check in progress";
169 url_request_.reset(NULL); // URLRequest::Cancel() is called in destructor. 172 url_request_.reset(NULL); // URLRequest::Cancel() is called in destructor.
170 } 173 }
171 } 174 }
172 175
173 } // namespace chromecast 176 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/chromecast.gyp ('k') | chromecast/net/network_change_notifier_cast.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698