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

Side by Side Diff: chrome/browser/chromeos/login/signin/oauth2_token_fetcher.cc

Issue 1138143002: Pass Device ID in the oauth2/token request. Keep Device ID in local state on Chrome OS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final version. Created 5 years, 7 months 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/chromeos/login/signin/oauth2_token_fetcher.h" 5 #include "chrome/browser/chromeos/login/signin/oauth2_token_fetcher.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "chromeos/network/network_handler.h" 9 #include "chromeos/network/network_handler.h"
10 #include "chromeos/network/network_state.h" 10 #include "chromeos/network/network_state.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 session_index, 61 session_index,
62 signin_scoped_device_id), 62 signin_scoped_device_id),
63 base::TimeDelta::FromMilliseconds(kRequestRestartDelay)); 63 base::TimeDelta::FromMilliseconds(kRequestRestartDelay));
64 return; 64 return;
65 } 65 }
66 auth_fetcher_.StartCookieForOAuthLoginTokenExchangeWithDeviceId( 66 auth_fetcher_.StartCookieForOAuthLoginTokenExchangeWithDeviceId(
67 session_index, signin_scoped_device_id); 67 session_index, signin_scoped_device_id);
68 } 68 }
69 69
70 void OAuth2TokenFetcher::StartExchangeFromAuthCode( 70 void OAuth2TokenFetcher::StartExchangeFromAuthCode(
71 const std::string& auth_code) { 71 const std::string& auth_code,
72 const std::string& signin_scoped_device_id) {
72 DCHECK_CURRENTLY_ON(BrowserThread::UI); 73 DCHECK_CURRENTLY_ON(BrowserThread::UI);
73 auth_code_ = auth_code; 74 auth_code_ = auth_code;
75 signin_scoped_device_id_ = signin_scoped_device_id;
74 // Delay the verification if the network is not connected or on a captive 76 // Delay the verification if the network is not connected or on a captive
75 // portal. 77 // portal.
76 const NetworkState* default_network = 78 const NetworkState* default_network =
77 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); 79 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
78 if (!default_network || 80 if (!default_network ||
79 default_network->connection_state() == shill::kStatePortal) { 81 default_network->connection_state() == shill::kStatePortal) {
80 // If network is offline, defer the token fetching until online. 82 // If network is offline, defer the token fetching until online.
81 VLOG(1) << "Network is offline. Deferring OAuth2 token fetch."; 83 VLOG(1) << "Network is offline. Deferring OAuth2 token fetch.";
82 BrowserThread::PostDelayedTask( 84 BrowserThread::PostDelayedTask(
83 BrowserThread::UI, FROM_HERE, 85 BrowserThread::UI, FROM_HERE,
84 base::Bind(&OAuth2TokenFetcher::StartExchangeFromAuthCode, 86 base::Bind(&OAuth2TokenFetcher::StartExchangeFromAuthCode, AsWeakPtr(),
85 AsWeakPtr(), 87 auth_code, signin_scoped_device_id),
86 auth_code),
87 base::TimeDelta::FromMilliseconds(kRequestRestartDelay)); 88 base::TimeDelta::FromMilliseconds(kRequestRestartDelay));
88 return; 89 return;
89 } 90 }
90 auth_fetcher_.StartAuthCodeForOAuth2TokenExchange(auth_code); 91 auth_fetcher_.StartAuthCodeForOAuth2TokenExchangeWithDeviceId(
92 auth_code, signin_scoped_device_id);
91 } 93 }
92 94
93 void OAuth2TokenFetcher::OnClientOAuthSuccess( 95 void OAuth2TokenFetcher::OnClientOAuthSuccess(
94 const GaiaAuthConsumer::ClientOAuthResult& oauth_tokens) { 96 const GaiaAuthConsumer::ClientOAuthResult& oauth_tokens) {
95 DCHECK_CURRENTLY_ON(BrowserThread::UI); 97 DCHECK_CURRENTLY_ON(BrowserThread::UI);
96 VLOG(1) << "Got OAuth2 tokens!"; 98 VLOG(1) << "Got OAuth2 tokens!";
97 retry_count_ = 0; 99 retry_count_ = 0;
98 oauth_tokens_ = oauth_tokens; 100 oauth_tokens_ = oauth_tokens;
99 delegate_->OnOAuth2TokensAvailable(oauth_tokens_); 101 delegate_->OnOAuth2TokensAvailable(oauth_tokens_);
100 } 102 }
101 103
102 void OAuth2TokenFetcher::OnClientOAuthFailure( 104 void OAuth2TokenFetcher::OnClientOAuthFailure(
103 const GoogleServiceAuthError& error) { 105 const GoogleServiceAuthError& error) {
104 DCHECK_CURRENTLY_ON(BrowserThread::UI); 106 DCHECK_CURRENTLY_ON(BrowserThread::UI);
105 RetryOnError(error, 107 RetryOnError(
106 auth_code_.empty() 108 error,
107 ? base::Bind(&OAuth2TokenFetcher::StartExchangeFromCookies, 109 auth_code_.empty()
108 AsWeakPtr(), 110 ? base::Bind(&OAuth2TokenFetcher::StartExchangeFromCookies,
109 session_index_, 111 AsWeakPtr(), session_index_, signin_scoped_device_id_)
110 signin_scoped_device_id_) 112 : base::Bind(&OAuth2TokenFetcher::StartExchangeFromAuthCode,
111 : base::Bind(&OAuth2TokenFetcher::StartExchangeFromAuthCode, 113 AsWeakPtr(), auth_code_, signin_scoped_device_id_),
112 AsWeakPtr(), 114 base::Bind(&Delegate::OnOAuth2TokensFetchFailed,
113 auth_code_), 115 base::Unretained(delegate_)));
114 base::Bind(&Delegate::OnOAuth2TokensFetchFailed,
115 base::Unretained(delegate_)));
116 } 116 }
117 117
118 void OAuth2TokenFetcher::RetryOnError(const GoogleServiceAuthError& error, 118 void OAuth2TokenFetcher::RetryOnError(const GoogleServiceAuthError& error,
119 const base::Closure& task, 119 const base::Closure& task,
120 const base::Closure& error_handler) { 120 const base::Closure& error_handler) {
121 DCHECK_CURRENTLY_ON(BrowserThread::UI); 121 DCHECK_CURRENTLY_ON(BrowserThread::UI);
122 if ((error.state() == GoogleServiceAuthError::CONNECTION_FAILED || 122 if ((error.state() == GoogleServiceAuthError::CONNECTION_FAILED ||
123 error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE || 123 error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE ||
124 error.state() == GoogleServiceAuthError::REQUEST_CANCELED) && 124 error.state() == GoogleServiceAuthError::REQUEST_CANCELED) &&
125 retry_count_ < kMaxRequestAttemptCount) { 125 retry_count_ < kMaxRequestAttemptCount) {
126 retry_count_++; 126 retry_count_++;
127 BrowserThread::PostDelayedTask( 127 BrowserThread::PostDelayedTask(
128 BrowserThread::UI, FROM_HERE, task, 128 BrowserThread::UI, FROM_HERE, task,
129 base::TimeDelta::FromMilliseconds(kRequestRestartDelay)); 129 base::TimeDelta::FromMilliseconds(kRequestRestartDelay));
130 return; 130 return;
131 } 131 }
132 LOG(ERROR) << "Unrecoverable error or retry count max reached. State: " 132 LOG(ERROR) << "Unrecoverable error or retry count max reached. State: "
133 << error.state() << ", network error: " << error.network_error() 133 << error.state() << ", network error: " << error.network_error()
134 << ", message: " << error.error_message(); 134 << ", message: " << error.error_message();
135 error_handler.Run(); 135 error_handler.Run();
136 } 136 }
137 137
138 } // namespace chromeos 138 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698