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

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

Issue 10384079: Reland "Implement random wallpaper feature" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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
Index: chrome/browser/chromeos/login/user_manager_impl.cc
diff --git a/chrome/browser/chromeos/login/user_manager_impl.cc b/chrome/browser/chromeos/login/user_manager_impl.cc
index 8ae199068ace8fd03d9095b319083082d6532d59..d50b8a7fb60603218b4400002c02c39a34dec811 100644
--- a/chrome/browser/chromeos/login/user_manager_impl.cc
+++ b/chrome/browser/chromeos/login/user_manager_impl.cc
@@ -8,7 +8,6 @@
#include "ash/shell.h"
#include "ash/desktop_background/desktop_background_controller.h"
-#include "ash/desktop_background/desktop_background_resources.h"
#include "base/bind.h"
#include "base/chromeos/chromeos_version.h"
#include "base/command_line.h"
@@ -77,6 +76,9 @@ const char kStubUser[] = "stub-user@example.com";
const char kImagePathNodeName[] = "path";
const char kImageIndexNodeName[] = "index";
+const char kWallpaperTypeNodeName[] = "type";
+const char kWallpaperIndexNodeName[] = "index";
+
// Index of the default image used for the |kStubUser| user.
const int kStubDefaultImageIndex = 0;
@@ -305,6 +307,8 @@ UserManagerImpl::UserManagerImpl()
StubUserLoggedIn();
}
+ MigrateWallpaperData();
+
registrar_.Add(this, chrome::NOTIFICATION_OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED,
content::NotificationService::AllSources());
registrar_.Add(this, chrome::NOTIFICATION_PROFILE_ADDED,
@@ -327,9 +331,6 @@ const UserList& UserManagerImpl::GetUsers() const {
}
void UserManagerImpl::UserLoggedIn(const std::string& email) {
- // Get a random wallpaper each time a user logged in.
- current_user_wallpaper_index_ = ash::GetDefaultWallpaperIndex();
-
// Remove the stub user if it is still around.
if (logged_in_user_) {
DCHECK(IsLoggedInAsStub());
@@ -429,8 +430,6 @@ void UserManagerImpl::DemoUserLoggedIn() {
void UserManagerImpl::GuestUserLoggedIn() {
is_current_user_ephemeral_ = true;
- // Guest user always uses the same wallpaper.
- current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex();
logged_in_user_ = new User(kGuestUser, true);
NotifyOnLogin();
}
@@ -446,7 +445,6 @@ void UserManagerImpl::EphemeralUserLoggedIn(const std::string& email) {
void UserManagerImpl::StubUserLoggedIn() {
is_current_user_ephemeral_ = true;
- current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex();
logged_in_user_ = new User(kStubUser, false);
logged_in_user_->SetImage(GetDefaultImage(kStubDefaultImageIndex),
kStubDefaultImageIndex);
@@ -454,8 +452,17 @@ void UserManagerImpl::StubUserLoggedIn() {
void UserManagerImpl::UserSelected(const std::string& email) {
if (IsKnownUser(email)) {
+ int index;
+ User::WallpaperType type;
+ GetUserWallpaperProperties(email, type, index);
+ if (type == User::RANDOM) {
+ // Generate a new random wallpaper index if the selected user chose
+ // RANDOM wallpaper.
+ index = ash::GetRandomWallpaperIndex();
+ SaveUserWallpaperProperties(email, User::RANDOM, index);
+ }
ash::Shell::GetInstance()->desktop_background_controller()->
- SetDefaultWallpaper(FindUserWallpaperIndex(email));
+ SetDefaultWallpaper(index);
}
}
@@ -905,20 +912,6 @@ const User* UserManagerImpl::FindUserInList(const std::string& email) const {
return NULL;
}
-int UserManagerImpl::FindUserWallpaperIndex(const std::string& email) {
- PrefService* local_state = g_browser_process->local_state();
- const DictionaryValue* user_wallpapers =
- local_state->GetDictionary(UserManager::kUserWallpapers);
- int index;
- if (!user_wallpapers->GetIntegerWithoutPathExpansion(email, &index))
- index = current_user_wallpaper_index_;
- if (index < 0 || index >= ash::GetWallpaperCount()) {
- index = ash::GetDefaultWallpaperIndex();
- SaveUserWallpaperIndex(index);
- }
- return index;
-}
-
void UserManagerImpl::NotifyOnLogin() {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
content::NotificationService::current()->Notify(
@@ -968,13 +961,18 @@ void UserManagerImpl::SetInitialUserImage(const std::string& username) {
}
void UserManagerImpl::SetInitialUserWallpaper(const std::string& username) {
+ current_user_wallpaper_type_ = User::DEFAULT;
// TODO(bshe): Ideally, wallpaper should start to load as soon as user click
// "Add user".
if (username == kGuestUser)
current_user_wallpaper_index_ = ash::GetGuestWallpaperIndex();
else
current_user_wallpaper_index_ = ash::GetDefaultWallpaperIndex();
- SaveUserWallpaperIndex(current_user_wallpaper_index_);
+
+ SaveUserWallpaperProperties(username,
+ current_user_wallpaper_type_,
+ current_user_wallpaper_index_);
+
// Some browser tests do not have shell instance. And it is not necessary to
// create a wallpaper for these tests. Add HasInstance check to prevent tests
// crash and speed up the tests by avoid loading wallpaper.
@@ -984,28 +982,69 @@ void UserManagerImpl::SetInitialUserWallpaper(const std::string& username) {
}
}
-int UserManagerImpl::GetUserWallpaperIndex() {
+void UserManagerImpl::MigrateWallpaperData() {
+ PrefService* local_state = g_browser_process->local_state();
+ if (local_state) {
+ const DictionaryValue* user_wallpapers =
+ local_state->GetDictionary(kUserWallpapers);
+ int index;
+ if (user_wallpapers) {
+ const UserList& users = GetUsers();
+ for (UserList::const_iterator it = users.begin();
+ it != users.end();
+ ++it) {
+ std::string username = (*it)->email();
+ if (user_wallpapers->GetIntegerWithoutPathExpansion((username),
+ &index)) {
+ DictionaryPrefUpdate prefs_wallpapers_update(local_state,
+ kUserWallpapers);
+ prefs_wallpapers_update->RemoveWithoutPathExpansion(username, NULL);
+ SaveUserWallpaperProperties(username, User::DEFAULT, index);
+ }
+ }
+ }
+ }
+}
+
+int UserManagerImpl::GetLoggedInUserWallpaperIndex() {
+ int index;
+ User::WallpaperType type;
+ GetLoggedInUserWallpaperProperties(type, index);
+ return index;
+}
+
+void UserManagerImpl::GetLoggedInUserWallpaperProperties(
+ User::WallpaperType& type, int& index) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- // If at login screen, use an invalid index to prevent any wallpaper
- // operation.
- if (!IsUserLoggedIn() || IsLoggedInAsStub())
- return ash::GetInvalidWallpaperIndex();
+ if (!IsUserLoggedIn() || IsLoggedInAsStub()) {
+ index = ash::GetInvalidWallpaperIndex();
+ current_user_wallpaper_index_ = index;
+ current_user_wallpaper_type_ = User::DEFAULT;
+ return;
+ }
+
// If logged in as other ephemeral users (Demo/Stub/Normal user with
// ephemeral policy enabled/Guest), use the index in memory.
- if (IsCurrentUserEphemeral())
- return current_user_wallpaper_index_;
+ if (IsCurrentUserEphemeral()) {
+ type = current_user_wallpaper_type_;
+ index = current_user_wallpaper_index_;
+ return;
+ }
const chromeos::User& user = GetLoggedInUser();
std::string username = user.email();
DCHECK(!username.empty());
- return FindUserWallpaperIndex(username);
+
+ GetUserWallpaperProperties(username, type, index);
}
-void UserManagerImpl::SaveUserWallpaperIndex(int wallpaper_index) {
+void UserManagerImpl::SaveLoggedInUserWallpaperProperties(
+ User::WallpaperType type, int index) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- current_user_wallpaper_index_ = wallpaper_index;
+ current_user_wallpaper_type_ = type;
+ current_user_wallpaper_index_ = index;
// Ephemeral users can not save data to local state. We just cache the index
// in memory for them.
if (IsCurrentUserEphemeral() || !IsUserLoggedIn()) {
@@ -1016,11 +1055,7 @@ void UserManagerImpl::SaveUserWallpaperIndex(int wallpaper_index) {
std::string username = user.email();
DCHECK(!username.empty());
- PrefService* local_state = g_browser_process->local_state();
- DictionaryPrefUpdate wallpapers_update(local_state,
- UserManager::kUserWallpapers);
- wallpapers_update->SetWithoutPathExpansion(username,
- new base::FundamentalValue(wallpaper_index));
+ SaveUserWallpaperProperties(username, type, index);
}
void UserManagerImpl::SetUserImage(const std::string& username,
@@ -1053,6 +1088,57 @@ void UserManagerImpl::SetUserImage(const std::string& username,
}
}
+void UserManagerImpl::GetUserWallpaperProperties(const std::string& username,
+ User::WallpaperType& type,
+ int& index) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ PrefService* local_state = g_browser_process->local_state();
+
+ const DictionaryValue* user_wallpapers =
+ local_state->GetDictionary(UserManager::kUserWallpapersProperties);
+
+ type = User::DEFAULT;
+ index = ash::GetDefaultWallpaperIndex();
+
+ if (user_wallpapers) {
+ base::DictionaryValue* wallpaper_properties;
+ user_wallpapers->GetDictionaryWithoutPathExpansion(username,
+ &wallpaper_properties);
+ if (wallpaper_properties) {
+ int saved_type = User::UNKNOWN;
+ wallpaper_properties->GetInteger(kWallpaperTypeNodeName, &saved_type);
+ type = static_cast<User::WallpaperType>(saved_type);
+ wallpaper_properties->GetInteger(kWallpaperIndexNodeName, &index);
+ }
+ }
+}
+
+void UserManagerImpl::SaveUserWallpaperProperties(const std::string& username,
+ User::WallpaperType type,
+ int index) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ current_user_wallpaper_type_ = type;
+ current_user_wallpaper_index_ = index;
+ // Ephemeral users can not save data to local state. We just cache the index
+ // in memory for them.
+ if (IsCurrentUserEphemeral()) {
+ return;
+ }
+
+ PrefService* local_state = g_browser_process->local_state();
+ DictionaryPrefUpdate wallpaper_update(local_state,
+ UserManager::kUserWallpapersProperties);
+
+ base::DictionaryValue* wallpaper_properties = new base::DictionaryValue();
+ wallpaper_properties->Set(kWallpaperTypeNodeName,
+ new base::FundamentalValue(type));
+ wallpaper_properties->Set(kWallpaperIndexNodeName,
+ new base::FundamentalValue(index));
+ wallpaper_update->SetWithoutPathExpansion(username, wallpaper_properties);
+}
+
void UserManagerImpl::SaveUserImageInternal(const std::string& username,
int image_index,
const SkBitmap& image) {
@@ -1280,7 +1366,7 @@ void UserManagerImpl::RemoveUserFromListInternal(const std::string& email) {
}
DictionaryPrefUpdate prefs_wallpapers_update(prefs,
- kUserWallpapers);
+ kUserWallpapersProperties);
prefs_wallpapers_update->RemoveWithoutPathExpansion(email, NULL);
DictionaryPrefUpdate prefs_images_update(prefs, kUserImages);

Powered by Google App Engine
This is Rietveld 408576698