Chromium Code Reviews| 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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)); |
| 988 scoped_ptr<extensions::Event> event( | 1093 scoped_ptr<extensions::Event> event( |
| 989 new extensions::Event( | 1094 new extensions::Event( |
| 990 extensions::api::wallpaper_private::OnRequestEnableSurpriseMe::kEventName, | 1095 extensions::api::wallpaper_private::OnRequestEnableSurpriseMe::kEventName, |
|
Daniel Erat
2014/04/19 14:24:08
i don't think that this is from your change (i'm j
Alexander Alekseev
2014/04/21 16:49:41
Done.
| |
| 991 extensions::api::wallpaper_private::OnRequestEnableSurpriseMe::Create())); | 1096 extensions::api::wallpaper_private::OnRequestEnableSurpriseMe::Create())); |
| 992 | 1097 |
| 993 extensions::EventRouter::Get(profile)->DispatchEventToExtension( | 1098 extensions::EventRouter::Get(profile)->DispatchEventToExtension( |
| 994 extension_misc::kWallpaperManagerId, event.Pass()); | 1099 extension_misc::kWallpaperManagerId, event.Pass()); |
| 995 } | 1100 } |
| 996 | 1101 |
| 997 void WallpaperManager::NotifyAnimationFinished() { | 1102 void WallpaperManager::NotifyAnimationFinished() { |
| 998 FOR_EACH_OBSERVER( | 1103 FOR_EACH_OBSERVER( |
| 999 Observer, observers_, OnWallpaperAnimationFinished(last_selected_user_)); | 1104 Observer, observers_, OnWallpaperAnimationFinished(last_selected_user_)); |
| 1000 } | 1105 } |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1532 if (!last_load_finished_at_.is_null()) { | 1637 if (!last_load_finished_at_.is_null()) { |
| 1533 const base::TimeDelta interval = base::Time::Now() - last_load_finished_at_; | 1638 const base::TimeDelta interval = base::Time::Now() - last_load_finished_at_; |
| 1534 if (interval > delay) | 1639 if (interval > delay) |
| 1535 delay = base::TimeDelta::FromMilliseconds(0); | 1640 delay = base::TimeDelta::FromMilliseconds(0); |
| 1536 else if (interval > base::TimeDelta::FromMilliseconds(0)) | 1641 else if (interval > base::TimeDelta::FromMilliseconds(0)) |
| 1537 delay -= interval; | 1642 delay -= interval; |
| 1538 } | 1643 } |
| 1539 return delay; | 1644 return delay; |
| 1540 } | 1645 } |
| 1541 | 1646 |
| 1647 void WallpaperManager::SetCustomizedDefaultWallpaperAfterCheck( | |
| 1648 const GURL& wallpaper_url, | |
| 1649 const base::FilePath& downloaded_file, | |
| 1650 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files) { | |
| 1651 PrefService* pref_service = g_browser_process->local_state(); | |
| 1652 | |
| 1653 std::string current_url = | |
| 1654 pref_service->GetString(prefs::kCustomizationDefaultWallpaperURL); | |
| 1655 if (current_url != wallpaper_url.spec() || !rescaled_files->AllSizesExist()) { | |
| 1656 DCHECK(rescaled_files->downloaded_exists()); | |
| 1657 | |
| 1658 // Either resized images do not exist or cached version is incorrect. | |
| 1659 // Need to start resize again. | |
| 1660 wallpaper_loader_->Start( | |
| 1661 downloaded_file.value(), | |
| 1662 0, // Do not crop. | |
| 1663 base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperDecoded, | |
| 1664 weak_factory_.GetWeakPtr(), | |
| 1665 wallpaper_url, | |
| 1666 base::Passed(rescaled_files.Pass()))); | |
| 1667 } else { | |
| 1668 SetDefaultWallpaperPath(rescaled_files->path_rescaled_small(), | |
| 1669 scoped_ptr<gfx::ImageSkia>().Pass(), | |
| 1670 rescaled_files->path_rescaled_large(), | |
| 1671 scoped_ptr<gfx::ImageSkia>().Pass()); | |
| 1672 } | |
| 1673 } | |
| 1674 | |
| 1675 void WallpaperManager::OnCustomizedDefaultWallpaperDecoded( | |
| 1676 const GURL& wallpaper_url, | |
| 1677 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | |
| 1678 const UserImage& wallpaper) { | |
| 1679 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1680 | |
| 1681 // If decoded wallpaper is empty, we have probably failed to decode the file. | |
| 1682 if (wallpaper.image().isNull()) { | |
| 1683 LOG(WARNING) << "Failed to decode customized wallpaper."; | |
| 1684 return; | |
| 1685 } | |
| 1686 | |
| 1687 wallpaper.image().EnsureRepsForSupportedScales(); | |
| 1688 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy()); | |
| 1689 | |
| 1690 scoped_ptr<bool> success(new bool(false)); | |
| 1691 scoped_ptr<gfx::ImageSkia> small_wallpaper_image(new gfx::ImageSkia); | |
| 1692 scoped_ptr<gfx::ImageSkia> large_wallpaper_image(new gfx::ImageSkia); | |
| 1693 | |
| 1694 // TODO(bshe): This may break if RawImage becomes RefCountedMemory. | |
| 1695 base::Closure resize_closure = | |
| 1696 base::Bind(&WallpaperManager::ResizeCustomizedDefaultWallpaper, | |
| 1697 base::Unretained(this), | |
| 1698 base::Passed(&deep_copy), | |
| 1699 wallpaper.raw_image(), | |
| 1700 base::Unretained(rescaled_files.get()), | |
| 1701 base::Unretained(success.get()), | |
| 1702 base::Unretained(small_wallpaper_image.get()), | |
| 1703 base::Unretained(large_wallpaper_image.get())); | |
| 1704 base::Closure on_resized_closure = | |
| 1705 base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperResized, | |
| 1706 weak_factory_.GetWeakPtr(), | |
| 1707 wallpaper_url, | |
| 1708 base::Passed(rescaled_files.Pass()), | |
| 1709 base::Passed(success.Pass()), | |
| 1710 base::Passed(small_wallpaper_image.Pass()), | |
| 1711 base::Passed(large_wallpaper_image.Pass())); | |
| 1712 | |
| 1713 if (!task_runner_->PostTaskAndReply( | |
| 1714 FROM_HERE, resize_closure, on_resized_closure)) { | |
| 1715 LOG(WARNING) << "Failed to start Customized Wallpaper resize."; | |
| 1716 } | |
| 1717 } | |
| 1718 | |
| 1719 void WallpaperManager::ResizeCustomizedDefaultWallpaper( | |
| 1720 scoped_ptr<gfx::ImageSkia> image, | |
| 1721 const UserImage::RawImage& raw_image, | |
| 1722 const CustomizedWallpaperRescaledFiles* rescaled_files, | |
| 1723 bool* success, | |
| 1724 gfx::ImageSkia* small_wallpaper_image, | |
| 1725 gfx::ImageSkia* large_wallpaper_image) { | |
| 1726 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | |
| 1727 sequence_token_)); | |
| 1728 UserImage wallpaper(*image.get(), raw_image); | |
| 1729 | |
| 1730 *success = true; | |
| 1731 | |
| 1732 *success &= ResizeAndSaveWallpaper(wallpaper, | |
| 1733 rescaled_files->path_rescaled_small(), | |
| 1734 ash::WALLPAPER_LAYOUT_STRETCH, | |
| 1735 kSmallWallpaperMaxWidth, | |
| 1736 kSmallWallpaperMaxHeight, | |
| 1737 small_wallpaper_image); | |
| 1738 | |
| 1739 *success &= ResizeAndSaveWallpaper(wallpaper, | |
| 1740 rescaled_files->path_rescaled_large(), | |
| 1741 ash::WALLPAPER_LAYOUT_STRETCH, | |
| 1742 kLargeWallpaperMaxWidth, | |
| 1743 kLargeWallpaperMaxHeight, | |
| 1744 large_wallpaper_image); | |
| 1745 } | |
| 1746 | |
| 1747 void WallpaperManager::OnCustomizedDefaultWallpaperResized( | |
| 1748 const GURL& wallpaper_url, | |
| 1749 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | |
| 1750 scoped_ptr<bool> success, | |
| 1751 scoped_ptr<gfx::ImageSkia> small_wallpaper_image, | |
| 1752 scoped_ptr<gfx::ImageSkia> large_wallpaper_image) { | |
| 1753 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1754 DCHECK(rescaled_files); | |
| 1755 DCHECK(success.get()); | |
| 1756 if (!*success) { | |
| 1757 LOG(WARNING) << "Failed to save resized customized default wallpaper"; | |
| 1758 return; | |
| 1759 } | |
| 1760 PrefService* pref_service = g_browser_process->local_state(); | |
| 1761 pref_service->SetString(prefs::kCustomizationDefaultWallpaperURL, | |
| 1762 wallpaper_url.spec()); | |
| 1763 SetDefaultWallpaperPath(rescaled_files->path_rescaled_small(), | |
| 1764 small_wallpaper_image.Pass(), | |
| 1765 rescaled_files->path_rescaled_large(), | |
| 1766 large_wallpaper_image.Pass()); | |
| 1767 VLOG(1) << "Customized default wallpaper applied."; | |
| 1768 } | |
| 1769 | |
| 1542 WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper( | 1770 WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper( |
| 1543 const std::string& user_id, | 1771 const std::string& user_id, |
| 1544 bool delayed) { | 1772 bool delayed) { |
| 1545 if (!pending_inactive_) { | 1773 if (!pending_inactive_) { |
| 1546 loading_.push_back(new WallpaperManager::PendingWallpaper( | 1774 loading_.push_back(new WallpaperManager::PendingWallpaper( |
| 1547 (delayed ? GetWallpaperLoadDelay() | 1775 (delayed ? GetWallpaperLoadDelay() |
| 1548 : base::TimeDelta::FromMilliseconds(0)), | 1776 : base::TimeDelta::FromMilliseconds(0)), |
| 1549 user_id)); | 1777 user_id)); |
| 1550 pending_inactive_ = loading_.back(); | 1778 pending_inactive_ = loading_.back(); |
| 1551 } | 1779 } |
| 1552 return pending_inactive_; | 1780 return pending_inactive_; |
| 1553 } | 1781 } |
| 1554 | 1782 |
| 1783 void WallpaperManager::SetCustomizedDefaultWallpaper( | |
| 1784 const GURL& wallpaper_url, | |
| 1785 const base::FilePath& downloaded_file, | |
| 1786 const base::FilePath& resized_directory) { | |
| 1787 // Should fail if this ever happens in tests. | |
| 1788 DCHECK(wallpaper_url.is_valid()); | |
| 1789 if (!wallpaper_url.is_valid()) { | |
| 1790 if (!wallpaper_url.is_empty()) { | |
| 1791 LOG(WARNING) << "Invalid Customized Wallpaper URL '" | |
| 1792 << wallpaper_url.spec() << "'"; | |
| 1793 } | |
| 1794 return; | |
| 1795 } | |
| 1796 std::string downloaded_file_name = downloaded_file.BaseName().value(); | |
| 1797 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files( | |
| 1798 new CustomizedWallpaperRescaledFiles( | |
| 1799 downloaded_file, | |
| 1800 resized_directory.Append(downloaded_file_name + | |
| 1801 kSmallWallpaperSuffix), | |
| 1802 resized_directory.Append(downloaded_file_name + | |
| 1803 kLargeWallpaperSuffix))); | |
| 1804 | |
| 1805 base::Closure check_file_exists = rescaled_files->CreateCheckerClosure(); | |
| 1806 base::Closure on_checked_closure = | |
| 1807 base::Bind(&WallpaperManager::SetCustomizedDefaultWallpaperAfterCheck, | |
| 1808 weak_factory_.GetWeakPtr(), | |
| 1809 wallpaper_url, | |
| 1810 downloaded_file, | |
| 1811 base::Passed(rescaled_files.Pass())); | |
| 1812 if (!BrowserThread::PostBlockingPoolTaskAndReply( | |
| 1813 FROM_HERE, check_file_exists, on_checked_closure)) { | |
| 1814 LOG(WARNING) << "Failed to start check CheckCustomizedWallpaperFilesExist."; | |
| 1815 } | |
| 1816 } | |
| 1817 | |
| 1555 void WallpaperManager::SetDefaultWallpaperPathsFromCommandLine( | 1818 void WallpaperManager::SetDefaultWallpaperPathsFromCommandLine( |
| 1556 base::CommandLine* command_line) { | 1819 base::CommandLine* command_line) { |
| 1557 default_small_wallpaper_file_ = command_line->GetSwitchValuePath( | 1820 default_small_wallpaper_file_ = command_line->GetSwitchValuePath( |
| 1558 ash::switches::kAshDefaultWallpaperSmall); | 1821 ash::switches::kAshDefaultWallpaperSmall); |
| 1559 default_large_wallpaper_file_ = command_line->GetSwitchValuePath( | 1822 default_large_wallpaper_file_ = command_line->GetSwitchValuePath( |
| 1560 ash::switches::kAshDefaultWallpaperLarge); | 1823 ash::switches::kAshDefaultWallpaperLarge); |
| 1561 guest_small_wallpaper_file_ = | 1824 guest_small_wallpaper_file_ = |
| 1562 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperSmall); | 1825 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperSmall); |
| 1563 guest_large_wallpaper_file_ = | 1826 guest_large_wallpaper_file_ = |
| 1564 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperLarge); | 1827 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperLarge); |
| 1565 default_wallpaper_image_.reset(); | 1828 default_wallpaper_image_.reset(); |
| 1566 } | 1829 } |
| 1567 | 1830 |
| 1568 void WallpaperManager::OnDefaultWallpaperDecoded( | 1831 void WallpaperManager::OnDefaultWallpaperDecoded( |
| 1569 const base::FilePath& path, | 1832 const base::FilePath& path, |
| 1570 const ash::WallpaperLayout layout, | 1833 const ash::WallpaperLayout layout, |
| 1571 scoped_ptr<chromeos::UserImage>* result_out, | 1834 scoped_ptr<chromeos::UserImage>* result_out, |
| 1572 MovableOnDestroyCallbackHolder on_finish, | 1835 MovableOnDestroyCallbackHolder on_finish, |
| 1573 const UserImage& wallpaper) { | 1836 const UserImage& wallpaper) { |
| 1574 result_out->reset(new UserImage(wallpaper.image())); | 1837 result_out->reset(new UserImage(wallpaper)); |
| 1575 (*result_out)->set_url(GURL(path.value())); | |
| 1576 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( | 1838 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( |
| 1577 wallpaper.image(), layout); | 1839 wallpaper.image(), layout); |
| 1578 } | 1840 } |
| 1579 | 1841 |
| 1580 void WallpaperManager::StartLoadAndSetDefaultWallpaper( | 1842 void WallpaperManager::StartLoadAndSetDefaultWallpaper( |
| 1581 const base::FilePath& path, | 1843 const base::FilePath& path, |
| 1582 const ash::WallpaperLayout layout, | 1844 const ash::WallpaperLayout layout, |
| 1583 MovableOnDestroyCallbackHolder on_finish, | 1845 MovableOnDestroyCallbackHolder on_finish, |
| 1584 scoped_ptr<chromeos::UserImage>* result_out) { | 1846 scoped_ptr<chromeos::UserImage>* result_out) { |
| 1585 wallpaper_loader_->Start( | 1847 wallpaper_loader_->Start( |
| 1586 path.value(), | 1848 path.value(), |
| 1587 0, // Do not crop. | 1849 0, // Do not crop. |
| 1588 base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded, | 1850 base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded, |
| 1589 weak_factory_.GetWeakPtr(), | 1851 weak_factory_.GetWeakPtr(), |
| 1590 path, | 1852 path, |
| 1591 layout, | 1853 layout, |
| 1592 base::Unretained(result_out), | 1854 base::Unretained(result_out), |
| 1593 base::Passed(on_finish.Pass()))); | 1855 base::Passed(on_finish.Pass()))); |
| 1594 } | 1856 } |
| 1595 | 1857 |
| 1596 const char* WallpaperManager::GetCustomWallpaperSubdirForCurrentResolution() { | 1858 const char* WallpaperManager::GetCustomWallpaperSubdirForCurrentResolution() { |
| 1597 WallpaperResolution resolution = GetAppropriateResolution(); | 1859 WallpaperResolution resolution = GetAppropriateResolution(); |
| 1598 return resolution == WALLPAPER_RESOLUTION_SMALL ? kSmallWallpaperSubDir | 1860 return resolution == WALLPAPER_RESOLUTION_SMALL ? kSmallWallpaperSubDir |
| 1599 : kLargeWallpaperSubDir; | 1861 : kLargeWallpaperSubDir; |
| 1600 } | 1862 } |
| 1601 | 1863 |
| 1864 void WallpaperManager::SetDefaultWallpaperPath( | |
| 1865 const base::FilePath& default_small_wallpaper_file, | |
| 1866 scoped_ptr<gfx::ImageSkia> small_wallpaper_image, | |
| 1867 const base::FilePath& default_large_wallpaper_file, | |
| 1868 scoped_ptr<gfx::ImageSkia> large_wallpaper_image) { | |
| 1869 default_small_wallpaper_file_ = default_small_wallpaper_file; | |
| 1870 default_large_wallpaper_file_ = default_large_wallpaper_file; | |
| 1871 | |
| 1872 ash::DesktopBackgroundController* dbc = | |
| 1873 ash::Shell::GetInstance()->desktop_background_controller(); | |
| 1874 | |
| 1875 // |need_update_screen| is true if the previous default wallpaper is visible | |
| 1876 // now, so we need to update wallpaper on the screen. | |
| 1877 // | |
| 1878 // Layout is ignored here, so ash::WALLPAPER_LAYOUT_CENTER is used | |
| 1879 // as a placeholder only. | |
| 1880 const bool need_update_screen = | |
| 1881 default_wallpaper_image_.get() && | |
| 1882 dbc->WallpaperIsAlreadyLoaded( | |
| 1883 &(default_wallpaper_image_->image()), | |
| 1884 ash::DesktopBackgroundController::kInvalidResourceID, | |
| 1885 false /* compare_layouts */, | |
| 1886 ash::WALLPAPER_LAYOUT_CENTER); | |
| 1887 | |
| 1888 default_wallpaper_image_.reset(); | |
| 1889 if (GetAppropriateResolution() == WALLPAPER_RESOLUTION_SMALL) { | |
| 1890 if (small_wallpaper_image) { | |
| 1891 default_wallpaper_image_.reset(new UserImage(*small_wallpaper_image)); | |
| 1892 default_wallpaper_image_->set_file_path( | |
| 1893 default_small_wallpaper_file.value()); | |
| 1894 } | |
| 1895 } else { | |
| 1896 if (large_wallpaper_image) { | |
| 1897 default_wallpaper_image_.reset(new UserImage(*large_wallpaper_image)); | |
| 1898 default_wallpaper_image_->set_file_path( | |
| 1899 default_large_wallpaper_file.value()); | |
| 1900 } | |
| 1901 } | |
| 1902 | |
| 1903 if (need_update_screen) { | |
| 1904 DoSetDefaultWallpaper(std::string(), | |
| 1905 MovableOnDestroyCallbackHolder().Pass()); | |
| 1906 } | |
| 1907 } | |
| 1908 | |
| 1602 } // namespace chromeos | 1909 } // namespace chromeos |
| OLD | NEW |