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