Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / screens / user_image_screen.h
blob884071974004cbdf7a751b1a0447d3bf35fa38b8
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 "base/memory/weak_ptr.h"
11 #include "chrome/browser/chromeos/login/screens/user_image_screen_actor.h"
12 #include "chrome/browser/chromeos/login/screens/wizard_screen.h"
13 #include "chrome/browser/chromeos/login/user.h"
14 #include "chrome/browser/chromeos/login/user_image_sync_observer.h"
15 #include "chrome/browser/image_decoder.h"
16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h"
19 namespace base {
20 class Timer;
21 class Value;
24 namespace policy {
25 class PolicyChangeRegistrar;
28 namespace chromeos {
30 class UserImageScreen: public WizardScreen,
31 public UserImageScreenActor::Delegate,
32 public ImageDecoder::Delegate,
33 public content::NotificationObserver,
34 public UserImageSyncObserver::Observer {
35 public:
36 UserImageScreen(ScreenObserver* screen_observer,
37 UserImageScreenActor* actor);
38 virtual ~UserImageScreen();
40 // Indicates whether profile picture is enabled for given user.
41 void SetProfilePictureEnabled(bool support_profile_picture);
42 // Sets |user_id| of user that would have picture updated.
43 void SetUserID(const std::string& user_id);
45 // WizardScreen implementation:
46 virtual void PrepareToShow() OVERRIDE;
47 virtual void Show() OVERRIDE;
48 virtual void Hide() OVERRIDE;
49 virtual std::string GetName() const OVERRIDE;
51 // UserImageScreenActor::Delegate implementation:
52 virtual void OnScreenReady() OVERRIDE;
53 virtual void OnPhotoTaken(const std::string& raw_data) OVERRIDE;
54 virtual void CheckCameraPresence() OVERRIDE;
55 virtual void OnImageSelected(const std::string& image_url,
56 const std::string& image_type,
57 bool is_user_selection) OVERRIDE;
58 virtual void OnImageAccepted() OVERRIDE;
59 virtual void OnActorDestroyed(UserImageScreenActor* actor) OVERRIDE;
61 virtual bool profile_picture_absent() OVERRIDE;
62 virtual int selected_image() OVERRIDE;
63 virtual std::string profile_picture_data_url() OVERRIDE;
65 // content::NotificationObserver implementation:
66 virtual void Observe(int type,
67 const content::NotificationSource& source,
68 const content::NotificationDetails& details) OVERRIDE;
70 // ImageDecoder::Delegate implementation:
71 virtual void OnImageDecoded(const ImageDecoder* decoder,
72 const SkBitmap& decoded_image) OVERRIDE;
73 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE;
75 // UserImageSyncObserver::Observer implementation:
76 virtual void OnInitialSync(bool local_image_updated) OVERRIDE;
78 bool user_selected_image() const { return user_has_selected_image_; }
80 private:
81 // Called when whaiting for sync timed out.
82 void OnSyncTimeout();
84 bool IsWaitingForSync() const;
86 // Called when the policy::key::kUserAvatarImage policy changes while the
87 // screen is being shown. If the policy is set, closes the screen because the
88 // user is not allowed to override a policy-set image.
89 void OnUserImagePolicyChanged(const base::Value* previous,
90 const base::Value* current);
92 // Returns current user.
93 const User* GetUser();
95 // Returns UserImageManager for the current user.
96 UserImageManager* GetUserImageManager();
98 // Returns UserImageSyncObserver for the current user.
99 UserImageSyncObserver* GetSyncObserver();
101 // Called when the camera presence check has been completed.
102 void OnCameraPresenceCheckDone();
104 // Called when it's decided not to skip the screen.
105 void HideCurtain();
107 // Closes the screen.
108 void ExitScreen();
110 content::NotificationRegistrar notification_registrar_;
112 scoped_ptr<policy::PolicyChangeRegistrar> policy_registrar_;
114 UserImageScreenActor* actor_;
116 base::WeakPtrFactory<UserImageScreen> weak_factory_;
118 // Last ImageDecoder instance used to decode an image blob received by
119 // HandlePhotoTaken.
120 scoped_refptr<ImageDecoder> image_decoder_;
122 // Last user photo, if taken.
123 gfx::ImageSkia user_photo_;
125 // If |true|, decoded photo should be immediately accepeted (i.e., both
126 // HandleTakePhoto and HandleImageAccepted have already been called but we're
127 // still waiting for photo image decoding to finish.
128 bool accept_photo_after_decoding_;
130 // Index of the selected user image.
131 int selected_image_;
133 bool profile_picture_enabled_;
135 // Encoded profile picture.
136 std::string profile_picture_data_url_;
138 // True if user has no custom profile picture.
139 bool profile_picture_absent_;
141 std::string user_id_;
143 // Timer used for waiting for user image sync.
144 scoped_ptr<base::Timer> sync_timer_;
146 // If screen ready to be shown.
147 bool is_screen_ready_;
149 // True if user has explicitly selected some image.
150 bool user_has_selected_image_;
152 // True if camera was available last time.
153 bool was_camera_present_;
155 DISALLOW_COPY_AND_ASSIGN(UserImageScreen);
158 } // namespace chromeos
160 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_USER_IMAGE_SCREEN_H_