OLD | NEW |
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 <map> | 7 #include <map> |
| 8 #include <memory> |
8 #include <set> | 9 #include <set> |
9 #include <string> | 10 #include <string> |
10 #include <utility> | 11 #include <utility> |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "ash/desktop_background/desktop_background_controller.h" | 14 #include "ash/desktop_background/desktop_background_controller.h" |
14 #include "ash/shell.h" | 15 #include "ash/shell.h" |
15 #include "ash/wm/mru_window_tracker.h" | 16 #include "ash/wm/mru_window_tracker.h" |
16 #include "ash/wm/window_state.h" | 17 #include "ash/wm/window_state.h" |
17 #include "ash/wm/window_util.h" | 18 #include "ash/wm/window_util.h" |
18 #include "base/command_line.h" | 19 #include "base/command_line.h" |
19 #include "base/files/file_enumerator.h" | 20 #include "base/files/file_enumerator.h" |
20 #include "base/files/file_util.h" | 21 #include "base/files/file_util.h" |
21 #include "base/macros.h" | 22 #include "base/macros.h" |
22 #include "base/memory/ref_counted_memory.h" | 23 #include "base/memory/ref_counted_memory.h" |
23 #include "base/memory/scoped_ptr.h" | |
24 #include "base/metrics/histogram_macros.h" | 24 #include "base/metrics/histogram_macros.h" |
25 #include "base/path_service.h" | 25 #include "base/path_service.h" |
26 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
27 #include "base/strings/stringprintf.h" | 27 #include "base/strings/stringprintf.h" |
28 #include "base/threading/worker_pool.h" | 28 #include "base/threading/worker_pool.h" |
29 #include "chrome/browser/browser_process.h" | 29 #include "chrome/browser/browser_process.h" |
30 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 30 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
31 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 31 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
32 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
33 #include "chrome/browser/sync/profile_sync_service_factory.h" | 33 #include "chrome/browser/sync/profile_sync_service_factory.h" |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 task_runner->PostTask(FROM_HERE, | 506 task_runner->PostTask(FROM_HERE, |
507 base::Bind(&WallpaperPrivateSetWallpaperFunction::SaveToFile, this)); | 507 base::Bind(&WallpaperPrivateSetWallpaperFunction::SaveToFile, this)); |
508 } | 508 } |
509 | 509 |
510 void WallpaperPrivateSetWallpaperFunction::SaveToFile() { | 510 void WallpaperPrivateSetWallpaperFunction::SaveToFile() { |
511 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | 511 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
512 sequence_token_)); | 512 sequence_token_)); |
513 std::string file_name = GURL(params->url).ExtractFileName(); | 513 std::string file_name = GURL(params->url).ExtractFileName(); |
514 if (SaveData(chrome::DIR_CHROMEOS_WALLPAPERS, file_name, params->wallpaper)) { | 514 if (SaveData(chrome::DIR_CHROMEOS_WALLPAPERS, file_name, params->wallpaper)) { |
515 wallpaper_.EnsureRepsForSupportedScales(); | 515 wallpaper_.EnsureRepsForSupportedScales(); |
516 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper_.DeepCopy()); | 516 std::unique_ptr<gfx::ImageSkia> deep_copy(wallpaper_.DeepCopy()); |
517 // ImageSkia is not RefCountedThreadSafe. Use a deep copied ImageSkia if | 517 // ImageSkia is not RefCountedThreadSafe. Use a deep copied ImageSkia if |
518 // post to another thread. | 518 // post to another thread. |
519 BrowserThread::PostTask( | 519 BrowserThread::PostTask( |
520 BrowserThread::UI, FROM_HERE, | 520 BrowserThread::UI, FROM_HERE, |
521 base::Bind(&WallpaperPrivateSetWallpaperFunction::SetDecodedWallpaper, | 521 base::Bind(&WallpaperPrivateSetWallpaperFunction::SetDecodedWallpaper, |
522 this, base::Passed(std::move(deep_copy)))); | 522 this, base::Passed(std::move(deep_copy)))); |
523 | 523 |
524 base::FilePath wallpaper_dir; | 524 base::FilePath wallpaper_dir; |
525 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)); | 525 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)); |
526 base::FilePath file_path = | 526 base::FilePath file_path = |
(...skipping 11 matching lines...) Expand all Loading... |
538 std::string error = base::StringPrintf( | 538 std::string error = base::StringPrintf( |
539 "Failed to create/write wallpaper to %s.", file_name.c_str()); | 539 "Failed to create/write wallpaper to %s.", file_name.c_str()); |
540 BrowserThread::PostTask( | 540 BrowserThread::PostTask( |
541 BrowserThread::UI, FROM_HERE, | 541 BrowserThread::UI, FROM_HERE, |
542 base::Bind(&WallpaperPrivateSetWallpaperFunction::OnFailure, | 542 base::Bind(&WallpaperPrivateSetWallpaperFunction::OnFailure, |
543 this, error)); | 543 this, error)); |
544 } | 544 } |
545 } | 545 } |
546 | 546 |
547 void WallpaperPrivateSetWallpaperFunction::SetDecodedWallpaper( | 547 void WallpaperPrivateSetWallpaperFunction::SetDecodedWallpaper( |
548 scoped_ptr<gfx::ImageSkia> image) { | 548 std::unique_ptr<gfx::ImageSkia> image) { |
549 chromeos::WallpaperManager* wallpaper_manager = | 549 chromeos::WallpaperManager* wallpaper_manager = |
550 chromeos::WallpaperManager::Get(); | 550 chromeos::WallpaperManager::Get(); |
551 | 551 |
552 wallpaper::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( | 552 wallpaper::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( |
553 wallpaper_base::ToString(params->layout)); | 553 wallpaper_base::ToString(params->layout)); |
554 | 554 |
555 bool update_wallpaper = | 555 bool update_wallpaper = |
556 account_id_ == | 556 account_id_ == |
557 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId(); | 557 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId(); |
558 wallpaper_manager->SetWallpaperFromImageSkia(account_id_, *image.get(), | 558 wallpaper_manager->SetWallpaperFromImageSkia(account_id_, *image.get(), |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 unsafe_wallpaper_decoder_ = NULL; | 656 unsafe_wallpaper_decoder_ = NULL; |
657 | 657 |
658 Profile* profile = Profile::FromBrowserContext(browser_context()); | 658 Profile* profile = Profile::FromBrowserContext(browser_context()); |
659 // TODO(xdai): This preference is unused now. For compatiblity concern, we | 659 // TODO(xdai): This preference is unused now. For compatiblity concern, we |
660 // need to keep it until it's safe to clean it up. | 660 // need to keep it until it's safe to clean it up. |
661 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, | 661 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, |
662 std::string()); | 662 std::string()); |
663 | 663 |
664 if (params->generate_thumbnail) { | 664 if (params->generate_thumbnail) { |
665 image.EnsureRepsForSupportedScales(); | 665 image.EnsureRepsForSupportedScales(); |
666 scoped_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy()); | 666 std::unique_ptr<gfx::ImageSkia> deep_copy(image.DeepCopy()); |
667 // Generates thumbnail before call api function callback. We can then | 667 // Generates thumbnail before call api function callback. We can then |
668 // request thumbnail in the javascript callback. | 668 // request thumbnail in the javascript callback. |
669 task_runner->PostTask(FROM_HERE, | 669 task_runner->PostTask(FROM_HERE, |
670 base::Bind( | 670 base::Bind( |
671 &WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail, | 671 &WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail, |
672 this, thumbnail_path, base::Passed(&deep_copy))); | 672 this, thumbnail_path, base::Passed(&deep_copy))); |
673 } else { | 673 } else { |
674 SendResponse(true); | 674 SendResponse(true); |
675 } | 675 } |
676 } | 676 } |
677 | 677 |
678 void WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail( | 678 void WallpaperPrivateSetCustomWallpaperFunction::GenerateThumbnail( |
679 const base::FilePath& thumbnail_path, scoped_ptr<gfx::ImageSkia> image) { | 679 const base::FilePath& thumbnail_path, |
| 680 std::unique_ptr<gfx::ImageSkia> image) { |
680 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | 681 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
681 sequence_token_)); | 682 sequence_token_)); |
682 if (!base::PathExists(thumbnail_path.DirName())) | 683 if (!base::PathExists(thumbnail_path.DirName())) |
683 base::CreateDirectory(thumbnail_path.DirName()); | 684 base::CreateDirectory(thumbnail_path.DirName()); |
684 | 685 |
685 scoped_refptr<base::RefCountedBytes> data; | 686 scoped_refptr<base::RefCountedBytes> data; |
686 chromeos::WallpaperManager::Get()->ResizeImage( | 687 chromeos::WallpaperManager::Get()->ResizeImage( |
687 *image, wallpaper::WALLPAPER_LAYOUT_STRETCH, | 688 *image, wallpaper::WALLPAPER_LAYOUT_STRETCH, |
688 wallpaper::kWallpaperThumbnailWidth, wallpaper::kWallpaperThumbnailHeight, | 689 wallpaper::kWallpaperThumbnailWidth, wallpaper::kWallpaperThumbnailHeight, |
689 &data, NULL); | 690 &data, NULL); |
(...skipping 12 matching lines...) Expand all Loading... |
702 SendResponse(true); | 703 SendResponse(true); |
703 } | 704 } |
704 | 705 |
705 WallpaperPrivateSetCustomWallpaperLayoutFunction:: | 706 WallpaperPrivateSetCustomWallpaperLayoutFunction:: |
706 WallpaperPrivateSetCustomWallpaperLayoutFunction() {} | 707 WallpaperPrivateSetCustomWallpaperLayoutFunction() {} |
707 | 708 |
708 WallpaperPrivateSetCustomWallpaperLayoutFunction:: | 709 WallpaperPrivateSetCustomWallpaperLayoutFunction:: |
709 ~WallpaperPrivateSetCustomWallpaperLayoutFunction() {} | 710 ~WallpaperPrivateSetCustomWallpaperLayoutFunction() {} |
710 | 711 |
711 bool WallpaperPrivateSetCustomWallpaperLayoutFunction::RunAsync() { | 712 bool WallpaperPrivateSetCustomWallpaperLayoutFunction::RunAsync() { |
712 scoped_ptr<set_custom_wallpaper_layout::Params> params( | 713 std::unique_ptr<set_custom_wallpaper_layout::Params> params( |
713 set_custom_wallpaper_layout::Params::Create(*args_)); | 714 set_custom_wallpaper_layout::Params::Create(*args_)); |
714 EXTENSION_FUNCTION_VALIDATE(params); | 715 EXTENSION_FUNCTION_VALIDATE(params); |
715 | 716 |
716 chromeos::WallpaperManager* wallpaper_manager = | 717 chromeos::WallpaperManager* wallpaper_manager = |
717 chromeos::WallpaperManager::Get(); | 718 chromeos::WallpaperManager::Get(); |
718 wallpaper::WallpaperInfo info; | 719 wallpaper::WallpaperInfo info; |
719 wallpaper_manager->GetLoggedInUserWallpaperInfo(&info); | 720 wallpaper_manager->GetLoggedInUserWallpaperInfo(&info); |
720 if (info.type != user_manager::User::CUSTOMIZED) { | 721 if (info.type != user_manager::User::CUSTOMIZED) { |
721 SetError("Only custom wallpaper can change layout."); | 722 SetError("Only custom wallpaper can change layout."); |
722 SendResponse(false); | 723 SendResponse(false); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 return true; | 766 return true; |
766 } | 767 } |
767 | 768 |
768 WallpaperPrivateGetThumbnailFunction::WallpaperPrivateGetThumbnailFunction() { | 769 WallpaperPrivateGetThumbnailFunction::WallpaperPrivateGetThumbnailFunction() { |
769 } | 770 } |
770 | 771 |
771 WallpaperPrivateGetThumbnailFunction::~WallpaperPrivateGetThumbnailFunction() { | 772 WallpaperPrivateGetThumbnailFunction::~WallpaperPrivateGetThumbnailFunction() { |
772 } | 773 } |
773 | 774 |
774 bool WallpaperPrivateGetThumbnailFunction::RunAsync() { | 775 bool WallpaperPrivateGetThumbnailFunction::RunAsync() { |
775 scoped_ptr<get_thumbnail::Params> params( | 776 std::unique_ptr<get_thumbnail::Params> params( |
776 get_thumbnail::Params::Create(*args_)); | 777 get_thumbnail::Params::Create(*args_)); |
777 EXTENSION_FUNCTION_VALIDATE(params); | 778 EXTENSION_FUNCTION_VALIDATE(params); |
778 | 779 |
779 base::FilePath thumbnail_path; | 780 base::FilePath thumbnail_path; |
780 if (params->source == wallpaper_private::WALLPAPER_SOURCE_ONLINE) { | 781 if (params->source == wallpaper_private::WALLPAPER_SOURCE_ONLINE) { |
781 std::string file_name = GURL(params->url_or_file).ExtractFileName(); | 782 std::string file_name = GURL(params->url_or_file).ExtractFileName(); |
782 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPER_THUMBNAILS, | 783 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPER_THUMBNAILS, |
783 &thumbnail_path)); | 784 &thumbnail_path)); |
784 thumbnail_path = thumbnail_path.Append(file_name); | 785 thumbnail_path = thumbnail_path.Append(file_name); |
785 } else { | 786 } else { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 } | 852 } |
852 } | 853 } |
853 | 854 |
854 WallpaperPrivateSaveThumbnailFunction::WallpaperPrivateSaveThumbnailFunction() { | 855 WallpaperPrivateSaveThumbnailFunction::WallpaperPrivateSaveThumbnailFunction() { |
855 } | 856 } |
856 | 857 |
857 WallpaperPrivateSaveThumbnailFunction:: | 858 WallpaperPrivateSaveThumbnailFunction:: |
858 ~WallpaperPrivateSaveThumbnailFunction() {} | 859 ~WallpaperPrivateSaveThumbnailFunction() {} |
859 | 860 |
860 bool WallpaperPrivateSaveThumbnailFunction::RunAsync() { | 861 bool WallpaperPrivateSaveThumbnailFunction::RunAsync() { |
861 scoped_ptr<save_thumbnail::Params> params( | 862 std::unique_ptr<save_thumbnail::Params> params( |
862 save_thumbnail::Params::Create(*args_)); | 863 save_thumbnail::Params::Create(*args_)); |
863 EXTENSION_FUNCTION_VALIDATE(params); | 864 EXTENSION_FUNCTION_VALIDATE(params); |
864 | 865 |
865 sequence_token_ = BrowserThread::GetBlockingPool()->GetNamedSequenceToken( | 866 sequence_token_ = BrowserThread::GetBlockingPool()->GetNamedSequenceToken( |
866 wallpaper::kWallpaperSequenceTokenName); | 867 wallpaper::kWallpaperSequenceTokenName); |
867 scoped_refptr<base::SequencedTaskRunner> task_runner = | 868 scoped_refptr<base::SequencedTaskRunner> task_runner = |
868 BrowserThread::GetBlockingPool()-> | 869 BrowserThread::GetBlockingPool()-> |
869 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, | 870 GetSequencedTaskRunnerWithShutdownBehavior(sequence_token_, |
870 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 871 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
871 | 872 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 bool WallpaperPrivateRecordWallpaperUMAFunction::RunSync() { | 960 bool WallpaperPrivateRecordWallpaperUMAFunction::RunSync() { |
960 scoped_ptr<record_wallpaper_uma::Params> params( | 961 scoped_ptr<record_wallpaper_uma::Params> params( |
961 record_wallpaper_uma::Params::Create(*args_)); | 962 record_wallpaper_uma::Params::Create(*args_)); |
962 EXTENSION_FUNCTION_VALIDATE(params); | 963 EXTENSION_FUNCTION_VALIDATE(params); |
963 | 964 |
964 user_manager::User::WallpaperType source = getWallpaperType(params->source); | 965 user_manager::User::WallpaperType source = getWallpaperType(params->source); |
965 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Source", source, | 966 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Source", source, |
966 user_manager::User::WALLPAPER_TYPE_COUNT); | 967 user_manager::User::WALLPAPER_TYPE_COUNT); |
967 return true; | 968 return true; |
968 } | 969 } |
OLD | NEW |