| 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 service = chromeos::DeviceOAuth2TokenServiceFactory::Get(); |
| 274 // account_id intentionally left empty here. |
| 269 #endif | 275 #endif |
| 270 } | 276 } |
| 271 | 277 |
| 272 if (service) { | 278 if (service) { |
| 273 OAuth2TokenService::ScopeSet oauth_scopes; | 279 OAuth2TokenService::ScopeSet oauth_scopes; |
| 274 oauth_scopes.insert(cloud_print::kCloudPrintAuth); | 280 oauth_scopes.insert(cloud_print::kCloudPrintAuth); |
| 275 scoped_ptr<OAuth2TokenService::Request> request( | 281 scoped_ptr<OAuth2TokenService::Request> request( |
| 276 service->StartRequest(oauth_scopes, this)); | 282 service->StartRequest(account_id, oauth_scopes, this)); |
| 277 requests_[type].reset(request.release()); | 283 requests_[type].reset(request.release()); |
| 278 } else { | 284 } else { |
| 279 handler_->SendAccessToken(type, std::string()); // Unknown type. | 285 handler_->SendAccessToken(type, std::string()); // Unknown type. |
| 280 } | 286 } |
| 281 } | 287 } |
| 282 | 288 |
| 283 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | 289 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 284 const std::string& access_token, | 290 const std::string& access_token, |
| 285 const base::Time& expiration_time) OVERRIDE { | 291 const base::Time& expiration_time) OVERRIDE { |
| 286 OnServiceResponce(request, access_token); | 292 OnServiceResponce(request, access_token); |
| (...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 if (!tmp_data.get()) { | 1055 if (!tmp_data.get()) { |
| 1050 // Nothing to print, no preview available. | 1056 // Nothing to print, no preview available. |
| 1051 return false; | 1057 return false; |
| 1052 } | 1058 } |
| 1053 DCHECK(tmp_data->size() && tmp_data->front()); | 1059 DCHECK(tmp_data->size() && tmp_data->front()); |
| 1054 | 1060 |
| 1055 *data = tmp_data; | 1061 *data = tmp_data; |
| 1056 *title = print_preview_ui->initiator_title(); | 1062 *title = print_preview_ui->initiator_title(); |
| 1057 return true; | 1063 return true; |
| 1058 } | 1064 } |
| OLD | NEW |