| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/users/wallpaper/wallpaper_manager.h" | 5 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 6 | 6 |
| 7 #include <numeric> | 7 #include <numeric> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/ash_constants.h" | 10 #include "ash/ash_constants.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "base/strings/string_util.h" | 26 #include "base/strings/string_util.h" |
| 27 #include "base/strings/stringprintf.h" | 27 #include "base/strings/stringprintf.h" |
| 28 #include "base/sys_info.h" | 28 #include "base/sys_info.h" |
| 29 #include "base/threading/worker_pool.h" | 29 #include "base/threading/worker_pool.h" |
| 30 #include "base/time/time.h" | 30 #include "base/time/time.h" |
| 31 #include "base/values.h" | 31 #include "base/values.h" |
| 32 #include "chrome/browser/browser_process.h" | 32 #include "chrome/browser/browser_process.h" |
| 33 #include "chrome/browser/chrome_notification_types.h" | 33 #include "chrome/browser/chrome_notification_types.h" |
| 34 #include "chrome/browser/chromeos/customization_document.h" | 34 #include "chrome/browser/chromeos/customization_document.h" |
| 35 #include "chrome/browser/chromeos/login/startup_utils.h" | 35 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 36 #include "chrome/browser/chromeos/login/users/avatar/user_image.h" | |
| 37 #include "chrome/browser/chromeos/login/users/user.h" | 36 #include "chrome/browser/chromeos/login/users/user.h" |
| 38 #include "chrome/browser/chromeos/login/users/user_manager.h" | 37 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 39 #include "chrome/browser/chromeos/login/wizard_controller.h" | 38 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 40 #include "chrome/browser/chromeos/settings/cros_settings.h" | 39 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 41 #include "chrome/common/chrome_paths.h" | 40 #include "chrome/common/chrome_paths.h" |
| 42 #include "chrome/common/chrome_switches.h" | 41 #include "chrome/common/chrome_switches.h" |
| 43 #include "chrome/common/pref_names.h" | 42 #include "chrome/common/pref_names.h" |
| 44 #include "chromeos/chromeos_switches.h" | 43 #include "chromeos/chromeos_switches.h" |
| 45 #include "chromeos/dbus/dbus_thread_manager.h" | 44 #include "chromeos/dbus/dbus_thread_manager.h" |
| 46 #include "chromeos/login/user_names.h" | 45 #include "chromeos/login/user_names.h" |
| 46 #include "components/user_manager/user_image/user_image.h" |
| 47 #include "components/user_manager/user_type.h" | 47 #include "components/user_manager/user_type.h" |
| 48 #include "content/public/browser/browser_thread.h" | 48 #include "content/public/browser/browser_thread.h" |
| 49 #include "content/public/browser/notification_service.h" | 49 #include "content/public/browser/notification_service.h" |
| 50 #include "third_party/skia/include/core/SkColor.h" | 50 #include "third_party/skia/include/core/SkColor.h" |
| 51 #include "ui/gfx/codec/jpeg_codec.h" | 51 #include "ui/gfx/codec/jpeg_codec.h" |
| 52 #include "ui/gfx/image/image_skia_operations.h" | 52 #include "ui/gfx/image/image_skia_operations.h" |
| 53 #include "ui/gfx/skia_util.h" | 53 #include "ui/gfx/skia_util.h" |
| 54 | 54 |
| 55 using content::BrowserThread; | 55 using content::BrowserThread; |
| 56 | 56 |
| (...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 base::FilePath WallpaperManager::GetCustomWallpaperPath( | 827 base::FilePath WallpaperManager::GetCustomWallpaperPath( |
| 828 const char* sub_dir, | 828 const char* sub_dir, |
| 829 const std::string& user_id_hash, | 829 const std::string& user_id_hash, |
| 830 const std::string& file) { | 830 const std::string& file) { |
| 831 base::FilePath custom_wallpaper_path = GetCustomWallpaperDir(sub_dir); | 831 base::FilePath custom_wallpaper_path = GetCustomWallpaperDir(sub_dir); |
| 832 return custom_wallpaper_path.Append(user_id_hash).Append(file); | 832 return custom_wallpaper_path.Append(user_id_hash).Append(file); |
| 833 } | 833 } |
| 834 | 834 |
| 835 void WallpaperManager::SetPolicyControlledWallpaper( | 835 void WallpaperManager::SetPolicyControlledWallpaper( |
| 836 const std::string& user_id, | 836 const std::string& user_id, |
| 837 const UserImage& user_image) { | 837 const user_manager::UserImage& user_image) { |
| 838 const User *user = chromeos::UserManager::Get()->FindUser(user_id); | 838 const User *user = chromeos::UserManager::Get()->FindUser(user_id); |
| 839 if (!user) { | 839 if (!user) { |
| 840 NOTREACHED() << "Unknown user."; | 840 NOTREACHED() << "Unknown user."; |
| 841 return; | 841 return; |
| 842 } | 842 } |
| 843 SetCustomWallpaper(user_id, | 843 SetCustomWallpaper(user_id, |
| 844 user->username_hash(), | 844 user->username_hash(), |
| 845 "policy-controlled.jpeg", | 845 "policy-controlled.jpeg", |
| 846 ash::WALLPAPER_LAYOUT_CENTER_CROPPED, | 846 ash::WALLPAPER_LAYOUT_CENTER_CROPPED, |
| 847 User::POLICY, | 847 User::POLICY, |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1532 logged_in_user->email(), | 1532 logged_in_user->email(), |
| 1533 logged_in_user->username_hash(), | 1533 logged_in_user->username_hash(), |
| 1534 weak_factory_.GetWeakPtr())); | 1534 weak_factory_.GetWeakPtr())); |
| 1535 } | 1535 } |
| 1536 | 1536 |
| 1537 void WallpaperManager::OnWallpaperDecoded( | 1537 void WallpaperManager::OnWallpaperDecoded( |
| 1538 const std::string& user_id, | 1538 const std::string& user_id, |
| 1539 ash::WallpaperLayout layout, | 1539 ash::WallpaperLayout layout, |
| 1540 bool update_wallpaper, | 1540 bool update_wallpaper, |
| 1541 MovableOnDestroyCallbackHolder on_finish, | 1541 MovableOnDestroyCallbackHolder on_finish, |
| 1542 const UserImage& user_image) { | 1542 const user_manager::UserImage& user_image) { |
| 1543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1544 TRACE_EVENT_ASYNC_END0("ui", "LoadAndDecodeWallpaper", this); | 1544 TRACE_EVENT_ASYNC_END0("ui", "LoadAndDecodeWallpaper", this); |
| 1545 | 1545 |
| 1546 // If decoded wallpaper is empty, we have probably failed to decode the file. | 1546 // If decoded wallpaper is empty, we have probably failed to decode the file. |
| 1547 // Use default wallpaper in this case. | 1547 // Use default wallpaper in this case. |
| 1548 if (user_image.image().isNull()) { | 1548 if (user_image.image().isNull()) { |
| 1549 // Updates user pref to default wallpaper. | 1549 // Updates user pref to default wallpaper. |
| 1550 WallpaperInfo info = { | 1550 WallpaperInfo info = { |
| 1551 "", | 1551 "", |
| 1552 ash::WALLPAPER_LAYOUT_CENTER_CROPPED, | 1552 ash::WALLPAPER_LAYOUT_CENTER_CROPPED, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1650 SetDefaultWallpaperPath(rescaled_files->path_rescaled_small(), | 1650 SetDefaultWallpaperPath(rescaled_files->path_rescaled_small(), |
| 1651 scoped_ptr<gfx::ImageSkia>().Pass(), | 1651 scoped_ptr<gfx::ImageSkia>().Pass(), |
| 1652 rescaled_files->path_rescaled_large(), | 1652 rescaled_files->path_rescaled_large(), |
| 1653 scoped_ptr<gfx::ImageSkia>().Pass()); | 1653 scoped_ptr<gfx::ImageSkia>().Pass()); |
| 1654 } | 1654 } |
| 1655 } | 1655 } |
| 1656 | 1656 |
| 1657 void WallpaperManager::OnCustomizedDefaultWallpaperDecoded( | 1657 void WallpaperManager::OnCustomizedDefaultWallpaperDecoded( |
| 1658 const GURL& wallpaper_url, | 1658 const GURL& wallpaper_url, |
| 1659 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | 1659 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, |
| 1660 const UserImage& wallpaper) { | 1660 const user_manager::UserImage& wallpaper) { |
| 1661 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1661 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1662 | 1662 |
| 1663 // If decoded wallpaper is empty, we have probably failed to decode the file. | 1663 // If decoded wallpaper is empty, we have probably failed to decode the file. |
| 1664 if (wallpaper.image().isNull()) { | 1664 if (wallpaper.image().isNull()) { |
| 1665 LOG(WARNING) << "Failed to decode customized wallpaper."; | 1665 LOG(WARNING) << "Failed to decode customized wallpaper."; |
| 1666 return; | 1666 return; |
| 1667 } | 1667 } |
| 1668 | 1668 |
| 1669 wallpaper.image().EnsureRepsForSupportedScales(); | 1669 wallpaper.image().EnsureRepsForSupportedScales(); |
| 1670 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy()); | 1670 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1692 base::Passed(large_wallpaper_image.Pass())); | 1692 base::Passed(large_wallpaper_image.Pass())); |
| 1693 | 1693 |
| 1694 if (!task_runner_->PostTaskAndReply( | 1694 if (!task_runner_->PostTaskAndReply( |
| 1695 FROM_HERE, resize_closure, on_resized_closure)) { | 1695 FROM_HERE, resize_closure, on_resized_closure)) { |
| 1696 LOG(WARNING) << "Failed to start Customized Wallpaper resize."; | 1696 LOG(WARNING) << "Failed to start Customized Wallpaper resize."; |
| 1697 } | 1697 } |
| 1698 } | 1698 } |
| 1699 | 1699 |
| 1700 void WallpaperManager::ResizeCustomizedDefaultWallpaper( | 1700 void WallpaperManager::ResizeCustomizedDefaultWallpaper( |
| 1701 scoped_ptr<gfx::ImageSkia> image, | 1701 scoped_ptr<gfx::ImageSkia> image, |
| 1702 const UserImage::RawImage& raw_image, | 1702 const user_manager::UserImage::RawImage& raw_image, |
| 1703 const CustomizedWallpaperRescaledFiles* rescaled_files, | 1703 const CustomizedWallpaperRescaledFiles* rescaled_files, |
| 1704 bool* success, | 1704 bool* success, |
| 1705 gfx::ImageSkia* small_wallpaper_image, | 1705 gfx::ImageSkia* small_wallpaper_image, |
| 1706 gfx::ImageSkia* large_wallpaper_image) { | 1706 gfx::ImageSkia* large_wallpaper_image) { |
| 1707 *success = true; | 1707 *success = true; |
| 1708 | 1708 |
| 1709 *success &= ResizeAndSaveWallpaper(*image, | 1709 *success &= ResizeAndSaveWallpaper(*image, |
| 1710 rescaled_files->path_rescaled_small(), | 1710 rescaled_files->path_rescaled_small(), |
| 1711 ash::WALLPAPER_LAYOUT_STRETCH, | 1711 ash::WALLPAPER_LAYOUT_STRETCH, |
| 1712 kSmallWallpaperMaxWidth, | 1712 kSmallWallpaperMaxWidth, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1821 guest_small_wallpaper_file_ = | 1821 guest_small_wallpaper_file_ = |
| 1822 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperSmall); | 1822 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperSmall); |
| 1823 guest_large_wallpaper_file_ = | 1823 guest_large_wallpaper_file_ = |
| 1824 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperLarge); | 1824 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperLarge); |
| 1825 default_wallpaper_image_.reset(); | 1825 default_wallpaper_image_.reset(); |
| 1826 } | 1826 } |
| 1827 | 1827 |
| 1828 void WallpaperManager::OnDefaultWallpaperDecoded( | 1828 void WallpaperManager::OnDefaultWallpaperDecoded( |
| 1829 const base::FilePath& path, | 1829 const base::FilePath& path, |
| 1830 const ash::WallpaperLayout layout, | 1830 const ash::WallpaperLayout layout, |
| 1831 scoped_ptr<chromeos::UserImage>* result_out, | 1831 scoped_ptr<user_manager::UserImage>* result_out, |
| 1832 MovableOnDestroyCallbackHolder on_finish, | 1832 MovableOnDestroyCallbackHolder on_finish, |
| 1833 const UserImage& user_image) { | 1833 const user_manager::UserImage& user_image) { |
| 1834 result_out->reset(new UserImage(user_image)); | 1834 result_out->reset(new user_manager::UserImage(user_image)); |
| 1835 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( | 1835 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( |
| 1836 user_image.image(), layout); | 1836 user_image.image(), layout); |
| 1837 } | 1837 } |
| 1838 | 1838 |
| 1839 void WallpaperManager::StartLoadAndSetDefaultWallpaper( | 1839 void WallpaperManager::StartLoadAndSetDefaultWallpaper( |
| 1840 const base::FilePath& path, | 1840 const base::FilePath& path, |
| 1841 const ash::WallpaperLayout layout, | 1841 const ash::WallpaperLayout layout, |
| 1842 MovableOnDestroyCallbackHolder on_finish, | 1842 MovableOnDestroyCallbackHolder on_finish, |
| 1843 scoped_ptr<chromeos::UserImage>* result_out) { | 1843 scoped_ptr<user_manager::UserImage>* result_out) { |
| 1844 wallpaper_loader_->Start( | 1844 wallpaper_loader_->Start( |
| 1845 path.value(), | 1845 path.value(), |
| 1846 0, // Do not crop. | 1846 0, // Do not crop. |
| 1847 base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded, | 1847 base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded, |
| 1848 weak_factory_.GetWeakPtr(), | 1848 weak_factory_.GetWeakPtr(), |
| 1849 path, | 1849 path, |
| 1850 layout, | 1850 layout, |
| 1851 base::Unretained(result_out), | 1851 base::Unretained(result_out), |
| 1852 base::Passed(on_finish.Pass()))); | 1852 base::Passed(on_finish.Pass()))); |
| 1853 } | 1853 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1876 // as a placeholder only. | 1876 // as a placeholder only. |
| 1877 const bool need_update_screen = | 1877 const bool need_update_screen = |
| 1878 default_wallpaper_image_.get() && | 1878 default_wallpaper_image_.get() && |
| 1879 dbc->WallpaperIsAlreadyLoaded(default_wallpaper_image_->image(), | 1879 dbc->WallpaperIsAlreadyLoaded(default_wallpaper_image_->image(), |
| 1880 false /* compare_layouts */, | 1880 false /* compare_layouts */, |
| 1881 ash::WALLPAPER_LAYOUT_CENTER); | 1881 ash::WALLPAPER_LAYOUT_CENTER); |
| 1882 | 1882 |
| 1883 default_wallpaper_image_.reset(); | 1883 default_wallpaper_image_.reset(); |
| 1884 if (GetAppropriateResolution() == WALLPAPER_RESOLUTION_SMALL) { | 1884 if (GetAppropriateResolution() == WALLPAPER_RESOLUTION_SMALL) { |
| 1885 if (small_wallpaper_image) { | 1885 if (small_wallpaper_image) { |
| 1886 default_wallpaper_image_.reset(new UserImage(*small_wallpaper_image)); | 1886 default_wallpaper_image_.reset( |
| 1887 new user_manager::UserImage(*small_wallpaper_image)); |
| 1887 default_wallpaper_image_->set_file_path( | 1888 default_wallpaper_image_->set_file_path( |
| 1888 default_small_wallpaper_file.value()); | 1889 default_small_wallpaper_file.value()); |
| 1889 } | 1890 } |
| 1890 } else { | 1891 } else { |
| 1891 if (large_wallpaper_image) { | 1892 if (large_wallpaper_image) { |
| 1892 default_wallpaper_image_.reset(new UserImage(*large_wallpaper_image)); | 1893 default_wallpaper_image_.reset( |
| 1894 new user_manager::UserImage(*large_wallpaper_image)); |
| 1893 default_wallpaper_image_->set_file_path( | 1895 default_wallpaper_image_->set_file_path( |
| 1894 default_large_wallpaper_file.value()); | 1896 default_large_wallpaper_file.value()); |
| 1895 } | 1897 } |
| 1896 } | 1898 } |
| 1897 | 1899 |
| 1898 if (need_update_screen) { | 1900 if (need_update_screen) { |
| 1899 DoSetDefaultWallpaper(std::string(), | 1901 DoSetDefaultWallpaper(std::string(), |
| 1900 MovableOnDestroyCallbackHolder().Pass()); | 1902 MovableOnDestroyCallbackHolder().Pass()); |
| 1901 } | 1903 } |
| 1902 } | 1904 } |
| 1903 | 1905 |
| 1904 void WallpaperManager::CreateSolidDefaultWallpaper() { | 1906 void WallpaperManager::CreateSolidDefaultWallpaper() { |
| 1905 loaded_wallpapers_++; | 1907 loaded_wallpapers_++; |
| 1906 SkBitmap bitmap; | 1908 SkBitmap bitmap; |
| 1907 bitmap.allocN32Pixels(1, 1); | 1909 bitmap.allocN32Pixels(1, 1); |
| 1908 bitmap.eraseColor(kDefaultWallpaperColor); | 1910 bitmap.eraseColor(kDefaultWallpaperColor); |
| 1909 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 1911 const gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 1910 default_wallpaper_image_.reset(new UserImage(image)); | 1912 default_wallpaper_image_.reset(new user_manager::UserImage(image)); |
| 1911 } | 1913 } |
| 1912 | 1914 |
| 1913 } // namespace chromeos | 1915 } // namespace chromeos |
| OLD | NEW |