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 kUsersWallpaperInfos[] = "UsersWallpaperInfos"; | |
Nikita (slow)
2012/07/23 22:06:47
s/Infos/Info/
bshe
2012/07/24 16:21:10
Done.
| |
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(kUsersWallpaperInfos, | |
57 PrefService::UNSYNCABLE_PREF); | |
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::SaveUserWallpaperInfos(const std::string& username, | |
87 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. | |
Nikita (slow)
2012/07/23 22:06:47
Do those users have access to custom wallpaper UI?
bshe
2012/07/24 16:21:10
As far as I can remember, only guest user can't ac
Nikita (slow)
2012/07/24 17:06:54
But any Ephemeral user would exit here.
What would
| |
94 if (UserManager::Get()->IsCurrentUserEphemeral()) { | |
Nikita (slow)
2012/07/23 22:06:47
nit: could omit { }
bshe
2012/07/24 16:21:10
Done.
| |
95 return; | |
96 } | |
97 | |
98 PrefService* local_state = g_browser_process->local_state(); | |
99 DictionaryPrefUpdate wallpaper_update(local_state, | |
100 kUsersWallpaperInfos); | |
101 | |
102 base::DictionaryValue* wallpaper_properties = new base::DictionaryValue(); | |
103 wallpaper_properties->SetString(kWallpaperDateNodeName, | |
104 base::Int64ToString(base::Time::Now().LocalMidnight().ToInternalValue())); | |
105 wallpaper_properties->SetString(kWallpaperFileNodeName, | |
106 file_name); | |
107 wallpaper_properties->Set(kWallpaperLayoutNodeName, | |
108 new base::FundamentalValue(layout)); | |
109 wallpaper_properties->Set(kWallpaperTypeNodeName, | |
110 new base::FundamentalValue(type)); | |
111 wallpaper_update->SetWithoutPathExpansion(username, wallpaper_properties); | |
112 } | |
113 | |
65 void WallpaperManager::SetLastSelectedUser( | 114 void WallpaperManager::SetLastSelectedUser( |
66 const std::string& last_selected_user) { | 115 const std::string& last_selected_user) { |
67 last_selected_user_ = last_selected_user; | 116 last_selected_user_ = last_selected_user; |
68 } | 117 } |
69 | 118 |
70 void WallpaperManager::SetWallpaperFromFile(std::string email, | 119 void WallpaperManager::SetWallpaperFromFilePath(const std::string& path, |
71 const std::string& path, | 120 ash::WallpaperLayout layout) { |
72 ash::WallpaperLayout layout) { | |
73 image_loader_->Start( | 121 image_loader_->Start( |
74 path, 0, false, | 122 path, 0, false, |
75 base::Bind(&WallpaperManager::OnCustomWallpaperLoaded, | 123 base::Bind(&WallpaperManager::OnWallpaperLoaded, |
76 base::Unretained(this), email, layout)); | 124 base::Unretained(this), layout)); |
125 } | |
126 | |
127 void WallpaperManager::SetWallpaperFromImageSkia( | |
128 ash::WallpaperLayout layout, | |
129 const gfx::ImageSkia& wallpaper) { | |
130 ash::Shell::GetInstance()->desktop_background_controller()-> | |
131 SetCustomWallpaper(wallpaper, layout); | |
77 } | 132 } |
78 | 133 |
79 void WallpaperManager::UserDeselected() { | 134 void WallpaperManager::UserDeselected() { |
80 if (!UserManager::Get()->IsUserLoggedIn()) { | 135 if (!UserManager::Get()->IsUserLoggedIn()) { |
81 // This will set default login wallpaper (#fefefe). | 136 // This will set default login wallpaper (#fefefe). |
82 ash::Shell::GetInstance()->desktop_background_controller()-> | 137 ash::Shell::GetInstance()->desktop_background_controller()-> |
83 SetDefaultWallpaper(ash::GetSolidColorIndex()); | 138 SetDefaultWallpaper(ash::GetSolidColorIndex()); |
84 } | 139 } |
85 } | 140 } |
86 | 141 |
87 // WallpaperManager, private: -------------------------------------------------- | 142 // WallpaperManager, private: -------------------------------------------------- |
88 | 143 |
89 WallpaperManager::~WallpaperManager() { | 144 WallpaperManager::~WallpaperManager() { |
90 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 145 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
91 system::TimezoneSettings::GetInstance()->RemoveObserver(this); | 146 system::TimezoneSettings::GetInstance()->RemoveObserver(this); |
92 } | 147 } |
93 | 148 |
94 void WallpaperManager::OnCustomWallpaperLoaded(const std::string& email, | |
95 ash::WallpaperLayout layout, | |
96 const UserImage& user_image) { | |
97 const SkBitmap& wallpaper = user_image.image(); | |
98 ash::Shell::GetInstance()->desktop_background_controller()-> | |
99 SetCustomWallpaper(wallpaper, layout); | |
100 } | |
101 | |
102 void WallpaperManager::BatchUpdateWallpaper() { | 149 void WallpaperManager::BatchUpdateWallpaper() { |
103 PrefService* local_state = g_browser_process->local_state(); | 150 PrefService* local_state = g_browser_process->local_state(); |
104 UserManager* user_manager = UserManager::Get(); | 151 UserManager* user_manager = UserManager::Get(); |
105 bool show_users = true; | 152 bool show_users = true; |
106 CrosSettings::Get()->GetBoolean( | 153 CrosSettings::Get()->GetBoolean( |
107 kAccountsPrefShowUserNamesOnSignIn, &show_users); | 154 kAccountsPrefShowUserNamesOnSignIn, &show_users); |
108 if (local_state) { | 155 if (local_state) { |
109 User::WallpaperType type; | 156 User::WallpaperType type; |
110 int index = 0; | 157 int index = 0; |
111 base::Time last_modification_date; | 158 base::Time last_modification_date; |
(...skipping 20 matching lines...) Expand all Loading... | |
132 user_manager->UserSelected(email); | 179 user_manager->UserSelected(email); |
133 } else if (show_users && | 180 } else if (show_users && |
134 email == last_selected_user_) { | 181 email == last_selected_user_) { |
135 user_manager->UserSelected(email); | 182 user_manager->UserSelected(email); |
136 } | 183 } |
137 } | 184 } |
138 } | 185 } |
139 RestartTimer(); | 186 RestartTimer(); |
140 } | 187 } |
141 | 188 |
189 void WallpaperManager::OnWallpaperLoaded(ash::WallpaperLayout layout, | |
190 const UserImage& user_image) { | |
191 const SkBitmap& wallpaper = user_image.image(); | |
192 SetWallpaperFromImageSkia(layout, wallpaper); | |
193 } | |
194 | |
142 void WallpaperManager::SystemResumed() { | 195 void WallpaperManager::SystemResumed() { |
143 BatchUpdateWallpaper(); | 196 BatchUpdateWallpaper(); |
144 } | 197 } |
145 | 198 |
146 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { | 199 void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { |
147 RestartTimer(); | 200 RestartTimer(); |
148 } | 201 } |
149 | 202 |
150 } // chromeos | 203 } // chromeos |
OLD | NEW |