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

Side by Side Diff: chrome/browser/chromeos/login/wallpaper_manager.cc

Issue 236013002: Apply default wallpaper from customization manifest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved call to EnsureCustomizationAppliedClosure() to a better place. Created 6 years, 8 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
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/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
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/login/startup_utils.h" 33 #include "chrome/browser/chromeos/login/startup_utils.h"
33 #include "chrome/browser/chromeos/login/user.h" 34 #include "chrome/browser/chromeos/login/user.h"
34 #include "chrome/browser/chromeos/login/user_manager.h" 35 #include "chrome/browser/chromeos/login/user_manager.h"
35 #include "chrome/browser/chromeos/login/wizard_controller.h" 36 #include "chrome/browser/chromeos/login/wizard_controller.h"
36 #include "chrome/browser/chromeos/settings/cros_settings.h" 37 #include "chrome/browser/chromeos/settings/cros_settings.h"
37 #include "chrome/common/chrome_paths.h" 38 #include "chrome/common/chrome_paths.h"
38 #include "chrome/common/chrome_switches.h" 39 #include "chrome/common/chrome_switches.h"
39 #include "chrome/common/pref_names.h" 40 #include "chrome/common/pref_names.h"
40 #include "chromeos/chromeos_switches.h" 41 #include "chromeos/chromeos_switches.h"
41 #include "chromeos/dbus/dbus_thread_manager.h" 42 #include "chromeos/dbus/dbus_thread_manager.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 const std::string& user_id, 111 const std::string& user_id,
111 const std::string& user_id_hash) { 112 const std::string& user_id_hash) {
112 base::FilePath base_path = GetCustomWallpaperDir(sub_dir); 113 base::FilePath base_path = GetCustomWallpaperDir(sub_dir);
113 base::FilePath to_path = base_path.Append(user_id_hash); 114 base::FilePath to_path = base_path.Append(user_id_hash);
114 base::FilePath from_path = base_path.Append(user_id); 115 base::FilePath from_path = base_path.Append(user_id);
115 if (base::PathExists(from_path)) 116 if (base::PathExists(from_path))
116 return base::Move(from_path, to_path); 117 return base::Move(from_path, to_path);
117 return false; 118 return false;
118 } 119 }
119 120
121 // These global default values are used to set customized default
122 // wallpaper path in WallpaperManager::InitializeWallpaper().
123 base::FilePath GetCustomizedWallpaperDefaultRescaledFileName(
124 const std::string& suffix) {
125 const base::FilePath default_downloaded_file_name =
126 ServicesCustomizationDocument::GetCustomizedWallpaperDownloadedFileName();
127 const base::FilePath default_cache_dir =
128 ServicesCustomizationDocument::GetCustomizedWallpaperCacheDir();
129 if (default_downloaded_file_name.empty() || default_cache_dir.empty())
130 return base::FilePath();
131 return default_cache_dir.Append(
132 default_downloaded_file_name.BaseName().value() + suffix);
133 }
134
135 // Whether DesktopBackgroundController should start with customized default
136 // wallpaper in WallpaperManager::InitializeWallpaper() or not.
137 bool ShouldUseCustomizedDefaultWallpaper() {
138 PrefService* pref_service = g_browser_process->local_state();
139
140 return !(pref_service->FindPreference(
141 prefs::kCustomizationDefaultWallpaperURL)
142 ->IsDefaultValue());
143 }
144
120 } // namespace 145 } // namespace
121 146
122 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence"; 147 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence";
123 148
124 const char kSmallWallpaperSuffix[] = "_small"; 149 const char kSmallWallpaperSuffix[] = "_small";
125 const char kLargeWallpaperSuffix[] = "_large"; 150 const char kLargeWallpaperSuffix[] = "_large";
126 151
127 const char kSmallWallpaperSubDir[] = "small"; 152 const char kSmallWallpaperSubDir[] = "small";
128 const char kLargeWallpaperSubDir[] = "large"; 153 const char kLargeWallpaperSubDir[] = "large";
129 const char kOriginalWallpaperSubDir[] = "original"; 154 const char kOriginalWallpaperSubDir[] = "original";
130 const char kThumbnailWallpaperSubDir[] = "thumb"; 155 const char kThumbnailWallpaperSubDir[] = "thumb";
131 156
132 const int kSmallWallpaperMaxWidth = 1366; 157 const int kSmallWallpaperMaxWidth = 1366;
133 const int kSmallWallpaperMaxHeight = 800; 158 const int kSmallWallpaperMaxHeight = 800;
134 const int kLargeWallpaperMaxWidth = 2560; 159 const int kLargeWallpaperMaxWidth = 2560;
135 const int kLargeWallpaperMaxHeight = 1700; 160 const int kLargeWallpaperMaxHeight = 1700;
136 const int kWallpaperThumbnailWidth = 108; 161 const int kWallpaperThumbnailWidth = 108;
137 const int kWallpaperThumbnailHeight = 68; 162 const int kWallpaperThumbnailHeight = 68;
138 163
139 static WallpaperManager* g_wallpaper_manager = NULL; 164 static WallpaperManager* g_wallpaper_manager = NULL;
140 165
166 class WallpaperManager::CustomizedWallpaperRescaledFiles {
167 public:
168 CustomizedWallpaperRescaledFiles(const base::FilePath& path_downloaded,
169 const base::FilePath& path_rescaled_small,
170 const base::FilePath& path_rescaled_large);
171
172 bool AllSizesExist() const;
173
174 // Closure will hold unretained pointer to this object. So caller must
175 // make sure that the closure will be destoyed before this object.
176 // Closure must be called on BlockingPool.
177 base::Closure CreateCheckerClosure();
178
179 const base::FilePath& path_downloaded() const { return path_downloaded_; }
180 const base::FilePath& path_rescaled_small() const {
181 return path_rescaled_small_;
182 }
183 const base::FilePath& path_rescaled_large() const {
184 return path_rescaled_large_;
185 }
186
187 const bool downloaded_exists() const { return downloaded_exists_; }
188 const bool rescaled_small_exists() const { return rescaled_small_exists_; }
189 const bool rescaled_large_exists() const { return rescaled_large_exists_; }
190
191 private:
192 // Must be called on BlockingPool.
193 void CheckCustomizedWallpaperFilesExist();
194
195 const base::FilePath path_downloaded_;
196 const base::FilePath path_rescaled_small_;
197 const base::FilePath path_rescaled_large_;
198
199 bool downloaded_exists_;
200 bool rescaled_small_exists_;
201 bool rescaled_large_exists_;
202 };
Daniel Erat 2014/04/17 16:24:22 add DISALLOW_COPY_AND_ASSIGN
Alexander Alekseev 2014/04/17 20:02:56 Done.
203
204 WallpaperManager::CustomizedWallpaperRescaledFiles::
205 CustomizedWallpaperRescaledFiles(const base::FilePath& path_downloaded,
206 const base::FilePath& path_rescaled_small,
207 const base::FilePath& path_rescaled_large)
208 : path_downloaded_(path_downloaded),
209 path_rescaled_small_(path_rescaled_small),
210 path_rescaled_large_(path_rescaled_large),
211 downloaded_exists_(false),
212 rescaled_small_exists_(false),
213 rescaled_large_exists_(false) {
214 }
215
216 base::Closure
217 WallpaperManager::CustomizedWallpaperRescaledFiles::CreateCheckerClosure() {
218 return base::Bind(&WallpaperManager::CustomizedWallpaperRescaledFiles::
219 CheckCustomizedWallpaperFilesExist,
220 base::Unretained(this));
221 }
222
223 void WallpaperManager::CustomizedWallpaperRescaledFiles::
224 CheckCustomizedWallpaperFilesExist() {
225 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
226 downloaded_exists_ = base::PathExists(path_downloaded_);
227 rescaled_small_exists_ = base::PathExists(path_rescaled_small_);
228 rescaled_large_exists_ = base::PathExists(path_rescaled_large_);
229 }
230
231 bool WallpaperManager::CustomizedWallpaperRescaledFiles::AllSizesExist() const {
232 return rescaled_small_exists_ && rescaled_large_exists_;
233 }
234
141 // This object is passed between several threads while wallpaper is being 235 // This object is passed between several threads while wallpaper is being
142 // loaded. It will notify callback when last reference to it is removed 236 // loaded. It will notify callback when last reference to it is removed
143 // (thus indicating that the last load action has finished). 237 // (thus indicating that the last load action has finished).
144 class MovableOnDestroyCallback { 238 class MovableOnDestroyCallback {
145 public: 239 public:
146 explicit MovableOnDestroyCallback(const base::Closure& callback) 240 explicit MovableOnDestroyCallback(const base::Closure& callback)
147 : callback_(callback) { 241 : callback_(callback) {
148 } 242 }
149 243
150 ~MovableOnDestroyCallback() { 244 ~MovableOnDestroyCallback() {
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 } 531 }
438 532
439 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(), 533 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(),
440 info); 534 info);
441 } 535 }
442 536
443 void WallpaperManager::InitializeWallpaper() { 537 void WallpaperManager::InitializeWallpaper() {
444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 538 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
445 UserManager* user_manager = UserManager::Get(); 539 UserManager* user_manager = UserManager::Get();
446 540
541 // Apply device customization.
542 if (ShouldUseCustomizedDefaultWallpaper()) {
543 SetDefaultWallpaperPath(
544 GetCustomizedWallpaperDefaultRescaledFileName(kSmallWallpaperSuffix),
545 scoped_ptr<gfx::ImageSkia>().Pass(),
546 GetCustomizedWallpaperDefaultRescaledFileName(kLargeWallpaperSuffix),
547 scoped_ptr<gfx::ImageSkia>().Pass());
548 }
549
447 CommandLine* command_line = GetCommandLine(); 550 CommandLine* command_line = GetCommandLine();
448 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) { 551 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) {
449 // Guest wallpaper should be initialized when guest login. 552 // Guest wallpaper should be initialized when guest login.
450 // Note: This maybe called before login. So IsLoggedInAsGuest can not be 553 // Note: This maybe called before login. So IsLoggedInAsGuest can not be
451 // used here to determine if current user is guest. 554 // used here to determine if current user is guest.
452 return; 555 return;
453 } 556 }
454 557
455 if (command_line->HasSwitch(::switches::kTestType)) 558 if (command_line->HasSwitch(::switches::kTestType))
456 WizardController::SetZeroDelays(); 559 WizardController::SetZeroDelays();
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 use_small ? &guest_small_wallpaper_file_ : &guest_large_wallpaper_file_; 893 use_small ? &guest_small_wallpaper_file_ : &guest_large_wallpaper_file_;
791 } else { 894 } else {
792 file = use_small ? &default_small_wallpaper_file_ 895 file = use_small ? &default_small_wallpaper_file_
793 : &default_large_wallpaper_file_; 896 : &default_large_wallpaper_file_;
794 } 897 }
795 const ash::WallpaperLayout layout = 898 const ash::WallpaperLayout layout =
796 use_small ? ash::WALLPAPER_LAYOUT_CENTER 899 use_small ? ash::WALLPAPER_LAYOUT_CENTER
797 : ash::WALLPAPER_LAYOUT_CENTER_CROPPED; 900 : ash::WALLPAPER_LAYOUT_CENTER_CROPPED;
798 DCHECK(file); 901 DCHECK(file);
799 if (!default_wallpaper_image_.get() || 902 if (!default_wallpaper_image_.get() ||
800 default_wallpaper_image_->url().spec() != file->value()) { 903 default_wallpaper_image_->file_path() != file->value()) {
801 default_wallpaper_image_.reset(); 904 default_wallpaper_image_.reset();
802 if (!file->empty()) { 905 if (!file->empty()) {
803 loaded_wallpapers_++; 906 loaded_wallpapers_++;
804 StartLoadAndSetDefaultWallpaper( 907 StartLoadAndSetDefaultWallpaper(
805 *file, layout, on_finish.Pass(), &default_wallpaper_image_); 908 *file, layout, on_finish.Pass(), &default_wallpaper_image_);
806 return; 909 return;
807 } 910 }
808 911
809 const int resource_id = use_small ? IDR_AURA_WALLPAPER_DEFAULT_SMALL 912 const int resource_id = use_small ? IDR_AURA_WALLPAPER_DEFAULT_SMALL
810 : IDR_AURA_WALLPAPER_DEFAULT_LARGE; 913 : IDR_AURA_WALLPAPER_DEFAULT_LARGE;
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 if (!last_load_finished_at_.is_null()) { 1616 if (!last_load_finished_at_.is_null()) {
1514 const base::TimeDelta interval = base::Time::Now() - last_load_finished_at_; 1617 const base::TimeDelta interval = base::Time::Now() - last_load_finished_at_;
1515 if (interval > delay) 1618 if (interval > delay)
1516 delay = base::TimeDelta::FromMilliseconds(0); 1619 delay = base::TimeDelta::FromMilliseconds(0);
1517 else if (interval > base::TimeDelta::FromMilliseconds(0)) 1620 else if (interval > base::TimeDelta::FromMilliseconds(0))
1518 delay -= interval; 1621 delay -= interval;
1519 } 1622 }
1520 return delay; 1623 return delay;
1521 } 1624 }
1522 1625
1626 void WallpaperManager::SetCustomizedDefaultWallpaperAfterCheck(
1627 const GURL& wallpaper_url,
1628 const base::FilePath& downloaded_file,
1629 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files) {
1630 PrefService* pref_service = g_browser_process->local_state();
1631
1632 std::string current_url =
1633 pref_service->GetString(prefs::kCustomizationDefaultWallpaperURL);
1634 if (current_url != wallpaper_url.spec() || !rescaled_files->AllSizesExist()) {
1635 DCHECK(rescaled_files->downloaded_exists());
1636
1637 // Either resized images do not exist or cached version is incorrect.
1638 // Need to start resize again.
1639 wallpaper_loader_->Start(
1640 downloaded_file.value(),
1641 0, // Do not crop.
1642 base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperDecoded,
1643 weak_factory_.GetWeakPtr(),
1644 wallpaper_url,
1645 base::Passed(rescaled_files.Pass())));
1646 } else {
1647 SetDefaultWallpaperPath(rescaled_files->path_rescaled_small(),
1648 scoped_ptr<gfx::ImageSkia>().Pass(),
1649 rescaled_files->path_rescaled_large(),
1650 scoped_ptr<gfx::ImageSkia>().Pass());
1651 }
1652 }
1653
1654 void WallpaperManager::OnCustomizedDefaultWallpaperDecoded(
1655 const GURL& wallpaper_url,
1656 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files,
1657 const UserImage& wallpaper) {
1658 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1659
1660 // If decoded wallpaper is empty, we have probably failed to decode the file.
1661 if (wallpaper.image().isNull()) {
1662 LOG(WARNING) << "Failed to decode customized wallpaper.";
1663 return;
1664 }
1665
1666 wallpaper.image().EnsureRepsForSupportedScales();
1667 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy());
1668
1669 scoped_ptr<bool> success(new bool(false));
1670 scoped_ptr<gfx::ImageSkia> small_wallpaper_image(new gfx::ImageSkia);
1671 scoped_ptr<gfx::ImageSkia> large_wallpaper_image(new gfx::ImageSkia);
1672
1673 // TODO(bshe): This may break if RawImage becomes RefCountedMemory.
1674 base::Closure resize_closure =
1675 base::Bind(&WallpaperManager::ResizeCustomizedDefaultWallpaper,
1676 base::Unretained(this),
1677 base::Passed(&deep_copy),
1678 wallpaper.raw_image(),
1679 base::Unretained(rescaled_files.get()),
1680 base::Unretained(success.get()),
1681 base::Unretained(small_wallpaper_image.get()),
1682 base::Unretained(large_wallpaper_image.get()));
1683 base::Closure on_resized_closure =
1684 base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperResized,
1685 weak_factory_.GetWeakPtr(),
1686 wallpaper_url,
1687 base::Passed(rescaled_files.Pass()),
1688 base::Passed(success.Pass()),
1689 base::Passed(small_wallpaper_image.Pass()),
1690 base::Passed(large_wallpaper_image.Pass()));
1691
1692 if (!task_runner_->PostTaskAndReply(
1693 FROM_HERE, resize_closure, on_resized_closure)) {
1694 LOG(WARNING) << "Failed to start Customized Wallpaper resize.";
1695 }
1696 }
1697
1698 void WallpaperManager::ResizeCustomizedDefaultWallpaper(
1699 scoped_ptr<gfx::ImageSkia> image,
1700 const UserImage::RawImage& raw_image,
1701 const CustomizedWallpaperRescaledFiles* rescaled_files,
1702 bool* success,
1703 gfx::ImageSkia* small_wallpaper_image,
1704 gfx::ImageSkia* large_wallpaper_image) {
1705 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread(
1706 sequence_token_));
1707 UserImage wallpaper(*image.get(), raw_image);
1708
1709 *success = true;
1710
1711 *success &= ResizeAndSaveWallpaper(wallpaper,
1712 rescaled_files->path_rescaled_small(),
1713 ash::WALLPAPER_LAYOUT_STRETCH,
1714 kSmallWallpaperMaxWidth,
1715 kSmallWallpaperMaxHeight,
1716 small_wallpaper_image);
1717
1718 *success &= ResizeAndSaveWallpaper(wallpaper,
1719 rescaled_files->path_rescaled_large(),
1720 ash::WALLPAPER_LAYOUT_STRETCH,
1721 kLargeWallpaperMaxWidth,
1722 kLargeWallpaperMaxHeight,
1723 large_wallpaper_image);
1724 }
1725
1726 void WallpaperManager::OnCustomizedDefaultWallpaperResized(
1727 const GURL& wallpaper_url,
1728 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files,
1729 scoped_ptr<bool> success,
1730 scoped_ptr<gfx::ImageSkia> small_wallpaper_image,
1731 scoped_ptr<gfx::ImageSkia> large_wallpaper_image) {
1732 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1733 DCHECK(rescaled_files);
1734 DCHECK(success.get());
1735 if (!*success) {
1736 LOG(WARNING) << "Failed to save resized customized default wallpaper";
1737 return;
1738 }
1739 PrefService* pref_service = g_browser_process->local_state();
1740 pref_service->SetString(prefs::kCustomizationDefaultWallpaperURL,
1741 wallpaper_url.spec());
1742 SetDefaultWallpaperPath(rescaled_files->path_rescaled_small(),
1743 small_wallpaper_image.Pass(),
1744 rescaled_files->path_rescaled_large(),
1745 large_wallpaper_image.Pass());
1746 VLOG(1) << "Customized default wallpaper applied.";
1747 }
1748
1523 WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper( 1749 WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper(
1524 const std::string& user_id, 1750 const std::string& user_id,
1525 bool delayed) { 1751 bool delayed) {
1526 if (!pending_inactive_) { 1752 if (!pending_inactive_) {
1527 loading_.push_back(new WallpaperManager::PendingWallpaper( 1753 loading_.push_back(new WallpaperManager::PendingWallpaper(
1528 (delayed ? GetWallpaperLoadDelay() 1754 (delayed ? GetWallpaperLoadDelay()
1529 : base::TimeDelta::FromMilliseconds(0)), 1755 : base::TimeDelta::FromMilliseconds(0)),
1530 user_id)); 1756 user_id));
1531 pending_inactive_ = loading_.back(); 1757 pending_inactive_ = loading_.back();
1532 } 1758 }
1533 return pending_inactive_; 1759 return pending_inactive_;
1534 } 1760 }
1535 1761
1762 void WallpaperManager::SetCustomizedDefaultWallpaper(
1763 const GURL& wallpaper_url,
1764 const base::FilePath& downloaded_file,
1765 const base::FilePath& resized_directory) {
1766 // Should fail if this ever happens in tests.
1767 DCHECK(wallpaper_url.is_valid());
1768 if (!wallpaper_url.is_valid()) {
1769 if (!wallpaper_url.is_empty()) {
1770 LOG(WARNING) << "Invalid Customized Wallpaper URL '"
1771 << wallpaper_url.spec() << "'";
1772 }
1773 return;
1774 }
1775 std::string downloaded_file_name = downloaded_file.BaseName().value();
1776 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files(
1777 new CustomizedWallpaperRescaledFiles(
1778 downloaded_file,
1779 resized_directory.Append(downloaded_file_name +
1780 kSmallWallpaperSuffix),
1781 resized_directory.Append(downloaded_file_name +
1782 kLargeWallpaperSuffix)));
1783
1784 base::Closure check_file_exists = rescaled_files->CreateCheckerClosure();
1785 base::Closure on_checked_closure =
1786 base::Bind(&WallpaperManager::SetCustomizedDefaultWallpaperAfterCheck,
1787 weak_factory_.GetWeakPtr(),
1788 wallpaper_url,
1789 downloaded_file,
1790 base::Passed(rescaled_files.Pass()));
1791 if (!BrowserThread::PostBlockingPoolTaskAndReply(
1792 FROM_HERE, check_file_exists, on_checked_closure)) {
1793 LOG(WARNING) << "Failed to start check CheckCustomizedWallpaperFilesExist.";
1794 }
1795 }
1796
1536 void WallpaperManager::SetDefaultWallpaperPathsFromCommandLine( 1797 void WallpaperManager::SetDefaultWallpaperPathsFromCommandLine(
1537 base::CommandLine* command_line) { 1798 base::CommandLine* command_line) {
1538 default_small_wallpaper_file_ = command_line->GetSwitchValuePath( 1799 default_small_wallpaper_file_ = command_line->GetSwitchValuePath(
1539 ash::switches::kAshDefaultWallpaperSmall); 1800 ash::switches::kAshDefaultWallpaperSmall);
1540 default_large_wallpaper_file_ = command_line->GetSwitchValuePath( 1801 default_large_wallpaper_file_ = command_line->GetSwitchValuePath(
1541 ash::switches::kAshDefaultWallpaperLarge); 1802 ash::switches::kAshDefaultWallpaperLarge);
1542 guest_small_wallpaper_file_ = 1803 guest_small_wallpaper_file_ =
1543 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperSmall); 1804 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperSmall);
1544 guest_large_wallpaper_file_ = 1805 guest_large_wallpaper_file_ =
1545 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperLarge); 1806 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperLarge);
1546 default_wallpaper_image_.reset(); 1807 default_wallpaper_image_.reset();
1547 } 1808 }
1548 1809
1549 void WallpaperManager::OnDefaultWallpaperDecoded( 1810 void WallpaperManager::OnDefaultWallpaperDecoded(
1550 const base::FilePath& path, 1811 const base::FilePath& path,
1551 const ash::WallpaperLayout layout, 1812 const ash::WallpaperLayout layout,
1552 scoped_ptr<chromeos::UserImage>* result_out, 1813 scoped_ptr<chromeos::UserImage>* result_out,
1553 MovableOnDestroyCallbackHolder on_finish, 1814 MovableOnDestroyCallbackHolder on_finish,
1554 const UserImage& wallpaper) { 1815 const UserImage& wallpaper) {
1555 result_out->reset(new UserImage(wallpaper.image())); 1816 result_out->reset(new UserImage(wallpaper));
1556 (*result_out)->set_url(GURL(path.value()));
1557 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( 1817 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage(
1558 wallpaper.image(), layout); 1818 wallpaper.image(), layout);
1559 } 1819 }
1560 1820
1561 void WallpaperManager::StartLoadAndSetDefaultWallpaper( 1821 void WallpaperManager::StartLoadAndSetDefaultWallpaper(
1562 const base::FilePath& path, 1822 const base::FilePath& path,
1563 const ash::WallpaperLayout layout, 1823 const ash::WallpaperLayout layout,
1564 MovableOnDestroyCallbackHolder on_finish, 1824 MovableOnDestroyCallbackHolder on_finish,
1565 scoped_ptr<chromeos::UserImage>* result_out) { 1825 scoped_ptr<chromeos::UserImage>* result_out) {
1566 wallpaper_loader_->Start( 1826 wallpaper_loader_->Start(
1567 path.value(), 1827 path.value(),
1568 0, // Do not crop. 1828 0, // Do not crop.
1569 base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded, 1829 base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded,
1570 weak_factory_.GetWeakPtr(), 1830 weak_factory_.GetWeakPtr(),
1571 path, 1831 path,
1572 layout, 1832 layout,
1573 base::Unretained(result_out), 1833 base::Unretained(result_out),
1574 base::Passed(on_finish.Pass()))); 1834 base::Passed(on_finish.Pass())));
1575 } 1835 }
1576 1836
1577 const char* WallpaperManager::GetCustomWallpaperSubdirForCurrentResolution() { 1837 const char* WallpaperManager::GetCustomWallpaperSubdirForCurrentResolution() {
1578 WallpaperResolution resolution = GetAppropriateResolution(); 1838 WallpaperResolution resolution = GetAppropriateResolution();
1579 return resolution == WALLPAPER_RESOLUTION_SMALL ? kSmallWallpaperSubDir 1839 return resolution == WALLPAPER_RESOLUTION_SMALL ? kSmallWallpaperSubDir
1580 : kLargeWallpaperSubDir; 1840 : kLargeWallpaperSubDir;
1581 } 1841 }
1582 1842
1843 void WallpaperManager::SetDefaultWallpaperPath(
1844 const base::FilePath& default_small_wallpaper_file,
1845 scoped_ptr<gfx::ImageSkia> small_wallpaper_image,
1846 const base::FilePath& default_large_wallpaper_file,
1847 scoped_ptr<gfx::ImageSkia> large_wallpaper_image) {
1848 default_small_wallpaper_file_ = default_small_wallpaper_file;
1849 default_large_wallpaper_file_ = default_large_wallpaper_file;
1850
1851 ash::DesktopBackgroundController* dbc =
1852 ash::Shell::GetInstance()->desktop_background_controller();
1853
1854 // |need_update_screen| is true if the previous default wallpaper is visible
1855 // now, so we need to update wallpaper on the screen.
1856 //
1857 // Layout is ignored here, so ash::WALLPAPER_LAYOUT_CENTER is used
1858 // as a placeholder only.
1859 const bool need_update_screen =
1860 default_wallpaper_image_.get() &&
1861 dbc->WallpaperIsAlreadyLoaded(
1862 &(default_wallpaper_image_->image()),
1863 ash::DesktopBackgroundController::kInvalidResourceID,
1864 false /* compare_layouts */,
1865 ash::WALLPAPER_LAYOUT_CENTER);
1866
1867 default_wallpaper_image_.reset();
1868 if (GetAppropriateResolution() == WALLPAPER_RESOLUTION_SMALL) {
1869 if (small_wallpaper_image) {
1870 default_wallpaper_image_.reset(new UserImage(*small_wallpaper_image));
1871 default_wallpaper_image_->set_file_path(
1872 default_small_wallpaper_file.value());
1873 }
1874 } else {
1875 if (large_wallpaper_image) {
1876 default_wallpaper_image_.reset(new UserImage(*large_wallpaper_image));
1877 default_wallpaper_image_->set_file_path(
1878 default_large_wallpaper_file.value());
1879 }
1880 }
1881
1882 if (need_update_screen) {
1883 DoSetDefaultWallpaper(std::string(),
1884 MovableOnDestroyCallbackHolder().Pass());
1885 }
1886 }
1887
1583 } // namespace chromeos 1888 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698