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. 4 5#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_MANAGER_H_ 6#define CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_MANAGER_H_ 7 8#include <string> 9 10#include "components/user_manager/user.h" 11 12class PrefRegistrySimple; 13 14namespace base { 15class FilePath; 16} 17 18namespace gfx { 19class ImageSkia; 20} 21 22namespace user_manager { 23class UserImage; 24} 25 26namespace chromeos { 27 28class UserImageSyncObserver; 29 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. 32class UserImageManager { 33 public: 34 // Registers user image manager preferences. 35 static void RegisterPrefs(PrefRegistrySimple* registry); 36 37 explicit UserImageManager(const std::string& user_id); 38 virtual ~UserImageManager(); 39 40 // Loads user image data from Local State. 41 virtual void LoadUserImage() = 0; 42 43 // Indicates that a user has just logged in. 44 virtual void UserLoggedIn(bool user_is_new, bool user_is_local) = 0; 45 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; 49 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; 53 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; 57 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; 64 65 // Deletes user image and the corresponding image file. 66 virtual void DeleteUserImage() = 0; 67 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; 73 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; 77 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; 81 82 // Unregisters preference observers before browser process shutdown. 83 // Also cancels any profile image download in progress. 84 virtual void Shutdown() = 0; 85 86 // Invoked when an external data reference is set for the user. 87 virtual void OnExternalDataSet(const std::string& policy) = 0; 88 89 // Invoked when the external data reference is cleared for the user. 90 virtual void OnExternalDataCleared(const std::string& policy) = 0; 91 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; 99 100 protected: 101 const std::string& user_id() const { return user_id_; } 102 103 // ID of user which images are managed by current instance of 104 // UserImageManager. 105 const std::string user_id_; 106}; 107 108} // namespace chromeos 109 110#endif // CHROME_BROWSER_CHROMEOS_LOGIN_USERS_AVATAR_USER_IMAGE_MANAGER_H_ 111