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

Unified Diff: components/wallpaper/wallpaper_manager_base.cc

Issue 1165323004: We should use UserID object to identify users instead of username. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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: components/wallpaper/wallpaper_manager_base.cc
diff --git a/components/wallpaper/wallpaper_manager_base.cc b/components/wallpaper/wallpaper_manager_base.cc
index 3e0b014eca98e714f0cc948906aaf64a9e20632e..4071ae54078dbbd7809fc633f7ded0ff871d9e5e 100644
--- a/components/wallpaper/wallpaper_manager_base.cc
+++ b/components/wallpaper/wallpaper_manager_base.cc
@@ -28,6 +28,7 @@
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/login/user_names.h"
#include "components/user_manager/user.h"
+#include "components/user_manager/user_id.h"
#include "components/user_manager/user_image/user_image.h"
#include "components/user_manager/user_manager.h"
#include "components/user_manager/user_type.h"
@@ -74,12 +75,12 @@ int dir_chromeos_custom_wallpapers_path_id =
-1; // chrome::DIR_CHROMEOS_CUSTOM_WALLPAPERS
bool MoveCustomWallpaperDirectory(const char* sub_dir,
- const std::string& user_id,
+ const user_manager::UserID& user_id,
const std::string& user_id_hash) {
base::FilePath base_path =
WallpaperManagerBase::GetCustomWallpaperDir(sub_dir);
base::FilePath to_path = base_path.Append(user_id_hash);
- base::FilePath from_path = base_path.Append(user_id);
+ base::FilePath from_path = base_path.Append(user_id.GetUserEmail());
if (base::PathExists(from_path))
return base::Move(from_path, to_path);
return false;
@@ -258,19 +259,19 @@ WallpaperManagerBase::TestApi::~TestApi() {
}
bool WallpaperManagerBase::TestApi::GetWallpaperFromCache(
- const std::string& user_id,
+ const user_manager::UserID& user_id,
gfx::ImageSkia* image) {
return wallpaper_manager_->GetWallpaperFromCache(user_id, image);
}
bool WallpaperManagerBase::TestApi::GetPathFromCache(
- const std::string& user_id,
+ const user_manager::UserID& user_id,
base::FilePath* path) {
return wallpaper_manager_->GetPathFromCache(user_id, path);
}
void WallpaperManagerBase::TestApi::SetWallpaperCache(
- const std::string& user_id,
+ const user_manager::UserID& user_id,
const base::FilePath& path,
const gfx::ImageSkia& image) {
DCHECK(!image.isNull());
@@ -318,25 +319,25 @@ void WallpaperManagerBase::EnsureLoggedInUserWallpaperLoaded() {
return;
}
SetUserWallpaperNow(
- user_manager::UserManager::Get()->GetLoggedInUser()->email());
+ user_manager::UserManager::Get()->GetLoggedInUser()->GetUserID());
}
void WallpaperManagerBase::ClearDisposableWallpaperCache() {
// Cancel callback for previous cache requests.
weak_factory_.InvalidateWeakPtrs();
// Keep the wallpaper of logged in users in cache at multi-profile mode.
- std::set<std::string> logged_in_users_names;
+ std::set<user_manager::UserID> logged_in_users_ids;
const user_manager::UserList& logged_users =
user_manager::UserManager::Get()->GetLoggedInUsers();
for (user_manager::UserList::const_iterator it = logged_users.begin();
it != logged_users.end(); ++it) {
- logged_in_users_names.insert((*it)->email());
+ logged_in_users_ids.insert((*it)->GetUserID());
}
CustomWallpaperMap logged_in_users_cache;
for (CustomWallpaperMap::iterator it = wallpaper_cache_.begin();
it != wallpaper_cache_.end(); ++it) {
- if (logged_in_users_names.find(it->first) != logged_in_users_names.end()) {
+ if (logged_in_users_ids.find(it->first) != logged_in_users_ids.end()) {
logged_in_users_cache.insert(*it);
}
}
@@ -358,7 +359,7 @@ bool WallpaperManagerBase::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) {
}
return GetUserWallpaperInfo(
- user_manager::UserManager::Get()->GetLoggedInUser()->email(), info);
+ user_manager::UserManager::Get()->GetLoggedInUser()->GetUserID(), info);
}
// static
@@ -443,7 +444,7 @@ bool WallpaperManagerBase::ResizeAndSaveWallpaper(const gfx::ImageSkia& image,
}
bool WallpaperManagerBase::IsPolicyControlled(
- const std::string& user_id) const {
+ const user_manager::UserID& user_id) const {
WallpaperInfo info;
if (!GetUserWallpaperInfo(user_id, &info))
return false;
@@ -451,7 +452,7 @@ bool WallpaperManagerBase::IsPolicyControlled(
}
void WallpaperManagerBase::OnPolicySet(const std::string& policy,
- const std::string& user_id) {
+ const user_manager::UserID& user_id) {
WallpaperInfo info;
GetUserWallpaperInfo(user_id, &info);
info.type = user_manager::User::POLICY;
@@ -459,7 +460,7 @@ void WallpaperManagerBase::OnPolicySet(const std::string& policy,
}
void WallpaperManagerBase::OnPolicyCleared(const std::string& policy,
- const std::string& user_id) {
+ const user_manager::UserID& user_id) {
WallpaperInfo info;
GetUserWallpaperInfo(user_id, &info);
info.type = user_manager::User::DEFAULT;
@@ -479,6 +480,7 @@ base::FilePath WallpaperManagerBase::GetCustomWallpaperPath(
WallpaperManagerBase::WallpaperManagerBase()
: loaded_wallpapers_for_test_(0),
command_line_for_testing_(NULL),
+ last_selected_user_(std::string(), std::string()),
should_cache_wallpaper_(false),
weak_factory_(this) {
SetDefaultWallpaperPathsFromCommandLine(
@@ -498,7 +500,7 @@ WallpaperManagerBase::~WallpaperManagerBase() {
}
void WallpaperManagerBase::SetPolicyControlledWallpaper(
- const std::string& user_id,
+ const user_manager::UserID& user_id,
const user_manager::UserImage& user_image) {
const user_manager::User* user =
user_manager::UserManager::Get()->FindUser(user_id);
@@ -522,7 +524,7 @@ void WallpaperManagerBase::SetPolicyControlledWallpaper(
}
void WallpaperManagerBase::SetCustomWallpaperOnSanitizedUsername(
- const std::string& user_id,
+ const user_manager::UserID& user_id,
const gfx::ImageSkia& image,
bool update_wallpaper,
bool cryptohome_success,
@@ -571,7 +573,7 @@ void WallpaperManagerBase::SaveCustomWallpaper(
// static
void WallpaperManagerBase::MoveCustomWallpapersOnWorker(
- const std::string& user_id,
+ const user_manager::UserID& user_id,
const std::string& user_id_hash,
base::WeakPtr<WallpaperManagerBase> weak_ptr) {
if (MoveCustomWallpaperDirectory(kOriginalWallpaperSubDir, user_id,
@@ -592,7 +594,7 @@ void WallpaperManagerBase::MoveCustomWallpapersOnWorker(
// static
void WallpaperManagerBase::GetCustomWallpaperInternal(
- const std::string& user_id,
+ const user_manager::UserID& user_id,
const WallpaperInfo& info,
const base::FilePath& wallpaper_path,
bool update_wallpaper,
@@ -610,7 +612,7 @@ void WallpaperManagerBase::GetCustomWallpaperInternal(
if (!base::PathExists(valid_path)) {
// Falls back to custom wallpaper that uses email as part of its file path.
// Note that email is used instead of user_id_hash here.
- valid_path = GetCustomWallpaperPath(kOriginalWallpaperSubDir, user_id,
+ valid_path = GetCustomWallpaperPath(kOriginalWallpaperSubDir, user_id.GetUserEmail() /* FIXME! */,
info.location);
}
@@ -630,7 +632,7 @@ void WallpaperManagerBase::GetCustomWallpaperInternal(
}
}
-void WallpaperManagerBase::InitInitialUserWallpaper(const std::string& user_id,
+void WallpaperManagerBase::InitInitialUserWallpaper(const user_manager::UserID& user_id,
bool is_persistent) {
current_user_wallpaper_info_.location = "";
current_user_wallpaper_info_.layout = WALLPAPER_LAYOUT_CENTER_CROPPED;
@@ -641,11 +643,11 @@ void WallpaperManagerBase::InitInitialUserWallpaper(const std::string& user_id,
SetUserWallpaperInfo(user_id, info, is_persistent);
}
-void WallpaperManagerBase::SetUserWallpaperDelayed(const std::string& user_id) {
+void WallpaperManagerBase::SetUserWallpaperDelayed(const user_manager::UserID& user_id) {
ScheduleSetUserWallpaper(user_id, true);
}
-void WallpaperManagerBase::SetUserWallpaperNow(const std::string& user_id) {
+void WallpaperManagerBase::SetUserWallpaperNow(const user_manager::UserID& user_id) {
ScheduleSetUserWallpaper(user_id, false);
}
@@ -658,7 +660,7 @@ void WallpaperManagerBase::UpdateWallpaper(bool clear_cache) {
// be set. It could result a black screen on external monitors.
// See http://crbug.com/265689 for detail.
if (last_selected_user_.empty()) {
- SetDefaultWallpaperNow(chromeos::login::kSignInUser);
+ SetDefaultWallpaperNow(chromeos::login::GetSignInUserID());
return;
}
SetUserWallpaperNow(last_selected_user_);
@@ -681,7 +683,7 @@ void WallpaperManagerBase::NotifyAnimationFinished() {
// WallpaperManager, protected: -----------------------------------------------
-bool WallpaperManagerBase::GetWallpaperFromCache(const std::string& user_id,
+bool WallpaperManagerBase::GetWallpaperFromCache(const user_manager::UserID& user_id,
gfx::ImageSkia* image) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
CustomWallpaperMap::const_iterator it = wallpaper_cache_.find(user_id);
@@ -692,7 +694,7 @@ bool WallpaperManagerBase::GetWallpaperFromCache(const std::string& user_id,
return false;
}
-bool WallpaperManagerBase::GetPathFromCache(const std::string& user_id,
+bool WallpaperManagerBase::GetPathFromCache(const user_manager::UserID& user_id,
base::FilePath* path) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
CustomWallpaperMap::const_iterator it = wallpaper_cache_.find(user_id);
@@ -718,13 +720,12 @@ void WallpaperManagerBase::CacheUsersWallpapers() {
it++;
for (int cached = 0; it != users.end() && cached < kMaxWallpapersToCache;
++it, ++cached) {
- std::string user_id = (*it)->email();
- CacheUserWallpaper(user_id);
+ CacheUserWallpaper((*it)->GetUserID());
}
}
}
-void WallpaperManagerBase::CacheUserWallpaper(const std::string& user_id) {
+void WallpaperManagerBase::CacheUserWallpaper(const user_manager::UserID& user_id) {
CustomWallpaperMap::iterator it = wallpaper_cache_.find(user_id);
if (it != wallpaper_cache_.end() && !it->second.second.isNull())
return;
@@ -757,31 +758,31 @@ void WallpaperManagerBase::CacheUserWallpaper(const std::string& user_id) {
}
void WallpaperManagerBase::DeleteUserWallpapers(
- const std::string& user_id,
+ const user_manager::UserID& user_id,
const std::string& path_to_file) {
std::vector<base::FilePath> file_to_remove;
// Remove small user wallpaper.
base::FilePath wallpaper_path = GetCustomWallpaperDir(kSmallWallpaperSubDir);
// Remove old directory if exists
- file_to_remove.push_back(wallpaper_path.Append(user_id));
+ file_to_remove.push_back(wallpaper_path.Append(user_id.GetUserEmail()));
wallpaper_path = wallpaper_path.Append(path_to_file).DirName();
file_to_remove.push_back(wallpaper_path);
// Remove large user wallpaper.
wallpaper_path = GetCustomWallpaperDir(kLargeWallpaperSubDir);
- file_to_remove.push_back(wallpaper_path.Append(user_id));
+ file_to_remove.push_back(wallpaper_path.Append(user_id.GetUserEmail()));
wallpaper_path = wallpaper_path.Append(path_to_file);
file_to_remove.push_back(wallpaper_path);
// Remove user wallpaper thumbnail.
wallpaper_path = GetCustomWallpaperDir(kThumbnailWallpaperSubDir);
- file_to_remove.push_back(wallpaper_path.Append(user_id));
+ file_to_remove.push_back(wallpaper_path.Append(user_id.GetUserEmail()));
wallpaper_path = wallpaper_path.Append(path_to_file);
file_to_remove.push_back(wallpaper_path);
// Remove original user wallpaper.
wallpaper_path = GetCustomWallpaperDir(kOriginalWallpaperSubDir);
- file_to_remove.push_back(wallpaper_path.Append(user_id));
+ file_to_remove.push_back(wallpaper_path.Append(user_id.GetUserEmail()));
wallpaper_path = wallpaper_path.Append(path_to_file);
file_to_remove.push_back(wallpaper_path);
@@ -803,7 +804,7 @@ base::CommandLine* WallpaperManagerBase::GetCommandLine() {
}
void WallpaperManagerBase::LoadWallpaper(
- const std::string& user_id,
+ const user_manager::UserID& user_id,
const WallpaperInfo& info,
bool update_wallpaper,
MovableOnDestroyCallbackHolder on_finish) {
@@ -815,12 +816,12 @@ void WallpaperManagerBase::LoadWallpaper(
info.type == user_manager::User::DEFAULT) {
if (info.location.empty()) {
if (base::SysInfo::IsRunningOnChromeOS()) {
- NOTREACHED() << "User wallpaper info appears to be broken: " << user_id;
+ NOTREACHED() << "User wallpaper info appears to be broken: " << user_id.GetUserEmail();
} else {
// Filename might be empty on debug configurations when stub users
// were created directly in Local State (for testing). Ignore such
// errors i.e. allowsuch type of debug configurations on the desktop.
- LOG(WARNING) << "User wallpaper info is empty: " << user_id;
+ LOG(WARNING) << "User wallpaper info is empty: " << user_id.GetUserEmail();
// |on_finish| callback will get called on destruction.
return;
@@ -875,7 +876,7 @@ void WallpaperManagerBase::LoadWallpaper(
}
void WallpaperManagerBase::MoveCustomWallpapersSuccess(
- const std::string& user_id,
+ const user_manager::UserID& user_id,
const std::string& user_id_hash) {
WallpaperInfo info;
GetUserWallpaperInfo(user_id, &info);
@@ -897,7 +898,7 @@ void WallpaperManagerBase::MoveLoggedInUserCustomWallpaper() {
task_runner_->PostTask(
FROM_HERE,
base::Bind(&WallpaperManagerBase::MoveCustomWallpapersOnWorker,
- logged_in_user->email(), logged_in_user->username_hash(),
+ logged_in_user->GetUserID(), logged_in_user->username_hash(),
weak_factory_.GetWeakPtr()));
}
}
« components/user_manager/user_id.cc ('K') | « components/wallpaper/wallpaper_manager_base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698