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

Unified Diff: components/wallpaper/wallpaper_manager_base.cc

Issue 1497973002: This CL replaces e-mail with AccountId in wallpaper manager code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 d526dbe559130ea626868f6f8b330168baf0d76d..80421936ee89bf6c7556a7cc1e72d8ca27b41f3c 100644
--- a/components/wallpaper/wallpaper_manager_base.cc
+++ b/components/wallpaper/wallpaper_manager_base.cc
@@ -75,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 std::string& user_id_hash) {
+ const std::string& from_name,
+ const std::string& to_name) {
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 to_path = base_path.Append(to_name);
+ base::FilePath from_path = base_path.Append(from_name);
if (base::PathExists(from_path))
return base::Move(from_path, to_path);
return false;
@@ -259,23 +259,23 @@ WallpaperManagerBase::TestApi::~TestApi() {
}
bool WallpaperManagerBase::TestApi::GetWallpaperFromCache(
- const std::string& user_id,
+ const AccountId& account_id,
gfx::ImageSkia* image) {
- return wallpaper_manager_->GetWallpaperFromCache(user_id, image);
+ return wallpaper_manager_->GetWallpaperFromCache(account_id, image);
}
bool WallpaperManagerBase::TestApi::GetPathFromCache(
- const std::string& user_id,
+ const AccountId& account_id,
base::FilePath* path) {
- return wallpaper_manager_->GetPathFromCache(user_id, path);
+ return wallpaper_manager_->GetPathFromCache(account_id, path);
}
void WallpaperManagerBase::TestApi::SetWallpaperCache(
- const std::string& user_id,
+ const AccountId& account_id,
const base::FilePath& path,
const gfx::ImageSkia& image) {
DCHECK(!image.isNull());
- wallpaper_manager_->wallpaper_cache_[user_id] =
+ wallpaper_manager_->wallpaper_cache_[account_id] =
CustomWallpaperElement(path, image);
}
@@ -319,25 +319,26 @@ void WallpaperManagerBase::EnsureLoggedInUserWallpaperLoaded() {
return;
}
SetUserWallpaperNow(
- user_manager::UserManager::Get()->GetLoggedInUser()->email());
+ user_manager::UserManager::Get()->GetLoggedInUser()->GetAccountId());
}
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<AccountId> logged_in_user_account_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_user_account_ids.insert((*it)->GetAccountId());
}
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_user_account_ids.find(it->first) !=
+ logged_in_user_account_ids.end()) {
logged_in_users_cache.insert(*it);
}
}
@@ -359,7 +360,8 @@ bool WallpaperManagerBase::GetLoggedInUserWallpaperInfo(WallpaperInfo* info) {
}
return GetUserWallpaperInfo(
- user_manager::UserManager::Get()->GetLoggedInUser()->email(), info);
+ user_manager::UserManager::Get()->GetLoggedInUser()->GetAccountId(),
+ info);
}
// static
@@ -444,28 +446,28 @@ bool WallpaperManagerBase::ResizeAndSaveWallpaper(const gfx::ImageSkia& image,
}
bool WallpaperManagerBase::IsPolicyControlled(
- const std::string& user_id) const {
+ const AccountId& account_id) const {
WallpaperInfo info;
- if (!GetUserWallpaperInfo(user_id, &info))
+ if (!GetUserWallpaperInfo(account_id, &info))
return false;
return info.type == user_manager::User::POLICY;
}
void WallpaperManagerBase::OnPolicySet(const std::string& policy,
- const std::string& user_id) {
+ const AccountId& account_id) {
WallpaperInfo info;
- GetUserWallpaperInfo(user_id, &info);
+ GetUserWallpaperInfo(account_id, &info);
info.type = user_manager::User::POLICY;
- SetUserWallpaperInfo(user_id, info, true /* is_persistent */);
+ SetUserWallpaperInfo(account_id, info, true /* is_persistent */);
}
void WallpaperManagerBase::OnPolicyCleared(const std::string& policy,
- const std::string& user_id) {
+ const AccountId& account_id) {
WallpaperInfo info;
- GetUserWallpaperInfo(user_id, &info);
+ GetUserWallpaperInfo(account_id, &info);
info.type = user_manager::User::DEFAULT;
- SetUserWallpaperInfo(user_id, info, true /* is_persistent */);
- SetDefaultWallpaperNow(user_id);
+ SetUserWallpaperInfo(account_id, info, true /* is_persistent */);
+ SetDefaultWallpaperNow(account_id);
}
// static
@@ -499,10 +501,10 @@ WallpaperManagerBase::~WallpaperManagerBase() {
}
void WallpaperManagerBase::SetPolicyControlledWallpaper(
- const std::string& user_id,
+ const AccountId& account_id,
const user_manager::UserImage& user_image) {
- const user_manager::User* user = user_manager::UserManager::Get()->FindUser(
- AccountId::FromUserEmail(user_id));
+ const user_manager::User* user =
+ user_manager::UserManager::Get()->FindUser(account_id);
if (!user) {
NOTREACHED() << "Unknown user.";
return;
@@ -510,27 +512,27 @@ void WallpaperManagerBase::SetPolicyControlledWallpaper(
if (user->username_hash().empty()) {
cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername(
- user_id,
+ account_id.GetUserEmail(),
base::Bind(&WallpaperManagerBase::SetCustomWallpaperOnSanitizedUsername,
- weak_factory_.GetWeakPtr(), user_id, user_image.image(),
+ weak_factory_.GetWeakPtr(), account_id, user_image.image(),
true /* update wallpaper */));
} else {
- SetCustomWallpaper(user_id, user->username_hash(), "policy-controlled.jpeg",
- WALLPAPER_LAYOUT_CENTER_CROPPED,
- user_manager::User::POLICY, user_image.image(),
- true /* update wallpaper */);
+ SetCustomWallpaper(
+ account_id, user->username_hash(), "policy-controlled.jpeg",
+ WALLPAPER_LAYOUT_CENTER_CROPPED, user_manager::User::POLICY,
+ user_image.image(), true /* update wallpaper */);
}
}
void WallpaperManagerBase::SetCustomWallpaperOnSanitizedUsername(
- const std::string& user_id,
+ const AccountId& account_id,
const gfx::ImageSkia& image,
bool update_wallpaper,
bool cryptohome_success,
const std::string& user_id_hash) {
if (!cryptohome_success)
return;
- SetCustomWallpaper(user_id, user_id_hash, "policy-controlled.jpeg",
+ SetCustomWallpaper(account_id, user_id_hash, "policy-controlled.jpeg",
WALLPAPER_LAYOUT_CENTER_CROPPED,
user_manager::User::POLICY, image, update_wallpaper);
}
@@ -572,28 +574,30 @@ void WallpaperManagerBase::SaveCustomWallpaper(
// static
void WallpaperManagerBase::MoveCustomWallpapersOnWorker(
- const std::string& user_id,
+ const AccountId& account_id,
const std::string& user_id_hash,
base::WeakPtr<WallpaperManagerBase> weak_ptr) {
- if (MoveCustomWallpaperDirectory(kOriginalWallpaperSubDir, user_id,
- user_id_hash)) {
+ if (MoveCustomWallpaperDirectory(kOriginalWallpaperSubDir,
+ account_id.GetUserEmail(), user_id_hash)) {
// Consider success if the original wallpaper is moved to the new directory.
// Original wallpaper is the fallback if the correct resolution wallpaper
// can not be found.
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&WallpaperManagerBase::MoveCustomWallpapersSuccess, weak_ptr,
- user_id, user_id_hash));
+ account_id, user_id_hash));
}
- MoveCustomWallpaperDirectory(kLargeWallpaperSubDir, user_id, user_id_hash);
- MoveCustomWallpaperDirectory(kSmallWallpaperSubDir, user_id, user_id_hash);
- MoveCustomWallpaperDirectory(kThumbnailWallpaperSubDir, user_id,
+ MoveCustomWallpaperDirectory(kLargeWallpaperSubDir, account_id.GetUserEmail(),
user_id_hash);
+ MoveCustomWallpaperDirectory(kSmallWallpaperSubDir, account_id.GetUserEmail(),
+ user_id_hash);
+ MoveCustomWallpaperDirectory(kThumbnailWallpaperSubDir,
+ account_id.GetUserEmail(), user_id_hash);
}
// static
void WallpaperManagerBase::GetCustomWallpaperInternal(
- const std::string& user_id,
+ const AccountId& account_id,
const WallpaperInfo& info,
const base::FilePath& wallpaper_path,
bool update_wallpaper,
@@ -609,12 +613,13 @@ 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.
+ // Falls back to custom wallpaper that uses AccountId as part of its file
+ // path.
+ // Note that account id is used instead of user_id_hash here.
LOG(ERROR) << "Failed to load custom wallpaper from its original fallback "
"file path: " << valid_path.value();
- valid_path = GetCustomWallpaperPath(kOriginalWallpaperSubDir, user_id,
- info.location);
+ valid_path = GetCustomWallpaperPath(
+ kOriginalWallpaperSubDir, account_id.GetUserEmail(), info.location);
}
if (!base::PathExists(valid_path)) {
@@ -624,17 +629,17 @@ void WallpaperManagerBase::GetCustomWallpaperInternal(
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&WallpaperManagerBase::DoSetDefaultWallpaper, weak_ptr,
- user_id, base::Passed(on_finish.Pass())));
+ account_id, base::Passed(on_finish.Pass())));
} else {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(&WallpaperManagerBase::StartLoad, weak_ptr, user_id, info,
+ base::Bind(&WallpaperManagerBase::StartLoad, weak_ptr, account_id, info,
update_wallpaper, valid_path,
base::Passed(on_finish.Pass())));
}
}
-void WallpaperManagerBase::InitInitialUserWallpaper(const std::string& user_id,
+void WallpaperManagerBase::InitInitialUserWallpaper(const AccountId& account_id,
bool is_persistent) {
current_user_wallpaper_info_.location = "";
current_user_wallpaper_info_.layout = WALLPAPER_LAYOUT_CENTER_CROPPED;
@@ -642,15 +647,16 @@ void WallpaperManagerBase::InitInitialUserWallpaper(const std::string& user_id,
current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight();
WallpaperInfo info = current_user_wallpaper_info_;
- SetUserWallpaperInfo(user_id, info, is_persistent);
+ SetUserWallpaperInfo(account_id, info, is_persistent);
}
-void WallpaperManagerBase::SetUserWallpaperDelayed(const std::string& user_id) {
- ScheduleSetUserWallpaper(user_id, true);
+void WallpaperManagerBase::SetUserWallpaperDelayed(
+ const AccountId& account_id) {
+ ScheduleSetUserWallpaper(account_id, true);
}
-void WallpaperManagerBase::SetUserWallpaperNow(const std::string& user_id) {
- ScheduleSetUserWallpaper(user_id, false);
+void WallpaperManagerBase::SetUserWallpaperNow(const AccountId& account_id) {
+ ScheduleSetUserWallpaper(account_id, false);
}
void WallpaperManagerBase::UpdateWallpaper(bool clear_cache) {
@@ -662,7 +668,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::SignInAccountId().GetUserEmail());
+ SetDefaultWallpaperNow(chromeos::login::SignInAccountId());
return;
}
SetUserWallpaperNow(last_selected_user_);
@@ -685,10 +691,10 @@ void WallpaperManagerBase::NotifyAnimationFinished() {
// WallpaperManager, protected: -----------------------------------------------
-bool WallpaperManagerBase::GetWallpaperFromCache(const std::string& user_id,
+bool WallpaperManagerBase::GetWallpaperFromCache(const AccountId& account_id,
gfx::ImageSkia* image) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- CustomWallpaperMap::const_iterator it = wallpaper_cache_.find(user_id);
+ CustomWallpaperMap::const_iterator it = wallpaper_cache_.find(account_id);
if (it != wallpaper_cache_.end() && !(*it).second.second.isNull()) {
*image = (*it).second.second;
return true;
@@ -696,10 +702,10 @@ bool WallpaperManagerBase::GetWallpaperFromCache(const std::string& user_id,
return false;
}
-bool WallpaperManagerBase::GetPathFromCache(const std::string& user_id,
+bool WallpaperManagerBase::GetPathFromCache(const AccountId& account_id,
base::FilePath* path) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- CustomWallpaperMap::const_iterator it = wallpaper_cache_.find(user_id);
+ CustomWallpaperMap::const_iterator it = wallpaper_cache_.find(account_id);
if (it != wallpaper_cache_.end()) {
*path = (*it).second.first;
return true;
@@ -722,18 +728,17 @@ 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)->GetAccountId());
}
}
}
-void WallpaperManagerBase::CacheUserWallpaper(const std::string& user_id) {
- CustomWallpaperMap::iterator it = wallpaper_cache_.find(user_id);
+void WallpaperManagerBase::CacheUserWallpaper(const AccountId& account_id) {
+ CustomWallpaperMap::iterator it = wallpaper_cache_.find(account_id);
if (it != wallpaper_cache_.end() && !it->second.second.isNull())
return;
WallpaperInfo info;
- if (GetUserWallpaperInfo(user_id, &info)) {
+ if (GetUserWallpaperInfo(account_id, &info)) {
if (info.location.empty())
return;
@@ -745,47 +750,48 @@ void WallpaperManagerBase::CacheUserWallpaper(const std::string& user_id) {
base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir);
wallpaper_path = wallpaper_path.Append(info.location);
// Set the path to the cache.
- wallpaper_cache_[user_id] = CustomWallpaperElement(wallpaper_path,
- gfx::ImageSkia());
+ wallpaper_cache_[account_id] =
+ CustomWallpaperElement(wallpaper_path, gfx::ImageSkia());
task_runner_->PostTask(
FROM_HERE,
- base::Bind(&WallpaperManagerBase::GetCustomWallpaperInternal, user_id,
- info, wallpaper_path, false /* do not update wallpaper */,
+ base::Bind(&WallpaperManagerBase::GetCustomWallpaperInternal,
+ account_id, info, wallpaper_path,
+ false /* do not update wallpaper */,
base::Passed(MovableOnDestroyCallbackHolder()),
weak_factory_.GetWeakPtr()));
return;
}
- LoadWallpaper(user_id, info, false /* do not update wallpaper */,
+ LoadWallpaper(account_id, info, false /* do not update wallpaper */,
MovableOnDestroyCallbackHolder().Pass());
}
}
void WallpaperManagerBase::DeleteUserWallpapers(
- const std::string& user_id,
+ const AccountId& account_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(account_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(account_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(account_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(account_id.GetUserEmail()));
wallpaper_path = wallpaper_path.Append(path_to_file);
file_to_remove.push_back(wallpaper_path);
@@ -807,7 +813,7 @@ base::CommandLine* WallpaperManagerBase::GetCommandLine() {
}
void WallpaperManagerBase::LoadWallpaper(
- const std::string& user_id,
+ const AccountId& account_id,
const WallpaperInfo& info,
bool update_wallpaper,
MovableOnDestroyCallbackHolder on_finish) {
@@ -819,12 +825,14 @@ 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: "
+ << account_id.Serialize();
} 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: "
+ << account_id.Serialize();
// |on_finish| callback will get called on destruction.
return;
@@ -850,14 +858,14 @@ void WallpaperManagerBase::LoadWallpaper(
// If the wallpaper exists and it contains already the correct image we can
// return immediately.
- CustomWallpaperMap::iterator it = wallpaper_cache_.find(user_id);
+ CustomWallpaperMap::iterator it = wallpaper_cache_.find(account_id);
if (it != wallpaper_cache_.end() &&
it->second.first == wallpaper_path &&
!it->second.second.isNull())
return;
loaded_wallpapers_for_test_++;
- StartLoad(user_id, info, update_wallpaper, wallpaper_path,
+ StartLoad(account_id, info, update_wallpaper, wallpaper_path,
on_finish.Pass());
} else if (info.type == user_manager::User::DEFAULT) {
// Default wallpapers are migrated from M21 user profiles. A code refactor
@@ -868,29 +876,29 @@ void WallpaperManagerBase::LoadWallpaper(
DCHECK(dir_user_data_path_id != -1);
PathService::Get(dir_user_data_path_id, &user_data_dir);
wallpaper_path = user_data_dir.Append(info.location);
- StartLoad(user_id, info, update_wallpaper, wallpaper_path,
+ StartLoad(account_id, info, update_wallpaper, wallpaper_path,
on_finish.Pass());
} else {
// In unexpected cases, revert to default wallpaper to fail safely. See
// crosbug.com/38429.
LOG(ERROR) << "Wallpaper reverts to default unexpected.";
- DoSetDefaultWallpaper(user_id, on_finish.Pass());
+ DoSetDefaultWallpaper(account_id, on_finish.Pass());
}
}
void WallpaperManagerBase::MoveCustomWallpapersSuccess(
- const std::string& user_id,
+ const AccountId& account_id,
const std::string& user_id_hash) {
WallpaperInfo info;
- GetUserWallpaperInfo(user_id, &info);
+ GetUserWallpaperInfo(account_id, &info);
if (info.type == user_manager::User::CUSTOMIZED) {
// New file field should include user id hash in addition to file name.
// This is needed because at login screen, user id hash is not available.
info.location = base::FilePath(user_id_hash).Append(info.location).value();
bool is_persistent =
!user_manager::UserManager::Get()->IsUserNonCryptohomeDataEphemeral(
- AccountId::FromUserEmail(user_id));
- SetUserWallpaperInfo(user_id, info, is_persistent);
+ account_id);
+ SetUserWallpaperInfo(account_id, info, is_persistent);
}
}
@@ -901,7 +909,8 @@ void WallpaperManagerBase::MoveLoggedInUserCustomWallpaper() {
task_runner_->PostTask(
FROM_HERE,
base::Bind(&WallpaperManagerBase::MoveCustomWallpapersOnWorker,
- logged_in_user->email(), logged_in_user->username_hash(),
+ logged_in_user->GetAccountId(),
+ logged_in_user->username_hash(),
weak_factory_.GetWeakPtr()));
}
}

Powered by Google App Engine
This is Rietveld 408576698