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_SCREENS_USER_IMAGE_SCREEN_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_USER_IMAGE_SCREEN_H_ 7 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" 18 19 namespace base { 20 class Timer; 21 class Value; 22 }; 23 24 namespace policy { 25 class PolicyChangeRegistrar; 26 } 27 28 namespace chromeos { 29 30 class UserImageManager; 31 class ScreenManager; 32 33 class UserImageScreen: public WizardScreen, 34 public UserImageScreenActor::Delegate, 35 public ImageDecoder::Delegate, 36 public content::NotificationObserver, 37 public UserImageSyncObserver::Observer, 38 public CameraPresenceNotifier::Observer { 39 public: 40 UserImageScreen(ScreenObserver* screen_observer, 41 UserImageScreenActor* actor); 42 virtual ~UserImageScreen(); 43 44 static UserImageScreen* Get(ScreenManager* manager); 45 46 // WizardScreen implementation: 47 virtual void PrepareToShow() OVERRIDE; 48 virtual void Show() OVERRIDE; 49 virtual void Hide() OVERRIDE; 50 virtual std::string GetName() const OVERRIDE; 51 52 // UserImageScreenActor::Delegate implementation: 53 virtual void OnScreenReady() OVERRIDE; 54 virtual void OnPhotoTaken(const std::string& raw_data) 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; 60 61 virtual bool profile_picture_absent() OVERRIDE; 62 virtual int selected_image() OVERRIDE; 63 virtual std::string profile_picture_data_url() OVERRIDE; 64 65 // content::NotificationObserver implementation: 66 virtual void Observe(int type, 67 const content::NotificationSource& source, 68 const content::NotificationDetails& details) OVERRIDE; 69 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; 74 75 // CameraPresenceNotifier::Observer implementation: 76 virtual void OnCameraPresenceCheckDone(bool is_camera_present) OVERRIDE; 77 78 // UserImageSyncObserver::Observer implementation: 79 virtual void OnInitialSync(bool local_image_updated) OVERRIDE; 80 user_selected_image()81 bool user_selected_image() const { return user_has_selected_image_; } 82 83 private: 84 // Called when whaiting for sync timed out. 85 void OnSyncTimeout(); 86 87 bool IsWaitingForSync() const; 88 89 // Called when the policy::key::kUserAvatarImage policy changes while the 90 // screen is being shown. If the policy is set, closes the screen because the 91 // user is not allowed to override a policy-set image. 92 void OnUserImagePolicyChanged(const base::Value* previous, 93 const base::Value* current); 94 95 // Returns current user. 96 const user_manager::User* GetUser(); 97 98 // Returns UserImageManager for the current user. 99 UserImageManager* GetUserImageManager(); 100 101 // Returns UserImageSyncObserver for the current user. 102 UserImageSyncObserver* GetSyncObserver(); 103 104 // Called when it's decided not to skip the screen. 105 void HideCurtain(); 106 107 // Closes the screen. 108 void ExitScreen(); 109 110 content::NotificationRegistrar notification_registrar_; 111 112 scoped_ptr<policy::PolicyChangeRegistrar> policy_registrar_; 113 114 UserImageScreenActor* actor_; 115 116 // Last ImageDecoder instance used to decode an image blob received by 117 // HandlePhotoTaken. 118 scoped_refptr<ImageDecoder> image_decoder_; 119 120 // Last user photo, if taken. 121 gfx::ImageSkia user_photo_; 122 123 // If |true|, decoded photo should be immediately accepeted (i.e., both 124 // HandleTakePhoto and HandleImageAccepted have already been called but we're 125 // still waiting for photo image decoding to finish. 126 bool accept_photo_after_decoding_; 127 128 // Index of the selected user image. 129 int selected_image_; 130 131 // Encoded profile picture. 132 std::string profile_picture_data_url_; 133 134 // True if user has no custom profile picture. 135 bool profile_picture_absent_; 136 137 // Timer used for waiting for user image sync. 138 scoped_ptr<base::Timer> sync_timer_; 139 140 // If screen ready to be shown. 141 bool is_screen_ready_; 142 143 // True if user has explicitly selected some image. 144 bool user_has_selected_image_; 145 146 DISALLOW_COPY_AND_ASSIGN(UserImageScreen); 147 }; 148 149 } // namespace chromeos 150 151 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_USER_IMAGE_SCREEN_H_ 152