| 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 21 matching lines...) Expand all Loading... |
| 32 } | 32 } |
| 33 | 33 |
| 34 SignalingConnector::SignalingConnector( | 34 SignalingConnector::SignalingConnector( |
| 35 XmppSignalStrategy* signal_strategy, | 35 XmppSignalStrategy* signal_strategy, |
| 36 const base::Closure& auth_failed_callback) | 36 const base::Closure& auth_failed_callback) |
| 37 : signal_strategy_(signal_strategy), | 37 : signal_strategy_(signal_strategy), |
| 38 auth_failed_callback_(auth_failed_callback), | 38 auth_failed_callback_(auth_failed_callback), |
| 39 reconnect_attempts_(0), | 39 reconnect_attempts_(0), |
| 40 refreshing_oauth_token_(false) { | 40 refreshing_oauth_token_(false) { |
| 41 DCHECK(!auth_failed_callback_.is_null()); | 41 DCHECK(!auth_failed_callback_.is_null()); |
| 42 net::NetworkChangeNotifier::AddOnlineStateObserver(this); | 42 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| 43 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 43 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
| 44 signal_strategy_->AddListener(this); | 44 signal_strategy_->AddListener(this); |
| 45 ScheduleTryReconnect(); | 45 ScheduleTryReconnect(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 SignalingConnector::~SignalingConnector() { | 48 SignalingConnector::~SignalingConnector() { |
| 49 signal_strategy_->RemoveListener(this); | 49 signal_strategy_->RemoveListener(this); |
| 50 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); | 50 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 51 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 51 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void SignalingConnector::EnableOAuth( | 54 void SignalingConnector::EnableOAuth( |
| 55 scoped_ptr<OAuthCredentials> oauth_credentials, | 55 scoped_ptr<OAuthCredentials> oauth_credentials, |
| 56 net::URLRequestContextGetter* url_context) { | 56 net::URLRequestContextGetter* url_context) { |
| 57 oauth_credentials_ = oauth_credentials.Pass(); | 57 oauth_credentials_ = oauth_credentials.Pass(); |
| 58 gaia_oauth_client_.reset(new GaiaOAuthClient( | 58 gaia_oauth_client_.reset(new GaiaOAuthClient( |
| 59 OAuthProviderInfo::GetDefault(), url_context)); | 59 OAuthProviderInfo::GetDefault(), url_context)); |
| 60 } | 60 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 void SignalingConnector::OnIPAddressChanged() { | 83 void SignalingConnector::OnIPAddressChanged() { |
| 84 DCHECK(CalledOnValidThread()); | 84 DCHECK(CalledOnValidThread()); |
| 85 LOG(INFO) << "IP address has changed."; | 85 LOG(INFO) << "IP address has changed."; |
| 86 ResetAndTryReconnect(); | 86 ResetAndTryReconnect(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void SignalingConnector::OnOnlineStateChanged(bool online) { | 89 void SignalingConnector::OnConnectionTypeChanged( |
| 90 net::NetworkChangeNotifier::ConnectionType type) { |
| 90 DCHECK(CalledOnValidThread()); | 91 DCHECK(CalledOnValidThread()); |
| 91 if (online) { | 92 if (type != net::NetworkChangeNotifier::CONNECTION_NONE) { |
| 92 LOG(INFO) << "Network state changed to online."; | 93 LOG(INFO) << "Network state changed to online."; |
| 93 ResetAndTryReconnect(); | 94 ResetAndTryReconnect(); |
| 94 } | 95 } |
| 95 } | 96 } |
| 96 | 97 |
| 97 void SignalingConnector::OnRefreshTokenResponse(const std::string& user_email, | 98 void SignalingConnector::OnRefreshTokenResponse(const std::string& user_email, |
| 98 const std::string& access_token, | 99 const std::string& access_token, |
| 99 int expires_seconds) { | 100 int expires_seconds) { |
| 100 DCHECK(CalledOnValidThread()); | 101 DCHECK(CalledOnValidThread()); |
| 101 DCHECK(oauth_credentials_.get()); | 102 DCHECK(oauth_credentials_.get()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 LOG(INFO) << "Refreshing OAuth token."; | 176 LOG(INFO) << "Refreshing OAuth token."; |
| 176 DCHECK(!refreshing_oauth_token_); | 177 DCHECK(!refreshing_oauth_token_); |
| 177 | 178 |
| 178 refreshing_oauth_token_ = true; | 179 refreshing_oauth_token_ = true; |
| 179 gaia_oauth_client_->RefreshToken( | 180 gaia_oauth_client_->RefreshToken( |
| 180 oauth_credentials_->client_info, | 181 oauth_credentials_->client_info, |
| 181 oauth_credentials_->refresh_token, this); | 182 oauth_credentials_->refresh_token, this); |
| 182 } | 183 } |
| 183 | 184 |
| 184 } // namespace remoting | 185 } // namespace remoting |
| OLD | NEW |