OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/desktop_background/desktop_background_resources.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/desktop_background/desktop_background_controller.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "base/time.h" | 10 #include "base/time.h" |
10 #include "base/values.h" | 11 #include "base/values.h" |
11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/chromeos/cros_settings.h" | 13 #include "chrome/browser/chromeos/cros_settings.h" |
13 #include "chrome/browser/chromeos/login/user.h" | 14 #include "chrome/browser/chromeos/login/user.h" |
14 #include "chrome/browser/chromeos/login/user_manager.h" | 15 #include "chrome/browser/chromeos/login/user_manager.h" |
15 #include "chrome/browser/chromeos/login/user_manager_impl.h" | 16 #include "chrome/browser/chromeos/login/user_manager_impl.h" |
16 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
17 #include "chromeos/dbus/dbus_thread_manager.h" | 18 #include "chromeos/dbus/dbus_thread_manager.h" |
18 #include "chromeos/dbus/power_manager_client.h" | 19 #include "chromeos/dbus/power_manager_client.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 const int kWallpaperUpdateIntervalSec = 24 * 60 * 60; | 22 const int kWallpaperUpdateIntervalSec = 24 * 60 * 60; |
22 } // namespace | 23 } // namespace |
23 | 24 |
24 namespace chromeos { | 25 namespace chromeos { |
25 | 26 |
26 static WallpaperManager* g_wallpaper_manager = NULL; | 27 static WallpaperManager* g_wallpaper_manager = NULL; |
27 | 28 |
28 WallpaperManager::WallpaperManager() : last_selected_user_("") { | 29 WallpaperManager::WallpaperManager() |
| 30 : ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_(new UserImageLoader)), |
| 31 last_selected_user_("") { |
29 system::TimezoneSettings::GetInstance()->AddObserver(this); | 32 system::TimezoneSettings::GetInstance()->AddObserver(this); |
30 RestartTimer(); | 33 RestartTimer(); |
31 } | 34 } |
32 | 35 |
33 WallpaperManager::~WallpaperManager() { | 36 WallpaperManager::~WallpaperManager() { |
34 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 37 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
35 system::TimezoneSettings::GetInstance()->RemoveObserver(this); | 38 system::TimezoneSettings::GetInstance()->RemoveObserver(this); |
36 } | 39 } |
37 | 40 |
38 void WallpaperManager::SetLastSelectedUser(std::string last_selected_user) { | 41 void WallpaperManager::SetLastSelectedUser(std::string last_selected_user) { |
(...skipping 14 matching lines...) Expand all Loading... |
53 BatchUpdateWallpaper(); | 56 BatchUpdateWallpaper(); |
54 } else { | 57 } else { |
55 // Set up a one shot timer which will batch update wallpaper at midnight. | 58 // Set up a one shot timer which will batch update wallpaper at midnight. |
56 timer_.Start(FROM_HERE, | 59 timer_.Start(FROM_HERE, |
57 base::TimeDelta::FromSeconds(remaining_seconds), | 60 base::TimeDelta::FromSeconds(remaining_seconds), |
58 this, | 61 this, |
59 &WallpaperManager::BatchUpdateWallpaper); | 62 &WallpaperManager::BatchUpdateWallpaper); |
60 } | 63 } |
61 } | 64 } |
62 | 65 |
| 66 void WallpaperManager::SetWallpaperFromFile(std::string email, |
| 67 const std::string& path, |
| 68 ash::WallpaperLayout layout) { |
| 69 image_loader_->Start( |
| 70 path, 0, false, |
| 71 base::Bind(&WallpaperManager::OnCustomWallpaperLoaded, |
| 72 base::Unretained(this), email, layout)); |
| 73 } |
| 74 |
63 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { | 75 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { |
64 RestartTimer(); | 76 RestartTimer(); |
65 } | 77 } |
66 | 78 |
67 void WallpaperManager::SystemResumed() { | 79 void WallpaperManager::SystemResumed() { |
68 BatchUpdateWallpaper(); | 80 BatchUpdateWallpaper(); |
69 } | 81 } |
70 | 82 |
| 83 void WallpaperManager::OnCustomWallpaperLoaded(const std::string& email, |
| 84 ash::WallpaperLayout layout, |
| 85 const UserImage& user_image) { |
| 86 const SkBitmap& wallpaper = user_image.image(); |
| 87 ash::Shell::GetInstance()->desktop_background_controller()-> |
| 88 SetCustomWallpaper(wallpaper, layout); |
| 89 } |
| 90 |
71 void WallpaperManager::BatchUpdateWallpaper() { | 91 void WallpaperManager::BatchUpdateWallpaper() { |
72 PrefService* local_state = g_browser_process->local_state(); | 92 PrefService* local_state = g_browser_process->local_state(); |
73 UserManager* user_manager = UserManager::Get(); | 93 UserManager* user_manager = UserManager::Get(); |
74 bool show_users = true; | 94 bool show_users = true; |
75 CrosSettings::Get()->GetBoolean( | 95 CrosSettings::Get()->GetBoolean( |
76 kAccountsPrefShowUserNamesOnSignIn, &show_users); | 96 kAccountsPrefShowUserNamesOnSignIn, &show_users); |
77 if (local_state) { | 97 if (local_state) { |
78 User::WallpaperType type; | 98 User::WallpaperType type; |
79 int index = 0; | 99 int index = 0; |
80 base::Time last_modification_date; | 100 base::Time last_modification_date; |
(...skipping 28 matching lines...) Expand all Loading... |
109 } | 129 } |
110 | 130 |
111 // static | 131 // static |
112 WallpaperManager* WallpaperManager::Get() { | 132 WallpaperManager* WallpaperManager::Get() { |
113 if(!g_wallpaper_manager) | 133 if(!g_wallpaper_manager) |
114 g_wallpaper_manager = new WallpaperManager(); | 134 g_wallpaper_manager = new WallpaperManager(); |
115 return g_wallpaper_manager; | 135 return g_wallpaper_manager; |
116 } | 136 } |
117 | 137 |
118 } // chromeos | 138 } // chromeos |
OLD | NEW |