1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_MANAGER_H_
10 #include "components/user_manager/user.h"
12 class PrefRegistrySimple;
22 namespace user_manager {
28 class UserImageSyncObserver;
30 // Base class that provides a mechanism for updating user images.
31 // There is an instance of this class for each user in the system.
32 class UserImageManager {
34 // Registers user image manager preferences.
35 static void RegisterPrefs(PrefRegistrySimple* registry);
37 explicit UserImageManager(const std::string& user_id);
38 virtual ~UserImageManager();
40 // Loads user image data from Local State.
41 virtual void LoadUserImage() = 0;
43 // Indicates that a user has just logged in.
44 virtual void UserLoggedIn(bool user_is_new, bool user_is_local) = 0;
46 // Sets user image to the default image with index |image_index|, sends
47 // LOGIN_USER_IMAGE_CHANGED notification and updates Local State.
48 virtual void SaveUserDefaultImageIndex(int image_index) = 0;
50 // Saves image to file, sends LOGIN_USER_IMAGE_CHANGED notification and
51 // updates Local State.
52 virtual void SaveUserImage(const user_manager::UserImage& user_image) = 0;
54 // Tries to load user image from disk; if successful, sets it for the user,
55 // sends LOGIN_USER_IMAGE_CHANGED notification and updates Local State.
56 virtual void SaveUserImageFromFile(const base::FilePath& path) = 0;
58 // Sets profile image as user image for the user, sends
59 // LOGIN_USER_IMAGE_CHANGED notification and updates Local State. If
60 // the user is not logged-in or the last |DownloadProfileImage| call
61 // has failed, a default grey avatar will be used until the user logs
62 // in and profile image is downloaded successfully.
63 virtual void SaveUserImageFromProfileImage() = 0;
65 // Deletes user image and the corresponding image file.
66 virtual void DeleteUserImage() = 0;
68 // Starts downloading the profile image for the user. If user's image
69 // index is |USER_IMAGE_PROFILE|, newly downloaded image is immediately
70 // set as user's current picture. |reason| is an arbitrary string
71 // (used to report UMA histograms with download times).
72 virtual void DownloadProfileImage(const std::string& reason) = 0;
74 // Returns the result of the last successful profile image download, if any.
75 // Otherwise, returns an empty bitmap.
76 virtual const gfx::ImageSkia& DownloadedProfileImage() const = 0;
78 // Returns sync observer attached to the user. Returns NULL if current
79 // user can't sync images or user is not logged in.
80 virtual UserImageSyncObserver* GetSyncObserver() const = 0;
82 // Unregisters preference observers before browser process shutdown.
83 // Also cancels any profile image download in progress.
84 virtual void Shutdown() = 0;
86 // Invoked when an external data reference is set for the user.
87 virtual void OnExternalDataSet(const std::string& policy) = 0;
89 // Invoked when the external data reference is cleared for the user.
90 virtual void OnExternalDataCleared(const std::string& policy) = 0;
92 // Invoked when the external data referenced for the user has been
93 // fetched. Failed fetches are retried and the method is called only
94 // when a fetch eventually succeeds. If a fetch fails permanently
95 // (e.g. because the external data reference specifies an invalid URL),
96 // the method is not called at all.
97 virtual void OnExternalDataFetched(const std::string& policy,
98 scoped_ptr<std::string> data) = 0;
101 const std::string& user_id() const { return user_id_; }
103 // ID of user which images are managed by current instance of
105 const std::string user_id_;
108 } // namespace chromeos
110 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_MANAGER_H_