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 // Indicates that a user profile was created.
47 virtual void UserProfileCreated() = 0;
49 // Sets user image to the default image with index |image_index|, sends
50 // LOGIN_USER_IMAGE_CHANGED notification and updates Local State.
51 virtual void SaveUserDefaultImageIndex(int image_index
) = 0;
53 // Saves image to file, sends LOGIN_USER_IMAGE_CHANGED notification and
54 // updates Local State.
55 virtual void SaveUserImage(const user_manager::UserImage
& user_image
) = 0;
57 // Tries to load user image from disk; if successful, sets it for the user,
58 // sends LOGIN_USER_IMAGE_CHANGED notification and updates Local State.
59 virtual void SaveUserImageFromFile(const base::FilePath
& path
) = 0;
61 // Sets profile image as user image for the user, sends
62 // LOGIN_USER_IMAGE_CHANGED notification and updates Local State. If
63 // the user is not logged-in or the last |DownloadProfileImage| call
64 // has failed, a default grey avatar will be used until the user logs
65 // in and profile image is downloaded successfully.
66 virtual void SaveUserImageFromProfileImage() = 0;
68 // Deletes user image and the corresponding image file.
69 virtual void DeleteUserImage() = 0;
71 // Starts downloading the profile image for the user. If user's image
72 // index is |USER_IMAGE_PROFILE|, newly downloaded image is immediately
73 // set as user's current picture. |reason| is an arbitrary string
74 // (used to report UMA histograms with download times).
75 virtual void DownloadProfileImage(const std::string
& reason
) = 0;
77 // Returns the result of the last successful profile image download, if any.
78 // Otherwise, returns an empty bitmap.
79 virtual const gfx::ImageSkia
& DownloadedProfileImage() const = 0;
81 // Returns sync observer attached to the user. Returns NULL if current
82 // user can't sync images or user is not logged in.
83 virtual UserImageSyncObserver
* GetSyncObserver() const = 0;
85 // Unregisters preference observers before browser process shutdown.
86 // Also cancels any profile image download in progress.
87 virtual void Shutdown() = 0;
89 // Invoked when an external data reference is set for the user.
90 virtual void OnExternalDataSet(const std::string
& policy
) = 0;
92 // Invoked when the external data reference is cleared for the user.
93 virtual void OnExternalDataCleared(const std::string
& policy
) = 0;
95 // Invoked when the external data referenced for the user has been
96 // fetched. Failed fetches are retried and the method is called only
97 // when a fetch eventually succeeds. If a fetch fails permanently
98 // (e.g. because the external data reference specifies an invalid URL),
99 // the method is not called at all.
100 virtual void OnExternalDataFetched(const std::string
& policy
,
101 scoped_ptr
<std::string
> data
) = 0;
104 const std::string
& user_id() const { return user_id_
; }
106 // ID of user which images are managed by current instance of
108 const std::string user_id_
;
111 } // namespace chromeos
113 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_MANAGER_H_