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_SCREENS_USER_IMAGE_SCREEN_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_USER_IMAGE_SCREEN_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/chromeos/login/screens/user_image_screen_actor.h"
11 #include "chrome/browser/chromeos/login/screens/wizard_screen.h"
12 #include "chrome/browser/chromeos/login/user.h"
13 #include "chrome/browser/chromeos/login/user_image_sync_observer.h"
14 #include "chrome/browser/image_decoder.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
24 class PolicyChangeRegistrar;
29 class UserImageScreen: public WizardScreen,
30 public UserImageScreenActor::Delegate,
31 public ImageDecoder::Delegate,
32 public content::NotificationObserver,
33 public UserImageSyncObserver::Observer {
35 UserImageScreen(ScreenObserver* screen_observer,
36 UserImageScreenActor* actor);
37 virtual ~UserImageScreen();
39 // Indicates whether profile picture is enabled for given user.
40 void SetProfilePictureEnabled(bool support_profile_picture);
41 // Sets |user_id| of user that would have picture updated.
42 void SetUserID(const std::string& user_id);
44 // WizardScreen implementation:
45 virtual void PrepareToShow() OVERRIDE;
46 virtual void Show() OVERRIDE;
47 virtual void Hide() OVERRIDE;
48 virtual std::string GetName() const OVERRIDE;
50 // UserImageScreenActor::Delegate implementation:
51 virtual void OnScreenReady() OVERRIDE;
52 virtual void OnPhotoTaken(const std::string& raw_data) OVERRIDE;
53 virtual void OnImageSelected(const std::string& image_url,
54 const std::string& image_type,
55 bool is_user_selection) OVERRIDE;
56 virtual void OnImageAccepted() OVERRIDE;
57 virtual void OnActorDestroyed(UserImageScreenActor* actor) OVERRIDE;
59 virtual bool profile_picture_absent() OVERRIDE;
60 virtual int selected_image() OVERRIDE;
61 virtual std::string profile_picture_data_url() OVERRIDE;
63 // content::NotificationObserver implementation:
64 virtual void Observe(int type,
65 const content::NotificationSource& source,
66 const content::NotificationDetails& details) OVERRIDE;
68 // ImageDecoder::Delegate implementation:
69 virtual void OnImageDecoded(const ImageDecoder* decoder,
70 const SkBitmap& decoded_image) OVERRIDE;
71 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE;
72 virtual void OnCameraPresenceCheckDone(bool is_camera_present) OVERRIDE;
74 // UserImageSyncObserver::Observer implementation:
75 virtual void OnInitialSync(bool local_image_updated) OVERRIDE;
77 bool user_selected_image() const { return user_has_selected_image_; }
80 // Called when whaiting for sync timed out.
83 bool IsWaitingForSync() const;
85 // Called when the policy::key::kUserAvatarImage policy changes while the
86 // screen is being shown. If the policy is set, closes the screen because the
87 // user is not allowed to override a policy-set image.
88 void OnUserImagePolicyChanged(const base::Value* previous,
89 const base::Value* current);
91 // Returns current user.
92 const User* GetUser();
94 // Returns UserImageManager for the current user.
95 UserImageManager* GetUserImageManager();
97 // Returns UserImageSyncObserver for the current user.
98 UserImageSyncObserver* GetSyncObserver();
100 // Called when it's decided not to skip the screen.
103 // Closes the screen.
106 content::NotificationRegistrar notification_registrar_;
108 scoped_ptr<policy::PolicyChangeRegistrar> policy_registrar_;
110 UserImageScreenActor* actor_;
112 // Last ImageDecoder instance used to decode an image blob received by
114 scoped_refptr<ImageDecoder> image_decoder_;
116 // Last user photo, if taken.
117 gfx::ImageSkia user_photo_;
119 // If |true|, decoded photo should be immediately accepeted (i.e., both
120 // HandleTakePhoto and HandleImageAccepted have already been called but we're
121 // still waiting for photo image decoding to finish.
122 bool accept_photo_after_decoding_;
124 // Index of the selected user image.
127 bool profile_picture_enabled_;
129 // Encoded profile picture.
130 std::string profile_picture_data_url_;
132 // True if user has no custom profile picture.
133 bool profile_picture_absent_;
135 std::string user_id_;
137 // Timer used for waiting for user image sync.
138 scoped_ptr<base::Timer> sync_timer_;
140 // If screen ready to be shown.
141 bool is_screen_ready_;
143 // True if user has explicitly selected some image.
144 bool user_has_selected_image_;
146 DISALLOW_COPY_AND_ASSIGN(UserImageScreen);
149 } // namespace chromeos
151 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_USER_IMAGE_SCREEN_H_