| 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 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 SignalingConnector::OAuthCredentials::OAuthCredentials( | 25 SignalingConnector::OAuthCredentials::OAuthCredentials( |
| 26 const std::string& login_value, | 26 const std::string& login_value, |
| 27 const std::string& refresh_token_value, | 27 const std::string& refresh_token_value, |
| 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( |
| 35 XmppSignalStrategy* signal_strategy, |
| 36 const base::Closure& auth_failed_callback) |
| 35 : signal_strategy_(signal_strategy), | 37 : signal_strategy_(signal_strategy), |
| 38 auth_failed_callback_(auth_failed_callback), |
| 36 reconnect_attempts_(0), | 39 reconnect_attempts_(0), |
| 37 refreshing_oauth_token_(false) { | 40 refreshing_oauth_token_(false) { |
| 41 DCHECK(!auth_failed_callback_.is_null()); |
| 38 net::NetworkChangeNotifier::AddOnlineStateObserver(this); | 42 net::NetworkChangeNotifier::AddOnlineStateObserver(this); |
| 39 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 43 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
| 40 signal_strategy_->AddListener(this); | 44 signal_strategy_->AddListener(this); |
| 41 ScheduleTryReconnect(); | 45 ScheduleTryReconnect(); |
| 42 } | 46 } |
| 43 | 47 |
| 44 SignalingConnector::~SignalingConnector() { | 48 SignalingConnector::~SignalingConnector() { |
| 45 signal_strategy_->RemoveListener(this); | 49 signal_strategy_->RemoveListener(this); |
| 46 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); | 50 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); |
| 47 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); | 51 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 48 } | 52 } |
| 49 | 53 |
| 50 void SignalingConnector::EnableOAuth( | 54 void SignalingConnector::EnableOAuth( |
| 51 scoped_ptr<OAuthCredentials> oauth_credentials, | 55 scoped_ptr<OAuthCredentials> oauth_credentials, |
| 52 const base::Closure& oauth_failed_callback, | |
| 53 net::URLRequestContextGetter* url_context) { | 56 net::URLRequestContextGetter* url_context) { |
| 54 oauth_credentials_ = oauth_credentials.Pass(); | 57 oauth_credentials_ = oauth_credentials.Pass(); |
| 55 oauth_failed_callback_ = oauth_failed_callback; | |
| 56 gaia_oauth_client_.reset(new GaiaOAuthClient(kGaiaOAuth2Url, url_context)); | 58 gaia_oauth_client_.reset(new GaiaOAuthClient(kGaiaOAuth2Url, url_context)); |
| 57 } | 59 } |
| 58 | 60 |
| 59 void SignalingConnector::OnSignalStrategyStateChange( | 61 void SignalingConnector::OnSignalStrategyStateChange( |
| 60 SignalStrategy::State state) { | 62 SignalStrategy::State state) { |
| 61 DCHECK(CalledOnValidThread()); | 63 DCHECK(CalledOnValidThread()); |
| 62 | 64 |
| 63 if (state == SignalStrategy::CONNECTED) { | 65 if (state == SignalStrategy::CONNECTED) { |
| 64 LOG(INFO) << "Signaling connected."; | 66 LOG(INFO) << "Signaling connected."; |
| 65 reconnect_attempts_ = 0; | 67 reconnect_attempts_ = 0; |
| 66 } else if (state == SignalStrategy::DISCONNECTED) { | 68 } else if (state == SignalStrategy::DISCONNECTED) { |
| 67 LOG(INFO) << "Signaling disconnected."; | 69 LOG(INFO) << "Signaling disconnected."; |
| 68 reconnect_attempts_++; | 70 reconnect_attempts_++; |
| 69 ScheduleTryReconnect(); | 71 |
| 72 // If authentication failed then we have an invalid OAuth token, |
| 73 // inform the upper layer about it. |
| 74 if (signal_strategy_->GetError() == SignalStrategy::AUTHENTICATION_FAILED) { |
| 75 auth_failed_callback_.Run(); |
| 76 } else { |
| 77 ScheduleTryReconnect(); |
| 78 } |
| 70 } | 79 } |
| 71 } | 80 } |
| 72 | 81 |
| 73 void SignalingConnector::OnIPAddressChanged() { | 82 void SignalingConnector::OnIPAddressChanged() { |
| 74 DCHECK(CalledOnValidThread()); | 83 DCHECK(CalledOnValidThread()); |
| 75 LOG(INFO) << "IP address has changed."; | 84 LOG(INFO) << "IP address has changed."; |
| 76 ResetAndTryReconnect(); | 85 ResetAndTryReconnect(); |
| 77 } | 86 } |
| 78 | 87 |
| 79 void SignalingConnector::OnOnlineStateChanged(bool online) { | 88 void SignalingConnector::OnOnlineStateChanged(bool online) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 99 // Now that we've got the new token, try to connect using it. | 108 // Now that we've got the new token, try to connect using it. |
| 100 DCHECK_EQ(signal_strategy_->GetState(), SignalStrategy::DISCONNECTED); | 109 DCHECK_EQ(signal_strategy_->GetState(), SignalStrategy::DISCONNECTED); |
| 101 signal_strategy_->Connect(); | 110 signal_strategy_->Connect(); |
| 102 } | 111 } |
| 103 | 112 |
| 104 void SignalingConnector::OnOAuthError() { | 113 void SignalingConnector::OnOAuthError() { |
| 105 DCHECK(CalledOnValidThread()); | 114 DCHECK(CalledOnValidThread()); |
| 106 LOG(ERROR) << "OAuth: invalid credentials."; | 115 LOG(ERROR) << "OAuth: invalid credentials."; |
| 107 refreshing_oauth_token_ = false; | 116 refreshing_oauth_token_ = false; |
| 108 reconnect_attempts_++; | 117 reconnect_attempts_++; |
| 109 oauth_failed_callback_.Run(); | 118 auth_failed_callback_.Run(); |
| 110 } | 119 } |
| 111 | 120 |
| 112 void SignalingConnector::OnNetworkError(int response_code) { | 121 void SignalingConnector::OnNetworkError(int response_code) { |
| 113 DCHECK(CalledOnValidThread()); | 122 DCHECK(CalledOnValidThread()); |
| 114 LOG(ERROR) << "Network error when trying to update OAuth token: " | 123 LOG(ERROR) << "Network error when trying to update OAuth token: " |
| 115 << response_code; | 124 << response_code; |
| 116 refreshing_oauth_token_ = false; | 125 refreshing_oauth_token_ = false; |
| 117 reconnect_attempts_++; | 126 reconnect_attempts_++; |
| 118 ScheduleTryReconnect(); | 127 ScheduleTryReconnect(); |
| 119 } | 128 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 LOG(INFO) << "Refreshing OAuth token."; | 165 LOG(INFO) << "Refreshing OAuth token."; |
| 157 DCHECK(!refreshing_oauth_token_); | 166 DCHECK(!refreshing_oauth_token_); |
| 158 | 167 |
| 159 refreshing_oauth_token_ = true; | 168 refreshing_oauth_token_ = true; |
| 160 gaia_oauth_client_->RefreshToken( | 169 gaia_oauth_client_->RefreshToken( |
| 161 oauth_credentials_->client_info, | 170 oauth_credentials_->client_info, |
| 162 oauth_credentials_->refresh_token, this); | 171 oauth_credentials_->refresh_token, this); |
| 163 } | 172 } |
| 164 | 173 |
| 165 } // namespace remoting | 174 } // namespace remoting |
| OLD | NEW |