Chromium Code Reviews| Index: chrome/browser/chromeos/login/wallpaper_manager.cc |
| diff --git a/chrome/browser/chromeos/login/wallpaper_manager.cc b/chrome/browser/chromeos/login/wallpaper_manager.cc |
| index 67fcafcf424dc596897979cb49e7567728834a42..860f15c3284a4aa4d53a53bfb796e7b03957890d 100644 |
| --- a/chrome/browser/chromeos/login/wallpaper_manager.cc |
| +++ b/chrome/browser/chromeos/login/wallpaper_manager.cc |
| @@ -8,19 +8,32 @@ |
| #include "ash/desktop_background/desktop_background_resources.h" |
| #include "ash/shell.h" |
| #include "base/logging.h" |
| +#include "base/string_number_conversions.h" |
| #include "base/time.h" |
| #include "base/values.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/chromeos/cros_settings.h" |
| -#include "chrome/browser/chromeos/login/user.h" |
| #include "chrome/browser/chromeos/login/user_manager.h" |
| #include "chrome/browser/chromeos/login/user_manager_impl.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| +#include "chrome/browser/prefs/scoped_user_pref_update.h" |
| +#include "chrome/common/pref_names.h" |
| #include "chromeos/dbus/dbus_thread_manager.h" |
| #include "chromeos/dbus/power_manager_client.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +using content::BrowserThread; |
| namespace { |
| + |
| const int kWallpaperUpdateIntervalSec = 24 * 60 * 60; |
| + |
| +// Names of nodes with info about wallpaper. |
| +const char kWallpaperDateNodeName[] = "date"; |
| +const char kWallpaperLayoutNodeName[] = "layout"; |
| +const char kWallpaperFileNodeName[] = "file"; |
| +const char kWallpaperTypeNodeName[] = "type"; |
| + |
| } // namespace |
| namespace chromeos { |
| @@ -36,6 +49,12 @@ WallpaperManager* WallpaperManager::Get() { |
| return g_wallpaper_manager; |
| } |
| +// static |
| +void WallpaperManager::RegisterPrefs(PrefService* local_state) { |
| + local_state->RegisterDictionaryPref(prefs::kUsersWallpaperInfo, |
| + PrefService::UNSYNCABLE_PREF); |
| +} |
| + |
| WallpaperManager::WallpaperManager() : last_selected_user_("") { |
| system::TimezoneSettings::GetInstance()->AddObserver(this); |
| RestartTimer(); |
| @@ -62,18 +81,51 @@ void WallpaperManager::RestartTimer() { |
| } |
| } |
| +void WallpaperManager::SaveUserWallpaperInfo(const std::string& username, |
| + const std::string& file_name, |
| + ash::WallpaperLayout layout, |
| + User::WallpaperType type) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + // Ephemeral users can not save data to local state. We just cache the index |
| + // in memory for them. |
| + if (UserManager::Get()->IsCurrentUserEphemeral()) |
| + return; |
| + |
| + PrefService* local_state = g_browser_process->local_state(); |
| + DictionaryPrefUpdate wallpaper_update(local_state, |
| + prefs::kUsersWallpaperInfo); |
| + |
| + base::DictionaryValue* wallpaper_properties = new base::DictionaryValue(); |
| + wallpaper_properties->SetString(kWallpaperDateNodeName, |
| + base::Int64ToString(base::Time::Now().LocalMidnight().ToInternalValue())); |
| + wallpaper_properties->SetString(kWallpaperFileNodeName, |
| + file_name); |
|
battre
2012/07/31 14:40:17
nit: no need to wrap these lines.
bshe
2012/07/31 14:55:28
Done.
|
| + wallpaper_properties->SetInteger(kWallpaperLayoutNodeName, |
| + layout); |
| + wallpaper_properties->SetInteger(kWallpaperTypeNodeName, |
| + type); |
| + wallpaper_update->SetWithoutPathExpansion(username, wallpaper_properties); |
| +} |
| + |
| void WallpaperManager::SetLastSelectedUser( |
| const std::string& last_selected_user) { |
| last_selected_user_ = last_selected_user; |
| } |
| -void WallpaperManager::SetWallpaperFromFile(std::string email, |
| - const std::string& path, |
| - ash::WallpaperLayout layout) { |
| +void WallpaperManager::SetWallpaperFromFilePath(const std::string& path, |
| + ash::WallpaperLayout layout) { |
| image_loader_->Start( |
| path, 0, false, |
| - base::Bind(&WallpaperManager::OnCustomWallpaperLoaded, |
| - base::Unretained(this), email, layout)); |
| + base::Bind(&WallpaperManager::OnWallpaperLoaded, |
| + base::Unretained(this), layout)); |
| +} |
| + |
| +void WallpaperManager::SetWallpaperFromImageSkia( |
| + const gfx::ImageSkia& wallpaper, |
| + ash::WallpaperLayout layout) { |
| + ash::Shell::GetInstance()->desktop_background_controller()-> |
| + SetCustomWallpaper(wallpaper, layout); |
| } |
| void WallpaperManager::UserDeselected() { |
| @@ -139,6 +191,12 @@ void WallpaperManager::BatchUpdateWallpaper() { |
| RestartTimer(); |
| } |
| +void WallpaperManager::OnWallpaperLoaded(ash::WallpaperLayout layout, |
| + const UserImage& user_image) { |
| + const SkBitmap& wallpaper = user_image.image(); |
| + SetWallpaperFromImageSkia(wallpaper, layout); |
| +} |
| + |
| void WallpaperManager::SystemResumed() { |
| BatchUpdateWallpaper(); |
| } |