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/login/wallpaper_manager.h" | 5 #include "chrome/browser/chromeos/login/wallpaper_manager.h" |
6 | 6 |
7 #include <numeric> | 7 #include <numeric> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "base/prefs/pref_service.h" | 22 #include "base/prefs/pref_service.h" |
23 #include "base/prefs/scoped_user_pref_update.h" | 23 #include "base/prefs/scoped_user_pref_update.h" |
24 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
25 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
26 #include "base/strings/stringprintf.h" | 26 #include "base/strings/stringprintf.h" |
27 #include "base/threading/worker_pool.h" | 27 #include "base/threading/worker_pool.h" |
28 #include "base/time/time.h" | 28 #include "base/time/time.h" |
29 #include "base/values.h" | 29 #include "base/values.h" |
30 #include "chrome/browser/browser_process.h" | 30 #include "chrome/browser/browser_process.h" |
31 #include "chrome/browser/chrome_notification_types.h" | 31 #include "chrome/browser/chrome_notification_types.h" |
| 32 #include "chrome/browser/chromeos/customization_document.h" |
32 #include "chrome/browser/chromeos/extensions/wallpaper_manager_util.h" | 33 #include "chrome/browser/chromeos/extensions/wallpaper_manager_util.h" |
33 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h" | 34 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h" |
34 #include "chrome/browser/chromeos/login/login_display_host_impl.h" | 35 #include "chrome/browser/chromeos/login/login_display_host_impl.h" |
35 #include "chrome/browser/chromeos/login/startup_utils.h" | 36 #include "chrome/browser/chromeos/login/startup_utils.h" |
36 #include "chrome/browser/chromeos/login/user.h" | 37 #include "chrome/browser/chromeos/login/user.h" |
37 #include "chrome/browser/chromeos/login/user_manager.h" | 38 #include "chrome/browser/chromeos/login/user_manager.h" |
38 #include "chrome/browser/chromeos/login/wizard_controller.h" | 39 #include "chrome/browser/chromeos/login/wizard_controller.h" |
39 #include "chrome/browser/chromeos/settings/cros_settings.h" | 40 #include "chrome/browser/chromeos/settings/cros_settings.h" |
40 #include "chrome/browser/extensions/extension_service.h" | 41 #include "chrome/browser/extensions/extension_service.h" |
41 #include "chrome/common/chrome_paths.h" | 42 #include "chrome/common/chrome_paths.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 const std::string& user_id, | 117 const std::string& user_id, |
117 const std::string& user_id_hash) { | 118 const std::string& user_id_hash) { |
118 base::FilePath base_path = GetCustomWallpaperDir(sub_dir); | 119 base::FilePath base_path = GetCustomWallpaperDir(sub_dir); |
119 base::FilePath to_path = base_path.Append(user_id_hash); | 120 base::FilePath to_path = base_path.Append(user_id_hash); |
120 base::FilePath from_path = base_path.Append(user_id); | 121 base::FilePath from_path = base_path.Append(user_id); |
121 if (base::PathExists(from_path)) | 122 if (base::PathExists(from_path)) |
122 return base::Move(from_path, to_path); | 123 return base::Move(from_path, to_path); |
123 return false; | 124 return false; |
124 } | 125 } |
125 | 126 |
| 127 // These global default values are used to set customized default |
| 128 // wallpaper path in WallpaperManager::InitializeWallpaper(). |
| 129 base::FilePath GetCustomizedWallpaperDefaultRescaledFileName( |
| 130 const std::string& suffix) { |
| 131 const base::FilePath default_downloaded_file_name = |
| 132 ServicesCustomizationDocument::GetCustomizedWallpaperDownloadedFileName(); |
| 133 const base::FilePath default_cache_dir = |
| 134 ServicesCustomizationDocument::GetCustomizedWallpaperCacheDir(); |
| 135 if (default_downloaded_file_name.empty() || default_cache_dir.empty()) |
| 136 return base::FilePath(); |
| 137 return default_cache_dir.Append( |
| 138 default_downloaded_file_name.BaseName().value() + suffix); |
| 139 } |
| 140 |
| 141 // Whether DesktopBackgroundController should start with customized default |
| 142 // wallpaper in WallpaperManager::InitializeWallpaper() or not. |
| 143 bool ShouldUseCustomizedDefaultWallpaper() { |
| 144 PrefService* pref_service = g_browser_process->local_state(); |
| 145 |
| 146 return !(pref_service->FindPreference( |
| 147 prefs::kCustomizationDefaultWallpaperURL) |
| 148 ->IsDefaultValue()); |
| 149 } |
| 150 |
126 } // namespace | 151 } // namespace |
127 | 152 |
128 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence"; | 153 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence"; |
129 | 154 |
130 const char kSmallWallpaperSuffix[] = "_small"; | 155 const char kSmallWallpaperSuffix[] = "_small"; |
131 const char kLargeWallpaperSuffix[] = "_large"; | 156 const char kLargeWallpaperSuffix[] = "_large"; |
132 | 157 |
133 const char kSmallWallpaperSubDir[] = "small"; | 158 const char kSmallWallpaperSubDir[] = "small"; |
134 const char kLargeWallpaperSubDir[] = "large"; | 159 const char kLargeWallpaperSubDir[] = "large"; |
135 const char kOriginalWallpaperSubDir[] = "original"; | 160 const char kOriginalWallpaperSubDir[] = "original"; |
136 const char kThumbnailWallpaperSubDir[] = "thumb"; | 161 const char kThumbnailWallpaperSubDir[] = "thumb"; |
137 | 162 |
138 const int kSmallWallpaperMaxWidth = 1366; | 163 const int kSmallWallpaperMaxWidth = 1366; |
139 const int kSmallWallpaperMaxHeight = 800; | 164 const int kSmallWallpaperMaxHeight = 800; |
140 const int kLargeWallpaperMaxWidth = 2560; | 165 const int kLargeWallpaperMaxWidth = 2560; |
141 const int kLargeWallpaperMaxHeight = 1700; | 166 const int kLargeWallpaperMaxHeight = 1700; |
142 const int kWallpaperThumbnailWidth = 108; | 167 const int kWallpaperThumbnailWidth = 108; |
143 const int kWallpaperThumbnailHeight = 68; | 168 const int kWallpaperThumbnailHeight = 68; |
144 | 169 |
145 static WallpaperManager* g_wallpaper_manager = NULL; | 170 static WallpaperManager* g_wallpaper_manager = NULL; |
146 | 171 |
| 172 class WallpaperManager::CustomizedWallpaperRescaledFiles { |
| 173 public: |
| 174 CustomizedWallpaperRescaledFiles(const base::FilePath& path_downloaded, |
| 175 const base::FilePath& path_rescaled_small, |
| 176 const base::FilePath& path_rescaled_large); |
| 177 |
| 178 bool AllSizesExist() const; |
| 179 |
| 180 // Closure will hold unretained pointer to this object. So caller must |
| 181 // make sure that the closure will be destoyed before this object. |
| 182 // Closure must be called on BlockingPool. |
| 183 base::Closure CreateCheckerClosure(); |
| 184 |
| 185 const base::FilePath& path_downloaded() const { return path_downloaded_; } |
| 186 const base::FilePath& path_rescaled_small() const { |
| 187 return path_rescaled_small_; |
| 188 } |
| 189 const base::FilePath& path_rescaled_large() const { |
| 190 return path_rescaled_large_; |
| 191 } |
| 192 |
| 193 const bool downloaded_exists() const { return downloaded_exists_; } |
| 194 const bool rescaled_small_exists() const { return rescaled_small_exists_; } |
| 195 const bool rescaled_large_exists() const { return rescaled_large_exists_; } |
| 196 |
| 197 private: |
| 198 // Must be called on BlockingPool. |
| 199 void CheckCustomizedWallpaperFilesExist(); |
| 200 |
| 201 const base::FilePath path_downloaded_; |
| 202 const base::FilePath path_rescaled_small_; |
| 203 const base::FilePath path_rescaled_large_; |
| 204 |
| 205 bool downloaded_exists_; |
| 206 bool rescaled_small_exists_; |
| 207 bool rescaled_large_exists_; |
| 208 |
| 209 DISALLOW_COPY_AND_ASSIGN(CustomizedWallpaperRescaledFiles); |
| 210 }; |
| 211 |
| 212 WallpaperManager::CustomizedWallpaperRescaledFiles:: |
| 213 CustomizedWallpaperRescaledFiles(const base::FilePath& path_downloaded, |
| 214 const base::FilePath& path_rescaled_small, |
| 215 const base::FilePath& path_rescaled_large) |
| 216 : path_downloaded_(path_downloaded), |
| 217 path_rescaled_small_(path_rescaled_small), |
| 218 path_rescaled_large_(path_rescaled_large), |
| 219 downloaded_exists_(false), |
| 220 rescaled_small_exists_(false), |
| 221 rescaled_large_exists_(false) { |
| 222 } |
| 223 |
| 224 base::Closure |
| 225 WallpaperManager::CustomizedWallpaperRescaledFiles::CreateCheckerClosure() { |
| 226 return base::Bind(&WallpaperManager::CustomizedWallpaperRescaledFiles:: |
| 227 CheckCustomizedWallpaperFilesExist, |
| 228 base::Unretained(this)); |
| 229 } |
| 230 |
| 231 void WallpaperManager::CustomizedWallpaperRescaledFiles:: |
| 232 CheckCustomizedWallpaperFilesExist() { |
| 233 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 234 downloaded_exists_ = base::PathExists(path_downloaded_); |
| 235 rescaled_small_exists_ = base::PathExists(path_rescaled_small_); |
| 236 rescaled_large_exists_ = base::PathExists(path_rescaled_large_); |
| 237 } |
| 238 |
| 239 bool WallpaperManager::CustomizedWallpaperRescaledFiles::AllSizesExist() const { |
| 240 return rescaled_small_exists_ && rescaled_large_exists_; |
| 241 } |
| 242 |
147 // This object is passed between several threads while wallpaper is being | 243 // This object is passed between several threads while wallpaper is being |
148 // loaded. It will notify callback when last reference to it is removed | 244 // loaded. It will notify callback when last reference to it is removed |
149 // (thus indicating that the last load action has finished). | 245 // (thus indicating that the last load action has finished). |
150 class MovableOnDestroyCallback { | 246 class MovableOnDestroyCallback { |
151 public: | 247 public: |
152 explicit MovableOnDestroyCallback(const base::Closure& callback) | 248 explicit MovableOnDestroyCallback(const base::Closure& callback) |
153 : callback_(callback) { | 249 : callback_(callback) { |
154 } | 250 } |
155 | 251 |
156 ~MovableOnDestroyCallback() { | 252 ~MovableOnDestroyCallback() { |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 } | 539 } |
444 | 540 |
445 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(), | 541 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(), |
446 info); | 542 info); |
447 } | 543 } |
448 | 544 |
449 void WallpaperManager::InitializeWallpaper() { | 545 void WallpaperManager::InitializeWallpaper() { |
450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
451 UserManager* user_manager = UserManager::Get(); | 547 UserManager* user_manager = UserManager::Get(); |
452 | 548 |
| 549 // Apply device customization. |
| 550 if (ShouldUseCustomizedDefaultWallpaper()) { |
| 551 SetDefaultWallpaperPath( |
| 552 GetCustomizedWallpaperDefaultRescaledFileName(kSmallWallpaperSuffix), |
| 553 scoped_ptr<gfx::ImageSkia>().Pass(), |
| 554 GetCustomizedWallpaperDefaultRescaledFileName(kLargeWallpaperSuffix), |
| 555 scoped_ptr<gfx::ImageSkia>().Pass()); |
| 556 } |
| 557 |
453 CommandLine* command_line = GetCommandLine(); | 558 CommandLine* command_line = GetCommandLine(); |
454 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) { | 559 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) { |
455 // Guest wallpaper should be initialized when guest login. | 560 // Guest wallpaper should be initialized when guest login. |
456 // Note: This maybe called before login. So IsLoggedInAsGuest can not be | 561 // Note: This maybe called before login. So IsLoggedInAsGuest can not be |
457 // used here to determine if current user is guest. | 562 // used here to determine if current user is guest. |
458 return; | 563 return; |
459 } | 564 } |
460 | 565 |
461 if (command_line->HasSwitch(::switches::kTestType)) | 566 if (command_line->HasSwitch(::switches::kTestType)) |
462 WizardController::SetZeroDelays(); | 567 WizardController::SetZeroDelays(); |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 use_small ? &guest_small_wallpaper_file_ : &guest_large_wallpaper_file_; | 901 use_small ? &guest_small_wallpaper_file_ : &guest_large_wallpaper_file_; |
797 } else { | 902 } else { |
798 file = use_small ? &default_small_wallpaper_file_ | 903 file = use_small ? &default_small_wallpaper_file_ |
799 : &default_large_wallpaper_file_; | 904 : &default_large_wallpaper_file_; |
800 } | 905 } |
801 const ash::WallpaperLayout layout = | 906 const ash::WallpaperLayout layout = |
802 use_small ? ash::WALLPAPER_LAYOUT_CENTER | 907 use_small ? ash::WALLPAPER_LAYOUT_CENTER |
803 : ash::WALLPAPER_LAYOUT_CENTER_CROPPED; | 908 : ash::WALLPAPER_LAYOUT_CENTER_CROPPED; |
804 DCHECK(file); | 909 DCHECK(file); |
805 if (!default_wallpaper_image_.get() || | 910 if (!default_wallpaper_image_.get() || |
806 default_wallpaper_image_->url().spec() != file->value()) { | 911 default_wallpaper_image_->file_path() != file->value()) { |
807 default_wallpaper_image_.reset(); | 912 default_wallpaper_image_.reset(); |
808 if (!file->empty()) { | 913 if (!file->empty()) { |
809 loaded_wallpapers_++; | 914 loaded_wallpapers_++; |
810 StartLoadAndSetDefaultWallpaper( | 915 StartLoadAndSetDefaultWallpaper( |
811 *file, layout, on_finish.Pass(), &default_wallpaper_image_); | 916 *file, layout, on_finish.Pass(), &default_wallpaper_image_); |
812 return; | 917 return; |
813 } | 918 } |
814 | 919 |
815 const int resource_id = use_small ? IDR_AURA_WALLPAPER_DEFAULT_SMALL | 920 const int resource_id = use_small ? IDR_AURA_WALLPAPER_DEFAULT_SMALL |
816 : IDR_AURA_WALLPAPER_DEFAULT_LARGE; | 921 : IDR_AURA_WALLPAPER_DEFAULT_LARGE; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 } | 1083 } |
979 | 1084 |
980 void WallpaperManager::RemoveObserver(WallpaperManager::Observer* observer) { | 1085 void WallpaperManager::RemoveObserver(WallpaperManager::Observer* observer) { |
981 observers_.RemoveObserver(observer); | 1086 observers_.RemoveObserver(observer); |
982 } | 1087 } |
983 | 1088 |
984 void WallpaperManager::EnableSurpriseMe() { | 1089 void WallpaperManager::EnableSurpriseMe() { |
985 Profile* profile = ProfileManager::GetActiveUserProfile(); | 1090 Profile* profile = ProfileManager::GetActiveUserProfile(); |
986 DCHECK(profile); | 1091 DCHECK(profile); |
987 DCHECK(extensions::EventRouter::Get(profile)); | 1092 DCHECK(extensions::EventRouter::Get(profile)); |
| 1093 |
| 1094 using namespace extensions::api::wallpaper_private; |
988 scoped_ptr<extensions::Event> event( | 1095 scoped_ptr<extensions::Event> event( |
989 new extensions::Event( | 1096 new extensions::Event(OnRequestEnableSurpriseMe::kEventName, |
990 extensions::api::wallpaper_private::OnRequestEnableSurpriseMe::kEventName, | 1097 OnRequestEnableSurpriseMe::Create())); |
991 extensions::api::wallpaper_private::OnRequestEnableSurpriseMe::Create())); | |
992 | 1098 |
993 extensions::EventRouter::Get(profile)->DispatchEventToExtension( | 1099 extensions::EventRouter::Get(profile)->DispatchEventToExtension( |
994 extension_misc::kWallpaperManagerId, event.Pass()); | 1100 extension_misc::kWallpaperManagerId, event.Pass()); |
995 } | 1101 } |
996 | 1102 |
997 void WallpaperManager::NotifyAnimationFinished() { | 1103 void WallpaperManager::NotifyAnimationFinished() { |
998 FOR_EACH_OBSERVER( | 1104 FOR_EACH_OBSERVER( |
999 Observer, observers_, OnWallpaperAnimationFinished(last_selected_user_)); | 1105 Observer, observers_, OnWallpaperAnimationFinished(last_selected_user_)); |
1000 } | 1106 } |
1001 | 1107 |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1532 if (!last_load_finished_at_.is_null()) { | 1638 if (!last_load_finished_at_.is_null()) { |
1533 const base::TimeDelta interval = base::Time::Now() - last_load_finished_at_; | 1639 const base::TimeDelta interval = base::Time::Now() - last_load_finished_at_; |
1534 if (interval > delay) | 1640 if (interval > delay) |
1535 delay = base::TimeDelta::FromMilliseconds(0); | 1641 delay = base::TimeDelta::FromMilliseconds(0); |
1536 else if (interval > base::TimeDelta::FromMilliseconds(0)) | 1642 else if (interval > base::TimeDelta::FromMilliseconds(0)) |
1537 delay -= interval; | 1643 delay -= interval; |
1538 } | 1644 } |
1539 return delay; | 1645 return delay; |
1540 } | 1646 } |
1541 | 1647 |
| 1648 void WallpaperManager::SetCustomizedDefaultWallpaperAfterCheck( |
| 1649 const GURL& wallpaper_url, |
| 1650 const base::FilePath& downloaded_file, |
| 1651 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files) { |
| 1652 PrefService* pref_service = g_browser_process->local_state(); |
| 1653 |
| 1654 std::string current_url = |
| 1655 pref_service->GetString(prefs::kCustomizationDefaultWallpaperURL); |
| 1656 if (current_url != wallpaper_url.spec() || !rescaled_files->AllSizesExist()) { |
| 1657 DCHECK(rescaled_files->downloaded_exists()); |
| 1658 |
| 1659 // Either resized images do not exist or cached version is incorrect. |
| 1660 // Need to start resize again. |
| 1661 wallpaper_loader_->Start( |
| 1662 downloaded_file.value(), |
| 1663 0, // Do not crop. |
| 1664 base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperDecoded, |
| 1665 weak_factory_.GetWeakPtr(), |
| 1666 wallpaper_url, |
| 1667 base::Passed(rescaled_files.Pass()))); |
| 1668 } else { |
| 1669 SetDefaultWallpaperPath(rescaled_files->path_rescaled_small(), |
| 1670 scoped_ptr<gfx::ImageSkia>().Pass(), |
| 1671 rescaled_files->path_rescaled_large(), |
| 1672 scoped_ptr<gfx::ImageSkia>().Pass()); |
| 1673 } |
| 1674 } |
| 1675 |
| 1676 void WallpaperManager::OnCustomizedDefaultWallpaperDecoded( |
| 1677 const GURL& wallpaper_url, |
| 1678 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, |
| 1679 const UserImage& wallpaper) { |
| 1680 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1681 |
| 1682 // If decoded wallpaper is empty, we have probably failed to decode the file. |
| 1683 if (wallpaper.image().isNull()) { |
| 1684 LOG(WARNING) << "Failed to decode customized wallpaper."; |
| 1685 return; |
| 1686 } |
| 1687 |
| 1688 wallpaper.image().EnsureRepsForSupportedScales(); |
| 1689 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy()); |
| 1690 |
| 1691 scoped_ptr<bool> success(new bool(false)); |
| 1692 scoped_ptr<gfx::ImageSkia> small_wallpaper_image(new gfx::ImageSkia); |
| 1693 scoped_ptr<gfx::ImageSkia> large_wallpaper_image(new gfx::ImageSkia); |
| 1694 |
| 1695 // TODO(bshe): This may break if RawImage becomes RefCountedMemory. |
| 1696 base::Closure resize_closure = |
| 1697 base::Bind(&WallpaperManager::ResizeCustomizedDefaultWallpaper, |
| 1698 base::Unretained(this), |
| 1699 base::Passed(&deep_copy), |
| 1700 wallpaper.raw_image(), |
| 1701 base::Unretained(rescaled_files.get()), |
| 1702 base::Unretained(success.get()), |
| 1703 base::Unretained(small_wallpaper_image.get()), |
| 1704 base::Unretained(large_wallpaper_image.get())); |
| 1705 base::Closure on_resized_closure = |
| 1706 base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperResized, |
| 1707 weak_factory_.GetWeakPtr(), |
| 1708 wallpaper_url, |
| 1709 base::Passed(rescaled_files.Pass()), |
| 1710 base::Passed(success.Pass()), |
| 1711 base::Passed(small_wallpaper_image.Pass()), |
| 1712 base::Passed(large_wallpaper_image.Pass())); |
| 1713 |
| 1714 if (!task_runner_->PostTaskAndReply( |
| 1715 FROM_HERE, resize_closure, on_resized_closure)) { |
| 1716 LOG(WARNING) << "Failed to start Customized Wallpaper resize."; |
| 1717 } |
| 1718 } |
| 1719 |
| 1720 void WallpaperManager::ResizeCustomizedDefaultWallpaper( |
| 1721 scoped_ptr<gfx::ImageSkia> image, |
| 1722 const UserImage::RawImage& raw_image, |
| 1723 const CustomizedWallpaperRescaledFiles* rescaled_files, |
| 1724 bool* success, |
| 1725 gfx::ImageSkia* small_wallpaper_image, |
| 1726 gfx::ImageSkia* large_wallpaper_image) { |
| 1727 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
| 1728 sequence_token_)); |
| 1729 UserImage wallpaper(*image.get(), raw_image); |
| 1730 |
| 1731 *success = true; |
| 1732 |
| 1733 *success &= ResizeAndSaveWallpaper(wallpaper, |
| 1734 rescaled_files->path_rescaled_small(), |
| 1735 ash::WALLPAPER_LAYOUT_STRETCH, |
| 1736 kSmallWallpaperMaxWidth, |
| 1737 kSmallWallpaperMaxHeight, |
| 1738 small_wallpaper_image); |
| 1739 |
| 1740 *success &= ResizeAndSaveWallpaper(wallpaper, |
| 1741 rescaled_files->path_rescaled_large(), |
| 1742 ash::WALLPAPER_LAYOUT_STRETCH, |
| 1743 kLargeWallpaperMaxWidth, |
| 1744 kLargeWallpaperMaxHeight, |
| 1745 large_wallpaper_image); |
| 1746 } |
| 1747 |
| 1748 void WallpaperManager::OnCustomizedDefaultWallpaperResized( |
| 1749 const GURL& wallpaper_url, |
| 1750 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, |
| 1751 scoped_ptr<bool> success, |
| 1752 scoped_ptr<gfx::ImageSkia> small_wallpaper_image, |
| 1753 scoped_ptr<gfx::ImageSkia> large_wallpaper_image) { |
| 1754 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1755 DCHECK(rescaled_files); |
| 1756 DCHECK(success.get()); |
| 1757 if (!*success) { |
| 1758 LOG(WARNING) << "Failed to save resized customized default wallpaper"; |
| 1759 return; |
| 1760 } |
| 1761 PrefService* pref_service = g_browser_process->local_state(); |
| 1762 pref_service->SetString(prefs::kCustomizationDefaultWallpaperURL, |
| 1763 wallpaper_url.spec()); |
| 1764 SetDefaultWallpaperPath(rescaled_files->path_rescaled_small(), |
| 1765 small_wallpaper_image.Pass(), |
| 1766 rescaled_files->path_rescaled_large(), |
| 1767 large_wallpaper_image.Pass()); |
| 1768 VLOG(1) << "Customized default wallpaper applied."; |
| 1769 } |
| 1770 |
1542 WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper( | 1771 WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper( |
1543 const std::string& user_id, | 1772 const std::string& user_id, |
1544 bool delayed) { | 1773 bool delayed) { |
1545 if (!pending_inactive_) { | 1774 if (!pending_inactive_) { |
1546 loading_.push_back(new WallpaperManager::PendingWallpaper( | 1775 loading_.push_back(new WallpaperManager::PendingWallpaper( |
1547 (delayed ? GetWallpaperLoadDelay() | 1776 (delayed ? GetWallpaperLoadDelay() |
1548 : base::TimeDelta::FromMilliseconds(0)), | 1777 : base::TimeDelta::FromMilliseconds(0)), |
1549 user_id)); | 1778 user_id)); |
1550 pending_inactive_ = loading_.back(); | 1779 pending_inactive_ = loading_.back(); |
1551 } | 1780 } |
1552 return pending_inactive_; | 1781 return pending_inactive_; |
1553 } | 1782 } |
1554 | 1783 |
| 1784 void WallpaperManager::SetCustomizedDefaultWallpaper( |
| 1785 const GURL& wallpaper_url, |
| 1786 const base::FilePath& downloaded_file, |
| 1787 const base::FilePath& resized_directory) { |
| 1788 // Should fail if this ever happens in tests. |
| 1789 DCHECK(wallpaper_url.is_valid()); |
| 1790 if (!wallpaper_url.is_valid()) { |
| 1791 if (!wallpaper_url.is_empty()) { |
| 1792 LOG(WARNING) << "Invalid Customized Wallpaper URL '" |
| 1793 << wallpaper_url.spec() << "'"; |
| 1794 } |
| 1795 return; |
| 1796 } |
| 1797 std::string downloaded_file_name = downloaded_file.BaseName().value(); |
| 1798 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files( |
| 1799 new CustomizedWallpaperRescaledFiles( |
| 1800 downloaded_file, |
| 1801 resized_directory.Append(downloaded_file_name + |
| 1802 kSmallWallpaperSuffix), |
| 1803 resized_directory.Append(downloaded_file_name + |
| 1804 kLargeWallpaperSuffix))); |
| 1805 |
| 1806 base::Closure check_file_exists = rescaled_files->CreateCheckerClosure(); |
| 1807 base::Closure on_checked_closure = |
| 1808 base::Bind(&WallpaperManager::SetCustomizedDefaultWallpaperAfterCheck, |
| 1809 weak_factory_.GetWeakPtr(), |
| 1810 wallpaper_url, |
| 1811 downloaded_file, |
| 1812 base::Passed(rescaled_files.Pass())); |
| 1813 if (!BrowserThread::PostBlockingPoolTaskAndReply( |
| 1814 FROM_HERE, check_file_exists, on_checked_closure)) { |
| 1815 LOG(WARNING) << "Failed to start check CheckCustomizedWallpaperFilesExist."; |
| 1816 } |
| 1817 } |
| 1818 |
1555 void WallpaperManager::SetDefaultWallpaperPathsFromCommandLine( | 1819 void WallpaperManager::SetDefaultWallpaperPathsFromCommandLine( |
1556 base::CommandLine* command_line) { | 1820 base::CommandLine* command_line) { |
1557 default_small_wallpaper_file_ = command_line->GetSwitchValuePath( | 1821 default_small_wallpaper_file_ = command_line->GetSwitchValuePath( |
1558 ash::switches::kAshDefaultWallpaperSmall); | 1822 ash::switches::kAshDefaultWallpaperSmall); |
1559 default_large_wallpaper_file_ = command_line->GetSwitchValuePath( | 1823 default_large_wallpaper_file_ = command_line->GetSwitchValuePath( |
1560 ash::switches::kAshDefaultWallpaperLarge); | 1824 ash::switches::kAshDefaultWallpaperLarge); |
1561 guest_small_wallpaper_file_ = | 1825 guest_small_wallpaper_file_ = |
1562 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperSmall); | 1826 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperSmall); |
1563 guest_large_wallpaper_file_ = | 1827 guest_large_wallpaper_file_ = |
1564 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperLarge); | 1828 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperLarge); |
1565 default_wallpaper_image_.reset(); | 1829 default_wallpaper_image_.reset(); |
1566 } | 1830 } |
1567 | 1831 |
1568 void WallpaperManager::OnDefaultWallpaperDecoded( | 1832 void WallpaperManager::OnDefaultWallpaperDecoded( |
1569 const base::FilePath& path, | 1833 const base::FilePath& path, |
1570 const ash::WallpaperLayout layout, | 1834 const ash::WallpaperLayout layout, |
1571 scoped_ptr<chromeos::UserImage>* result_out, | 1835 scoped_ptr<chromeos::UserImage>* result_out, |
1572 MovableOnDestroyCallbackHolder on_finish, | 1836 MovableOnDestroyCallbackHolder on_finish, |
1573 const UserImage& wallpaper) { | 1837 const UserImage& wallpaper) { |
1574 result_out->reset(new UserImage(wallpaper.image())); | 1838 result_out->reset(new UserImage(wallpaper)); |
1575 (*result_out)->set_url(GURL(path.value())); | |
1576 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( | 1839 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( |
1577 wallpaper.image(), layout); | 1840 wallpaper.image(), layout); |
1578 } | 1841 } |
1579 | 1842 |
1580 void WallpaperManager::StartLoadAndSetDefaultWallpaper( | 1843 void WallpaperManager::StartLoadAndSetDefaultWallpaper( |
1581 const base::FilePath& path, | 1844 const base::FilePath& path, |
1582 const ash::WallpaperLayout layout, | 1845 const ash::WallpaperLayout layout, |
1583 MovableOnDestroyCallbackHolder on_finish, | 1846 MovableOnDestroyCallbackHolder on_finish, |
1584 scoped_ptr<chromeos::UserImage>* result_out) { | 1847 scoped_ptr<chromeos::UserImage>* result_out) { |
1585 wallpaper_loader_->Start( | 1848 wallpaper_loader_->Start( |
1586 path.value(), | 1849 path.value(), |
1587 0, // Do not crop. | 1850 0, // Do not crop. |
1588 base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded, | 1851 base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded, |
1589 weak_factory_.GetWeakPtr(), | 1852 weak_factory_.GetWeakPtr(), |
1590 path, | 1853 path, |
1591 layout, | 1854 layout, |
1592 base::Unretained(result_out), | 1855 base::Unretained(result_out), |
1593 base::Passed(on_finish.Pass()))); | 1856 base::Passed(on_finish.Pass()))); |
1594 } | 1857 } |
1595 | 1858 |
1596 const char* WallpaperManager::GetCustomWallpaperSubdirForCurrentResolution() { | 1859 const char* WallpaperManager::GetCustomWallpaperSubdirForCurrentResolution() { |
1597 WallpaperResolution resolution = GetAppropriateResolution(); | 1860 WallpaperResolution resolution = GetAppropriateResolution(); |
1598 return resolution == WALLPAPER_RESOLUTION_SMALL ? kSmallWallpaperSubDir | 1861 return resolution == WALLPAPER_RESOLUTION_SMALL ? kSmallWallpaperSubDir |
1599 : kLargeWallpaperSubDir; | 1862 : kLargeWallpaperSubDir; |
1600 } | 1863 } |
1601 | 1864 |
| 1865 void WallpaperManager::SetDefaultWallpaperPath( |
| 1866 const base::FilePath& default_small_wallpaper_file, |
| 1867 scoped_ptr<gfx::ImageSkia> small_wallpaper_image, |
| 1868 const base::FilePath& default_large_wallpaper_file, |
| 1869 scoped_ptr<gfx::ImageSkia> large_wallpaper_image) { |
| 1870 default_small_wallpaper_file_ = default_small_wallpaper_file; |
| 1871 default_large_wallpaper_file_ = default_large_wallpaper_file; |
| 1872 |
| 1873 ash::DesktopBackgroundController* dbc = |
| 1874 ash::Shell::GetInstance()->desktop_background_controller(); |
| 1875 |
| 1876 // |need_update_screen| is true if the previous default wallpaper is visible |
| 1877 // now, so we need to update wallpaper on the screen. |
| 1878 // |
| 1879 // Layout is ignored here, so ash::WALLPAPER_LAYOUT_CENTER is used |
| 1880 // as a placeholder only. |
| 1881 const bool need_update_screen = |
| 1882 default_wallpaper_image_.get() && |
| 1883 dbc->WallpaperIsAlreadyLoaded( |
| 1884 &(default_wallpaper_image_->image()), |
| 1885 ash::DesktopBackgroundController::kInvalidResourceID, |
| 1886 false /* compare_layouts */, |
| 1887 ash::WALLPAPER_LAYOUT_CENTER); |
| 1888 |
| 1889 default_wallpaper_image_.reset(); |
| 1890 if (GetAppropriateResolution() == WALLPAPER_RESOLUTION_SMALL) { |
| 1891 if (small_wallpaper_image) { |
| 1892 default_wallpaper_image_.reset(new UserImage(*small_wallpaper_image)); |
| 1893 default_wallpaper_image_->set_file_path( |
| 1894 default_small_wallpaper_file.value()); |
| 1895 } |
| 1896 } else { |
| 1897 if (large_wallpaper_image) { |
| 1898 default_wallpaper_image_.reset(new UserImage(*large_wallpaper_image)); |
| 1899 default_wallpaper_image_->set_file_path( |
| 1900 default_large_wallpaper_file.value()); |
| 1901 } |
| 1902 } |
| 1903 |
| 1904 if (need_update_screen) { |
| 1905 DoSetDefaultWallpaper(std::string(), |
| 1906 MovableOnDestroyCallbackHolder().Pass()); |
| 1907 } |
| 1908 } |
| 1909 |
1602 } // namespace chromeos | 1910 } // namespace chromeos |
OLD | NEW |