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

Side by Side Diff: chrome/browser/chromeos/extensions/wallpaper_private_api.cc

Issue 375413002: Replace chromeos::UserManager::Get() with chromeos::GetUserManager(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 6 years, 5 months 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/chromeos/extensions/wallpaper_private_api.h" 5 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/desktop_background/desktop_background_controller.h" 10 #include "ash/desktop_background/desktop_background_controller.h"
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 WallpaperPrivateSetWallpaperIfExistsFunction:: 295 WallpaperPrivateSetWallpaperIfExistsFunction::
296 WallpaperPrivateSetWallpaperIfExistsFunction() {} 296 WallpaperPrivateSetWallpaperIfExistsFunction() {}
297 297
298 WallpaperPrivateSetWallpaperIfExistsFunction:: 298 WallpaperPrivateSetWallpaperIfExistsFunction::
299 ~WallpaperPrivateSetWallpaperIfExistsFunction() {} 299 ~WallpaperPrivateSetWallpaperIfExistsFunction() {}
300 300
301 bool WallpaperPrivateSetWallpaperIfExistsFunction::RunAsync() { 301 bool WallpaperPrivateSetWallpaperIfExistsFunction::RunAsync() {
302 params = set_wallpaper_if_exists::Params::Create(*args_); 302 params = set_wallpaper_if_exists::Params::Create(*args_);
303 EXTENSION_FUNCTION_VALIDATE(params); 303 EXTENSION_FUNCTION_VALIDATE(params);
304 304
305 user_id_ = chromeos::UserManager::Get()->GetActiveUser()->email(); 305 user_id_ = chromeos::GetUserManager()->GetActiveUser()->email();
306 306
307 base::FilePath wallpaper_path; 307 base::FilePath wallpaper_path;
308 base::FilePath fallback_path; 308 base::FilePath fallback_path;
309 chromeos::WallpaperManager::WallpaperResolution resolution = 309 chromeos::WallpaperManager::WallpaperResolution resolution =
310 chromeos::WallpaperManager::GetAppropriateResolution(); 310 chromeos::WallpaperManager::GetAppropriateResolution();
311 311
312 std::string file_name = GURL(params->url).ExtractFileName(); 312 std::string file_name = GURL(params->url).ExtractFileName();
313 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, 313 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS,
314 &wallpaper_path)); 314 &wallpaper_path));
315 fallback_path = wallpaper_path.Append(file_name); 315 fallback_path = wallpaper_path.Append(file_name);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 const gfx::ImageSkia& image) { 366 const gfx::ImageSkia& image) {
367 // Set unsafe_wallpaper_decoder_ to null since the decoding already finished. 367 // Set unsafe_wallpaper_decoder_ to null since the decoding already finished.
368 unsafe_wallpaper_decoder_ = NULL; 368 unsafe_wallpaper_decoder_ = NULL;
369 369
370 chromeos::WallpaperManager* wallpaper_manager = 370 chromeos::WallpaperManager* wallpaper_manager =
371 chromeos::WallpaperManager::Get(); 371 chromeos::WallpaperManager::Get();
372 ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( 372 ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum(
373 wallpaper_private::ToString(params->layout)); 373 wallpaper_private::ToString(params->layout));
374 374
375 bool update_wallpaper = 375 bool update_wallpaper =
376 user_id_ == chromeos::UserManager::Get()->GetActiveUser()->email(); 376 user_id_ == chromeos::GetUserManager()->GetActiveUser()->email();
377 wallpaper_manager->SetWallpaperFromImageSkia( 377 wallpaper_manager->SetWallpaperFromImageSkia(
378 user_id_, image, layout, update_wallpaper); 378 user_id_, image, layout, update_wallpaper);
379 bool is_persistent = 379 bool is_persistent =
380 !chromeos::UserManager::Get()->IsCurrentUserNonCryptohomeDataEphemeral(); 380 !chromeos::GetUserManager()->IsCurrentUserNonCryptohomeDataEphemeral();
381 chromeos::WallpaperInfo info = { 381 chromeos::WallpaperInfo info = {
382 params->url, 382 params->url,
383 layout, 383 layout,
384 chromeos::User::ONLINE, 384 chromeos::User::ONLINE,
385 base::Time::Now().LocalMidnight() 385 base::Time::Now().LocalMidnight()
386 }; 386 };
387 wallpaper_manager->SetUserWallpaperInfo(user_id_, info, is_persistent); 387 wallpaper_manager->SetUserWallpaperInfo(user_id_, info, is_persistent);
388 SetResult(base::Value::CreateBooleanValue(true)); 388 SetResult(base::Value::CreateBooleanValue(true));
389 Profile* profile = Profile::FromBrowserContext(browser_context()); 389 Profile* profile = Profile::FromBrowserContext(browser_context());
390 // This API is only available to the component wallpaper picker. We do not 390 // This API is only available to the component wallpaper picker. We do not
(...skipping 14 matching lines...) Expand all
405 } 405 }
406 406
407 WallpaperPrivateSetWallpaperFunction::~WallpaperPrivateSetWallpaperFunction() { 407 WallpaperPrivateSetWallpaperFunction::~WallpaperPrivateSetWallpaperFunction() {
408 } 408 }
409 409
410 bool WallpaperPrivateSetWallpaperFunction::RunAsync() { 410 bool WallpaperPrivateSetWallpaperFunction::RunAsync() {
411 params = set_wallpaper::Params::Create(*args_); 411 params = set_wallpaper::Params::Create(*args_);
412 EXTENSION_FUNCTION_VALIDATE(params); 412 EXTENSION_FUNCTION_VALIDATE(params);
413 413
414 // Gets email address while at UI thread. 414 // Gets email address while at UI thread.
415 user_id_ = chromeos::UserManager::Get()->GetActiveUser()->email(); 415 user_id_ = chromeos::GetUserManager()->GetActiveUser()->email();
416 416
417 StartDecode(params->wallpaper); 417 StartDecode(params->wallpaper);
418 418
419 return true; 419 return true;
420 } 420 }
421 421
422 void WallpaperPrivateSetWallpaperFunction::OnWallpaperDecoded( 422 void WallpaperPrivateSetWallpaperFunction::OnWallpaperDecoded(
423 const gfx::ImageSkia& image) { 423 const gfx::ImageSkia& image) {
424 wallpaper_ = image; 424 wallpaper_ = image;
425 // Set unsafe_wallpaper_decoder_ to null since the decoding already finished. 425 // Set unsafe_wallpaper_decoder_ to null since the decoding already finished.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 479
480 void WallpaperPrivateSetWallpaperFunction::SetDecodedWallpaper( 480 void WallpaperPrivateSetWallpaperFunction::SetDecodedWallpaper(
481 scoped_ptr<gfx::ImageSkia> image) { 481 scoped_ptr<gfx::ImageSkia> image) {
482 chromeos::WallpaperManager* wallpaper_manager = 482 chromeos::WallpaperManager* wallpaper_manager =
483 chromeos::WallpaperManager::Get(); 483 chromeos::WallpaperManager::Get();
484 484
485 ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( 485 ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum(
486 wallpaper_private::ToString(params->layout)); 486 wallpaper_private::ToString(params->layout));
487 487
488 bool update_wallpaper = 488 bool update_wallpaper =
489 user_id_ == chromeos::UserManager::Get()->GetActiveUser()->email(); 489 user_id_ == chromeos::GetUserManager()->GetActiveUser()->email();
490 wallpaper_manager->SetWallpaperFromImageSkia( 490 wallpaper_manager->SetWallpaperFromImageSkia(
491 user_id_, *image.get(), layout, update_wallpaper); 491 user_id_, *image.get(), layout, update_wallpaper);
492 492
493 bool is_persistent = 493 bool is_persistent =
494 !chromeos::UserManager::Get()->IsCurrentUserNonCryptohomeDataEphemeral(); 494 !chromeos::GetUserManager()->IsCurrentUserNonCryptohomeDataEphemeral();
495 chromeos::WallpaperInfo info = { 495 chromeos::WallpaperInfo info = {
496 params->url, 496 params->url,
497 layout, 497 layout,
498 chromeos::User::ONLINE, 498 chromeos::User::ONLINE,
499 base::Time::Now().LocalMidnight() 499 base::Time::Now().LocalMidnight()
500 }; 500 };
501 Profile* profile = Profile::FromBrowserContext(browser_context()); 501 Profile* profile = Profile::FromBrowserContext(browser_context());
502 // This API is only available to the component wallpaper picker. We do not 502 // This API is only available to the component wallpaper picker. We do not
503 // need to show the app's name if it is the component wallpaper picker. So set 503 // need to show the app's name if it is the component wallpaper picker. So set
504 // the pref to empty string. 504 // the pref to empty string.
505 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, 505 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName,
506 std::string()); 506 std::string());
507 wallpaper_manager->SetUserWallpaperInfo(user_id_, info, is_persistent); 507 wallpaper_manager->SetUserWallpaperInfo(user_id_, info, is_persistent);
508 SendResponse(true); 508 SendResponse(true);
509 } 509 }
510 510
511 WallpaperPrivateResetWallpaperFunction:: 511 WallpaperPrivateResetWallpaperFunction::
512 WallpaperPrivateResetWallpaperFunction() {} 512 WallpaperPrivateResetWallpaperFunction() {}
513 513
514 WallpaperPrivateResetWallpaperFunction:: 514 WallpaperPrivateResetWallpaperFunction::
515 ~WallpaperPrivateResetWallpaperFunction() {} 515 ~WallpaperPrivateResetWallpaperFunction() {}
516 516
517 bool WallpaperPrivateResetWallpaperFunction::RunAsync() { 517 bool WallpaperPrivateResetWallpaperFunction::RunAsync() {
518 chromeos::WallpaperManager* wallpaper_manager = 518 chromeos::WallpaperManager* wallpaper_manager =
519 chromeos::WallpaperManager::Get(); 519 chromeos::WallpaperManager::Get();
520 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); 520 chromeos::UserManager* user_manager = chromeos::GetUserManager();
521 521
522 std::string user_id = user_manager->GetActiveUser()->email(); 522 std::string user_id = user_manager->GetActiveUser()->email();
523 wallpaper_manager->RemoveUserWallpaperInfo(user_id); 523 wallpaper_manager->RemoveUserWallpaperInfo(user_id);
524 524
525 chromeos::WallpaperInfo info = { 525 chromeos::WallpaperInfo info = {
526 "", 526 "",
527 ash::WALLPAPER_LAYOUT_CENTER, 527 ash::WALLPAPER_LAYOUT_CENTER,
528 chromeos::User::DEFAULT, 528 chromeos::User::DEFAULT,
529 base::Time::Now().LocalMidnight() 529 base::Time::Now().LocalMidnight()
530 }; 530 };
(...skipping 15 matching lines...) Expand all
546 WallpaperPrivateSetCustomWallpaperFunction() {} 546 WallpaperPrivateSetCustomWallpaperFunction() {}
547 547
548 WallpaperPrivateSetCustomWallpaperFunction:: 548 WallpaperPrivateSetCustomWallpaperFunction::
549 ~WallpaperPrivateSetCustomWallpaperFunction() {} 549 ~WallpaperPrivateSetCustomWallpaperFunction() {}
550 550
551 bool WallpaperPrivateSetCustomWallpaperFunction::RunAsync() { 551 bool WallpaperPrivateSetCustomWallpaperFunction::RunAsync() {
552 params = set_custom_wallpaper::Params::Create(*args_); 552 params = set_custom_wallpaper::Params::Create(*args_);
553 EXTENSION_FUNCTION_VALIDATE(params); 553 EXTENSION_FUNCTION_VALIDATE(params);
554 554
555 // Gets email address and username hash while at UI thread. 555 // Gets email address and username hash while at UI thread.
556 user_id_ = chromeos::UserManager::Get()->GetActiveUser()->email(); 556 user_id_ = chromeos::GetUserManager()->GetActiveUser()->email();
557 user_id_hash_ = 557 user_id_hash_ = chromeos::GetUserManager()->GetActiveUser()->username_hash();
558 chromeos::UserManager::Get()->GetActiveUser()->username_hash();
559 558
560 StartDecode(params->wallpaper); 559 StartDecode(params->wallpaper);
561 560
562 return true; 561 return true;
563 } 562 }
564 563
565 void WallpaperPrivateSetCustomWallpaperFunction::OnWallpaperDecoded( 564 void WallpaperPrivateSetCustomWallpaperFunction::OnWallpaperDecoded(
566 const gfx::ImageSkia& image) { 565 const gfx::ImageSkia& image) {
567 chromeos::WallpaperManager* wallpaper_manager = 566 chromeos::WallpaperManager* wallpaper_manager =
568 chromeos::WallpaperManager::Get(); 567 chromeos::WallpaperManager::Get();
569 base::FilePath thumbnail_path = wallpaper_manager->GetCustomWallpaperPath( 568 base::FilePath thumbnail_path = wallpaper_manager->GetCustomWallpaperPath(
570 chromeos::kThumbnailWallpaperSubDir, user_id_hash_, params->file_name); 569 chromeos::kThumbnailWallpaperSubDir, user_id_hash_, params->file_name);
571 570
572 sequence_token_ = BrowserThread::GetBlockingPool()-> 571 sequence_token_ = BrowserThread::GetBlockingPool()->
573 GetNamedSequenceToken(chromeos::kWallpaperSequenceTokenName); 572 GetNamedSequenceToken(chromeos::kWallpaperSequenceTokenName);
574 scoped_refptr<base::SequencedTaskRunner> task_runner = 573 scoped_refptr<base::SequencedTaskRunner> task_runner =
575 BrowserThread::GetBlockingPool()-> 574 BrowserThread::GetBlockingPool()->
576 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, 575 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_,
577 base::SequencedWorkerPool::BLOCK_SHUTDOWN); 576 base::SequencedWorkerPool::BLOCK_SHUTDOWN);
578 577
579 ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( 578 ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum(
580 wallpaper_private::ToString(params->layout)); 579 wallpaper_private::ToString(params->layout));
581 580
582 bool update_wallpaper = 581 bool update_wallpaper =
583 user_id_ == chromeos::UserManager::Get()->GetActiveUser()->email(); 582 user_id_ == chromeos::GetUserManager()->GetActiveUser()->email();
584 wallpaper_manager->SetCustomWallpaper(user_id_, 583 wallpaper_manager->SetCustomWallpaper(user_id_,
585 user_id_hash_, 584 user_id_hash_,
586 params->file_name, 585 params->file_name,
587 layout, 586 layout,
588 chromeos::User::CUSTOMIZED, 587 chromeos::User::CUSTOMIZED,
589 image, 588 image,
590 update_wallpaper); 589 update_wallpaper);
591 unsafe_wallpaper_decoder_ = NULL; 590 unsafe_wallpaper_decoder_ = NULL;
592 591
593 Profile* profile = Profile::FromBrowserContext(browser_context()); 592 Profile* profile = Profile::FromBrowserContext(browser_context());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 chromeos::WallpaperInfo info; 656 chromeos::WallpaperInfo info;
658 wallpaper_manager->GetLoggedInUserWallpaperInfo(&info); 657 wallpaper_manager->GetLoggedInUserWallpaperInfo(&info);
659 if (info.type != chromeos::User::CUSTOMIZED) { 658 if (info.type != chromeos::User::CUSTOMIZED) {
660 SetError("Only custom wallpaper can change layout."); 659 SetError("Only custom wallpaper can change layout.");
661 SendResponse(false); 660 SendResponse(false);
662 return false; 661 return false;
663 } 662 }
664 info.layout = wallpaper_api_util::GetLayoutEnum( 663 info.layout = wallpaper_api_util::GetLayoutEnum(
665 wallpaper_private::ToString(params->layout)); 664 wallpaper_private::ToString(params->layout));
666 665
667 std::string email = chromeos::UserManager::Get()->GetActiveUser()->email(); 666 std::string email = chromeos::GetUserManager()->GetActiveUser()->email();
668 bool is_persistent = 667 bool is_persistent =
669 !chromeos::UserManager::Get()->IsCurrentUserNonCryptohomeDataEphemeral(); 668 !chromeos::GetUserManager()->IsCurrentUserNonCryptohomeDataEphemeral();
670 wallpaper_manager->SetUserWallpaperInfo(email, info, is_persistent); 669 wallpaper_manager->SetUserWallpaperInfo(email, info, is_persistent);
671 wallpaper_manager->UpdateWallpaper(false /* clear_cache */); 670 wallpaper_manager->UpdateWallpaper(false /* clear_cache */);
672 SendResponse(true); 671 SendResponse(true);
673 672
674 // Gets email address while at UI thread. 673 // Gets email address while at UI thread.
675 return true; 674 return true;
676 } 675 }
677 676
678 WallpaperPrivateMinimizeInactiveWindowsFunction:: 677 WallpaperPrivateMinimizeInactiveWindowsFunction::
679 WallpaperPrivateMinimizeInactiveWindowsFunction() { 678 WallpaperPrivateMinimizeInactiveWindowsFunction() {
680 } 679 }
681 680
682 WallpaperPrivateMinimizeInactiveWindowsFunction:: 681 WallpaperPrivateMinimizeInactiveWindowsFunction::
683 ~WallpaperPrivateMinimizeInactiveWindowsFunction() { 682 ~WallpaperPrivateMinimizeInactiveWindowsFunction() {
684 } 683 }
685 684
686 bool WallpaperPrivateMinimizeInactiveWindowsFunction::RunAsync() { 685 bool WallpaperPrivateMinimizeInactiveWindowsFunction::RunAsync() {
687 WindowStateManager::MinimizeInactiveWindows( 686 WindowStateManager::MinimizeInactiveWindows(
688 chromeos::UserManager::Get()->GetActiveUser()->username_hash()); 687 chromeos::GetUserManager()->GetActiveUser()->username_hash());
689 return true; 688 return true;
690 } 689 }
691 690
692 WallpaperPrivateRestoreMinimizedWindowsFunction:: 691 WallpaperPrivateRestoreMinimizedWindowsFunction::
693 WallpaperPrivateRestoreMinimizedWindowsFunction() { 692 WallpaperPrivateRestoreMinimizedWindowsFunction() {
694 } 693 }
695 694
696 WallpaperPrivateRestoreMinimizedWindowsFunction:: 695 WallpaperPrivateRestoreMinimizedWindowsFunction::
697 ~WallpaperPrivateRestoreMinimizedWindowsFunction() { 696 ~WallpaperPrivateRestoreMinimizedWindowsFunction() {
698 } 697 }
699 698
700 bool WallpaperPrivateRestoreMinimizedWindowsFunction::RunAsync() { 699 bool WallpaperPrivateRestoreMinimizedWindowsFunction::RunAsync() {
701 WindowStateManager::RestoreWindows( 700 WindowStateManager::RestoreWindows(
702 chromeos::UserManager::Get()->GetActiveUser()->username_hash()); 701 chromeos::GetUserManager()->GetActiveUser()->username_hash());
703 return true; 702 return true;
704 } 703 }
705 704
706 WallpaperPrivateGetThumbnailFunction::WallpaperPrivateGetThumbnailFunction() { 705 WallpaperPrivateGetThumbnailFunction::WallpaperPrivateGetThumbnailFunction() {
707 } 706 }
708 707
709 WallpaperPrivateGetThumbnailFunction::~WallpaperPrivateGetThumbnailFunction() { 708 WallpaperPrivateGetThumbnailFunction::~WallpaperPrivateGetThumbnailFunction() {
710 } 709 }
711 710
712 bool WallpaperPrivateGetThumbnailFunction::RunAsync() { 711 bool WallpaperPrivateGetThumbnailFunction::RunAsync() {
713 scoped_ptr<get_thumbnail::Params> params( 712 scoped_ptr<get_thumbnail::Params> params(
714 get_thumbnail::Params::Create(*args_)); 713 get_thumbnail::Params::Create(*args_));
715 EXTENSION_FUNCTION_VALIDATE(params); 714 EXTENSION_FUNCTION_VALIDATE(params);
716 715
717 base::FilePath thumbnail_path; 716 base::FilePath thumbnail_path;
718 std::string email = chromeos::UserManager::Get()->GetActiveUser()->email(); 717 std::string email = chromeos::GetUserManager()->GetActiveUser()->email();
719 if (params->source == get_thumbnail::Params::SOURCE_ONLINE) { 718 if (params->source == get_thumbnail::Params::SOURCE_ONLINE) {
720 std::string file_name = GURL(params->url_or_file).ExtractFileName(); 719 std::string file_name = GURL(params->url_or_file).ExtractFileName();
721 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPER_THUMBNAILS, 720 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPER_THUMBNAILS,
722 &thumbnail_path)); 721 &thumbnail_path));
723 thumbnail_path = thumbnail_path.Append(file_name); 722 thumbnail_path = thumbnail_path.Append(file_name);
724 } else { 723 } else {
725 if (!IsOEMDefaultWallpaper()) { 724 if (!IsOEMDefaultWallpaper()) {
726 SetError("No OEM wallpaper."); 725 SetError("No OEM wallpaper.");
727 SendResponse(false); 726 SendResponse(false);
728 return false; 727 return false;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 this, file_list)); 885 this, file_list));
887 } 886 }
888 887
889 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( 888 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete(
890 const std::vector<std::string>& file_list) { 889 const std::vector<std::string>& file_list) {
891 base::ListValue* results = new base::ListValue(); 890 base::ListValue* results = new base::ListValue();
892 results->AppendStrings(file_list); 891 results->AppendStrings(file_list);
893 SetResult(results); 892 SetResult(results);
894 SendResponse(true); 893 SendResponse(true);
895 } 894 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698