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

Side by Side Diff: remoting/host/signaling_connector.cc

Issue 9147026: API for connection type (Ethernet/WIFI/WWAN ...) in NetworkChangeNotifier. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: sync Created 8 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "remoting/host/signaling_connector.h" 5 #include "remoting/host/signaling_connector.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "remoting/host/chromoting_host_context.h" 9 #include "remoting/host/chromoting_host_context.h"
10 #include "remoting/host/url_request_context.h" 10 #include "remoting/host/url_request_context.h"
(...skipping 17 matching lines...) Expand all
28 const OAuthClientInfo& client_info_value) 28 const OAuthClientInfo& client_info_value)
29 : login(login_value), 29 : login(login_value),
30 refresh_token(refresh_token_value), 30 refresh_token(refresh_token_value),
31 client_info(client_info_value) { 31 client_info(client_info_value) {
32 } 32 }
33 33
34 SignalingConnector::SignalingConnector(XmppSignalStrategy* signal_strategy) 34 SignalingConnector::SignalingConnector(XmppSignalStrategy* signal_strategy)
35 : signal_strategy_(signal_strategy), 35 : signal_strategy_(signal_strategy),
36 reconnect_attempts_(0), 36 reconnect_attempts_(0),
37 refreshing_oauth_token_(false) { 37 refreshing_oauth_token_(false) {
38 net::NetworkChangeNotifier::AddOnlineStateObserver(this); 38 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
39 net::NetworkChangeNotifier::AddIPAddressObserver(this); 39 net::NetworkChangeNotifier::AddIPAddressObserver(this);
40 signal_strategy_->AddListener(this); 40 signal_strategy_->AddListener(this);
41 ScheduleTryReconnect(); 41 ScheduleTryReconnect();
42 } 42 }
43 43
44 SignalingConnector::~SignalingConnector() { 44 SignalingConnector::~SignalingConnector() {
45 signal_strategy_->RemoveListener(this); 45 signal_strategy_->RemoveListener(this);
46 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); 46 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
47 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); 47 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
48 } 48 }
49 49
50 void SignalingConnector::EnableOAuth( 50 void SignalingConnector::EnableOAuth(
51 scoped_ptr<OAuthCredentials> oauth_credentials, 51 scoped_ptr<OAuthCredentials> oauth_credentials,
52 const base::Closure& oauth_failed_callback, 52 const base::Closure& oauth_failed_callback,
53 net::URLRequestContextGetter* url_context) { 53 net::URLRequestContextGetter* url_context) {
54 oauth_credentials_ = oauth_credentials.Pass(); 54 oauth_credentials_ = oauth_credentials.Pass();
55 oauth_failed_callback_ = oauth_failed_callback; 55 oauth_failed_callback_ = oauth_failed_callback;
56 gaia_oauth_client_.reset(new GaiaOAuthClient(kGaiaOAuth2Url, url_context)); 56 gaia_oauth_client_.reset(new GaiaOAuthClient(kGaiaOAuth2Url, url_context));
(...skipping 12 matching lines...) Expand all
69 ScheduleTryReconnect(); 69 ScheduleTryReconnect();
70 } 70 }
71 } 71 }
72 72
73 void SignalingConnector::OnIPAddressChanged() { 73 void SignalingConnector::OnIPAddressChanged() {
74 DCHECK(CalledOnValidThread()); 74 DCHECK(CalledOnValidThread());
75 LOG(INFO) << "IP address has changed."; 75 LOG(INFO) << "IP address has changed.";
76 ResetAndTryReconnect(); 76 ResetAndTryReconnect();
77 } 77 }
78 78
79 void SignalingConnector::OnOnlineStateChanged(bool online) { 79 void SignalingConnector::OnConnectionTypeChanged(
80 net::NetworkChangeNotifier::ConnectionType type) {
80 DCHECK(CalledOnValidThread()); 81 DCHECK(CalledOnValidThread());
81 if (online) { 82 if (type != net::NetworkChangeNotifier::CONNECTION_NONE) {
82 LOG(INFO) << "Network state changed to online."; 83 LOG(INFO) << "Network state changed to online.";
83 ResetAndTryReconnect(); 84 ResetAndTryReconnect();
84 } 85 }
85 } 86 }
86 87
87 void SignalingConnector::OnRefreshTokenResponse(const std::string& access_token, 88 void SignalingConnector::OnRefreshTokenResponse(const std::string& access_token,
88 int expires_seconds) { 89 int expires_seconds) {
89 DCHECK(CalledOnValidThread()); 90 DCHECK(CalledOnValidThread());
90 DCHECK(oauth_credentials_.get()); 91 DCHECK(oauth_credentials_.get());
91 LOG(INFO) << "Received OAuth token."; 92 LOG(INFO) << "Received OAuth token.";
(...skipping 21 matching lines...) Expand all
113 DCHECK(CalledOnValidThread()); 114 DCHECK(CalledOnValidThread());
114 LOG(ERROR) << "Network error when trying to update OAuth token: " 115 LOG(ERROR) << "Network error when trying to update OAuth token: "
115 << response_code; 116 << response_code;
116 refreshing_oauth_token_ = false; 117 refreshing_oauth_token_ = false;
117 reconnect_attempts_++; 118 reconnect_attempts_++;
118 ScheduleTryReconnect(); 119 ScheduleTryReconnect();
119 } 120 }
120 121
121 void SignalingConnector::ScheduleTryReconnect() { 122 void SignalingConnector::ScheduleTryReconnect() {
122 DCHECK(CalledOnValidThread()); 123 DCHECK(CalledOnValidThread());
123 if (timer_.IsRunning() || net::NetworkChangeNotifier::IsOffline()) 124 if (timer_.IsRunning() ||
125 net::NetworkChangeNotifier::GetConnectionType() ==
126 net::NetworkChangeNotifier::CONNECTION_NONE)
wtc 2012/05/11 01:35:05 Nit: this line doesn't need to be indented.
124 return; 127 return;
125 int delay_s = std::min(1 << (reconnect_attempts_ * 2), 128 int delay_s = std::min(1 << (reconnect_attempts_ * 2),
126 kMaxReconnectDelaySeconds); 129 kMaxReconnectDelaySeconds);
127 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(delay_s), 130 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(delay_s),
128 this, &SignalingConnector::TryReconnect); 131 this, &SignalingConnector::TryReconnect);
129 } 132 }
130 133
131 void SignalingConnector::ResetAndTryReconnect() { 134 void SignalingConnector::ResetAndTryReconnect() {
132 DCHECK(CalledOnValidThread()); 135 DCHECK(CalledOnValidThread());
133 signal_strategy_->Disconnect(); 136 signal_strategy_->Disconnect();
(...skipping 22 matching lines...) Expand all
156 LOG(INFO) << "Refreshing OAuth token."; 159 LOG(INFO) << "Refreshing OAuth token.";
157 DCHECK(!refreshing_oauth_token_); 160 DCHECK(!refreshing_oauth_token_);
158 161
159 refreshing_oauth_token_ = true; 162 refreshing_oauth_token_ = true;
160 gaia_oauth_client_->RefreshToken( 163 gaia_oauth_client_->RefreshToken(
161 oauth_credentials_->client_info, 164 oauth_credentials_->client_info,
162 oauth_credentials_->refresh_token, this); 165 oauth_credentials_->refresh_token, this);
163 } 166 }
164 167
165 } // namespace remoting 168 } // namespace remoting
OLDNEW
« net/url_request/url_request_throttler_unittest.cc ('K') | « remoting/host/signaling_connector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698