Home | History | Annotate | Download | only in login
      1 // Copyright (c) 2012 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_USER_IMAGE_MANAGER_H_
      6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_MANAGER_H_
      7 
      8 #include <string>
      9 
     10 #include "chrome/browser/chromeos/login/user.h"
     11 
     12 class PrefRegistrySimple;
     13 
     14 namespace base {
     15 class FilePath;
     16 }
     17 
     18 namespace gfx {
     19 class ImageSkia;
     20 }
     21 
     22 namespace chromeos {
     23 
     24 class UserImage;
     25 class UserImageSyncObserver;
     26 
     27 // Base class that provides a mechanism for updating user images.
     28 class UserImageManager {
     29  public:
     30   // Registers user image manager preferences.
     31   static void RegisterPrefs(PrefRegistrySimple* registry);
     32 
     33   virtual ~UserImageManager();
     34 
     35   // Loads user image data from Local State.
     36   virtual void LoadUserImages(const UserList& users) = 0;
     37 
     38   // Indicates that a user with the given |user_id| has just logged in.
     39   virtual void UserLoggedIn(const std::string& user_id,
     40                             bool user_is_new,
     41                             bool user_is_local) = 0;
     42 
     43   // Sets user image to the default image with index |image_index|, sends
     44   // LOGIN_USER_IMAGE_CHANGED notification and updates Local State.
     45   virtual void SaveUserDefaultImageIndex(const std::string& user_id,
     46                                          int image_index) = 0;
     47 
     48   // Saves image to file, sends LOGIN_USER_IMAGE_CHANGED notification and
     49   // updates Local State.
     50   virtual void SaveUserImage(const std::string& user_id,
     51                              const UserImage& user_image) = 0;
     52 
     53   // Tries to load user image from disk; if successful, sets it for the user,
     54   // sends LOGIN_USER_IMAGE_CHANGED notification and updates Local State.
     55   virtual void SaveUserImageFromFile(const std::string& user_id,
     56                                      const base::FilePath& path) = 0;
     57 
     58   // Sets profile image as user image for |user_id|, sends
     59   // LOGIN_USER_IMAGE_CHANGED notification and updates Local State. If the user
     60   // is not logged-in or the last |DownloadProfileImage| call has failed, a
     61   // default grey avatar will be used until the user logs in and profile image
     62   // is downloaded successfully.
     63   virtual void SaveUserImageFromProfileImage(const std::string& user_id) = 0;
     64 
     65   // Deletes user image and the corresponding image file.
     66   virtual void DeleteUserImage(const std::string& user_id) = 0;
     67 
     68   // Starts downloading the profile image for the logged-in user.
     69   // If user's image index is |kProfileImageIndex|, newly downloaded image
     70   // is immediately set as user's current picture.
     71   // |reason| is an arbitrary string (used to report UMA histograms with
     72   // download times).
     73   virtual void DownloadProfileImage(const std::string& reason) = 0;
     74 
     75   // Returns the result of the last successful profile image download, if any.
     76   // Otherwise, returns an empty bitmap.
     77   virtual const gfx::ImageSkia& DownloadedProfileImage() const = 0;
     78 
     79   // Returns sync observer attached to current user. Returns NULL if current
     80   // user can't sync images or user is not logged in.
     81   virtual UserImageSyncObserver* GetSyncObserver() const = 0;
     82 
     83   // Unregisters preference observers before browser process shutdown.
     84   // Also cancels any profile image download in progress.
     85   virtual void Shutdown() = 0;
     86 };
     87 
     88 }  // namespace chromeos
     89 
     90 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_MANAGER_H_
     91