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 "chrome/browser/ui/webui/print_preview/print_preview_handler.h" | 5 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 public: | 252 public: |
253 explicit AccessTokenService(PrintPreviewHandler* handler) | 253 explicit AccessTokenService(PrintPreviewHandler* handler) |
254 : handler_(handler) { | 254 : handler_(handler) { |
255 } | 255 } |
256 | 256 |
257 void RequestToken(const std::string& type) { | 257 void RequestToken(const std::string& type) { |
258 if (requests_.find(type) != requests_.end()) | 258 if (requests_.find(type) != requests_.end()) |
259 return; // Already in progress. | 259 return; // Already in progress. |
260 | 260 |
261 OAuth2TokenService* service = NULL; | 261 OAuth2TokenService* service = NULL; |
| 262 std::string account_id; |
262 if (type == "profile") { | 263 if (type == "profile") { |
263 Profile* profile = Profile::FromWebUI(handler_->web_ui()); | 264 Profile* profile = Profile::FromWebUI(handler_->web_ui()); |
264 if (profile) | 265 if (profile) { |
265 service = ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 266 ProfileOAuth2TokenService* token_service = |
| 267 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 268 account_id = token_service->GetPrimaryAccountId(); |
| 269 service = token_service; |
| 270 } |
266 } else if (type == "device") { | 271 } else if (type == "device") { |
267 #if defined(OS_CHROMEOS) | 272 #if defined(OS_CHROMEOS) |
268 service = chromeos::DeviceOAuth2TokenServiceFactory::Get(); | 273 chromeos::DeviceOAuth2TokenService* token_service = |
| 274 chromeos::DeviceOAuth2TokenServiceFactory::Get(); |
| 275 account_id = token_service->GetRobotAccountId(); |
| 276 service = token_service; |
269 #endif | 277 #endif |
270 } | 278 } |
271 | 279 |
272 if (service) { | 280 if (service) { |
273 OAuth2TokenService::ScopeSet oauth_scopes; | 281 OAuth2TokenService::ScopeSet oauth_scopes; |
274 oauth_scopes.insert(cloud_print::kCloudPrintAuth); | 282 oauth_scopes.insert(cloud_print::kCloudPrintAuth); |
275 scoped_ptr<OAuth2TokenService::Request> request( | 283 scoped_ptr<OAuth2TokenService::Request> request( |
276 service->StartRequest(oauth_scopes, this)); | 284 service->StartRequest(account_id, oauth_scopes, this)); |
277 requests_[type].reset(request.release()); | 285 requests_[type].reset(request.release()); |
278 } else { | 286 } else { |
279 handler_->SendAccessToken(type, std::string()); // Unknown type. | 287 handler_->SendAccessToken(type, std::string()); // Unknown type. |
280 } | 288 } |
281 } | 289 } |
282 | 290 |
283 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 291 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
284 const std::string& access_token, | 292 const std::string& access_token, |
285 const base::Time& expiration_time) OVERRIDE { | 293 const base::Time& expiration_time) OVERRIDE { |
286 OnServiceResponce(request, access_token); | 294 OnServiceResponce(request, access_token); |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 if (!tmp_data.get()) { | 1057 if (!tmp_data.get()) { |
1050 // Nothing to print, no preview available. | 1058 // Nothing to print, no preview available. |
1051 return false; | 1059 return false; |
1052 } | 1060 } |
1053 DCHECK(tmp_data->size() && tmp_data->front()); | 1061 DCHECK(tmp_data->size() && tmp_data->front()); |
1054 | 1062 |
1055 *data = tmp_data; | 1063 *data = tmp_data; |
1056 *title = print_preview_ui->initiator_title(); | 1064 *title = print_preview_ui->initiator_title(); |
1057 return true; | 1065 return true; |
1058 } | 1066 } |
OLD | NEW |