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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 std::string printer_name; | 366 std::string printer_name; |
367 printing::ColorModel color_model; | 367 printing::ColorModel color_model; |
368 printing::ColorModel bw_model; | 368 printing::ColorModel bw_model; |
369 }; | 369 }; |
370 #endif | 370 #endif |
371 | 371 |
372 class PrintPreviewHandler::AccessTokenService | 372 class PrintPreviewHandler::AccessTokenService |
373 : public OAuth2TokenService::Consumer { | 373 : public OAuth2TokenService::Consumer { |
374 public: | 374 public: |
375 explicit AccessTokenService(PrintPreviewHandler* handler) | 375 explicit AccessTokenService(PrintPreviewHandler* handler) |
376 : handler_(handler) { | 376 : handler_(handler), |
| 377 weak_factory_(this) { |
377 } | 378 } |
378 | 379 |
379 void RequestToken(const std::string& type) { | 380 void RequestToken(const std::string& type) { |
380 if (requests_.find(type) != requests_.end()) | 381 if (requests_.find(type) != requests_.end()) |
381 return; // Already in progress. | 382 return; // Already in progress. |
382 | 383 |
383 OAuth2TokenService* service = NULL; | 384 OAuth2TokenService* service = NULL; |
384 std::string account_id; | 385 std::string account_id; |
385 if (type == "profile") { | 386 if (type == "profile") { |
386 Profile* profile = Profile::FromWebUI(handler_->web_ui()); | 387 Profile* profile = Profile::FromWebUI(handler_->web_ui()); |
387 if (profile) { | 388 if (profile) { |
388 ProfileOAuth2TokenService* token_service = | 389 ProfileOAuth2TokenService* token_service = |
389 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 390 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
390 account_id = token_service->GetPrimaryAccountId(); | 391 account_id = token_service->GetPrimaryAccountId(); |
391 service = token_service; | 392 service = token_service; |
392 } | 393 } |
393 } else if (type == "device") { | 394 } else if (type == "device") { |
394 #if defined(OS_CHROMEOS) | 395 #if defined(OS_CHROMEOS) |
395 chromeos::DeviceOAuth2TokenService* token_service = | 396 chromeos::DeviceOAuth2TokenServiceFactory::Get( |
396 chromeos::DeviceOAuth2TokenServiceFactory::Get(); | 397 base::Bind( |
397 account_id = token_service->GetRobotAccountId(); | 398 &AccessTokenService::DidGetTokenService, |
398 service = token_service; | 399 weak_factory_.GetWeakPtr(), |
| 400 type)); |
| 401 return; |
399 #endif | 402 #endif |
400 } | 403 } |
401 | 404 |
| 405 ContinueRequestToken(type, service, account_id); |
| 406 } |
| 407 |
| 408 #if defined(OS_CHROMEOS) |
| 409 // Continuation of RequestToken(). |
| 410 void DidGetTokenService(const std::string& type, |
| 411 chromeos::DeviceOAuth2TokenService* token_service) { |
| 412 std::string account_id; |
| 413 if (token_service) |
| 414 account_id = token_service->GetRobotAccountId(); |
| 415 ContinueRequestToken(type, |
| 416 token_service, |
| 417 account_id); |
| 418 } |
| 419 #endif |
| 420 |
| 421 // Continuation of RequestToken(). |
| 422 void ContinueRequestToken(const std::string& type, |
| 423 OAuth2TokenService* service, |
| 424 const std::string& account_id) { |
402 if (service) { | 425 if (service) { |
403 OAuth2TokenService::ScopeSet oauth_scopes; | 426 OAuth2TokenService::ScopeSet oauth_scopes; |
404 oauth_scopes.insert(cloud_print::kCloudPrintAuth); | 427 oauth_scopes.insert(cloud_print::kCloudPrintAuth); |
405 scoped_ptr<OAuth2TokenService::Request> request( | 428 scoped_ptr<OAuth2TokenService::Request> request( |
406 service->StartRequest(account_id, oauth_scopes, this)); | 429 service->StartRequest(account_id, oauth_scopes, this)); |
407 requests_[type].reset(request.release()); | 430 requests_[type].reset(request.release()); |
408 } else { | 431 } else { |
409 handler_->SendAccessToken(type, std::string()); // Unknown type. | 432 handler_->SendAccessToken(type, std::string()); // Unknown type. |
410 } | 433 } |
411 } | 434 } |
(...skipping 19 matching lines...) Expand all Loading... |
431 return; | 454 return; |
432 } | 455 } |
433 } | 456 } |
434 NOTREACHED(); | 457 NOTREACHED(); |
435 } | 458 } |
436 | 459 |
437 typedef std::map<std::string, | 460 typedef std::map<std::string, |
438 linked_ptr<OAuth2TokenService::Request> > Requests; | 461 linked_ptr<OAuth2TokenService::Request> > Requests; |
439 Requests requests_; | 462 Requests requests_; |
440 PrintPreviewHandler* handler_; | 463 PrintPreviewHandler* handler_; |
| 464 base::WeakPtrFactory<AccessTokenService> weak_factory_; |
441 | 465 |
442 DISALLOW_COPY_AND_ASSIGN(AccessTokenService); | 466 DISALLOW_COPY_AND_ASSIGN(AccessTokenService); |
443 }; | 467 }; |
444 | 468 |
445 PrintPreviewHandler::PrintPreviewHandler() | 469 PrintPreviewHandler::PrintPreviewHandler() |
446 : print_backend_(printing::PrintBackend::CreateInstance(NULL)), | 470 : print_backend_(printing::PrintBackend::CreateInstance(NULL)), |
447 regenerate_preview_request_count_(0), | 471 regenerate_preview_request_count_(0), |
448 manage_printers_dialog_request_count_(0), | 472 manage_printers_dialog_request_count_(0), |
449 manage_cloud_printers_dialog_request_count_(0), | 473 manage_cloud_printers_dialog_request_count_(0), |
450 reported_failed_preview_(false), | 474 reported_failed_preview_(false), |
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1235 settings->SetInteger(printing::kSettingColor, bw_model); | 1259 settings->SetInteger(printing::kSettingColor, bw_model); |
1236 return; | 1260 return; |
1237 } | 1261 } |
1238 DCHECK_EQ(printing::COLOR, color); | 1262 DCHECK_EQ(printing::COLOR, color); |
1239 printing::ColorModel color_model = cups_printer_color_models_->color_model; | 1263 printing::ColorModel color_model = cups_printer_color_models_->color_model; |
1240 if (color_model != printing::UNKNOWN_COLOR_MODEL) | 1264 if (color_model != printing::UNKNOWN_COLOR_MODEL) |
1241 settings->SetInteger(printing::kSettingColor, color_model); | 1265 settings->SetInteger(printing::kSettingColor, color_model); |
1242 } | 1266 } |
1243 | 1267 |
1244 #endif | 1268 #endif |
OLD | NEW |