| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 SignalingConnector::~SignalingConnector() { | 48 SignalingConnector::~SignalingConnector() { |
| 49 signal_strategy_->RemoveListener(this); | 49 signal_strategy_->RemoveListener(this); |
| 50 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this); | 50 net::NetworkChangeNotifier::RemoveOnlineStateObserver(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(kGaiaOAuth2Url, url_context)); | 58 gaia_oauth_client_.reset(new GaiaOAuthClient( |
| 59 OAuthProviderInfo::GetDefault(), url_context)); |
| 59 } | 60 } |
| 60 | 61 |
| 61 void SignalingConnector::OnSignalStrategyStateChange( | 62 void SignalingConnector::OnSignalStrategyStateChange( |
| 62 SignalStrategy::State state) { | 63 SignalStrategy::State state) { |
| 63 DCHECK(CalledOnValidThread()); | 64 DCHECK(CalledOnValidThread()); |
| 64 | 65 |
| 65 if (state == SignalStrategy::CONNECTED) { | 66 if (state == SignalStrategy::CONNECTED) { |
| 66 LOG(INFO) << "Signaling connected."; | 67 LOG(INFO) << "Signaling connected."; |
| 67 reconnect_attempts_ = 0; | 68 reconnect_attempts_ = 0; |
| 68 } else if (state == SignalStrategy::DISCONNECTED) { | 69 } else if (state == SignalStrategy::DISCONNECTED) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 86 } | 87 } |
| 87 | 88 |
| 88 void SignalingConnector::OnOnlineStateChanged(bool online) { | 89 void SignalingConnector::OnOnlineStateChanged(bool online) { |
| 89 DCHECK(CalledOnValidThread()); | 90 DCHECK(CalledOnValidThread()); |
| 90 if (online) { | 91 if (online) { |
| 91 LOG(INFO) << "Network state changed to online."; | 92 LOG(INFO) << "Network state changed to online."; |
| 92 ResetAndTryReconnect(); | 93 ResetAndTryReconnect(); |
| 93 } | 94 } |
| 94 } | 95 } |
| 95 | 96 |
| 96 void SignalingConnector::OnRefreshTokenResponse(const std::string& access_token, | 97 void SignalingConnector::OnRefreshTokenResponse(const std::string& user_email, |
| 98 const std::string& access_token, |
| 97 int expires_seconds) { | 99 int expires_seconds) { |
| 98 DCHECK(CalledOnValidThread()); | 100 DCHECK(CalledOnValidThread()); |
| 99 DCHECK(oauth_credentials_.get()); | 101 DCHECK(oauth_credentials_.get()); |
| 100 LOG(INFO) << "Received OAuth token."; | 102 LOG(INFO) << "Received OAuth token."; |
| 103 |
| 104 if (user_email != oauth_credentials_->login) { |
| 105 LOG(ERROR) << "OAuth token and email address do not refer to " |
| 106 "the same account."; |
| 107 auth_failed_callback_.Run(); |
| 108 return; |
| 109 } |
| 110 |
| 101 refreshing_oauth_token_ = false; | 111 refreshing_oauth_token_ = false; |
| 102 auth_token_expiry_time_ = base::Time::Now() + | 112 auth_token_expiry_time_ = base::Time::Now() + |
| 103 base::TimeDelta::FromSeconds(expires_seconds) - | 113 base::TimeDelta::FromSeconds(expires_seconds) - |
| 104 base::TimeDelta::FromSeconds(kTokenUpdateTimeBeforeExpirySeconds); | 114 base::TimeDelta::FromSeconds(kTokenUpdateTimeBeforeExpirySeconds); |
| 105 signal_strategy_->SetAuthInfo(oauth_credentials_->login, | 115 signal_strategy_->SetAuthInfo(oauth_credentials_->login, |
| 106 access_token, "oauth2"); | 116 access_token, "oauth2"); |
| 107 | 117 |
| 108 // Now that we've got the new token, try to connect using it. | 118 // Now that we've got the new token, try to connect using it. |
| 109 DCHECK_EQ(signal_strategy_->GetState(), SignalStrategy::DISCONNECTED); | 119 DCHECK_EQ(signal_strategy_->GetState(), SignalStrategy::DISCONNECTED); |
| 110 signal_strategy_->Connect(); | 120 signal_strategy_->Connect(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 LOG(INFO) << "Refreshing OAuth token."; | 175 LOG(INFO) << "Refreshing OAuth token."; |
| 166 DCHECK(!refreshing_oauth_token_); | 176 DCHECK(!refreshing_oauth_token_); |
| 167 | 177 |
| 168 refreshing_oauth_token_ = true; | 178 refreshing_oauth_token_ = true; |
| 169 gaia_oauth_client_->RefreshToken( | 179 gaia_oauth_client_->RefreshToken( |
| 170 oauth_credentials_->client_info, | 180 oauth_credentials_->client_info, |
| 171 oauth_credentials_->refresh_token, this); | 181 oauth_credentials_->refresh_token, this); |
| 172 } | 182 } |
| 173 | 183 |
| 174 } // namespace remoting | 184 } // namespace remoting |
| OLD | NEW |