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

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

Issue 995933002: Observe IP address change in connectivity_checker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src/@master
Patch Set: Observe IP address change in connectivity_checker. 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/net/connectivity_checker.h ('k') | 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 connectivity_check_url_.reset(new GURL( 53 connectivity_check_url_.reset(new GURL(
54 check_url_str.empty() ? kDefaultConnectivityCheckUrl : check_url_str)); 54 check_url_str.empty() ? kDefaultConnectivityCheckUrl : check_url_str));
55 55
56 net::URLRequestContextBuilder builder; 56 net::URLRequestContextBuilder builder;
57 builder.set_proxy_config_service( 57 builder.set_proxy_config_service(
58 new net::ProxyConfigServiceFixed(net::ProxyConfig::CreateDirect())); 58 new net::ProxyConfigServiceFixed(net::ProxyConfig::CreateDirect()));
59 builder.DisableHttpCache(); 59 builder.DisableHttpCache();
60 url_request_context_.reset(builder.Build()); 60 url_request_context_.reset(builder.Build());
61 61
62 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 62 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
63 net::NetworkChangeNotifier::AddIPAddressObserver(this);
63 loop_proxy_->PostTask(FROM_HERE, 64 loop_proxy_->PostTask(FROM_HERE,
64 base::Bind(&ConnectivityChecker::Check, this)); 65 base::Bind(&ConnectivityChecker::Check, this));
65 } 66 }
66 67
67 ConnectivityChecker::~ConnectivityChecker() { 68 ConnectivityChecker::~ConnectivityChecker() {
68 DCHECK(loop_proxy_.get()); 69 DCHECK(loop_proxy_.get());
70 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
71 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
69 loop_proxy_->DeleteSoon(FROM_HERE, url_request_context_.release()); 72 loop_proxy_->DeleteSoon(FROM_HERE, url_request_context_.release());
70 loop_proxy_->DeleteSoon(FROM_HERE, url_request_.release()); 73 loop_proxy_->DeleteSoon(FROM_HERE, url_request_.release());
71 } 74 }
72 75
73 void ConnectivityChecker::AddConnectivityObserver( 76 void ConnectivityChecker::AddConnectivityObserver(
74 ConnectivityObserver* observer) { 77 ConnectivityObserver* observer) {
75 connectivity_observer_list_->AddObserver(observer); 78 connectivity_observer_list_->AddObserver(observer);
76 } 79 }
77 80
78 void ConnectivityChecker::RemoveConnectivityObserver( 81 void ConnectivityChecker::RemoveConnectivityObserver(
(...skipping 30 matching lines...) Expand all
109 112
110 VLOG(1) << "Connectivity check: url=" << *connectivity_check_url_; 113 VLOG(1) << "Connectivity check: url=" << *connectivity_check_url_;
111 url_request_ = url_request_context_->CreateRequest( 114 url_request_ = url_request_context_->CreateRequest(
112 *connectivity_check_url_, net::MAXIMUM_PRIORITY, this, NULL); 115 *connectivity_check_url_, net::MAXIMUM_PRIORITY, this, NULL);
113 url_request_->set_method("HEAD"); 116 url_request_->set_method("HEAD");
114 url_request_->Start(); 117 url_request_->Start();
115 } 118 }
116 119
117 void ConnectivityChecker::OnConnectionTypeChanged( 120 void ConnectivityChecker::OnConnectionTypeChanged(
118 net::NetworkChangeNotifier::ConnectionType type) { 121 net::NetworkChangeNotifier::ConnectionType type) {
122 VLOG(2) << "OnConnectionTypeChanged " << type;
119 if (type == net::NetworkChangeNotifier::CONNECTION_NONE) 123 if (type == net::NetworkChangeNotifier::CONNECTION_NONE)
120 SetConnectivity(false); 124 SetConnectivity(false);
121 125
122 Cancel(); 126 Cancel();
123 Check(); 127 Check();
124 } 128 }
125 129
130 void ConnectivityChecker::OnIPAddressChanged() {
131 VLOG(2) << "OnIPAddressChanged";
132
133 Cancel();
134 Check();
135 }
136
126 void ConnectivityChecker::OnResponseStarted(net::URLRequest* request) { 137 void ConnectivityChecker::OnResponseStarted(net::URLRequest* request) {
127 int http_response_code = 138 int http_response_code =
128 (request->status().is_success() && 139 (request->status().is_success() &&
129 request->response_info().headers.get() != NULL) 140 request->response_info().headers.get() != NULL)
130 ? request->response_info().headers->response_code() 141 ? request->response_info().headers->response_code()
131 : net::HTTP_BAD_REQUEST; 142 : net::HTTP_BAD_REQUEST;
132 143
133 // Clears resources. 144 // Clears resources.
134 url_request_.reset(NULL); // URLRequest::Cancel() is called in destructor. 145 url_request_.reset(NULL); // URLRequest::Cancel() is called in destructor.
135 146
(...skipping 23 matching lines...) Expand all
159 } 170 }
160 171
161 void ConnectivityChecker::Cancel() { 172 void ConnectivityChecker::Cancel() {
162 if (url_request_.get()) { 173 if (url_request_.get()) {
163 VLOG(2) << "Cancel connectivity check in progress"; 174 VLOG(2) << "Cancel connectivity check in progress";
164 url_request_.reset(NULL); // URLRequest::Cancel() is called in destructor. 175 url_request_.reset(NULL); // URLRequest::Cancel() is called in destructor.
165 } 176 }
166 } 177 }
167 178
168 } // namespace chromecast 179 } // namespace chromecast
OLDNEW
« no previous file with comments | « chromecast/net/connectivity_checker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698