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/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 Loading... | |
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 void CheckCustomizedWallpaperFilesExist( | |
122 const base::FilePath& downloaded_file, | |
123 const WallpaperManager::CustomizedWallpaperRescaledFiles* rescaled_files, | |
124 WallpaperManager::CustomizedWallpaperFilesExist* exist) { | |
125 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | |
126 DCHECK(rescaled_files); | |
127 DCHECK(exist); | |
128 exist->downloaded = base::PathExists(downloaded_file); | |
129 exist->rescaled_small = base::PathExists(rescaled_files->path_rescaled_small); | |
130 exist->rescaled_large = base::PathExists(rescaled_files->path_rescaled_large); | |
131 } | |
132 | |
120 } // namespace | 133 } // namespace |
121 | 134 |
122 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence"; | 135 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence"; |
123 | 136 |
124 const char kSmallWallpaperSuffix[] = "_small"; | 137 const char kSmallWallpaperSuffix[] = "_small"; |
125 const char kLargeWallpaperSuffix[] = "_large"; | 138 const char kLargeWallpaperSuffix[] = "_large"; |
126 | 139 |
127 const char kSmallWallpaperSubDir[] = "small"; | 140 const char kSmallWallpaperSubDir[] = "small"; |
128 const char kLargeWallpaperSubDir[] = "large"; | 141 const char kLargeWallpaperSubDir[] = "large"; |
129 const char kOriginalWallpaperSubDir[] = "original"; | 142 const char kOriginalWallpaperSubDir[] = "original"; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 i != manager->loading_.end(); | 282 i != manager->loading_.end(); |
270 ++i) | 283 ++i) |
271 if (i->get() == this) { | 284 if (i->get() == this) { |
272 manager->loading_.erase(i); | 285 manager->loading_.erase(i); |
273 break; | 286 break; |
274 } | 287 } |
275 } | 288 } |
276 | 289 |
277 // WallpaperManager, public: --------------------------------------------------- | 290 // WallpaperManager, public: --------------------------------------------------- |
278 | 291 |
292 WallpaperManager::CustomizedWallpaperRescaledFiles:: | |
293 CustomizedWallpaperRescaledFiles(const base::FilePath& path_rescaled_small, | |
294 const base::FilePath& path_rescaled_large) | |
295 : path_rescaled_small(path_rescaled_small), | |
296 path_rescaled_large(path_rescaled_large) { | |
297 } | |
298 | |
299 WallpaperManager::CustomizedWallpaperFilesExist::CustomizedWallpaperFilesExist() | |
300 : downloaded(false), rescaled_small(false), rescaled_large(false) { | |
301 } | |
302 | |
303 bool WallpaperManager::CustomizedWallpaperFilesExist::AllRescaledExist() const { | |
304 return rescaled_small && rescaled_large; | |
305 } | |
306 | |
279 // TestApi. For testing purpose | 307 // TestApi. For testing purpose |
280 WallpaperManager::TestApi::TestApi(WallpaperManager* wallpaper_manager) | 308 WallpaperManager::TestApi::TestApi(WallpaperManager* wallpaper_manager) |
281 : wallpaper_manager_(wallpaper_manager) { | 309 : wallpaper_manager_(wallpaper_manager) { |
282 } | 310 } |
283 | 311 |
284 WallpaperManager::TestApi::~TestApi() { | 312 WallpaperManager::TestApi::~TestApi() { |
285 } | 313 } |
286 | 314 |
287 base::FilePath WallpaperManager::TestApi::current_wallpaper_path() { | 315 base::FilePath WallpaperManager::TestApi::current_wallpaper_path() { |
288 return wallpaper_manager_->current_wallpaper_path_; | 316 return wallpaper_manager_->current_wallpaper_path_; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 } | 465 } |
438 | 466 |
439 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(), | 467 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(), |
440 info); | 468 info); |
441 } | 469 } |
442 | 470 |
443 void WallpaperManager::InitializeWallpaper() { | 471 void WallpaperManager::InitializeWallpaper() { |
444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 472 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
445 UserManager* user_manager = UserManager::Get(); | 473 UserManager* user_manager = UserManager::Get(); |
446 | 474 |
475 // eApply device nustomization. | |
Daniel Erat
2014/04/14 15:26:15
nit: Apply device customization.
Alexander Alekseev
2014/04/15 01:57:16
Done.
| |
476 if (ShouldUseCustomizedDefaultWallpaper()) { | |
477 SetDefaultWallpaperPath( | |
478 GetCustomizedWallpaperDefaultRescaledFileName(kSmallWallpaperSuffix), | |
479 scoped_ptr<gfx::ImageSkia>().Pass(), | |
480 GetCustomizedWallpaperDefaultRescaledFileName(kLargeWallpaperSuffix), | |
481 scoped_ptr<gfx::ImageSkia>().Pass()); | |
482 } | |
483 | |
447 CommandLine* command_line = GetCommandLine(); | 484 CommandLine* command_line = GetCommandLine(); |
448 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) { | 485 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) { |
449 // Guest wallpaper should be initialized when guest login. | 486 // Guest wallpaper should be initialized when guest login. |
450 // Note: This maybe called before login. So IsLoggedInAsGuest can not be | 487 // Note: This maybe called before login. So IsLoggedInAsGuest can not be |
451 // used here to determine if current user is guest. | 488 // used here to determine if current user is guest. |
452 return; | 489 return; |
453 } | 490 } |
454 | 491 |
455 if (command_line->HasSwitch(::switches::kTestType)) | 492 if (command_line->HasSwitch(::switches::kTestType)) |
456 WizardController::SetZeroDelays(); | 493 WizardController::SetZeroDelays(); |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
790 use_small ? &guest_small_wallpaper_file_ : &guest_large_wallpaper_file_; | 827 use_small ? &guest_small_wallpaper_file_ : &guest_large_wallpaper_file_; |
791 } else { | 828 } else { |
792 file = use_small ? &default_small_wallpaper_file_ | 829 file = use_small ? &default_small_wallpaper_file_ |
793 : &default_large_wallpaper_file_; | 830 : &default_large_wallpaper_file_; |
794 } | 831 } |
795 const ash::WallpaperLayout layout = | 832 const ash::WallpaperLayout layout = |
796 use_small ? ash::WALLPAPER_LAYOUT_CENTER | 833 use_small ? ash::WALLPAPER_LAYOUT_CENTER |
797 : ash::WALLPAPER_LAYOUT_CENTER_CROPPED; | 834 : ash::WALLPAPER_LAYOUT_CENTER_CROPPED; |
798 DCHECK(file); | 835 DCHECK(file); |
799 if (!default_wallpaper_image_.get() || | 836 if (!default_wallpaper_image_.get() || |
800 default_wallpaper_image_->url().spec() != file->value()) { | 837 default_wallpaper_image_->file_path() != file->value()) { |
801 default_wallpaper_image_.reset(); | 838 default_wallpaper_image_.reset(); |
802 if (!file->empty()) { | 839 if (!file->empty()) { |
803 loaded_wallpapers_++; | 840 loaded_wallpapers_++; |
804 StartLoadAndSetDefaultWallpaper( | 841 StartLoadAndSetDefaultWallpaper( |
805 *file, layout, on_finish.Pass(), &default_wallpaper_image_); | 842 *file, layout, on_finish.Pass(), &default_wallpaper_image_); |
806 return; | 843 return; |
807 } | 844 } |
808 | 845 |
809 const int resource_id = use_small ? IDR_AURA_WALLPAPER_DEFAULT_SMALL | 846 const int resource_id = use_small ? IDR_AURA_WALLPAPER_DEFAULT_SMALL |
810 : IDR_AURA_WALLPAPER_DEFAULT_LARGE; | 847 : IDR_AURA_WALLPAPER_DEFAULT_LARGE; |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1513 if (!last_load_finished_at_.is_null()) { | 1550 if (!last_load_finished_at_.is_null()) { |
1514 const base::TimeDelta interval = base::Time::Now() - last_load_finished_at_; | 1551 const base::TimeDelta interval = base::Time::Now() - last_load_finished_at_; |
1515 if (interval > delay) | 1552 if (interval > delay) |
1516 delay = base::TimeDelta::FromMilliseconds(0); | 1553 delay = base::TimeDelta::FromMilliseconds(0); |
1517 else if (interval > base::TimeDelta::FromMilliseconds(0)) | 1554 else if (interval > base::TimeDelta::FromMilliseconds(0)) |
1518 delay -= interval; | 1555 delay -= interval; |
1519 } | 1556 } |
1520 return delay; | 1557 return delay; |
1521 } | 1558 } |
1522 | 1559 |
1560 void WallpaperManager::SetCustomizedDefaultWallpaperAfterCheck( | |
1561 const GURL& wallpaper_url, | |
1562 const base::FilePath& downloaded_file, | |
1563 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | |
1564 scoped_ptr<CustomizedWallpaperFilesExist> exist) { | |
1565 PrefService* pref_service = g_browser_process->local_state(); | |
1566 | |
1567 std::string current_url = | |
1568 pref_service->GetString(prefs::kCustomizationDefaultWallpaperURL); | |
1569 if (current_url != wallpaper_url.spec() || !exist->AllRescaledExist()) { | |
1570 DCHECK(exist->downloaded); | |
1571 // Need rescale | |
1572 wallpaper_loader_->Start( | |
1573 downloaded_file.value(), | |
1574 0, // Do not crop. | |
1575 base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperDecoded, | |
1576 weak_factory_.GetWeakPtr(), | |
1577 wallpaper_url, | |
1578 base::Passed(rescaled_files.Pass()))); | |
1579 } else { | |
1580 SetDefaultWallpaperPath(rescaled_files->path_rescaled_small, | |
1581 scoped_ptr<gfx::ImageSkia>().Pass(), | |
1582 rescaled_files->path_rescaled_large, | |
1583 scoped_ptr<gfx::ImageSkia>().Pass()); | |
1584 } | |
1585 } | |
1586 | |
1587 void WallpaperManager::OnCustomizedDefaultWallpaperDecoded( | |
1588 const GURL& wallpaper_url, | |
1589 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | |
1590 const UserImage& wallpaper) { | |
1591 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
1592 | |
1593 // If decoded wallpaper is empty, we have probably failed to decode the file. | |
1594 if (wallpaper.image().isNull()) { | |
1595 LOG(WARNING) << "Failed to decode customized wallpaper."; | |
1596 return; | |
1597 } | |
1598 | |
1599 wallpaper.image().EnsureRepsForSupportedScales(); | |
1600 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy()); | |
1601 | |
1602 scoped_ptr<bool> success(new bool(false)); | |
1603 scoped_ptr<gfx::ImageSkia> small_wallpaper_image(new gfx::ImageSkia); | |
1604 scoped_ptr<gfx::ImageSkia> large_wallpaper_image(new gfx::ImageSkia); | |
1605 | |
1606 // TODO(bshe): This may break if RawImage becomes RefCountedMemory. | |
1607 base::Closure resize_closure = | |
1608 base::Bind(&WallpaperManager::ResizeCustomizedDefaultWallpaper, | |
1609 base::Unretained(this), | |
1610 base::Passed(&deep_copy), | |
1611 wallpaper.raw_image(), | |
1612 base::Unretained(rescaled_files.get()), | |
1613 base::Unretained(success.get()), | |
1614 base::Unretained(small_wallpaper_image.get()), | |
1615 base::Unretained(large_wallpaper_image.get())); | |
1616 base::Closure on_resized_closure = | |
1617 base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperResized, | |
1618 weak_factory_.GetWeakPtr(), | |
1619 wallpaper_url, | |
1620 base::Passed(rescaled_files.Pass()), | |
1621 base::Passed(success.Pass()), | |
1622 base::Passed(small_wallpaper_image.Pass()), | |
1623 base::Passed(large_wallpaper_image.Pass())); | |
1624 | |
1625 if (!task_runner_->PostTaskAndReply( | |
1626 FROM_HERE, resize_closure, on_resized_closure)) { | |
1627 LOG(WARNING) << "Failed to start Customized Wallpaper resize."; | |
1628 } | |
1629 } | |
1630 | |
1631 void WallpaperManager::ResizeCustomizedDefaultWallpaper( | |
1632 scoped_ptr<gfx::ImageSkia> image, | |
1633 const UserImage::RawImage& raw_image, | |
1634 const CustomizedWallpaperRescaledFiles* rescaled_files, | |
1635 bool* success, | |
1636 gfx::ImageSkia* small_wallpaper_image, | |
1637 gfx::ImageSkia* large_wallpaper_image) { | |
1638 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | |
1639 sequence_token_)); | |
1640 UserImage wallpaper(*image.get(), raw_image); | |
1641 | |
1642 *success = true; | |
1643 | |
1644 *success &= ResizeAndSaveWallpaper(wallpaper, | |
1645 rescaled_files->path_rescaled_small, | |
1646 ash::WALLPAPER_LAYOUT_STRETCH, | |
1647 kSmallWallpaperMaxWidth, | |
1648 kSmallWallpaperMaxHeight, | |
1649 small_wallpaper_image); | |
1650 | |
1651 *success &= ResizeAndSaveWallpaper(wallpaper, | |
1652 rescaled_files->path_rescaled_large, | |
1653 ash::WALLPAPER_LAYOUT_STRETCH, | |
1654 kLargeWallpaperMaxWidth, | |
1655 kLargeWallpaperMaxHeight, | |
1656 large_wallpaper_image); | |
1657 } | |
1658 | |
1659 void WallpaperManager::OnCustomizedDefaultWallpaperResized( | |
1660 const GURL& wallpaper_url, | |
1661 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | |
1662 scoped_ptr<bool> success, | |
1663 scoped_ptr<gfx::ImageSkia> small_wallpaper_image, | |
1664 scoped_ptr<gfx::ImageSkia> large_wallpaper_image) { | |
1665 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
1666 DCHECK(rescaled_files.get()); | |
1667 DCHECK(success.get()); | |
1668 if (!*success) { | |
1669 LOG(WARNING) << "Failed to save Resized Customized Default Wallpaper"; | |
Daniel Erat
2014/04/14 15:26:15
nit: "resized customized default wallpaper" (capit
Alexander Alekseev
2014/04/15 01:57:16
Done.
| |
1670 return; | |
1671 } | |
1672 PrefService* pref_service = g_browser_process->local_state(); | |
1673 pref_service->SetString(prefs::kCustomizationDefaultWallpaperURL, | |
1674 wallpaper_url.spec()); | |
1675 SetDefaultWallpaperPath(rescaled_files->path_rescaled_small, | |
1676 small_wallpaper_image.Pass(), | |
1677 rescaled_files->path_rescaled_large, | |
1678 large_wallpaper_image.Pass()); | |
1679 VLOG(1) << "Customized Default Wallpaper applied."; | |
1680 } | |
1681 | |
1523 WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper( | 1682 WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper( |
1524 const std::string& user_id, | 1683 const std::string& user_id, |
1525 bool delayed) { | 1684 bool delayed) { |
1526 if (!pending_inactive_) { | 1685 if (!pending_inactive_) { |
1527 loading_.push_back(new WallpaperManager::PendingWallpaper( | 1686 loading_.push_back(new WallpaperManager::PendingWallpaper( |
1528 (delayed ? GetWallpaperLoadDelay() | 1687 (delayed ? GetWallpaperLoadDelay() |
1529 : base::TimeDelta::FromMilliseconds(0)), | 1688 : base::TimeDelta::FromMilliseconds(0)), |
1530 user_id)); | 1689 user_id)); |
1531 pending_inactive_ = loading_.back(); | 1690 pending_inactive_ = loading_.back(); |
1532 } | 1691 } |
1533 return pending_inactive_; | 1692 return pending_inactive_; |
1534 } | 1693 } |
1535 | 1694 |
1695 // static | |
1696 base::FilePath WallpaperManager::GetCustomizedWallpaperDefaultRescaledFileName( | |
1697 const char* suffix) { | |
1698 const base::FilePath default_downloaded_file_name = | |
1699 ServicesCustomizationDocument::GetCustomizedWallpaperDownloadedFileName(); | |
1700 const base::FilePath default_cache_dir = | |
1701 ServicesCustomizationDocument::GetCustomizedWallpaperCacheDir(); | |
1702 if (default_downloaded_file_name.empty() || default_cache_dir.empty()) | |
1703 return base::FilePath(); | |
1704 return default_cache_dir.Append( | |
1705 default_downloaded_file_name.BaseName().value() + suffix); | |
1706 } | |
1707 | |
1708 void WallpaperManager::SetCustomizedDefaultWallpaper( | |
1709 const GURL& wallpaper_url, | |
1710 const base::FilePath& downloaded_file, | |
1711 const base::FilePath& resized_directory) { | |
1712 // Should fail if this ever happens in tests. | |
1713 DCHECK(wallpaper_url.is_valid() || wallpaper_url.is_empty()); | |
Daniel Erat
2014/04/14 15:26:15
same comment as before about is_empty
Alexander Alekseev
2014/04/15 01:57:16
Done.
| |
1714 if (!wallpaper_url.is_valid()) { | |
1715 if (!wallpaper_url.is_empty()) { | |
1716 LOG(WARNING) << "Invalid Customized Wallpaper URL."; | |
1717 } | |
1718 return; | |
1719 } | |
1720 std::string downloaded_file_name = downloaded_file.BaseName().value(); | |
1721 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files( | |
1722 new CustomizedWallpaperRescaledFiles( | |
1723 resized_directory.Append(downloaded_file_name + | |
1724 kSmallWallpaperSuffix), | |
1725 resized_directory.Append(downloaded_file_name + | |
1726 kLargeWallpaperSuffix))); | |
1727 scoped_ptr<CustomizedWallpaperFilesExist> exist( | |
1728 new CustomizedWallpaperFilesExist); | |
1729 | |
1730 base::Closure check_file_exists = | |
1731 base::Bind(&CheckCustomizedWallpaperFilesExist, | |
1732 downloaded_file, | |
1733 base::Unretained(rescaled_files.get()), | |
1734 base::Unretained(exist.get())); | |
1735 base::Closure on_checked_closure = | |
1736 base::Bind(&WallpaperManager::SetCustomizedDefaultWallpaperAfterCheck, | |
1737 weak_factory_.GetWeakPtr(), | |
1738 wallpaper_url, | |
1739 downloaded_file, | |
1740 base::Passed(rescaled_files.Pass()), | |
1741 base::Passed(exist.Pass())); | |
1742 if (!BrowserThread::PostBlockingPoolTaskAndReply( | |
1743 FROM_HERE, check_file_exists, on_checked_closure)) { | |
1744 LOG(WARNING) << "Failed to start check CheckCustomizedWallpaperFilesExist."; | |
1745 } | |
1746 } | |
1747 | |
1748 // static | |
1749 bool WallpaperManager::ShouldUseCustomizedDefaultWallpaper() { | |
1750 PrefService* pref_service = g_browser_process->local_state(); | |
1751 | |
1752 return !(pref_service->FindPreference( | |
1753 prefs::kCustomizationDefaultWallpaperURL) | |
1754 ->IsDefaultValue()); | |
1755 } | |
1756 | |
1536 void WallpaperManager::SetDefaultWallpaperPathsFromCommandLine( | 1757 void WallpaperManager::SetDefaultWallpaperPathsFromCommandLine( |
1537 base::CommandLine* command_line) { | 1758 base::CommandLine* command_line) { |
1538 default_small_wallpaper_file_ = command_line->GetSwitchValuePath( | 1759 default_small_wallpaper_file_ = command_line->GetSwitchValuePath( |
1539 ash::switches::kAshDefaultWallpaperSmall); | 1760 ash::switches::kAshDefaultWallpaperSmall); |
1540 default_large_wallpaper_file_ = command_line->GetSwitchValuePath( | 1761 default_large_wallpaper_file_ = command_line->GetSwitchValuePath( |
1541 ash::switches::kAshDefaultWallpaperLarge); | 1762 ash::switches::kAshDefaultWallpaperLarge); |
1542 guest_small_wallpaper_file_ = | 1763 guest_small_wallpaper_file_ = |
1543 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperSmall); | 1764 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperSmall); |
1544 guest_large_wallpaper_file_ = | 1765 guest_large_wallpaper_file_ = |
1545 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperLarge); | 1766 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperLarge); |
1546 default_wallpaper_image_.reset(); | 1767 default_wallpaper_image_.reset(); |
1547 } | 1768 } |
1548 | 1769 |
1549 void WallpaperManager::OnDefaultWallpaperDecoded( | 1770 void WallpaperManager::OnDefaultWallpaperDecoded( |
1550 const base::FilePath& path, | 1771 const base::FilePath& path, |
1551 const ash::WallpaperLayout layout, | 1772 const ash::WallpaperLayout layout, |
1552 scoped_ptr<chromeos::UserImage>* result_out, | 1773 scoped_ptr<chromeos::UserImage>* result_out, |
1553 MovableOnDestroyCallbackHolder on_finish, | 1774 MovableOnDestroyCallbackHolder on_finish, |
1554 const UserImage& wallpaper) { | 1775 const UserImage& wallpaper) { |
1555 result_out->reset(new UserImage(wallpaper.image())); | 1776 result_out->reset(new UserImage(wallpaper)); |
1556 (*result_out)->set_url(GURL(path.value())); | |
1557 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( | 1777 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( |
1558 wallpaper.image(), layout); | 1778 wallpaper.image(), layout); |
1559 } | 1779 } |
1560 | 1780 |
1561 void WallpaperManager::StartLoadAndSetDefaultWallpaper( | 1781 void WallpaperManager::StartLoadAndSetDefaultWallpaper( |
1562 const base::FilePath& path, | 1782 const base::FilePath& path, |
1563 const ash::WallpaperLayout layout, | 1783 const ash::WallpaperLayout layout, |
1564 MovableOnDestroyCallbackHolder on_finish, | 1784 MovableOnDestroyCallbackHolder on_finish, |
1565 scoped_ptr<chromeos::UserImage>* result_out) { | 1785 scoped_ptr<chromeos::UserImage>* result_out) { |
1566 wallpaper_loader_->Start( | 1786 wallpaper_loader_->Start( |
1567 path.value(), | 1787 path.value(), |
1568 0, // Do not crop. | 1788 0, // Do not crop. |
1569 base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded, | 1789 base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded, |
1570 weak_factory_.GetWeakPtr(), | 1790 weak_factory_.GetWeakPtr(), |
1571 path, | 1791 path, |
1572 layout, | 1792 layout, |
1573 base::Unretained(result_out), | 1793 base::Unretained(result_out), |
1574 base::Passed(on_finish.Pass()))); | 1794 base::Passed(on_finish.Pass()))); |
1575 } | 1795 } |
1576 | 1796 |
1577 const char* WallpaperManager::GetCustomWallpaperSubdirForCurrentResolution() { | 1797 const char* WallpaperManager::GetCustomWallpaperSubdirForCurrentResolution() { |
1578 WallpaperResolution resolution = GetAppropriateResolution(); | 1798 WallpaperResolution resolution = GetAppropriateResolution(); |
1579 return resolution == WALLPAPER_RESOLUTION_SMALL ? kSmallWallpaperSubDir | 1799 return resolution == WALLPAPER_RESOLUTION_SMALL ? kSmallWallpaperSubDir |
1580 : kLargeWallpaperSubDir; | 1800 : kLargeWallpaperSubDir; |
1581 } | 1801 } |
1582 | 1802 |
1803 void WallpaperManager::SetDefaultWallpaperPath( | |
1804 const base::FilePath& default_small_wallpaper_file, | |
1805 scoped_ptr<gfx::ImageSkia> small_wallpaper_image, | |
1806 const base::FilePath& default_large_wallpaper_file, | |
1807 scoped_ptr<gfx::ImageSkia> large_wallpaper_image) { | |
1808 default_small_wallpaper_file_ = default_small_wallpaper_file; | |
1809 default_large_wallpaper_file_ = default_large_wallpaper_file; | |
1810 | |
1811 ash::DesktopBackgroundController* dbc = | |
1812 ash::Shell::GetInstance()->desktop_background_controller(); | |
1813 const bool need_reload = | |
1814 default_wallpaper_image_.get() && | |
1815 dbc->WallpaperIsAlreadyLoaded(&(default_wallpaper_image_->image()), | |
1816 ash::kInvalidResourceID, | |
1817 ash::WALLPAPER_LAYOUT_UNKNOWN); | |
1818 | |
1819 default_wallpaper_image_.reset(); | |
1820 if (GetAppropriateResolution() == WALLPAPER_RESOLUTION_SMALL) { | |
1821 if (small_wallpaper_image) { | |
1822 default_wallpaper_image_.reset(new UserImage(*small_wallpaper_image)); | |
1823 default_wallpaper_image_->set_file_path( | |
1824 default_small_wallpaper_file.value()); | |
1825 } | |
1826 } else { | |
1827 if (large_wallpaper_image) { | |
1828 default_wallpaper_image_.reset(new UserImage(*large_wallpaper_image)); | |
1829 default_wallpaper_image_->set_file_path( | |
1830 default_large_wallpaper_file.value()); | |
1831 } | |
1832 } | |
1833 | |
1834 if (need_reload) { | |
1835 DoSetDefaultWallpaper(std::string(), | |
1836 MovableOnDestroyCallbackHolder().Pass()); | |
1837 } | |
1838 } | |
1839 | |
1583 } // namespace chromeos | 1840 } // namespace chromeos |
OLD | NEW |