Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / user_image_manager.h
blobad13a1e05ce9b5bdad5934d3f569af4d1a37307b
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.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_MANAGER_H_
8 #include <string>
10 #include "chrome/browser/chromeos/login/user.h"
12 class PrefRegistrySimple;
14 namespace base {
15 class FilePath;
18 namespace gfx {
19 class ImageSkia;
22 namespace chromeos {
24 class UserImage;
25 class UserImageSyncObserver;
27 // Base class that provides a mechanism for updating user images.
28 // There is an instance of this class for each user in the system.
29 class UserImageManager {
30 public:
31 // Registers user image manager preferences.
32 static void RegisterPrefs(PrefRegistrySimple* registry);
34 explicit UserImageManager(const std::string& user_id);
35 virtual ~UserImageManager();
37 // Loads user image data from Local State.
38 virtual void LoadUserImage() = 0;
40 // Indicates that a user has just logged in.
41 virtual void UserLoggedIn(bool user_is_new, bool user_is_local) = 0;
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(int image_index) = 0;
47 // Saves image to file, sends LOGIN_USER_IMAGE_CHANGED notification and
48 // updates Local State.
49 virtual void SaveUserImage(const UserImage& user_image) = 0;
51 // Tries to load user image from disk; if successful, sets it for the user,
52 // sends LOGIN_USER_IMAGE_CHANGED notification and updates Local State.
53 virtual void SaveUserImageFromFile(const base::FilePath& path) = 0;
55 // Sets profile image as user image for the user, sends
56 // LOGIN_USER_IMAGE_CHANGED notification and updates Local State. If
57 // the user is not logged-in or the last |DownloadProfileImage| call
58 // has failed, a default grey avatar will be used until the user logs
59 // in and profile image is downloaded successfully.
60 virtual void SaveUserImageFromProfileImage() = 0;
62 // Deletes user image and the corresponding image file.
63 virtual void DeleteUserImage() = 0;
65 // Starts downloading the profile image for the user. If user's image
66 // index is |kProfileImageIndex|, newly downloaded image is immediately
67 // set as user's current picture. |reason| is an arbitrary string
68 // (used to report UMA histograms with download times).
69 virtual void DownloadProfileImage(const std::string& reason) = 0;
71 // Returns the result of the last successful profile image download, if any.
72 // Otherwise, returns an empty bitmap.
73 virtual const gfx::ImageSkia& DownloadedProfileImage() const = 0;
75 // Returns sync observer attached to the user. Returns NULL if current
76 // user can't sync images or user is not logged in.
77 virtual UserImageSyncObserver* GetSyncObserver() const = 0;
79 // Unregisters preference observers before browser process shutdown.
80 // Also cancels any profile image download in progress.
81 virtual void Shutdown() = 0;
83 // Invoked when an external data reference is set for the user.
84 virtual void OnExternalDataSet(const std::string& policy) = 0;
86 // Invoked when the external data reference is cleared for the user.
87 virtual void OnExternalDataCleared(const std::string& policy) = 0;
89 // Invoked when the external data referenced for the user has been
90 // fetched. Failed fetches are retried and the method is called only
91 // when a fetch eventually succeeds. If a fetch fails permanently
92 // (e.g. because the external data reference specifies an invalid URL),
93 // the method is not called at all.
94 virtual void OnExternalDataFetched(const std::string& policy,
95 scoped_ptr<std::string> data) = 0;
97 protected:
98 const std::string& user_id() const { return user_id_; }
100 // ID of user which images are managed by current instance of
101 // UserImageManager.
102 const std::string user_id_;
105 } // namespace chromeos
107 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_USER_IMAGE_MANAGER_H_