Chromium Code Reviews| 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 &PrintPreviewHandler::AccessTokenService::DidGetTokenService, |
|
pneubeck (no reviews)
2013/10/22 09:05:03
PrintPreviewHandler:: really required? I thought q
satorux1
2013/10/22 09:56:43
good point. will fix.
satorux1
2013/10/23 06:35:44
Done.
| |
| 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) { | |
|
hashimoto
2013/10/22 08:49:51
nit: No need to have a NULL check here?
satorux1
2013/10/22 09:56:43
will add.
satorux1
2013/10/23 06:35:44
Done.
| |
| 412 ContinueRequestToken(type, | |
| 413 token_service, | |
| 414 token_service->GetRobotAccountId()); | |
| 415 } | |
| 416 #endif | |
| 417 | |
| 418 // Continuation of RequestToken(). | |
| 419 void ContinueRequestToken(const std::string& type, | |
| 420 OAuth2TokenService* service, | |
| 421 const std::string& account_id) { | |
| 402 if (service) { | 422 if (service) { |
| 403 OAuth2TokenService::ScopeSet oauth_scopes; | 423 OAuth2TokenService::ScopeSet oauth_scopes; |
| 404 oauth_scopes.insert(cloud_print::kCloudPrintAuth); | 424 oauth_scopes.insert(cloud_print::kCloudPrintAuth); |
| 405 scoped_ptr<OAuth2TokenService::Request> request( | 425 scoped_ptr<OAuth2TokenService::Request> request( |
| 406 service->StartRequest(account_id, oauth_scopes, this)); | 426 service->StartRequest(account_id, oauth_scopes, this)); |
| 407 requests_[type].reset(request.release()); | 427 requests_[type].reset(request.release()); |
| 408 } else { | 428 } else { |
| 409 handler_->SendAccessToken(type, std::string()); // Unknown type. | 429 handler_->SendAccessToken(type, std::string()); // Unknown type. |
| 410 } | 430 } |
| 411 } | 431 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 431 return; | 451 return; |
| 432 } | 452 } |
| 433 } | 453 } |
| 434 NOTREACHED(); | 454 NOTREACHED(); |
| 435 } | 455 } |
| 436 | 456 |
| 437 typedef std::map<std::string, | 457 typedef std::map<std::string, |
| 438 linked_ptr<OAuth2TokenService::Request> > Requests; | 458 linked_ptr<OAuth2TokenService::Request> > Requests; |
| 439 Requests requests_; | 459 Requests requests_; |
| 440 PrintPreviewHandler* handler_; | 460 PrintPreviewHandler* handler_; |
| 461 base::WeakPtrFactory<AccessTokenService> weak_factory_; | |
| 441 | 462 |
| 442 DISALLOW_COPY_AND_ASSIGN(AccessTokenService); | 463 DISALLOW_COPY_AND_ASSIGN(AccessTokenService); |
| 443 }; | 464 }; |
| 444 | 465 |
| 445 PrintPreviewHandler::PrintPreviewHandler() | 466 PrintPreviewHandler::PrintPreviewHandler() |
| 446 : print_backend_(printing::PrintBackend::CreateInstance(NULL)), | 467 : print_backend_(printing::PrintBackend::CreateInstance(NULL)), |
| 447 regenerate_preview_request_count_(0), | 468 regenerate_preview_request_count_(0), |
| 448 manage_printers_dialog_request_count_(0), | 469 manage_printers_dialog_request_count_(0), |
| 449 manage_cloud_printers_dialog_request_count_(0), | 470 manage_cloud_printers_dialog_request_count_(0), |
| 450 reported_failed_preview_(false), | 471 reported_failed_preview_(false), |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1235 settings->SetInteger(printing::kSettingColor, bw_model); | 1256 settings->SetInteger(printing::kSettingColor, bw_model); |
| 1236 return; | 1257 return; |
| 1237 } | 1258 } |
| 1238 DCHECK_EQ(printing::COLOR, color); | 1259 DCHECK_EQ(printing::COLOR, color); |
| 1239 printing::ColorModel color_model = cups_printer_color_models_->color_model; | 1260 printing::ColorModel color_model = cups_printer_color_models_->color_model; |
| 1240 if (color_model != printing::UNKNOWN_COLOR_MODEL) | 1261 if (color_model != printing::UNKNOWN_COLOR_MODEL) |
| 1241 settings->SetInteger(printing::kSettingColor, color_model); | 1262 settings->SetInteger(printing::kSettingColor, color_model); |
| 1242 } | 1263 } |
| 1243 | 1264 |
| 1244 #endif | 1265 #endif |
| OLD | NEW |