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