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, | |
103 file_name); | |
battre
2012/07/31 14:40:17
nit: no need to wrap these lines.
bshe
2012/07/31 14:55:28
Done.
| |
104 wallpaper_properties->SetInteger(kWallpaperLayoutNodeName, | |
105 layout); | |
106 wallpaper_properties->SetInteger(kWallpaperTypeNodeName, | |
107 type); | |
108 wallpaper_update->SetWithoutPathExpansion(username, wallpaper_properties); | |
109 } | |
110 | |
65 void WallpaperManager::SetLastSelectedUser( | 111 void WallpaperManager::SetLastSelectedUser( |
66 const std::string& last_selected_user) { | 112 const std::string& last_selected_user) { |
67 last_selected_user_ = last_selected_user; | 113 last_selected_user_ = last_selected_user; |
68 } | 114 } |
69 | 115 |
70 void WallpaperManager::SetWallpaperFromFile(std::string email, | 116 void WallpaperManager::SetWallpaperFromFilePath(const std::string& path, |
71 const std::string& path, | 117 ash::WallpaperLayout layout) { |
72 ash::WallpaperLayout layout) { | |
73 image_loader_->Start( | 118 image_loader_->Start( |
74 path, 0, false, | 119 path, 0, false, |
75 base::Bind(&WallpaperManager::OnCustomWallpaperLoaded, | 120 base::Bind(&WallpaperManager::OnWallpaperLoaded, |
76 base::Unretained(this), email, layout)); | 121 base::Unretained(this), layout)); |
122 } | |
123 | |
124 void WallpaperManager::SetWallpaperFromImageSkia( | |
125 const gfx::ImageSkia& wallpaper, | |
126 ash::WallpaperLayout layout) { | |
127 ash::Shell::GetInstance()->desktop_background_controller()-> | |
128 SetCustomWallpaper(wallpaper, layout); | |
77 } | 129 } |
78 | 130 |
79 void WallpaperManager::UserDeselected() { | 131 void WallpaperManager::UserDeselected() { |
80 if (!UserManager::Get()->IsUserLoggedIn()) { | 132 if (!UserManager::Get()->IsUserLoggedIn()) { |
81 // This will set default login wallpaper (#fefefe). | 133 // This will set default login wallpaper (#fefefe). |
82 ash::Shell::GetInstance()->desktop_background_controller()-> | 134 ash::Shell::GetInstance()->desktop_background_controller()-> |
83 SetDefaultWallpaper(ash::GetSolidColorIndex()); | 135 SetDefaultWallpaper(ash::GetSolidColorIndex()); |
84 } | 136 } |
85 } | 137 } |
86 | 138 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 user_manager->UserSelected(email); | 184 user_manager->UserSelected(email); |
133 } else if (show_users && | 185 } else if (show_users && |
134 email == last_selected_user_) { | 186 email == last_selected_user_) { |
135 user_manager->UserSelected(email); | 187 user_manager->UserSelected(email); |
136 } | 188 } |
137 } | 189 } |
138 } | 190 } |
139 RestartTimer(); | 191 RestartTimer(); |
140 } | 192 } |
141 | 193 |
194 void WallpaperManager::OnWallpaperLoaded(ash::WallpaperLayout layout, | |
195 const UserImage& user_image) { | |
196 const SkBitmap& wallpaper = user_image.image(); | |
197 SetWallpaperFromImageSkia(wallpaper, layout); | |
198 } | |
199 | |
142 void WallpaperManager::SystemResumed() { | 200 void WallpaperManager::SystemResumed() { |
143 BatchUpdateWallpaper(); | 201 BatchUpdateWallpaper(); |
144 } | 202 } |
145 | 203 |
146 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { | 204 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { |
147 RestartTimer(); | 205 RestartTimer(); |
148 } | 206 } |
149 | 207 |
150 } // chromeos | 208 } // chromeos |
OLD | NEW |