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_controller.h" | 7 #include "ash/desktop_background/desktop_background_controller.h" |
8 #include "ash/desktop_background/desktop_background_resources.h" | 8 #include "ash/desktop_background/desktop_background_resources.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/string_number_conversions.h" |
11 #include "base/time.h" | 12 #include "base/time.h" |
12 #include "base/values.h" | 13 #include "base/values.h" |
13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/chromeos/cros_settings.h" | 15 #include "chrome/browser/chromeos/cros_settings.h" |
15 #include "chrome/browser/chromeos/login/user.h" | |
16 #include "chrome/browser/chromeos/login/user_manager.h" | 16 #include "chrome/browser/chromeos/login/user_manager.h" |
17 #include "chrome/browser/chromeos/login/user_manager_impl.h" | 17 #include "chrome/browser/chromeos/login/user_manager_impl.h" |
18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 19 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 20 #include "chrome/common/pref_names.h" |
19 #include "chromeos/dbus/dbus_thread_manager.h" | 21 #include "chromeos/dbus/dbus_thread_manager.h" |
20 #include "chromeos/dbus/power_manager_client.h" | 22 #include "chromeos/dbus/power_manager_client.h" |
| 23 #include "content/public/browser/browser_thread.h" |
| 24 |
| 25 using content::BrowserThread; |
21 | 26 |
22 namespace { | 27 namespace { |
| 28 |
23 const int kWallpaperUpdateIntervalSec = 24 * 60 * 60; | 29 const int kWallpaperUpdateIntervalSec = 24 * 60 * 60; |
| 30 |
| 31 // Names of nodes with info about wallpaper. |
| 32 const char kWallpaperDateNodeName[] = "date"; |
| 33 const char kWallpaperLayoutNodeName[] = "layout"; |
| 34 const char kWallpaperFileNodeName[] = "file"; |
| 35 const char kWallpaperTypeNodeName[] = "type"; |
| 36 |
24 } // namespace | 37 } // namespace |
25 | 38 |
26 namespace chromeos { | 39 namespace chromeos { |
27 | 40 |
28 static WallpaperManager* g_wallpaper_manager = NULL; | 41 static WallpaperManager* g_wallpaper_manager = NULL; |
29 | 42 |
30 // WallpaperManager, public: --------------------------------------------------- | 43 // WallpaperManager, public: --------------------------------------------------- |
31 | 44 |
32 // static | 45 // static |
33 WallpaperManager* WallpaperManager::Get() { | 46 WallpaperManager* WallpaperManager::Get() { |
34 if (!g_wallpaper_manager) | 47 if (!g_wallpaper_manager) |
35 g_wallpaper_manager = new WallpaperManager(); | 48 g_wallpaper_manager = new WallpaperManager(); |
36 return g_wallpaper_manager; | 49 return g_wallpaper_manager; |
37 } | 50 } |
38 | 51 |
| 52 // static |
| 53 void WallpaperManager::RegisterPrefs(PrefService* local_state) { |
| 54 local_state->RegisterDictionaryPref(prefs::kUsersWallpaperInfo, |
| 55 PrefService::UNSYNCABLE_PREF); |
| 56 } |
| 57 |
39 WallpaperManager::WallpaperManager() : last_selected_user_("") { | 58 WallpaperManager::WallpaperManager() : last_selected_user_("") { |
40 system::TimezoneSettings::GetInstance()->AddObserver(this); | 59 system::TimezoneSettings::GetInstance()->AddObserver(this); |
41 RestartTimer(); | 60 RestartTimer(); |
42 } | 61 } |
43 | 62 |
44 void WallpaperManager::AddPowerManagerClientObserver() { | 63 void WallpaperManager::AddPowerManagerClientObserver() { |
45 if (!DBusThreadManager::Get()->GetPowerManagerClient()->HasObserver(this)) | 64 if (!DBusThreadManager::Get()->GetPowerManagerClient()->HasObserver(this)) |
46 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); | 65 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
47 } | 66 } |
48 | 67 |
49 void WallpaperManager::RestartTimer() { | 68 void WallpaperManager::RestartTimer() { |
50 timer_.Stop(); | 69 timer_.Stop(); |
51 base::Time midnight = base::Time::Now().LocalMidnight(); | 70 base::Time midnight = base::Time::Now().LocalMidnight(); |
52 base::TimeDelta interval = base::Time::Now() - midnight; | 71 base::TimeDelta interval = base::Time::Now() - midnight; |
53 int64 remaining_seconds = kWallpaperUpdateIntervalSec - interval.InSeconds(); | 72 int64 remaining_seconds = kWallpaperUpdateIntervalSec - interval.InSeconds(); |
54 if (remaining_seconds <= 0) { | 73 if (remaining_seconds <= 0) { |
55 BatchUpdateWallpaper(); | 74 BatchUpdateWallpaper(); |
56 } else { | 75 } else { |
57 // Set up a one shot timer which will batch update wallpaper at midnight. | 76 // Set up a one shot timer which will batch update wallpaper at midnight. |
58 timer_.Start(FROM_HERE, | 77 timer_.Start(FROM_HERE, |
59 base::TimeDelta::FromSeconds(remaining_seconds), | 78 base::TimeDelta::FromSeconds(remaining_seconds), |
60 this, | 79 this, |
61 &WallpaperManager::BatchUpdateWallpaper); | 80 &WallpaperManager::BatchUpdateWallpaper); |
62 } | 81 } |
63 } | 82 } |
64 | 83 |
| 84 void WallpaperManager::SaveUserWallpaperInfo(const std::string& username, |
| 85 const std::string& file_name, |
| 86 ash::WallpaperLayout layout, |
| 87 User::WallpaperType type) { |
| 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 89 |
| 90 // Ephemeral users can not save data to local state. We just cache the index |
| 91 // in memory for them. |
| 92 if (UserManager::Get()->IsCurrentUserEphemeral()) |
| 93 return; |
| 94 |
| 95 PrefService* local_state = g_browser_process->local_state(); |
| 96 DictionaryPrefUpdate wallpaper_update(local_state, |
| 97 prefs::kUsersWallpaperInfo); |
| 98 |
| 99 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue(); |
| 100 wallpaper_properties->SetString(kWallpaperDateNodeName, |
| 101 base::Int64ToString(base::Time::Now().LocalMidnight().ToInternalValue())); |
| 102 wallpaper_properties->SetString(kWallpaperFileNodeName, file_name); |
| 103 wallpaper_properties->SetInteger(kWallpaperLayoutNodeName, layout); |
| 104 wallpaper_properties->SetInteger(kWallpaperTypeNodeName, type); |
| 105 wallpaper_update->SetWithoutPathExpansion(username, wallpaper_properties); |
| 106 } |
| 107 |
65 void WallpaperManager::SetLastSelectedUser( | 108 void WallpaperManager::SetLastSelectedUser( |
66 const std::string& last_selected_user) { | 109 const std::string& last_selected_user) { |
67 last_selected_user_ = last_selected_user; | 110 last_selected_user_ = last_selected_user; |
68 } | 111 } |
69 | 112 |
70 void WallpaperManager::SetWallpaperFromFile(std::string email, | 113 void WallpaperManager::SetWallpaperFromFilePath(const std::string& path, |
71 const std::string& path, | 114 ash::WallpaperLayout layout) { |
72 ash::WallpaperLayout layout) { | |
73 image_loader_->Start( | 115 image_loader_->Start( |
74 path, 0, false, | 116 path, 0, false, |
75 base::Bind(&WallpaperManager::OnCustomWallpaperLoaded, | 117 base::Bind(&WallpaperManager::OnWallpaperLoaded, |
76 base::Unretained(this), email, layout)); | 118 base::Unretained(this), layout)); |
| 119 } |
| 120 |
| 121 void WallpaperManager::SetWallpaperFromImageSkia( |
| 122 const gfx::ImageSkia& wallpaper, |
| 123 ash::WallpaperLayout layout) { |
| 124 ash::Shell::GetInstance()->desktop_background_controller()-> |
| 125 SetCustomWallpaper(wallpaper, layout); |
77 } | 126 } |
78 | 127 |
79 void WallpaperManager::UserDeselected() { | 128 void WallpaperManager::UserDeselected() { |
80 if (!UserManager::Get()->IsUserLoggedIn()) { | 129 if (!UserManager::Get()->IsUserLoggedIn()) { |
81 // This will set default login wallpaper (#fefefe). | 130 // This will set default login wallpaper (#fefefe). |
82 ash::Shell::GetInstance()->desktop_background_controller()-> | 131 ash::Shell::GetInstance()->desktop_background_controller()-> |
83 SetDefaultWallpaper(ash::GetSolidColorIndex()); | 132 SetDefaultWallpaper(ash::GetSolidColorIndex()); |
84 } | 133 } |
85 } | 134 } |
86 | 135 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 user_manager->UserSelected(email); | 181 user_manager->UserSelected(email); |
133 } else if (show_users && | 182 } else if (show_users && |
134 email == last_selected_user_) { | 183 email == last_selected_user_) { |
135 user_manager->UserSelected(email); | 184 user_manager->UserSelected(email); |
136 } | 185 } |
137 } | 186 } |
138 } | 187 } |
139 RestartTimer(); | 188 RestartTimer(); |
140 } | 189 } |
141 | 190 |
| 191 void WallpaperManager::OnWallpaperLoaded(ash::WallpaperLayout layout, |
| 192 const UserImage& user_image) { |
| 193 const SkBitmap& wallpaper = user_image.image(); |
| 194 SetWallpaperFromImageSkia(wallpaper, layout); |
| 195 } |
| 196 |
142 void WallpaperManager::SystemResumed() { | 197 void WallpaperManager::SystemResumed() { |
143 BatchUpdateWallpaper(); | 198 BatchUpdateWallpaper(); |
144 } | 199 } |
145 | 200 |
146 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { | 201 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { |
147 RestartTimer(); | 202 RestartTimer(); |
148 } | 203 } |
149 | 204 |
150 } // chromeos | 205 } // chromeos |
OLD | NEW |