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

Side by Side Diff: chrome/service/cloud_print/cloud_print_auth.cc

Issue 11360151: Move common cloud print methods from service/cloud_print to common/cloud_print. (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
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 "chrome/service/cloud_print/cloud_print_auth.h" 5 #include "chrome/service/cloud_print/cloud_print_auth.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/common/cloud_print/cloud_print_constants.h"
10 #include "chrome/common/cloud_print/cloud_print_helpers.h"
9 #include "chrome/service/cloud_print/cloud_print_consts.h" 11 #include "chrome/service/cloud_print/cloud_print_consts.h"
10 #include "chrome/service/cloud_print/cloud_print_helpers.h" 12 #include "chrome/service/cloud_print/cloud_print_helpers.h"
msw 2012/11/17 00:22:30 This isn't used any more, please remove.
Chen Yu 2012/11/26 12:07:06 Done.
11 #include "chrome/service/cloud_print/cloud_print_token_store.h" 13 #include "chrome/service/cloud_print/cloud_print_token_store.h"
12 #include "chrome/service/gaia/service_gaia_authenticator.h" 14 #include "chrome/service/gaia/service_gaia_authenticator.h"
13 #include "chrome/service/net/service_url_request_context.h" 15 #include "chrome/service/net/service_url_request_context.h"
14 #include "chrome/service/service_process.h" 16 #include "chrome/service/service_process.h"
15 #include "google_apis/gaia/gaia_urls.h" 17 #include "google_apis/gaia/gaia_urls.h"
16 18
17 CloudPrintAuth::CloudPrintAuth( 19 CloudPrintAuth::CloudPrintAuth(
18 Client* client, 20 Client* client,
19 const GURL& cloud_print_server_url, 21 const GURL& cloud_print_server_url,
20 const gaia::OAuthClientInfo& oauth_client_info, 22 const gaia::OAuthClientInfo& oauth_client_info,
21 const std::string& proxy_id) 23 const std::string& proxy_id)
22 : client_(client), 24 : client_(client),
23 oauth_client_info_(oauth_client_info), 25 oauth_client_info_(oauth_client_info),
24 cloud_print_server_url_(cloud_print_server_url), 26 cloud_print_server_url_(cloud_print_server_url),
25 proxy_id_(proxy_id) { 27 proxy_id_(proxy_id) {
26 DCHECK(client); 28 DCHECK(client);
27 } 29 }
28 30
29 void CloudPrintAuth::AuthenticateWithLsid( 31 void CloudPrintAuth::AuthenticateWithLsid(
30 const std::string& lsid, 32 const std::string& lsid,
31 const std::string& last_robot_refresh_token, 33 const std::string& last_robot_refresh_token,
32 const std::string& last_robot_email, 34 const std::string& last_robot_email,
33 const std::string& last_user_email) { 35 const std::string& last_user_email) {
34 // Keeping VLOGs for Cloud Print proxy logging. It is convinient for finding 36 // Keeping VLOGs for Cloud Print proxy logging. It is convinient for finding
35 // issues with GCP in the field, where only release version is avaialble. 37 // issues with GCP in the field, where only release version is avaialble.
36 VLOG(1) << "CP_AUTH: Authenticating with LSID"; 38 VLOG(1) << "CP_AUTH: Authenticating with LSID";
37 scoped_refptr<ServiceGaiaAuthenticator> gaia_auth_for_print( 39 scoped_refptr<ServiceGaiaAuthenticator> gaia_auth_for_print(
38 new ServiceGaiaAuthenticator( 40 new ServiceGaiaAuthenticator(
39 kProxyAuthUserAgent, kCloudPrintGaiaServiceId, 41 cloud_print::kProxyAuthUserAgent,
msw 2012/11/17 00:22:30 nit: consider putting this file's contents in the
Chen Yu 2012/11/26 12:07:06 Done.
42 cloud_print::kCloudPrintGaiaServiceId,
40 GaiaUrls::GetInstance()->client_login_url(), 43 GaiaUrls::GetInstance()->client_login_url(),
41 g_service_process->io_thread()->message_loop_proxy())); 44 g_service_process->io_thread()->message_loop_proxy()));
42 gaia_auth_for_print->set_message_loop(MessageLoop::current()); 45 gaia_auth_for_print->set_message_loop(MessageLoop::current());
43 if (gaia_auth_for_print->AuthenticateWithLsid(lsid)) { 46 if (gaia_auth_for_print->AuthenticateWithLsid(lsid)) {
44 // Stash away the user email so we can save it in prefs. 47 // Stash away the user email so we can save it in prefs.
45 user_email_ = gaia_auth_for_print->email(); 48 user_email_ = gaia_auth_for_print->email();
46 // If the same user is re-enabling Cloud Print and we have stashed robot 49 // If the same user is re-enabling Cloud Print and we have stashed robot
47 // credentials, we will use those. 50 // credentials, we will use those.
48 if ((0 == base::strcasecmp(user_email_.c_str(), last_user_email.c_str())) && 51 if ((0 == base::strcasecmp(user_email_.c_str(), last_user_email.c_str())) &&
49 !last_robot_refresh_token.empty() && 52 !last_robot_refresh_token.empty() &&
50 !last_robot_email.empty()) { 53 !last_robot_email.empty()) {
51 AuthenticateWithRobotToken(last_robot_refresh_token, 54 AuthenticateWithRobotToken(last_robot_refresh_token,
52 last_robot_email); 55 last_robot_email);
53 } 56 }
54 AuthenticateWithToken(gaia_auth_for_print->auth_token()); 57 AuthenticateWithToken(gaia_auth_for_print->auth_token());
55 } else { 58 } else {
56 // Notify client about authentication error. 59 // Notify client about authentication error.
57 client_->OnInvalidCredentials(); 60 client_->OnInvalidCredentials();
58 } 61 }
59 } 62 }
60 63
61 void CloudPrintAuth::AuthenticateWithToken( 64 void CloudPrintAuth::AuthenticateWithToken(
62 const std::string& cloud_print_token) { 65 const std::string& cloud_print_token) {
63 VLOG(1) << "CP_AUTH: Authenticating with token"; 66 VLOG(1) << "CP_AUTH: Authenticating with token";
64 67
65 client_login_token_ = cloud_print_token; 68 client_login_token_ = cloud_print_token;
66 69
67 // We need to get the credentials of the robot here. 70 // We need to get the credentials of the robot here.
68 GURL get_authcode_url = 71 GURL get_authcode_url =
69 CloudPrintHelpers::GetUrlForGetAuthCode(cloud_print_server_url_, 72 cloud_print::GetUrlForGetAuthCode(cloud_print_server_url_,
70 oauth_client_info_.client_id, 73 oauth_client_info_.client_id,
71 proxy_id_); 74 proxy_id_);
72 request_ = new CloudPrintURLFetcher; 75 request_ = new CloudPrintURLFetcher;
73 request_->StartGetRequest(get_authcode_url, 76 request_->StartGetRequest(get_authcode_url,
74 this, 77 this,
75 kCloudPrintAuthMaxRetryCount, 78 kCloudPrintAuthMaxRetryCount,
76 std::string()); 79 std::string());
77 } 80 }
78 81
79 void CloudPrintAuth::AuthenticateWithRobotToken( 82 void CloudPrintAuth::AuthenticateWithRobotToken(
80 const std::string& robot_oauth_refresh_token, 83 const std::string& robot_oauth_refresh_token,
81 const std::string& robot_email) { 84 const std::string& robot_email) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 const GURL& url, 157 const GURL& url,
155 base::DictionaryValue* json_data, 158 base::DictionaryValue* json_data,
156 bool succeeded) { 159 bool succeeded) {
157 if (!succeeded) { 160 if (!succeeded) {
158 VLOG(1) << "CP_AUTH: Creating robot account failed"; 161 VLOG(1) << "CP_AUTH: Creating robot account failed";
159 client_->OnInvalidCredentials(); 162 client_->OnInvalidCredentials();
160 return CloudPrintURLFetcher::STOP_PROCESSING; 163 return CloudPrintURLFetcher::STOP_PROCESSING;
161 } 164 }
162 165
163 std::string auth_code; 166 std::string auth_code;
164 if (!json_data->GetString(kOAuthCodeValue, &auth_code)) { 167 if (!json_data->GetString(cloud_print::kOAuthCodeValue, &auth_code)) {
165 VLOG(1) << "CP_AUTH: Creating robot account returned invalid json response"; 168 VLOG(1) << "CP_AUTH: Creating robot account returned invalid json response";
166 client_->OnInvalidCredentials(); 169 client_->OnInvalidCredentials();
167 return CloudPrintURLFetcher::STOP_PROCESSING; 170 return CloudPrintURLFetcher::STOP_PROCESSING;
168 } 171 }
169 172
170 json_data->GetString(kXMPPJidValue, &robot_email_); 173 json_data->GetString(cloud_print::kXMPPJidValue, &robot_email_);
171 // Now that we have an auth code we need to get the refresh and access tokens. 174 // Now that we have an auth code we need to get the refresh and access tokens.
172 oauth_client_.reset(new gaia::GaiaOAuthClient( 175 oauth_client_.reset(new gaia::GaiaOAuthClient(
173 gaia::kGaiaOAuth2Url, 176 gaia::kGaiaOAuth2Url,
174 g_service_process->GetServiceURLRequestContextGetter())); 177 g_service_process->GetServiceURLRequestContextGetter()));
175 oauth_client_->GetTokensFromAuthCode(oauth_client_info_, 178 oauth_client_->GetTokensFromAuthCode(oauth_client_info_,
176 auth_code, 179 auth_code,
177 kCloudPrintAPIMaxRetryCount, 180 kCloudPrintAPIMaxRetryCount,
178 this); 181 this);
179 182
180 return CloudPrintURLFetcher::STOP_PROCESSING; 183 return CloudPrintURLFetcher::STOP_PROCESSING;
181 } 184 }
182 185
183 CloudPrintURLFetcher::ResponseAction CloudPrintAuth::OnRequestAuthError() { 186 CloudPrintURLFetcher::ResponseAction CloudPrintAuth::OnRequestAuthError() {
184 VLOG(1) << "CP_AUTH: Creating robot account authentication error"; 187 VLOG(1) << "CP_AUTH: Creating robot account authentication error";
185 // Notify client about authentication error. 188 // Notify client about authentication error.
186 client_->OnInvalidCredentials(); 189 client_->OnInvalidCredentials();
187 return CloudPrintURLFetcher::STOP_PROCESSING; 190 return CloudPrintURLFetcher::STOP_PROCESSING;
188 } 191 }
189 192
190 std::string CloudPrintAuth::GetAuthHeader() { 193 std::string CloudPrintAuth::GetAuthHeader() {
191 DCHECK(!client_login_token_.empty()); 194 DCHECK(!client_login_token_.empty());
192 std::string header; 195 std::string header;
193 header = "Authorization: GoogleLogin auth="; 196 header = "Authorization: GoogleLogin auth=";
194 header += client_login_token_; 197 header += client_login_token_;
195 return header; 198 return header;
196 } 199 }
197 200
198 CloudPrintAuth::~CloudPrintAuth() {} 201 CloudPrintAuth::~CloudPrintAuth() {}
199 202
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698