| 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 #include "chrome/browser/chromeos/login/screens/user_image_screen.h" | 5 #include "chrome/browser/chromeos/login/screens/user_image_screen.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 UserImageScreen::UserImageScreen(BaseScreenDelegate* base_screen_delegate, | 66 UserImageScreen::UserImageScreen(BaseScreenDelegate* base_screen_delegate, |
| 67 UserImageView* view) | 67 UserImageView* view) |
| 68 : UserImageModel(base_screen_delegate), | 68 : UserImageModel(base_screen_delegate), |
| 69 view_(view), | 69 view_(view), |
| 70 accept_photo_after_decoding_(false), | 70 accept_photo_after_decoding_(false), |
| 71 selected_image_(user_manager::User::USER_IMAGE_INVALID), | 71 selected_image_(user_manager::User::USER_IMAGE_INVALID), |
| 72 is_screen_ready_(false), | 72 is_screen_ready_(false), |
| 73 user_has_selected_image_(false) { | 73 user_has_selected_image_(false) { |
| 74 if (view_) | 74 if (view_) |
| 75 view_->Bind(*this); | 75 view_->Bind(*this); |
| 76 notification_registrar_.Add(this, | 76 user_manager::UserManager::Get()->AddObserver(this); |
| 77 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED, | |
| 78 content::NotificationService::AllSources()); | |
| 79 notification_registrar_.Add(this, | |
| 80 chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED, | |
| 81 content::NotificationService::AllSources()); | |
| 82 notification_registrar_.Add(this, | |
| 83 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, | |
| 84 content::NotificationService::AllSources()); | |
| 85 GetContextEditor().SetString(kContextKeyProfilePictureDataURL, std::string()); | 77 GetContextEditor().SetString(kContextKeyProfilePictureDataURL, std::string()); |
| 86 } | 78 } |
| 87 | 79 |
| 88 UserImageScreen::~UserImageScreen() { | 80 UserImageScreen::~UserImageScreen() { |
| 81 user_manager::UserManager::Get()->RemoveObserver(this); |
| 89 CameraPresenceNotifier::GetInstance()->RemoveObserver(this); | 82 CameraPresenceNotifier::GetInstance()->RemoveObserver(this); |
| 90 if (view_) | 83 if (view_) |
| 91 view_->Unbind(); | 84 view_->Unbind(); |
| 92 } | 85 } |
| 93 | 86 |
| 94 void UserImageScreen::OnScreenReady() { | 87 void UserImageScreen::OnScreenReady() { |
| 95 is_screen_ready_ = true; | 88 is_screen_ready_ = true; |
| 96 if (!IsWaitingForSync()) | 89 if (!IsWaitingForSync()) |
| 97 HideCurtain(); | 90 HideCurtain(); |
| 98 } | 91 } |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 GetContextEditor().SetString( | 279 GetContextEditor().SetString( |
| 287 kContextKeySelectedImageURL, | 280 kContextKeySelectedImageURL, |
| 288 default_user_image::GetDefaultImageUrl(selected_image_)); | 281 default_user_image::GetDefaultImageUrl(selected_image_)); |
| 289 | 282 |
| 290 // Start fetching the profile image. | 283 // Start fetching the profile image. |
| 291 GetUserImageManager()->DownloadProfileImage(kProfileDownloadReason); | 284 GetUserImageManager()->DownloadProfileImage(kProfileDownloadReason); |
| 292 } | 285 } |
| 293 | 286 |
| 294 void UserImageScreen::Hide() { | 287 void UserImageScreen::Hide() { |
| 295 CameraPresenceNotifier::GetInstance()->RemoveObserver(this); | 288 CameraPresenceNotifier::GetInstance()->RemoveObserver(this); |
| 296 notification_registrar_.RemoveAll(); | 289 user_manager::UserManager::Get()->RemoveObserver(this); |
| 297 policy_registrar_.reset(); | 290 policy_registrar_.reset(); |
| 298 sync_timer_.reset(); | 291 sync_timer_.reset(); |
| 299 if (UserImageSyncObserver* sync_observer = GetSyncObserver()) | 292 if (UserImageSyncObserver* sync_observer = GetSyncObserver()) |
| 300 sync_observer->RemoveObserver(this); | 293 sync_observer->RemoveObserver(this); |
| 301 if (view_) | 294 if (view_) |
| 302 view_->Hide(); | 295 view_->Hide(); |
| 303 } | 296 } |
| 304 | 297 |
| 305 void UserImageScreen::OnViewDestroyed(UserImageView* view) { | 298 void UserImageScreen::OnViewDestroyed(UserImageView* view) { |
| 306 if (view_ == view) | 299 if (view_ == view) |
| 307 view_ = nullptr; | 300 view_ = nullptr; |
| 308 } | 301 } |
| 309 | 302 |
| 310 void UserImageScreen::Observe(int type, | 303 void UserImageScreen::OnUserImageChanged(const user_manager::User& user) { |
| 311 const content::NotificationSource& source, | 304 GetContextEditor().SetString( |
| 312 const content::NotificationDetails& details) { | 305 kContextKeySelectedImageURL, |
| 313 switch (type) { | 306 default_user_image::GetDefaultImageUrl(GetUser()->image_index())); |
| 314 case chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED: { | 307 } |
| 315 // We've got a new profile image. | 308 |
| 316 GetContextEditor().SetString( | 309 void UserImageScreen::OnUserProfileImageUpdateFailed( |
| 317 kContextKeyProfilePictureDataURL, | 310 const user_manager::User& user) { |
| 318 webui::GetBitmapDataUrl( | 311 // User has a default profile image or fetching profile image has failed. |
| 319 *content::Details<const gfx::ImageSkia>(details) | 312 GetContextEditor().SetString(kContextKeyProfilePictureDataURL, std::string()); |
| 320 .ptr() | 313 } |
| 321 ->bitmap())); | 314 |
| 322 break; | 315 void UserImageScreen::OnUserProfileImageUpdated( |
| 323 } | 316 const user_manager::User& user, |
| 324 case chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED: { | 317 const gfx::ImageSkia& profile_image) { |
| 325 // User has a default profile image or fetching profile image has failed. | 318 // We've got a new profile image. |
| 326 GetContextEditor().SetString(kContextKeyProfilePictureDataURL, | 319 GetContextEditor().SetString( |
| 327 std::string()); | 320 kContextKeyProfilePictureDataURL, |
| 328 break; | 321 webui::GetBitmapDataUrl(*profile_image.bitmap())); |
| 329 } | |
| 330 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: { | |
| 331 GetContextEditor().SetString( | |
| 332 kContextKeySelectedImageURL, | |
| 333 default_user_image::GetDefaultImageUrl(GetUser()->image_index())); | |
| 334 break; | |
| 335 } | |
| 336 default: | |
| 337 NOTREACHED(); | |
| 338 } | |
| 339 } | 322 } |
| 340 | 323 |
| 341 void UserImageScreen::ExitScreen() { | 324 void UserImageScreen::ExitScreen() { |
| 342 policy_registrar_.reset(); | 325 policy_registrar_.reset(); |
| 343 sync_timer_.reset(); | 326 sync_timer_.reset(); |
| 344 if (UserImageSyncObserver* sync_observer = GetSyncObserver()) | 327 if (UserImageSyncObserver* sync_observer = GetSyncObserver()) |
| 345 sync_observer->RemoveObserver(this); | 328 sync_observer->RemoveObserver(this); |
| 346 Finish(BaseScreenDelegate::USER_IMAGE_SELECTED); | 329 Finish(BaseScreenDelegate::USER_IMAGE_SELECTED); |
| 347 } | 330 } |
| 348 | 331 |
| 349 void UserImageScreen::ReportSyncResult(SyncResult timed_out) const { | 332 void UserImageScreen::ReportSyncResult(SyncResult timed_out) const { |
| 350 base::TimeDelta duration = base::Time::Now() - sync_waiting_start_time_; | 333 base::TimeDelta duration = base::Time::Now() - sync_waiting_start_time_; |
| 351 UMA_HISTOGRAM_TIMES("Login.NewUserPriorityPrefsSyncTime", duration); | 334 UMA_HISTOGRAM_TIMES("Login.NewUserPriorityPrefsSyncTime", duration); |
| 352 UMA_HISTOGRAM_ENUMERATION("Login.NewUserPriorityPrefsSyncResult", | 335 UMA_HISTOGRAM_ENUMERATION("Login.NewUserPriorityPrefsSyncResult", |
| 353 static_cast<int>(timed_out), | 336 static_cast<int>(timed_out), |
| 354 static_cast<int>(SyncResult::COUNT)); | 337 static_cast<int>(SyncResult::COUNT)); |
| 355 } | 338 } |
| 356 | 339 |
| 357 } // namespace chromeos | 340 } // namespace chromeos |
| OLD | NEW |