summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraltimofeev@chromium.org <altimofeev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-03 15:08:18 +0000
committeraltimofeev@chromium.org <altimofeev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-03 15:08:18 +0000
commit4841b4d12c3f1f466a071df43b1b805b67e9bfdf (patch)
tree27a7b030b4274fe9de0e141a75df7e627f36e251
parent37b031eccf2c14712b396bd7dca270d1eed20e66 (diff)
downloadchromium_src-4841b4d12c3f1f466a071df43b1b805b67e9bfdf.zip
chromium_src-4841b4d12c3f1f466a071df43b1b805b67e9bfdf.tar.gz
chromium_src-4841b4d12c3f1f466a071df43b1b805b67e9bfdf.tar.bz2
Delete user image when user is removed.
BUG=chromium-os:8161 TEST=manual Review URL: http://codereview.chromium.org/4332002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64915 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/login/user_manager.cc39
-rw-r--r--chrome/browser/chromeos/login/user_manager.h6
2 files changed, 40 insertions, 5 deletions
diff --git a/chrome/browser/chromeos/login/user_manager.cc b/chrome/browser/chromeos/login/user_manager.cc
index 36f3163..74aad31 100644
--- a/chrome/browser/chromeos/login/user_manager.cc
+++ b/chrome/browser/chromeos/login/user_manager.cc
@@ -99,6 +99,15 @@ void SaveImageToFile(const SkBitmap& image,
username, image_path.value()));
}
+// Deletes user's image file. Runs on FILE thread.
+void DeleteUserImage(const FilePath& image_path) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ if (!file_util::Delete(image_path, false)) {
+ LOG(ERROR) << "Failed to remove user image.";
+ return;
+ }
+}
+
// Checks if given path is one of the default ones. If it is, returns true
// and its index in kDefaultImageNames through |image_id|. If not, returns
// false.
@@ -262,6 +271,7 @@ void UserManager::RemoveUser(const std::string& email) {
// Clear the prefs view of the users.
PrefService* prefs = g_browser_process->local_state();
ListValue* prefs_users = prefs->GetMutableList(kLoggedInUsers);
+ DCHECK(prefs_users);
prefs_users->Clear();
for (std::vector<User>::iterator it = users.begin();
@@ -272,7 +282,24 @@ void UserManager::RemoveUser(const std::string& email) {
if (email != user_email)
prefs_users->Append(Value::CreateStringValue(user_email));
}
+
+ DictionaryValue* prefs_images = prefs->GetMutableDictionary(kUserImages);
+ DCHECK(prefs_images);
+ std::string image_path_string;
+ prefs_images->GetStringWithoutPathExpansion(email, &image_path_string);
+ prefs_images->RemoveWithoutPathExpansion(email, NULL);
+
prefs->SavePersistentPrefs();
+
+ size_t default_image_id;
+ if (!IsDefaultImagePath(image_path_string, &default_image_id)) {
+ FilePath image_path(image_path_string);
+ BrowserThread::PostTask(
+ BrowserThread::FILE,
+ FROM_HERE,
+ NewRunnableFunction(&DeleteUserImage,
+ image_path));
+ }
}
bool UserManager::IsKnownUser(const std::string& email) {
@@ -297,10 +324,7 @@ void UserManager::SetLoggedInUserImage(const SkBitmap& image) {
void UserManager::SaveUserImage(const std::string& username,
const SkBitmap& image) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- std::string filename = username + ".png";
- FilePath user_data_dir;
- PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
- FilePath image_path = user_data_dir.AppendASCII(filename);
+ FilePath image_path = GetImagePathForUser(username);
DVLOG(1) << "Saving user image to " << image_path.value();
BrowserThread::PostTask(
@@ -378,6 +402,13 @@ UserManager::~UserManager() {
image_loader_->set_delegate(NULL);
}
+FilePath UserManager::GetImagePathForUser(const std::string& username) {
+ std::string filename = username + ".png";
+ FilePath user_data_dir;
+ PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
+ return user_data_dir.AppendASCII(filename);
+}
+
void UserManager::NotifyOnLogin() {
NotificationService::current()->Notify(
NotificationType::LOGIN_USER_CHANGED,
diff --git a/chrome/browser/chromeos/login/user_manager.h b/chrome/browser/chromeos/login/user_manager.h
index 8168eaa..01766d0 100644
--- a/chrome/browser/chromeos/login/user_manager.h
+++ b/chrome/browser/chromeos/login/user_manager.h
@@ -17,6 +17,7 @@
#include "chrome/common/notification_registrar.h"
#include "third_party/skia/include/core/SkBitmap.h"
+class FilePath;
class PrefService;
namespace chromeos {
@@ -83,7 +84,7 @@ class UserManager : public UserImageLoader::Delegate,
// Saves image to file and saves image path in local state preferences.
void SaveUserImage(const std::string& username,
- const SkBitmap& image);
+ const SkBitmap& image);
// Sets one of the default images to the specified user and saves this
// setting in local state.
@@ -110,6 +111,9 @@ class UserManager : public UserImageLoader::Delegate,
UserManager();
virtual ~UserManager();
+ // Returns image filepath for the given user.
+ FilePath GetImagePathForUser(const std::string& username);
+
private:
// Notifies on new user session.
void NotifyOnLogin();