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

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

Issue 11273024: Remove GaiaOauthClient and GaiaUserEmailFetcher from remoting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « remoting/host/signaling_connector.h ('k') | remoting/remoting.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "google_apis/google_api_keys.h"
9 #include "net/url_request/url_fetcher.h" 10 #include "net/url_request/url_fetcher.h"
10 #include "net/url_request/url_request_context_getter.h" 11 #include "net/url_request/url_request_context_getter.h"
11 #include "remoting/host/dns_blackhole_checker.h" 12 #include "remoting/host/dns_blackhole_checker.h"
12 13
13 namespace remoting { 14 namespace remoting {
14 15
15 namespace { 16 namespace {
16 17
17 // The delay between reconnect attempts will increase exponentially up 18 // The delay between reconnect attempts will increase exponentially up
18 // to the maximum specified here. 19 // to the maximum specified here.
19 const int kMaxReconnectDelaySeconds = 10 * 60; 20 const int kMaxReconnectDelaySeconds = 10 * 60;
20 21
21 // Time when we we try to update OAuth token before its expiration. 22 // Time when we we try to update OAuth token before its expiration.
22 const int kTokenUpdateTimeBeforeExpirySeconds = 60; 23 const int kTokenUpdateTimeBeforeExpirySeconds = 60;
23 24
24 } // namespace 25 } // namespace
25 26
26 SignalingConnector::OAuthCredentials::OAuthCredentials( 27 SignalingConnector::OAuthCredentials::OAuthCredentials(
27 const std::string& login_value, 28 const std::string& login_value,
28 const std::string& refresh_token_value, 29 const std::string& refresh_token_value)
29 const OAuthClientInfo& client_info_value)
30 : login(login_value), 30 : login(login_value),
31 refresh_token(refresh_token_value), 31 refresh_token(refresh_token_value) {
32 client_info(client_info_value) {
33 } 32 }
34 33
35 SignalingConnector::SignalingConnector( 34 SignalingConnector::SignalingConnector(
36 XmppSignalStrategy* signal_strategy, 35 XmppSignalStrategy* signal_strategy,
37 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter, 36 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter,
38 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker, 37 scoped_ptr<DnsBlackholeChecker> dns_blackhole_checker,
39 const base::Closure& auth_failed_callback) 38 const base::Closure& auth_failed_callback)
40 : signal_strategy_(signal_strategy), 39 : signal_strategy_(signal_strategy),
41 url_request_context_getter_(url_request_context_getter), 40 url_request_context_getter_(url_request_context_getter),
42 auth_failed_callback_(auth_failed_callback), 41 auth_failed_callback_(auth_failed_callback),
(...skipping 10 matching lines...) Expand all
53 52
54 SignalingConnector::~SignalingConnector() { 53 SignalingConnector::~SignalingConnector() {
55 signal_strategy_->RemoveListener(this); 54 signal_strategy_->RemoveListener(this);
56 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); 55 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
57 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); 56 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
58 } 57 }
59 58
60 void SignalingConnector::EnableOAuth( 59 void SignalingConnector::EnableOAuth(
61 scoped_ptr<OAuthCredentials> oauth_credentials) { 60 scoped_ptr<OAuthCredentials> oauth_credentials) {
62 oauth_credentials_ = oauth_credentials.Pass(); 61 oauth_credentials_ = oauth_credentials.Pass();
63 gaia_oauth_client_.reset(new GaiaOAuthClient( 62 gaia_oauth_client_.reset(new gaia::GaiaOAuthClient(
64 OAuthProviderInfo::GetDefault(), url_request_context_getter_)); 63 gaia::kGaiaOAuth2Url, url_request_context_getter_));
65 } 64 }
66 65
67 void SignalingConnector::OnSignalStrategyStateChange( 66 void SignalingConnector::OnSignalStrategyStateChange(
68 SignalStrategy::State state) { 67 SignalStrategy::State state) {
69 DCHECK(CalledOnValidThread()); 68 DCHECK(CalledOnValidThread());
70 69
71 if (state == SignalStrategy::CONNECTED) { 70 if (state == SignalStrategy::CONNECTED) {
72 LOG(INFO) << "Signaling connected."; 71 LOG(INFO) << "Signaling connected.";
73 reconnect_attempts_ = 0; 72 reconnect_attempts_ = 0;
74 } else if (state == SignalStrategy::DISCONNECTED) { 73 } else if (state == SignalStrategy::DISCONNECTED) {
(...skipping 23 matching lines...) Expand all
98 ResetAndTryReconnect(); 97 ResetAndTryReconnect();
99 } 98 }
100 } 99 }
101 100
102 void SignalingConnector::OnIPAddressChanged() { 101 void SignalingConnector::OnIPAddressChanged() {
103 DCHECK(CalledOnValidThread()); 102 DCHECK(CalledOnValidThread());
104 LOG(INFO) << "IP address has changed."; 103 LOG(INFO) << "IP address has changed.";
105 ResetAndTryReconnect(); 104 ResetAndTryReconnect();
106 } 105 }
107 106
108 void SignalingConnector::OnRefreshTokenResponse(const std::string& user_email, 107 void SignalingConnector::OnGetTokensResponse(const std::string& user_email,
109 const std::string& access_token, 108 const std::string& access_token,
110 int expires_seconds) { 109 int expires_seconds) {
110 NOTREACHED();
111 }
112
113 void SignalingConnector::OnRefreshTokenResponse(
114 const std::string& access_token,
115 int expires_seconds) {
111 DCHECK(CalledOnValidThread()); 116 DCHECK(CalledOnValidThread());
112 DCHECK(oauth_credentials_.get()); 117 DCHECK(oauth_credentials_.get());
113 LOG(INFO) << "Received OAuth token."; 118 LOG(INFO) << "Received OAuth token.";
114 119
120 oauth_access_token_ = access_token;
121 auth_token_expiry_time_ = base::Time::Now() +
122 base::TimeDelta::FromSeconds(expires_seconds) -
123 base::TimeDelta::FromSeconds(kTokenUpdateTimeBeforeExpirySeconds);
124
125 gaia_oauth_client_->GetUserInfo(access_token, 1, this);
126 }
127
128 void SignalingConnector::OnGetUserInfoResponse(const std::string& user_email) {
129 DCHECK(CalledOnValidThread());
130 DCHECK(oauth_credentials_.get());
131 LOG(INFO) << "Received user info.";
132
115 if (user_email != oauth_credentials_->login) { 133 if (user_email != oauth_credentials_->login) {
116 LOG(ERROR) << "OAuth token and email address do not refer to " 134 LOG(ERROR) << "OAuth token and email address do not refer to "
117 "the same account."; 135 "the same account.";
118 auth_failed_callback_.Run(); 136 auth_failed_callback_.Run();
119 return; 137 return;
120 } 138 }
121 139
140 signal_strategy_->SetAuthInfo(oauth_credentials_->login,
141 oauth_access_token_, "oauth2");
122 refreshing_oauth_token_ = false; 142 refreshing_oauth_token_ = false;
123 auth_token_expiry_time_ = base::Time::Now() +
124 base::TimeDelta::FromSeconds(expires_seconds) -
125 base::TimeDelta::FromSeconds(kTokenUpdateTimeBeforeExpirySeconds);
126 signal_strategy_->SetAuthInfo(oauth_credentials_->login,
127 access_token, "oauth2");
128 143
129 // Now that we've got the new token, try to connect using it. 144 // Now that we've refreshed the token and verified that it's for the correct
145 // user account, try to connect using the new token.
130 DCHECK_EQ(signal_strategy_->GetState(), SignalStrategy::DISCONNECTED); 146 DCHECK_EQ(signal_strategy_->GetState(), SignalStrategy::DISCONNECTED);
131 signal_strategy_->Connect(); 147 signal_strategy_->Connect();
132 } 148 }
133 149
134 void SignalingConnector::OnOAuthError() { 150 void SignalingConnector::OnOAuthError() {
135 DCHECK(CalledOnValidThread()); 151 DCHECK(CalledOnValidThread());
136 LOG(ERROR) << "OAuth: invalid credentials."; 152 LOG(ERROR) << "OAuth: invalid credentials.";
137 refreshing_oauth_token_ = false; 153 refreshing_oauth_token_ = false;
138 reconnect_attempts_++; 154 reconnect_attempts_++;
139 auth_failed_callback_.Run(); 155 auth_failed_callback_.Run();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 signal_strategy_->Connect(); 218 signal_strategy_->Connect();
203 } 219 }
204 } 220 }
205 } 221 }
206 222
207 void SignalingConnector::RefreshOAuthToken() { 223 void SignalingConnector::RefreshOAuthToken() {
208 DCHECK(CalledOnValidThread()); 224 DCHECK(CalledOnValidThread());
209 LOG(INFO) << "Refreshing OAuth token."; 225 LOG(INFO) << "Refreshing OAuth token.";
210 DCHECK(!refreshing_oauth_token_); 226 DCHECK(!refreshing_oauth_token_);
211 227
228 gaia::OAuthClientInfo client_info = {
229 google_apis::GetOAuth2ClientID(google_apis::CLIENT_REMOTING),
230 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_REMOTING),
231 // Redirect URL is only used when getting tokens from auth code. It
232 // is not required when getting access tokens.
233 ""
234 };
235
212 refreshing_oauth_token_ = true; 236 refreshing_oauth_token_ = true;
213 gaia_oauth_client_->RefreshToken( 237 gaia_oauth_client_->RefreshToken(
214 oauth_credentials_->client_info, 238 client_info, oauth_credentials_->refresh_token, 1, this);
215 oauth_credentials_->refresh_token, this);
216 } 239 }
217 240
218 } // namespace remoting 241 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/signaling_connector.h ('k') | remoting/remoting.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698