Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_USER_IMAGE_SCREEN_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_USER_IMAGE_SCREEN_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_USER_IMAGE_SCREEN_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_USER_IMAGE_SCREEN_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "chrome/browser/chromeos/camera_presence_notifier.h" | 13 #include "chrome/browser/chromeos/camera_presence_notifier.h" |
| 14 #include "chrome/browser/chromeos/login/screens/base_screen.h" | 14 #include "chrome/browser/chromeos/login/screens/base_screen.h" |
| 15 #include "chrome/browser/chromeos/login/screens/user_image_model.h" | |
| 16 #include "chrome/browser/chromeos/login/users/avatar/user_image_sync_observer.h" | 15 #include "chrome/browser/chromeos/login/users/avatar/user_image_sync_observer.h" |
| 17 #include "chrome/browser/image_decoder.h" | 16 #include "chrome/browser/image_decoder.h" |
| 18 #include "components/user_manager/user.h" | 17 #include "components/user_manager/user.h" |
| 19 #include "components/user_manager/user_manager.h" | 18 #include "components/user_manager/user_manager.h" |
| 20 | 19 |
| 21 namespace base { | 20 namespace base { |
| 22 class Timer; | 21 class Timer; |
| 23 class Value; | 22 class Value; |
| 24 } | 23 } |
| 25 | 24 |
| 26 namespace policy { | 25 namespace policy { |
| 27 class PolicyChangeRegistrar; | 26 class PolicyChangeRegistrar; |
| 28 } | 27 } |
| 29 | 28 |
| 30 namespace chromeos { | 29 namespace chromeos { |
| 31 | 30 |
| 32 class ScreenManager; | 31 class ScreenManager; |
| 33 class UserImageManager; | 32 class UserImageManager; |
| 34 class UserImageView; | 33 class UserImageView; |
| 35 | 34 |
| 36 class UserImageScreen : public UserImageModel, | 35 class UserImageScreen : public BaseScreen, |
| 36 public CameraPresenceNotifier::Observer, | |
| 37 public ImageDecoder::ImageRequest, | 37 public ImageDecoder::ImageRequest, |
| 38 public user_manager::UserManager::Observer, | 38 public user_manager::UserManager::Observer, |
| 39 public UserImageSyncObserver::Observer, | 39 public UserImageSyncObserver::Observer { |
| 40 public CameraPresenceNotifier::Observer { | |
| 41 public: | 40 public: |
| 41 static UserImageScreen* Get(ScreenManager* manager); | |
| 42 | |
| 42 UserImageScreen(BaseScreenDelegate* base_screen_delegate, | 43 UserImageScreen(BaseScreenDelegate* base_screen_delegate, |
| 43 UserImageView* view); | 44 UserImageView* view); |
| 44 ~UserImageScreen() override; | 45 ~UserImageScreen() override; |
| 45 | 46 |
| 46 static UserImageScreen* Get(ScreenManager* manager); | 47 // Called when the UI ready to be shown. |
| 48 void OnScreenReady(); | |
| 47 | 49 |
| 48 // BaseScreen implementation: | 50 // Called when the user accepts a photo as their login user image. |
| 49 void Show() override; | 51 void OnPhotoTaken(const std::string& raw_data); |
| 50 void Hide() override; | |
| 51 | 52 |
| 52 // UserImageScreenActor::Delegate implementation: | 53 // Called when some image was selected. |is_user_selection| indicates if |
| 53 void OnScreenReady() override; | 54 // it was user selection or image was selected programmatically. |
| 54 void OnPhotoTaken(const std::string& raw_data) override; | |
| 55 void OnImageSelected(const std::string& image_url, | 55 void OnImageSelected(const std::string& image_url, |
| 56 const std::string& image_type, | 56 const std::string& image_type, |
| 57 bool is_user_selection) override; | 57 bool is_user_selection); |
| 58 void OnImageAccepted() override; | |
| 59 void OnViewDestroyed(UserImageView* view) override; | |
| 60 | 58 |
| 61 // user_manager::UserManager::Observer implementation: | 59 // Called when user accepts currently selected image |
|
achuithb
2017/02/08 20:05:56
nit period
jdufault
2017/02/10 20:32:23
Done.
| |
| 62 void OnUserImageChanged(const user_manager::User& user) override; | 60 void OnImageAccepted(); |
| 63 void OnUserProfileImageUpdateFailed(const user_manager::User& user) override; | |
| 64 void OnUserProfileImageUpdated(const user_manager::User& user, | |
| 65 const gfx::ImageSkia& profile_image) override; | |
| 66 | 61 |
| 67 // ImageDecoder::ImageRequest implementation: | 62 // Called when actor is destroyed so there's no dead reference to it. |
|
achuithb
2017/02/08 20:05:56
Don't use 'actor' here?
jdufault
2017/02/10 20:32:23
Done.
| |
| 68 void OnImageDecoded(const SkBitmap& decoded_image) override; | 63 void OnViewDestroyed(UserImageView* view); |
| 69 void OnDecodeImageFailed() override; | |
| 70 | |
| 71 // CameraPresenceNotifier::Observer implementation: | |
| 72 void OnCameraPresenceCheckDone(bool is_camera_present) override; | |
| 73 | |
| 74 // UserImageSyncObserver::Observer implementation: | |
| 75 void OnInitialSync(bool local_image_updated) override; | |
| 76 | 64 |
| 77 bool user_selected_image() const { return user_has_selected_image_; } | 65 bool user_selected_image() const { return user_has_selected_image_; } |
| 78 | 66 |
| 79 private: | 67 private: |
| 80 // Must be kept synced with |NewUserPriorityPrefsSyncResult| enum from | 68 // Must be kept synced with |NewUserPriorityPrefsSyncResult| enum from |
| 81 // histograms.xml. | 69 // histograms.xml. |
| 82 enum class SyncResult { | 70 enum class SyncResult { |
| 83 SUCCEEDED, | 71 SUCCEEDED, |
| 84 TIMED_OUT, | 72 TIMED_OUT, |
| 85 // Keeps a number of different sync results. Should be the last in the list. | 73 // Keeps a number of different sync results. Should be the last in the list. |
| 86 COUNT | 74 COUNT |
| 87 }; | 75 }; |
| 88 | 76 |
| 77 // BaseScreen implementation: | |
| 78 void Show() override; | |
| 79 void Hide() override; | |
| 80 | |
| 81 // CameraPresenceNotifier::Observer implementation: | |
| 82 void OnCameraPresenceCheckDone(bool is_camera_present) override; | |
| 83 | |
| 84 // ImageDecoder::ImageRequest implementation: | |
| 85 void OnImageDecoded(const SkBitmap& decoded_image) override; | |
| 86 void OnDecodeImageFailed() override; | |
| 87 | |
| 88 // user_manager::UserManager::Observer implementation: | |
| 89 void OnUserImageChanged(const user_manager::User& user) override; | |
| 90 void OnUserProfileImageUpdateFailed(const user_manager::User& user) override; | |
| 91 void OnUserProfileImageUpdated(const user_manager::User& user, | |
| 92 const gfx::ImageSkia& profile_image) override; | |
| 93 | |
| 94 // UserImageSyncObserver::Observer implementation: | |
| 95 void OnInitialSync(bool local_image_updated) override; | |
| 96 | |
| 89 // Called when whaiting for sync timed out. | 97 // Called when whaiting for sync timed out. |
| 90 void OnSyncTimeout(); | 98 void OnSyncTimeout(); |
| 91 | 99 |
| 92 bool IsWaitingForSync() const; | 100 bool IsWaitingForSync() const; |
| 93 | 101 |
| 94 // Called when the policy::key::kUserAvatarImage policy changes while the | 102 // Called when the policy::key::kUserAvatarImage policy changes while the |
| 95 // screen is being shown. If the policy is set, closes the screen because the | 103 // screen is being shown. If the policy is set, closes the screen because the |
| 96 // user is not allowed to override a policy-set image. | 104 // user is not allowed to override a policy-set image. |
| 97 void OnUserImagePolicyChanged(const base::Value* previous, | 105 void OnUserImagePolicyChanged(const base::Value* previous, |
| 98 const base::Value* current); | 106 const base::Value* current); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 110 void HideCurtain(); | 118 void HideCurtain(); |
| 111 | 119 |
| 112 // Closes the screen. | 120 // Closes the screen. |
| 113 void ExitScreen(); | 121 void ExitScreen(); |
| 114 | 122 |
| 115 // Reports sync duration and result to UMA. | 123 // Reports sync duration and result to UMA. |
| 116 void ReportSyncResult(SyncResult timed_out) const; | 124 void ReportSyncResult(SyncResult timed_out) const; |
| 117 | 125 |
| 118 std::unique_ptr<policy::PolicyChangeRegistrar> policy_registrar_; | 126 std::unique_ptr<policy::PolicyChangeRegistrar> policy_registrar_; |
| 119 | 127 |
| 120 UserImageView* view_; | 128 UserImageView* view_ = nullptr; |
| 121 | 129 |
| 122 // Last user photo, if taken. | 130 // Last user photo, if taken. |
| 123 gfx::ImageSkia user_photo_; | 131 gfx::ImageSkia user_photo_; |
| 124 | 132 |
| 125 // If |true|, decoded photo should be immediately accepted (i.e., both | 133 // If |true|, decoded photo should be immediately accepted (i.e., both |
| 126 // HandleTakePhoto and HandleImageAccepted have already been called but we're | 134 // HandleTakePhoto and HandleImageAccepted have already been called but we're |
| 127 // still waiting for photo image decoding to finish. | 135 // still waiting for photo image decoding to finish. |
| 128 bool accept_photo_after_decoding_; | 136 bool accept_photo_after_decoding_ = false; |
| 129 | 137 |
| 130 // Index of the selected user image. | 138 // Index of the selected user image. |
| 131 int selected_image_; | 139 int selected_image_ = user_manager::User::USER_IMAGE_INVALID; |
| 132 | 140 |
| 133 // Timer used for waiting for user image sync. | 141 // Timer used for waiting for user image sync. |
| 134 std::unique_ptr<base::Timer> sync_timer_; | 142 std::unique_ptr<base::Timer> sync_timer_; |
|
achuithb
2017/02/08 20:05:56
Move this to next to sync_waiting_start_time_?
jdufault
2017/02/10 20:32:23
Done.
| |
| 135 | 143 |
| 136 // If screen ready to be shown. | 144 // If screen ready to be shown. |
| 137 bool is_screen_ready_; | 145 bool is_screen_ready_ = false; |
| 138 | 146 |
| 139 // True if user has explicitly selected some image. | 147 // True if user has explicitly selected some image. |
| 140 bool user_has_selected_image_; | 148 bool user_has_selected_image_ = false; |
| 141 | 149 |
| 142 // The time when we started wait for user image sync. | 150 // The time when we started wait for user image sync. |
| 143 base::Time sync_waiting_start_time_; | 151 base::Time sync_waiting_start_time_; |
| 144 | 152 |
| 145 DISALLOW_COPY_AND_ASSIGN(UserImageScreen); | 153 DISALLOW_COPY_AND_ASSIGN(UserImageScreen); |
| 146 }; | 154 }; |
| 147 | 155 |
| 148 } // namespace chromeos | 156 } // namespace chromeos |
| 149 | 157 |
| 150 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_USER_IMAGE_SCREEN_H_ | 158 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_USER_IMAGE_SCREEN_H_ |
| OLD | NEW |