| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_MANAGER_IMPL_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_MANAGER_IMPL_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_MANAGER_IMPL_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_MANAGER_IMPL_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "base/timer.h" | 14 #include "base/timer.h" |
| 15 #include "chrome/browser/chromeos/login/user.h" | 15 #include "chrome/browser/chromeos/login/user.h" |
| 16 #include "chrome/browser/chromeos/login/user_image_loader.h" | 16 #include "chrome/browser/chromeos/login/user_image_loader.h" |
| 17 #include "chrome/browser/chromeos/login/user_image_manager.h" | 17 #include "chrome/browser/chromeos/login/user_image_manager.h" |
| 18 #include "chrome/browser/profiles/profile_downloader_delegate.h" | 18 #include "chrome/browser/profiles/profile_downloader_delegate.h" |
| 19 #include "ui/gfx/image/image_skia.h" | 19 #include "ui/gfx/image/image_skia.h" |
| 20 | 20 |
| 21 class ProfileDownloader; | 21 class ProfileDownloader; |
| 22 class UserImage; | 22 class UserImage; |
| 23 | 23 |
| 24 namespace base { |
| 25 class FilePath; |
| 26 } |
| 27 |
| 24 namespace chromeos { | 28 namespace chromeos { |
| 25 | 29 |
| 26 class UserImageManagerImpl : public UserImageManager, | 30 class UserImageManagerImpl : public UserImageManager, |
| 27 public ProfileDownloaderDelegate { | 31 public ProfileDownloaderDelegate { |
| 28 public: | 32 public: |
| 29 UserImageManagerImpl(); | 33 UserImageManagerImpl(); |
| 30 | 34 |
| 31 // UserImageManager implemenation: | 35 // UserImageManager implemenation: |
| 32 virtual ~UserImageManagerImpl(); | 36 virtual ~UserImageManagerImpl(); |
| 33 virtual void LoadUserImages(const UserList& users) OVERRIDE; | 37 virtual void LoadUserImages(const UserList& users) OVERRIDE; |
| 34 virtual void UserLoggedIn(const std::string& email, | 38 virtual void UserLoggedIn(const std::string& email, |
| 35 bool user_is_new, | 39 bool user_is_new, |
| 36 bool user_is_local) OVERRIDE; | 40 bool user_is_local) OVERRIDE; |
| 37 virtual void SaveUserDefaultImageIndex(const std::string& username, | 41 virtual void SaveUserDefaultImageIndex(const std::string& username, |
| 38 int image_index) OVERRIDE; | 42 int image_index) OVERRIDE; |
| 39 virtual void SaveUserImage(const std::string& username, | 43 virtual void SaveUserImage(const std::string& username, |
| 40 const UserImage& user_image) OVERRIDE; | 44 const UserImage& user_image) OVERRIDE; |
| 41 virtual void SaveUserImageFromFile(const std::string& username, | 45 virtual void SaveUserImageFromFile(const std::string& username, |
| 42 const FilePath& path) OVERRIDE; | 46 const base::FilePath& path) OVERRIDE; |
| 43 virtual void SaveUserImageFromProfileImage( | 47 virtual void SaveUserImageFromProfileImage( |
| 44 const std::string& username) OVERRIDE; | 48 const std::string& username) OVERRIDE; |
| 45 virtual void DeleteUserImage(const std::string& username) OVERRIDE; | 49 virtual void DeleteUserImage(const std::string& username) OVERRIDE; |
| 46 virtual void DownloadProfileImage(const std::string& reason) OVERRIDE; | 50 virtual void DownloadProfileImage(const std::string& reason) OVERRIDE; |
| 47 virtual const gfx::ImageSkia& DownloadedProfileImage() const OVERRIDE; | 51 virtual const gfx::ImageSkia& DownloadedProfileImage() const OVERRIDE; |
| 48 | 52 |
| 49 private: | 53 private: |
| 50 friend class UserImageManagerTest; | 54 friend class UserImageManagerTest; |
| 51 | 55 |
| 52 // Non-const for testing purposes. | 56 // Non-const for testing purposes. |
| 53 static int user_image_migration_delay_sec; | 57 static int user_image_migration_delay_sec; |
| 54 | 58 |
| 55 // ProfileDownloaderDelegate implementation: | 59 // ProfileDownloaderDelegate implementation: |
| 56 virtual bool NeedsProfilePicture() const OVERRIDE; | 60 virtual bool NeedsProfilePicture() const OVERRIDE; |
| 57 virtual int GetDesiredImageSideLength() const OVERRIDE; | 61 virtual int GetDesiredImageSideLength() const OVERRIDE; |
| 58 virtual Profile* GetBrowserProfile() OVERRIDE; | 62 virtual Profile* GetBrowserProfile() OVERRIDE; |
| 59 virtual std::string GetCachedPictureURL() const OVERRIDE; | 63 virtual std::string GetCachedPictureURL() const OVERRIDE; |
| 60 virtual void OnProfileDownloadSuccess(ProfileDownloader* downloader) OVERRIDE; | 64 virtual void OnProfileDownloadSuccess(ProfileDownloader* downloader) OVERRIDE; |
| 61 virtual void OnProfileDownloadFailure( | 65 virtual void OnProfileDownloadFailure( |
| 62 ProfileDownloader* downloader, | 66 ProfileDownloader* downloader, |
| 63 ProfileDownloaderDelegate::FailureReason reason) OVERRIDE; | 67 ProfileDownloaderDelegate::FailureReason reason) OVERRIDE; |
| 64 | 68 |
| 65 // Returns image filepath for the given user. | 69 // Returns image filepath for the given user. |
| 66 FilePath GetImagePathForUser(const std::string& username); | 70 base::FilePath GetImagePathForUser(const std::string& username); |
| 67 | 71 |
| 68 // Sets one of the default images for the specified user and saves this | 72 // Sets one of the default images for the specified user and saves this |
| 69 // setting in local state. | 73 // setting in local state. |
| 70 // Does not send LOGIN_USER_IMAGE_CHANGED notification. | 74 // Does not send LOGIN_USER_IMAGE_CHANGED notification. |
| 71 void SetInitialUserImage(const std::string& username); | 75 void SetInitialUserImage(const std::string& username); |
| 72 | 76 |
| 73 // Sets image for user |username| and sends LOGIN_USER_IMAGE_CHANGED | 77 // Sets image for user |username| and sends LOGIN_USER_IMAGE_CHANGED |
| 74 // notification unless this is a new user and image is set for the first time. | 78 // notification unless this is a new user and image is set for the first time. |
| 75 // If |image| is empty, sets a stub image for the user. | 79 // If |image| is empty, sets a stub image for the user. |
| 76 void SetUserImage(const std::string& username, | 80 void SetUserImage(const std::string& username, |
| 77 int image_index, | 81 int image_index, |
| 78 const GURL& image_url, | 82 const GURL& image_url, |
| 79 const UserImage& user_image); | 83 const UserImage& user_image); |
| 80 | 84 |
| 81 // Saves image to file, updates local state preferences to given image index | 85 // Saves image to file, updates local state preferences to given image index |
| 82 // and sends LOGIN_USER_IMAGE_CHANGED notification. | 86 // and sends LOGIN_USER_IMAGE_CHANGED notification. |
| 83 void SaveUserImageInternal(const std::string& username, | 87 void SaveUserImageInternal(const std::string& username, |
| 84 int image_index, | 88 int image_index, |
| 85 const GURL& image_url, | 89 const GURL& image_url, |
| 86 const UserImage& user_image); | 90 const UserImage& user_image); |
| 87 | 91 |
| 88 // Saves image to file with specified path and sends LOGIN_USER_IMAGE_CHANGED | 92 // Saves image to file with specified path and sends LOGIN_USER_IMAGE_CHANGED |
| 89 // notification. Runs on FILE thread. Posts task for saving image info to | 93 // notification. Runs on FILE thread. Posts task for saving image info to |
| 90 // Local State on UI thread. | 94 // Local State on UI thread. |
| 91 void SaveImageToFile(const std::string& username, | 95 void SaveImageToFile(const std::string& username, |
| 92 const UserImage& user_image, | 96 const UserImage& user_image, |
| 93 const FilePath& image_path, | 97 const base::FilePath& image_path, |
| 94 int image_index, | 98 int image_index, |
| 95 const GURL& image_url); | 99 const GURL& image_url); |
| 96 | 100 |
| 97 // Stores path to the image and its index in local state. Runs on UI thread. | 101 // Stores path to the image and its index in local state. Runs on UI thread. |
| 98 // If |is_async| is true, it has been posted from the FILE thread after | 102 // If |is_async| is true, it has been posted from the FILE thread after |
| 99 // saving the image. | 103 // saving the image. |
| 100 void SaveImageToLocalState(const std::string& username, | 104 void SaveImageToLocalState(const std::string& username, |
| 101 const std::string& image_path, | 105 const std::string& image_path, |
| 102 int image_index, | 106 int image_index, |
| 103 const GURL& image_url, | 107 const GURL& image_url, |
| 104 bool is_async); | 108 bool is_async); |
| 105 | 109 |
| 106 // Saves |image| to the specified |image_path|. Runs on FILE thread. | 110 // Saves |image| to the specified |image_path|. Runs on FILE thread. |
| 107 bool SaveBitmapToFile(const UserImage& user_image, | 111 bool SaveBitmapToFile(const UserImage& user_image, |
| 108 const FilePath& image_path); | 112 const base::FilePath& image_path); |
| 109 | 113 |
| 110 // Initializes |downloaded_profile_image_| with the picture of the logged-in | 114 // Initializes |downloaded_profile_image_| with the picture of the logged-in |
| 111 // user. | 115 // user. |
| 112 void InitDownloadedProfileImage(); | 116 void InitDownloadedProfileImage(); |
| 113 | 117 |
| 114 // Download user's profile data, including full name and picture, when | 118 // Download user's profile data, including full name and picture, when |
| 115 // |download_image| is true. | 119 // |download_image| is true. |
| 116 // |reason| is an arbitrary string (used to report UMA histograms with | 120 // |reason| is an arbitrary string (used to report UMA histograms with |
| 117 // download times). | 121 // download times). |
| 118 void DownloadProfileData(const std::string& reason, bool download_image); | 122 void DownloadProfileData(const std::string& reason, bool download_image); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 174 |
| 171 // If |true|, current user image should be migrated right after it is loaded. | 175 // If |true|, current user image should be migrated right after it is loaded. |
| 172 bool migrate_current_user_on_load_; | 176 bool migrate_current_user_on_load_; |
| 173 | 177 |
| 174 DISALLOW_COPY_AND_ASSIGN(UserImageManagerImpl); | 178 DISALLOW_COPY_AND_ASSIGN(UserImageManagerImpl); |
| 175 }; | 179 }; |
| 176 | 180 |
| 177 } // namespace chromeos | 181 } // namespace chromeos |
| 178 | 182 |
| 179 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_MANAGER_IMPL_H_ | 183 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_MANAGER_IMPL_H_ |
| OLD | NEW |