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/camera_presence_notifier.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/users/avatar/user_image_sync_observer.h"
14 #include "chrome/browser/image_decoder.h"
15 #include "components/user_manager/user.h"
16 #include "content/public/browser/notification_observer.h"
17 #include "content/public/browser/notification_registrar.h"
25 class PolicyChangeRegistrar;
30 class UserImageManager;
32 class UserImageScreen: public WizardScreen,
33 public UserImageScreenActor::Delegate,
34 public ImageDecoder::Delegate,
35 public content::NotificationObserver,
36 public UserImageSyncObserver::Observer,
37 public CameraPresenceNotifier::Observer {
39 UserImageScreen(ScreenObserver* screen_observer,
40 UserImageScreenActor* actor);
41 virtual ~UserImageScreen();
43 // WizardScreen implementation:
44 virtual void PrepareToShow() OVERRIDE;
45 virtual void Show() OVERRIDE;
46 virtual void Hide() OVERRIDE;
47 virtual std::string GetName() const OVERRIDE;
49 // UserImageScreenActor::Delegate implementation:
50 virtual void OnScreenReady() OVERRIDE;
51 virtual void OnPhotoTaken(const std::string& raw_data) OVERRIDE;
52 virtual void OnImageSelected(const std::string& image_url,
53 const std::string& image_type,
54 bool is_user_selection) OVERRIDE;
55 virtual void OnImageAccepted() OVERRIDE;
56 virtual void OnActorDestroyed(UserImageScreenActor* actor) OVERRIDE;
58 virtual bool profile_picture_absent() OVERRIDE;
59 virtual int selected_image() OVERRIDE;
60 virtual std::string profile_picture_data_url() OVERRIDE;
62 // content::NotificationObserver implementation:
63 virtual void Observe(int type,
64 const content::NotificationSource& source,
65 const content::NotificationDetails& details) OVERRIDE;
67 // ImageDecoder::Delegate implementation:
68 virtual void OnImageDecoded(const ImageDecoder* decoder,
69 const SkBitmap& decoded_image) OVERRIDE;
70 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE;
72 // CameraPresenceNotifier::Observer implementation:
73 virtual void OnCameraPresenceCheckDone(bool is_camera_present) 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_; }
81 // Called when whaiting for sync timed out.
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_manager::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 it's decided not to skip the screen.
104 // Closes the screen.
107 content::NotificationRegistrar notification_registrar_;
109 scoped_ptr<policy::PolicyChangeRegistrar> policy_registrar_;
111 UserImageScreenActor* actor_;
113 // Last ImageDecoder instance used to decode an image blob received by
115 scoped_refptr<ImageDecoder> image_decoder_;
117 // Last user photo, if taken.
118 gfx::ImageSkia user_photo_;
120 // If |true|, decoded photo should be immediately accepeted (i.e., both
121 // HandleTakePhoto and HandleImageAccepted have already been called but we're
122 // still waiting for photo image decoding to finish.
123 bool accept_photo_after_decoding_;
125 // Index of the selected user image.
128 // Encoded profile picture.
129 std::string profile_picture_data_url_;
131 // True if user has no custom profile picture.
132 bool profile_picture_absent_;
134 // Timer used for waiting for user image sync.
135 scoped_ptr<base::Timer> sync_timer_;
137 // If screen ready to be shown.
138 bool is_screen_ready_;
140 // True if user has explicitly selected some image.
141 bool user_has_selected_image_;
143 DISALLOW_COPY_AND_ASSIGN(UserImageScreen);
146 } // namespace chromeos
148 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_USER_IMAGE_SCREEN_H_