| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/wallpaper/wallpaper_manager_base.h" | 5 #include "components/wallpaper/wallpaper_manager_base.h" |
| 6 | 6 |
| 7 #include <numeric> | 7 #include <numeric> |
| 8 #include <vector> | 8 #include <vector> |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 info.type = user_manager::User::POLICY; | 466 info.type = user_manager::User::POLICY; |
| 467 SetUserWallpaperInfo(account_id, info, true /* is_persistent */); | 467 SetUserWallpaperInfo(account_id, info, true /* is_persistent */); |
| 468 } | 468 } |
| 469 | 469 |
| 470 void WallpaperManagerBase::OnPolicyCleared(const std::string& policy, | 470 void WallpaperManagerBase::OnPolicyCleared(const std::string& policy, |
| 471 const AccountId& account_id) { | 471 const AccountId& account_id) { |
| 472 WallpaperInfo info; | 472 WallpaperInfo info; |
| 473 GetUserWallpaperInfo(account_id, &info); | 473 GetUserWallpaperInfo(account_id, &info); |
| 474 info.type = user_manager::User::DEFAULT; | 474 info.type = user_manager::User::DEFAULT; |
| 475 SetUserWallpaperInfo(account_id, info, true /* is_persistent */); | 475 SetUserWallpaperInfo(account_id, info, true /* is_persistent */); |
| 476 SetDefaultWallpaperNow(account_id); | 476 // If the user's policy is cleared, try to set the device wallpaper first. |
| 477 // Note We have to modify the user wallpaper info first. Otherwise, we won't |
| 478 // be able to override the current user policy wallpaper. The wallpaper info |
| 479 // will be set correctly if the device wallpaper is set successfully. |
| 480 if (!SetDeviceWallpaperIfApplicable(account_id)) { |
| 481 SetDefaultWallpaperNow(account_id); |
| 482 } |
| 477 } | 483 } |
| 478 | 484 |
| 479 // static | 485 // static |
| 480 base::FilePath WallpaperManagerBase::GetCustomWallpaperPath( | 486 base::FilePath WallpaperManagerBase::GetCustomWallpaperPath( |
| 481 const char* sub_dir, | 487 const char* sub_dir, |
| 482 const wallpaper::WallpaperFilesId& wallpaper_files_id, | 488 const wallpaper::WallpaperFilesId& wallpaper_files_id, |
| 483 const std::string& file) { | 489 const std::string& file) { |
| 484 base::FilePath custom_wallpaper_path = GetCustomWallpaperDir(sub_dir); | 490 base::FilePath custom_wallpaper_path = GetCustomWallpaperDir(sub_dir); |
| 485 return custom_wallpaper_path.Append(wallpaper_files_id.id()).Append(file); | 491 return custom_wallpaper_path.Append(wallpaper_files_id.id()).Append(file); |
| 486 } | 492 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 } | 614 } |
| 609 } | 615 } |
| 610 | 616 |
| 611 void WallpaperManagerBase::InitInitialUserWallpaper(const AccountId& account_id, | 617 void WallpaperManagerBase::InitInitialUserWallpaper(const AccountId& account_id, |
| 612 bool is_persistent) { | 618 bool is_persistent) { |
| 613 current_user_wallpaper_info_.location = ""; | 619 current_user_wallpaper_info_.location = ""; |
| 614 current_user_wallpaper_info_.layout = WALLPAPER_LAYOUT_CENTER_CROPPED; | 620 current_user_wallpaper_info_.layout = WALLPAPER_LAYOUT_CENTER_CROPPED; |
| 615 current_user_wallpaper_info_.type = user_manager::User::DEFAULT; | 621 current_user_wallpaper_info_.type = user_manager::User::DEFAULT; |
| 616 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight(); | 622 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight(); |
| 617 | 623 |
| 624 std::string device_wallpaper_url; |
| 625 std::string device_wallpaper_hash; |
| 626 if (ShouldSetDeviceWallpaper(account_id, &device_wallpaper_url, |
| 627 &device_wallpaper_hash)) { |
| 628 current_user_wallpaper_info_.location = |
| 629 GetDeviceWallpaperFilePath().value(); |
| 630 current_user_wallpaper_info_.type = user_manager::User::DEVICE; |
| 631 } |
| 632 |
| 618 WallpaperInfo info = current_user_wallpaper_info_; | 633 WallpaperInfo info = current_user_wallpaper_info_; |
| 619 SetUserWallpaperInfo(account_id, info, is_persistent); | 634 SetUserWallpaperInfo(account_id, info, is_persistent); |
| 620 } | 635 } |
| 621 | 636 |
| 622 void WallpaperManagerBase::SetUserWallpaperDelayed( | 637 void WallpaperManagerBase::SetUserWallpaperDelayed( |
| 623 const AccountId& account_id) { | 638 const AccountId& account_id) { |
| 624 ScheduleSetUserWallpaper(account_id, true); | 639 ScheduleSetUserWallpaper(account_id, true); |
| 625 } | 640 } |
| 626 | 641 |
| 627 void WallpaperManagerBase::SetUserWallpaperNow(const AccountId& account_id) { | 642 void WallpaperManagerBase::SetUserWallpaperNow(const AccountId& account_id) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 if (it != wallpaper_cache_.end() && !it->second.second.isNull()) | 716 if (it != wallpaper_cache_.end() && !it->second.second.isNull()) |
| 702 return; | 717 return; |
| 703 WallpaperInfo info; | 718 WallpaperInfo info; |
| 704 if (GetUserWallpaperInfo(account_id, &info)) { | 719 if (GetUserWallpaperInfo(account_id, &info)) { |
| 705 if (info.location.empty()) | 720 if (info.location.empty()) |
| 706 return; | 721 return; |
| 707 | 722 |
| 708 base::FilePath wallpaper_dir; | 723 base::FilePath wallpaper_dir; |
| 709 base::FilePath wallpaper_path; | 724 base::FilePath wallpaper_path; |
| 710 if (info.type == user_manager::User::CUSTOMIZED || | 725 if (info.type == user_manager::User::CUSTOMIZED || |
| 711 info.type == user_manager::User::POLICY) { | 726 info.type == user_manager::User::POLICY || |
| 712 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); | 727 info.type == user_manager::User::DEVICE) { |
| 713 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); | 728 base::FilePath wallpaper_path; |
| 714 wallpaper_path = wallpaper_path.Append(info.location); | 729 if (info.type == user_manager::User::DEVICE) { |
| 730 wallpaper_path = GetDeviceWallpaperFilePath(); |
| 731 } else { |
| 732 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); |
| 733 wallpaper_path = GetCustomWallpaperDir(sub_dir).Append(info.location); |
| 734 } |
| 715 // Set the path to the cache. | 735 // Set the path to the cache. |
| 716 wallpaper_cache_[account_id] = | 736 wallpaper_cache_[account_id] = |
| 717 CustomWallpaperElement(wallpaper_path, gfx::ImageSkia()); | 737 CustomWallpaperElement(wallpaper_path, gfx::ImageSkia()); |
| 718 task_runner_->PostTask( | 738 task_runner_->PostTask( |
| 719 FROM_HERE, | 739 FROM_HERE, |
| 720 base::Bind(&WallpaperManagerBase::GetCustomWallpaperInternal, | 740 base::Bind(&WallpaperManagerBase::GetCustomWallpaperInternal, |
| 721 account_id, info, wallpaper_path, | 741 account_id, info, wallpaper_path, |
| 722 false /* do not update wallpaper */, | 742 false /* do not update wallpaper */, |
| 723 base::ThreadTaskRunnerHandle::Get(), | 743 base::ThreadTaskRunnerHandle::Get(), |
| 724 base::Passed(MovableOnDestroyCallbackHolder()), | 744 base::Passed(MovableOnDestroyCallbackHolder()), |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 void WallpaperManagerBase::CreateSolidDefaultWallpaper() { | 1039 void WallpaperManagerBase::CreateSolidDefaultWallpaper() { |
| 1020 loaded_wallpapers_for_test_++; | 1040 loaded_wallpapers_for_test_++; |
| 1021 SkBitmap bitmap; | 1041 SkBitmap bitmap; |
| 1022 bitmap.allocN32Pixels(1, 1); | 1042 bitmap.allocN32Pixels(1, 1); |
| 1023 bitmap.eraseColor(kDefaultWallpaperColor); | 1043 bitmap.eraseColor(kDefaultWallpaperColor); |
| 1024 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 1044 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 1025 default_wallpaper_image_.reset(new user_manager::UserImage(image)); | 1045 default_wallpaper_image_.reset(new user_manager::UserImage(image)); |
| 1026 } | 1046 } |
| 1027 | 1047 |
| 1028 } // namespace wallpaper | 1048 } // namespace wallpaper |
| OLD | NEW |