Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(691)

Unified Diff: chrome/browser/chromeos/login/wallpaper_manager.cc

Issue 10815047: Save user selected wallpaper information to local state. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: format nits Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/login/wallpaper_manager.h ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..3f2a1e7ee594573b83732c7e3f6ca448ec74848b 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,48 @@ 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);
+ 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 +188,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();
}
« no previous file with comments | « chrome/browser/chromeos/login/wallpaper_manager.h ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698