Skip to content

Commit

Permalink
Observe IP address change in connectivity_checker.
Browse files Browse the repository at this point in the history
Observing ConnectionType alone doesn't detect network
changes on some OEM platforms. Observe IP address
to address this.

BUG=

Review URL: https://codereview.chromium.org/995933002

Cr-Commit-Position: refs/heads/master@{#320148}
  • Loading branch information
wzhong authored and Commit bot committed Mar 11, 2015
1 parent 67a8953 commit 0c95f2d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions chromecast/net/connectivity_checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,15 @@ void ConnectivityChecker::Initialize() {
url_request_context_.reset(builder.Build());

net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
net::NetworkChangeNotifier::AddIPAddressObserver(this);
loop_proxy_->PostTask(FROM_HERE,
base::Bind(&ConnectivityChecker::Check, this));
}

ConnectivityChecker::~ConnectivityChecker() {
DCHECK(loop_proxy_.get());
net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
loop_proxy_->DeleteSoon(FROM_HERE, url_request_context_.release());
loop_proxy_->DeleteSoon(FROM_HERE, url_request_.release());
}
Expand Down Expand Up @@ -116,13 +119,21 @@ void ConnectivityChecker::Check() {

void ConnectivityChecker::OnConnectionTypeChanged(
net::NetworkChangeNotifier::ConnectionType type) {
VLOG(2) << "OnConnectionTypeChanged " << type;
if (type == net::NetworkChangeNotifier::CONNECTION_NONE)
SetConnectivity(false);

Cancel();
Check();
}

void ConnectivityChecker::OnIPAddressChanged() {
VLOG(2) << "OnIPAddressChanged";

Cancel();
Check();
}

void ConnectivityChecker::OnResponseStarted(net::URLRequest* request) {
int http_response_code =
(request->status().is_success() &&
Expand Down
6 changes: 5 additions & 1 deletion chromecast/net/connectivity_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ namespace chromecast {
class ConnectivityChecker
: public base::RefCountedThreadSafe<ConnectivityChecker>,
public net::URLRequest::Delegate,
public net::NetworkChangeNotifier::ConnectionTypeObserver {
public net::NetworkChangeNotifier::ConnectionTypeObserver,
public net::NetworkChangeNotifier::IPAddressObserver {
public:
class ConnectivityObserver {
public:
Expand Down Expand Up @@ -72,6 +73,9 @@ class ConnectivityChecker
void OnConnectionTypeChanged(
net::NetworkChangeNotifier::ConnectionType type) override;

// net::NetworkChangeNotifier::IPAddressObserver implementation:
void OnIPAddressChanged() override;

// Cancels current connectivity checking in progress.
void Cancel();

Expand Down

0 comments on commit 0c95f2d

Please sign in to comment.