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

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: After-review. 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"
42 #include "content/public/browser/browser_thread.h" 43 #include "content/public/browser/browser_thread.h"
43 #include "content/public/browser/notification_service.h" 44 #include "content/public/browser/notification_service.h"
44 #include "grit/ash_resources.h" 45 #include "grit/ash_resources.h"
45 #include "ui/base/resource/resource_bundle.h" 46 #include "ui/base/resource/resource_bundle.h"
46 #include "ui/gfx/codec/jpeg_codec.h" 47 #include "ui/gfx/codec/jpeg_codec.h"
47 #include "ui/gfx/image/image_skia_operations.h" 48 #include "ui/gfx/image/image_skia_operations.h"
48 #include "ui/gfx/skia_util.h" 49 #include "ui/gfx/skia_util.h"
49 50
50 using content::BrowserThread; 51 using content::BrowserThread;
51 52
52 namespace chromeos { 53 namespace chromeos {
53 54
55 class WallpaperManager::CustomizedWallpaperRescaledFiles {
56 public:
57 CustomizedWallpaperRescaledFiles(const base::FilePath& path_downloaded,
58 const base::FilePath& path_rescaled_small,
59 const base::FilePath& path_rescaled_large);
60
61 bool AllRescaledExist() const;
Nikita (slow) 2014/04/15 13:40:00 nit: Rename to AllSizesExist()
Alexander Alekseev 2014/04/15 22:47:31 Done.
62
63 const base::FilePath path_downloaded;
Daniel Erat 2014/04/15 03:06:30 these should all be private members with underscor
Alexander Alekseev 2014/04/15 22:47:31 Done.
64 const base::FilePath path_rescaled_small;
65 const base::FilePath path_rescaled_large;
66
67 bool downloaded_exists;
68 bool rescaled_small_exists;
69 bool rescaled_large_exists;
70 };
71
54 namespace { 72 namespace {
55 73
56 // The amount of delay before starts to move custom wallpapers to the new place. 74 // The amount of delay before starts to move custom wallpapers to the new place.
57 const int kMoveCustomWallpaperDelaySeconds = 30; 75 const int kMoveCustomWallpaperDelaySeconds = 30;
58 76
59 // Default quality for encoding wallpaper. 77 // Default quality for encoding wallpaper.
60 const int kDefaultEncodingQuality = 90; 78 const int kDefaultEncodingQuality = 90;
61 79
62 // A dictionary pref that maps usernames to file paths to their wallpapers. 80 // A dictionary pref that maps usernames to file paths to their wallpapers.
63 // Deprecated. Will remove this const char after done migration. 81 // Deprecated. Will remove this const char after done migration.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 const std::string& user_id, 128 const std::string& user_id,
111 const std::string& user_id_hash) { 129 const std::string& user_id_hash) {
112 base::FilePath base_path = GetCustomWallpaperDir(sub_dir); 130 base::FilePath base_path = GetCustomWallpaperDir(sub_dir);
113 base::FilePath to_path = base_path.Append(user_id_hash); 131 base::FilePath to_path = base_path.Append(user_id_hash);
114 base::FilePath from_path = base_path.Append(user_id); 132 base::FilePath from_path = base_path.Append(user_id);
115 if (base::PathExists(from_path)) 133 if (base::PathExists(from_path))
116 return base::Move(from_path, to_path); 134 return base::Move(from_path, to_path);
117 return false; 135 return false;
118 } 136 }
119 137
138 void CheckCustomizedWallpaperFilesExist(
139 WallpaperManager::CustomizedWallpaperRescaledFiles* files) {
140 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
141 DCHECK(files);
142 files->downloaded_exists = base::PathExists(files->path_downloaded);
143 files->rescaled_small_exists = base::PathExists(files->path_rescaled_small);
144 files->rescaled_large_exists = base::PathExists(files->path_rescaled_large);
145 }
146
147 // These global default values are used to set customized default
148 // wallpaper path in WallpaperManager::InitializeWallpaper().
149 base::FilePath GetCustomizedWallpaperDefaultRescaledFileName(
150 const char* suffix) {
Daniel Erat 2014/04/15 03:06:30 any reason this can't take const std::string& ?
Alexander Alekseev 2014/04/15 22:47:31 Done.
151 const base::FilePath default_downloaded_file_name =
152 ServicesCustomizationDocument::GetCustomizedWallpaperDownloadedFileName();
153 const base::FilePath default_cache_dir =
154 ServicesCustomizationDocument::GetCustomizedWallpaperCacheDir();
155 if (default_downloaded_file_name.empty() || default_cache_dir.empty())
156 return base::FilePath();
157 return default_cache_dir.Append(
158 default_downloaded_file_name.BaseName().value() + suffix);
159 }
160
161 // If DesktopBackgroundController should start with customized default
Nikita (slow) 2014/04/15 13:40:00 nit: if > whether
Alexander Alekseev 2014/04/15 22:47:31 Done.
162 // wallpaper in WallpaperManager::InitializeWallpaper().
163 bool ShouldUseCustomizedDefaultWallpaper() {
164 PrefService* pref_service = g_browser_process->local_state();
165
166 return !(pref_service->FindPreference(
167 prefs::kCustomizationDefaultWallpaperURL)
168 ->IsDefaultValue());
169 }
170
120 } // namespace 171 } // namespace
121 172
122 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence"; 173 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence";
123 174
124 const char kSmallWallpaperSuffix[] = "_small"; 175 const char kSmallWallpaperSuffix[] = "_small";
125 const char kLargeWallpaperSuffix[] = "_large"; 176 const char kLargeWallpaperSuffix[] = "_large";
126 177
127 const char kSmallWallpaperSubDir[] = "small"; 178 const char kSmallWallpaperSubDir[] = "small";
128 const char kLargeWallpaperSubDir[] = "large"; 179 const char kLargeWallpaperSubDir[] = "large";
129 const char kOriginalWallpaperSubDir[] = "original"; 180 const char kOriginalWallpaperSubDir[] = "original";
130 const char kThumbnailWallpaperSubDir[] = "thumb"; 181 const char kThumbnailWallpaperSubDir[] = "thumb";
131 182
132 const int kSmallWallpaperMaxWidth = 1366; 183 const int kSmallWallpaperMaxWidth = 1366;
133 const int kSmallWallpaperMaxHeight = 800; 184 const int kSmallWallpaperMaxHeight = 800;
134 const int kLargeWallpaperMaxWidth = 2560; 185 const int kLargeWallpaperMaxWidth = 2560;
135 const int kLargeWallpaperMaxHeight = 1700; 186 const int kLargeWallpaperMaxHeight = 1700;
136 const int kWallpaperThumbnailWidth = 108; 187 const int kWallpaperThumbnailWidth = 108;
137 const int kWallpaperThumbnailHeight = 68; 188 const int kWallpaperThumbnailHeight = 68;
138 189
139 static WallpaperManager* g_wallpaper_manager = NULL; 190 static WallpaperManager* g_wallpaper_manager = NULL;
140 191
192 WallpaperManager::CustomizedWallpaperRescaledFiles::
193 CustomizedWallpaperRescaledFiles(const base::FilePath& path_downloaded,
194 const base::FilePath& path_rescaled_small,
195 const base::FilePath& path_rescaled_large)
196 : path_downloaded(path_downloaded),
197 path_rescaled_small(path_rescaled_small),
198 path_rescaled_large(path_rescaled_large),
199 downloaded_exists(false),
200 rescaled_small_exists(false),
201 rescaled_large_exists(false) {
202 }
203
204 bool WallpaperManager::CustomizedWallpaperRescaledFiles::AllRescaledExist()
205 const {
206 return rescaled_small_exists && rescaled_large_exists;
207 }
208
141 // This object is passed between several threads while wallpaper is being 209 // This object is passed between several threads while wallpaper is being
142 // loaded. It will notify callback when last reference to it is removed 210 // loaded. It will notify callback when last reference to it is removed
143 // (thus indicating that the last load action has finished). 211 // (thus indicating that the last load action has finished).
144 class MovableOnDestroyCallback { 212 class MovableOnDestroyCallback {
145 public: 213 public:
146 explicit MovableOnDestroyCallback(const base::Closure& callback) 214 explicit MovableOnDestroyCallback(const base::Closure& callback)
147 : callback_(callback) { 215 : callback_(callback) {
148 } 216 }
149 217
150 ~MovableOnDestroyCallback() { 218 ~MovableOnDestroyCallback() {
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 } 505 }
438 506
439 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(), 507 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(),
440 info); 508 info);
441 } 509 }
442 510
443 void WallpaperManager::InitializeWallpaper() { 511 void WallpaperManager::InitializeWallpaper() {
444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 512 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
445 UserManager* user_manager = UserManager::Get(); 513 UserManager* user_manager = UserManager::Get();
446 514
515 // Apply device customization.
516 if (ShouldUseCustomizedDefaultWallpaper()) {
517 SetDefaultWallpaperPath(
518 GetCustomizedWallpaperDefaultRescaledFileName(kSmallWallpaperSuffix),
519 scoped_ptr<gfx::ImageSkia>().Pass(),
520 GetCustomizedWallpaperDefaultRescaledFileName(kLargeWallpaperSuffix),
521 scoped_ptr<gfx::ImageSkia>().Pass());
522 }
523
447 CommandLine* command_line = GetCommandLine(); 524 CommandLine* command_line = GetCommandLine();
448 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) { 525 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) {
449 // Guest wallpaper should be initialized when guest login. 526 // Guest wallpaper should be initialized when guest login.
450 // Note: This maybe called before login. So IsLoggedInAsGuest can not be 527 // Note: This maybe called before login. So IsLoggedInAsGuest can not be
451 // used here to determine if current user is guest. 528 // used here to determine if current user is guest.
452 return; 529 return;
453 } 530 }
454 531
455 if (command_line->HasSwitch(::switches::kTestType)) 532 if (command_line->HasSwitch(::switches::kTestType))
456 WizardController::SetZeroDelays(); 533 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_; 867 use_small ? &guest_small_wallpaper_file_ : &guest_large_wallpaper_file_;
791 } else { 868 } else {
792 file = use_small ? &default_small_wallpaper_file_ 869 file = use_small ? &default_small_wallpaper_file_
793 : &default_large_wallpaper_file_; 870 : &default_large_wallpaper_file_;
794 } 871 }
795 const ash::WallpaperLayout layout = 872 const ash::WallpaperLayout layout =
796 use_small ? ash::WALLPAPER_LAYOUT_CENTER 873 use_small ? ash::WALLPAPER_LAYOUT_CENTER
797 : ash::WALLPAPER_LAYOUT_CENTER_CROPPED; 874 : ash::WALLPAPER_LAYOUT_CENTER_CROPPED;
798 DCHECK(file); 875 DCHECK(file);
799 if (!default_wallpaper_image_.get() || 876 if (!default_wallpaper_image_.get() ||
800 default_wallpaper_image_->url().spec() != file->value()) { 877 default_wallpaper_image_->file_path() != file->value()) {
801 default_wallpaper_image_.reset(); 878 default_wallpaper_image_.reset();
802 if (!file->empty()) { 879 if (!file->empty()) {
803 loaded_wallpapers_++; 880 loaded_wallpapers_++;
804 StartLoadAndSetDefaultWallpaper( 881 StartLoadAndSetDefaultWallpaper(
805 *file, layout, on_finish.Pass(), &default_wallpaper_image_); 882 *file, layout, on_finish.Pass(), &default_wallpaper_image_);
806 return; 883 return;
807 } 884 }
808 885
809 const int resource_id = use_small ? IDR_AURA_WALLPAPER_DEFAULT_SMALL 886 const int resource_id = use_small ? IDR_AURA_WALLPAPER_DEFAULT_SMALL
810 : IDR_AURA_WALLPAPER_DEFAULT_LARGE; 887 : 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()) { 1590 if (!last_load_finished_at_.is_null()) {
1514 const base::TimeDelta interval = base::Time::Now() - last_load_finished_at_; 1591 const base::TimeDelta interval = base::Time::Now() - last_load_finished_at_;
1515 if (interval > delay) 1592 if (interval > delay)
1516 delay = base::TimeDelta::FromMilliseconds(0); 1593 delay = base::TimeDelta::FromMilliseconds(0);
1517 else if (interval > base::TimeDelta::FromMilliseconds(0)) 1594 else if (interval > base::TimeDelta::FromMilliseconds(0))
1518 delay -= interval; 1595 delay -= interval;
1519 } 1596 }
1520 return delay; 1597 return delay;
1521 } 1598 }
1522 1599
1600 void WallpaperManager::SetCustomizedDefaultWallpaperAfterCheck(
1601 const GURL& wallpaper_url,
1602 const base::FilePath& downloaded_file,
1603 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files) {
1604 PrefService* pref_service = g_browser_process->local_state();
1605
1606 std::string current_url =
1607 pref_service->GetString(prefs::kCustomizationDefaultWallpaperURL);
1608 if (current_url != wallpaper_url.spec() ||
1609 !rescaled_files->AllRescaledExist()) {
1610 DCHECK(rescaled_files->downloaded_exists);
1611 // Need rescale
Nikita (slow) 2014/04/15 13:40:00 nit: dot at the end otherwise comment looks like i
Alexander Alekseev 2014/04/15 22:47:31 Done.
1612 wallpaper_loader_->Start(
1613 downloaded_file.value(),
1614 0, // Do not crop.
1615 base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperDecoded,
1616 weak_factory_.GetWeakPtr(),
1617 wallpaper_url,
1618 base::Passed(rescaled_files.Pass())));
1619 } else {
1620 SetDefaultWallpaperPath(rescaled_files->path_rescaled_small,
1621 scoped_ptr<gfx::ImageSkia>().Pass(),
1622 rescaled_files->path_rescaled_large,
1623 scoped_ptr<gfx::ImageSkia>().Pass());
1624 }
1625 }
1626
1627 void WallpaperManager::OnCustomizedDefaultWallpaperDecoded(
1628 const GURL& wallpaper_url,
1629 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files,
1630 const UserImage& wallpaper) {
1631 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1632
1633 // If decoded wallpaper is empty, we have probably failed to decode the file.
1634 if (wallpaper.image().isNull()) {
1635 LOG(WARNING) << "Failed to decode customized wallpaper.";
1636 return;
1637 }
1638
1639 wallpaper.image().EnsureRepsForSupportedScales();
1640 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy());
1641
1642 scoped_ptr<bool> success(new bool(false));
1643 scoped_ptr<gfx::ImageSkia> small_wallpaper_image(new gfx::ImageSkia);
1644 scoped_ptr<gfx::ImageSkia> large_wallpaper_image(new gfx::ImageSkia);
1645
1646 // TODO(bshe): This may break if RawImage becomes RefCountedMemory.
1647 base::Closure resize_closure =
1648 base::Bind(&WallpaperManager::ResizeCustomizedDefaultWallpaper,
1649 base::Unretained(this),
1650 base::Passed(&deep_copy),
1651 wallpaper.raw_image(),
1652 base::Unretained(rescaled_files.get()),
1653 base::Unretained(success.get()),
1654 base::Unretained(small_wallpaper_image.get()),
1655 base::Unretained(large_wallpaper_image.get()));
1656 base::Closure on_resized_closure =
1657 base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperResized,
1658 weak_factory_.GetWeakPtr(),
1659 wallpaper_url,
1660 base::Passed(rescaled_files.Pass()),
1661 base::Passed(success.Pass()),
1662 base::Passed(small_wallpaper_image.Pass()),
1663 base::Passed(large_wallpaper_image.Pass()));
1664
1665 if (!task_runner_->PostTaskAndReply(
1666 FROM_HERE, resize_closure, on_resized_closure)) {
1667 LOG(WARNING) << "Failed to start Customized Wallpaper resize.";
1668 }
1669 }
1670
1671 void WallpaperManager::ResizeCustomizedDefaultWallpaper(
1672 scoped_ptr<gfx::ImageSkia> image,
1673 const UserImage::RawImage& raw_image,
1674 const CustomizedWallpaperRescaledFiles* rescaled_files,
1675 bool* success,
1676 gfx::ImageSkia* small_wallpaper_image,
1677 gfx::ImageSkia* large_wallpaper_image) {
1678 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread(
1679 sequence_token_));
1680 UserImage wallpaper(*image.get(), raw_image);
1681
1682 *success = true;
1683
1684 *success &= ResizeAndSaveWallpaper(wallpaper,
1685 rescaled_files->path_rescaled_small,
1686 ash::WALLPAPER_LAYOUT_STRETCH,
1687 kSmallWallpaperMaxWidth,
1688 kSmallWallpaperMaxHeight,
1689 small_wallpaper_image);
1690
1691 *success &= ResizeAndSaveWallpaper(wallpaper,
1692 rescaled_files->path_rescaled_large,
1693 ash::WALLPAPER_LAYOUT_STRETCH,
1694 kLargeWallpaperMaxWidth,
1695 kLargeWallpaperMaxHeight,
1696 large_wallpaper_image);
1697 }
1698
1699 void WallpaperManager::OnCustomizedDefaultWallpaperResized(
1700 const GURL& wallpaper_url,
1701 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files,
1702 scoped_ptr<bool> success,
1703 scoped_ptr<gfx::ImageSkia> small_wallpaper_image,
1704 scoped_ptr<gfx::ImageSkia> large_wallpaper_image) {
1705 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1706 DCHECK(rescaled_files.get());
1707 DCHECK(success.get());
1708 if (!*success) {
1709 LOG(WARNING) << "Failed to save resized customized default wallpaper";
1710 return;
1711 }
1712 PrefService* pref_service = g_browser_process->local_state();
1713 pref_service->SetString(prefs::kCustomizationDefaultWallpaperURL,
1714 wallpaper_url.spec());
1715 SetDefaultWallpaperPath(rescaled_files->path_rescaled_small,
1716 small_wallpaper_image.Pass(),
1717 rescaled_files->path_rescaled_large,
1718 large_wallpaper_image.Pass());
1719 VLOG(1) << "Customized default wallpaper applied.";
1720 }
1721
1523 WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper( 1722 WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper(
1524 const std::string& user_id, 1723 const std::string& user_id,
1525 bool delayed) { 1724 bool delayed) {
1526 if (!pending_inactive_) { 1725 if (!pending_inactive_) {
1527 loading_.push_back(new WallpaperManager::PendingWallpaper( 1726 loading_.push_back(new WallpaperManager::PendingWallpaper(
1528 (delayed ? GetWallpaperLoadDelay() 1727 (delayed ? GetWallpaperLoadDelay()
1529 : base::TimeDelta::FromMilliseconds(0)), 1728 : base::TimeDelta::FromMilliseconds(0)),
1530 user_id)); 1729 user_id));
1531 pending_inactive_ = loading_.back(); 1730 pending_inactive_ = loading_.back();
1532 } 1731 }
1533 return pending_inactive_; 1732 return pending_inactive_;
1534 } 1733 }
1535 1734
1735 void WallpaperManager::SetCustomizedDefaultWallpaper(
1736 const GURL& wallpaper_url,
1737 const base::FilePath& downloaded_file,
1738 const base::FilePath& resized_directory) {
1739 // Should fail if this ever happens in tests.
1740 DCHECK(wallpaper_url.is_valid());
1741 if (!wallpaper_url.is_valid()) {
1742 if (!wallpaper_url.is_empty()) {
Daniel Erat 2014/04/15 03:06:30 nit: omit curly brackets here
Alexander Alekseev 2014/04/15 22:47:31 Now it occupies 2 lines.
1743 LOG(WARNING) << "Invalid Customized Wallpaper URL.";
1744 }
1745 return;
1746 }
1747 std::string downloaded_file_name = downloaded_file.BaseName().value();
1748 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files(
1749 new CustomizedWallpaperRescaledFiles(
1750 downloaded_file,
1751 resized_directory.Append(downloaded_file_name +
1752 kSmallWallpaperSuffix),
1753 resized_directory.Append(downloaded_file_name +
1754 kLargeWallpaperSuffix)));
1755
1756 base::Closure check_file_exists =
1757 base::Bind(&CheckCustomizedWallpaperFilesExist,
1758 base::Unretained(rescaled_files.get()));
1759 base::Closure on_checked_closure =
1760 base::Bind(&WallpaperManager::SetCustomizedDefaultWallpaperAfterCheck,
1761 weak_factory_.GetWeakPtr(),
1762 wallpaper_url,
1763 downloaded_file,
1764 base::Passed(rescaled_files.Pass()));
1765 if (!BrowserThread::PostBlockingPoolTaskAndReply(
1766 FROM_HERE, check_file_exists, on_checked_closure)) {
1767 LOG(WARNING) << "Failed to start check CheckCustomizedWallpaperFilesExist.";
1768 }
1769 }
1770
1536 void WallpaperManager::SetDefaultWallpaperPathsFromCommandLine( 1771 void WallpaperManager::SetDefaultWallpaperPathsFromCommandLine(
1537 base::CommandLine* command_line) { 1772 base::CommandLine* command_line) {
1538 default_small_wallpaper_file_ = command_line->GetSwitchValuePath( 1773 default_small_wallpaper_file_ = command_line->GetSwitchValuePath(
1539 ash::switches::kAshDefaultWallpaperSmall); 1774 ash::switches::kAshDefaultWallpaperSmall);
1540 default_large_wallpaper_file_ = command_line->GetSwitchValuePath( 1775 default_large_wallpaper_file_ = command_line->GetSwitchValuePath(
1541 ash::switches::kAshDefaultWallpaperLarge); 1776 ash::switches::kAshDefaultWallpaperLarge);
1542 guest_small_wallpaper_file_ = 1777 guest_small_wallpaper_file_ =
1543 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperSmall); 1778 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperSmall);
1544 guest_large_wallpaper_file_ = 1779 guest_large_wallpaper_file_ =
1545 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperLarge); 1780 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperLarge);
1546 default_wallpaper_image_.reset(); 1781 default_wallpaper_image_.reset();
1547 } 1782 }
1548 1783
1549 void WallpaperManager::OnDefaultWallpaperDecoded( 1784 void WallpaperManager::OnDefaultWallpaperDecoded(
1550 const base::FilePath& path, 1785 const base::FilePath& path,
1551 const ash::WallpaperLayout layout, 1786 const ash::WallpaperLayout layout,
1552 scoped_ptr<chromeos::UserImage>* result_out, 1787 scoped_ptr<chromeos::UserImage>* result_out,
1553 MovableOnDestroyCallbackHolder on_finish, 1788 MovableOnDestroyCallbackHolder on_finish,
1554 const UserImage& wallpaper) { 1789 const UserImage& wallpaper) {
1555 result_out->reset(new UserImage(wallpaper.image())); 1790 result_out->reset(new UserImage(wallpaper));
1556 (*result_out)->set_url(GURL(path.value()));
1557 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( 1791 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage(
1558 wallpaper.image(), layout); 1792 wallpaper.image(), layout);
1559 } 1793 }
1560 1794
1561 void WallpaperManager::StartLoadAndSetDefaultWallpaper( 1795 void WallpaperManager::StartLoadAndSetDefaultWallpaper(
1562 const base::FilePath& path, 1796 const base::FilePath& path,
1563 const ash::WallpaperLayout layout, 1797 const ash::WallpaperLayout layout,
1564 MovableOnDestroyCallbackHolder on_finish, 1798 MovableOnDestroyCallbackHolder on_finish,
1565 scoped_ptr<chromeos::UserImage>* result_out) { 1799 scoped_ptr<chromeos::UserImage>* result_out) {
1566 wallpaper_loader_->Start( 1800 wallpaper_loader_->Start(
1567 path.value(), 1801 path.value(),
1568 0, // Do not crop. 1802 0, // Do not crop.
1569 base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded, 1803 base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded,
1570 weak_factory_.GetWeakPtr(), 1804 weak_factory_.GetWeakPtr(),
1571 path, 1805 path,
1572 layout, 1806 layout,
1573 base::Unretained(result_out), 1807 base::Unretained(result_out),
1574 base::Passed(on_finish.Pass()))); 1808 base::Passed(on_finish.Pass())));
1575 } 1809 }
1576 1810
1577 const char* WallpaperManager::GetCustomWallpaperSubdirForCurrentResolution() { 1811 const char* WallpaperManager::GetCustomWallpaperSubdirForCurrentResolution() {
1578 WallpaperResolution resolution = GetAppropriateResolution(); 1812 WallpaperResolution resolution = GetAppropriateResolution();
1579 return resolution == WALLPAPER_RESOLUTION_SMALL ? kSmallWallpaperSubDir 1813 return resolution == WALLPAPER_RESOLUTION_SMALL ? kSmallWallpaperSubDir
1580 : kLargeWallpaperSubDir; 1814 : kLargeWallpaperSubDir;
1581 } 1815 }
1582 1816
1817 void WallpaperManager::SetDefaultWallpaperPath(
1818 const base::FilePath& default_small_wallpaper_file,
1819 scoped_ptr<gfx::ImageSkia> small_wallpaper_image,
1820 const base::FilePath& default_large_wallpaper_file,
1821 scoped_ptr<gfx::ImageSkia> large_wallpaper_image) {
1822 default_small_wallpaper_file_ = default_small_wallpaper_file;
1823 default_large_wallpaper_file_ = default_large_wallpaper_file;
1824
1825 ash::DesktopBackgroundController* dbc =
1826 ash::Shell::GetInstance()->desktop_background_controller();
1827 // Layout is ignored here, so ash::WALLPAPER_LAYOUT_CENTER is used
1828 // as a placeholder only.
1829 const bool need_reload =
Nikita (slow) 2014/04/15 13:40:00 nit: Insert empty line before comment. Can you pl
Alexander Alekseev 2014/04/15 22:47:31 Done.
1830 default_wallpaper_image_.get() &&
1831 dbc->WallpaperIsAlreadyLoaded(
1832 &(default_wallpaper_image_->image()),
1833 ash::DesktopBackgroundController::kInvalidResourceID,
1834 false /* compare_layouts */,
1835 ash::WALLPAPER_LAYOUT_CENTER);
1836
1837 default_wallpaper_image_.reset();
1838 if (GetAppropriateResolution() == WALLPAPER_RESOLUTION_SMALL) {
1839 if (small_wallpaper_image) {
1840 default_wallpaper_image_.reset(new UserImage(*small_wallpaper_image));
1841 default_wallpaper_image_->set_file_path(
1842 default_small_wallpaper_file.value());
1843 }
1844 } else {
1845 if (large_wallpaper_image) {
1846 default_wallpaper_image_.reset(new UserImage(*large_wallpaper_image));
1847 default_wallpaper_image_->set_file_path(
1848 default_large_wallpaper_file.value());
1849 }
1850 }
1851
1852 if (need_reload) {
1853 DoSetDefaultWallpaper(std::string(),
1854 MovableOnDestroyCallbackHolder().Pass());
1855 }
1856 }
1857
1583 } // namespace chromeos 1858 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698