| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 LOG(INFO) << "Refreshing OAuth token."; | 157 LOG(INFO) << "Refreshing OAuth token."; |
| 157 DCHECK(!refreshing_oauth_token_); | 158 DCHECK(!refreshing_oauth_token_); |
| 158 | 159 |
| 159 refreshing_oauth_token_ = true; | 160 refreshing_oauth_token_ = true; |
| 160 gaia_oauth_client_->RefreshToken( | 161 gaia_oauth_client_->RefreshToken( |
| 161 oauth_credentials_->client_info, | 162 oauth_credentials_->client_info, |
| 162 oauth_credentials_->refresh_token, this); | 163 oauth_credentials_->refresh_token, this); |
| 163 } | 164 } |
| 164 | 165 |
| 165 } // namespace remoting | 166 } // namespace remoting |
| OLD | NEW |