| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/ui/webui/options/chromeos/change_picture_options_handle
r.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/change_picture_options_handle
r.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 75 } |
| 76 | 76 |
| 77 // Time histogram suffix for profile image download. | 77 // Time histogram suffix for profile image download. |
| 78 const char kProfileDownloadReason[] = "Preferences"; | 78 const char kProfileDownloadReason[] = "Preferences"; |
| 79 | 79 |
| 80 } // namespace | 80 } // namespace |
| 81 | 81 |
| 82 ChangePictureOptionsHandler::ChangePictureOptionsHandler() | 82 ChangePictureOptionsHandler::ChangePictureOptionsHandler() |
| 83 : previous_image_url_(url::kAboutBlankURL), | 83 : previous_image_url_(url::kAboutBlankURL), |
| 84 previous_image_index_(user_manager::User::USER_IMAGE_INVALID) { | 84 previous_image_index_(user_manager::User::USER_IMAGE_INVALID) { |
| 85 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED, | 85 user_manager::UserManager::Get()->AddObserver(this); |
| 86 content::NotificationService::AllSources()); | |
| 87 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_IMAGE_UPDATE_FAILED, | |
| 88 content::NotificationService::AllSources()); | |
| 89 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, | |
| 90 content::NotificationService::AllSources()); | |
| 91 | 86 |
| 92 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 87 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 93 media::SoundsManager* manager = media::SoundsManager::Get(); | 88 media::SoundsManager* manager = media::SoundsManager::Get(); |
| 94 manager->Initialize(SOUND_OBJECT_DELETE, | 89 manager->Initialize(SOUND_OBJECT_DELETE, |
| 95 bundle.GetRawDataResource(IDR_SOUND_OBJECT_DELETE_WAV)); | 90 bundle.GetRawDataResource(IDR_SOUND_OBJECT_DELETE_WAV)); |
| 96 manager->Initialize(SOUND_CAMERA_SNAP, | 91 manager->Initialize(SOUND_CAMERA_SNAP, |
| 97 bundle.GetRawDataResource(IDR_SOUND_CAMERA_SNAP_WAV)); | 92 bundle.GetRawDataResource(IDR_SOUND_CAMERA_SNAP_WAV)); |
| 98 } | 93 } |
| 99 | 94 |
| 100 ChangePictureOptionsHandler::~ChangePictureOptionsHandler() { | 95 ChangePictureOptionsHandler::~ChangePictureOptionsHandler() { |
| 96 user_manager::UserManager::Get()->RemoveObserver(this); |
| 101 CameraPresenceNotifier::GetInstance()->RemoveObserver(this); | 97 CameraPresenceNotifier::GetInstance()->RemoveObserver(this); |
| 102 if (select_file_dialog_.get()) | 98 if (select_file_dialog_.get()) |
| 103 select_file_dialog_->ListenerDestroyed(); | 99 select_file_dialog_->ListenerDestroyed(); |
| 104 } | 100 } |
| 105 | 101 |
| 106 void ChangePictureOptionsHandler::GetLocalizedValues( | 102 void ChangePictureOptionsHandler::GetLocalizedValues( |
| 107 base::DictionaryValue* localized_strings) { | 103 base::DictionaryValue* localized_strings) { |
| 108 DCHECK(localized_strings); | 104 DCHECK(localized_strings); |
| 109 localized_strings->SetString("changePicturePage", | 105 localized_strings->SetString("changePicturePage", |
| 110 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_DIALOG_TITLE)); | 106 l10n_util::GetStringUTF16(IDS_OPTIONS_CHANGE_PICTURE_DIALOG_TITLE)); |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 | 427 |
| 432 web_ui()->CallJavascriptFunctionUnsafe( | 428 web_ui()->CallJavascriptFunctionUnsafe( |
| 433 "ChangePictureOptions.setCameraPresent", present_value); | 429 "ChangePictureOptions.setCameraPresent", present_value); |
| 434 } | 430 } |
| 435 | 431 |
| 436 void ChangePictureOptionsHandler::OnCameraPresenceCheckDone( | 432 void ChangePictureOptionsHandler::OnCameraPresenceCheckDone( |
| 437 bool is_camera_present) { | 433 bool is_camera_present) { |
| 438 SetCameraPresent(is_camera_present); | 434 SetCameraPresent(is_camera_present); |
| 439 } | 435 } |
| 440 | 436 |
| 441 void ChangePictureOptionsHandler::Observe( | 437 void ChangePictureOptionsHandler::OnUserImageChanged( |
| 442 int type, | 438 const user_manager::User& user) { |
| 443 const content::NotificationSource& source, | 439 // Not initialized yet. |
| 444 const content::NotificationDetails& details) { | 440 if (previous_image_index_ == user_manager::User::USER_IMAGE_INVALID) |
| 445 if (type == chrome::NOTIFICATION_PROFILE_IMAGE_UPDATED) { | 441 return; |
| 446 // User profile image has been updated. | 442 SendSelectedImage(); |
| 447 SendProfileImage(*content::Details<const gfx::ImageSkia>(details).ptr(), | 443 } |
| 448 false); | 444 |
| 449 } else if (type == chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED) { | 445 void ChangePictureOptionsHandler::OnUserProfileImageUpdated( |
| 450 // Not initialized yet. | 446 const user_manager::User& user, |
| 451 if (previous_image_index_ == user_manager::User::USER_IMAGE_INVALID) | 447 const gfx::ImageSkia& profile_image) { |
| 452 return; | 448 // User profile image has been updated. |
| 453 SendSelectedImage(); | 449 SendProfileImage(profile_image, false); |
| 454 } | |
| 455 } | 450 } |
| 456 | 451 |
| 457 gfx::NativeWindow ChangePictureOptionsHandler::GetBrowserWindow() const { | 452 gfx::NativeWindow ChangePictureOptionsHandler::GetBrowserWindow() const { |
| 458 Browser* browser = | 453 Browser* browser = |
| 459 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); | 454 chrome::FindBrowserWithWebContents(web_ui()->GetWebContents()); |
| 460 return browser->window()->GetNativeWindow(); | 455 return browser->window()->GetNativeWindow(); |
| 461 } | 456 } |
| 462 | 457 |
| 463 void ChangePictureOptionsHandler::OnImageDecoded( | 458 void ChangePictureOptionsHandler::OnImageDecoded( |
| 464 const SkBitmap& decoded_image) { | 459 const SkBitmap& decoded_image) { |
| 465 user_photo_ = gfx::ImageSkia::CreateFrom1xBitmap(decoded_image); | 460 user_photo_ = gfx::ImageSkia::CreateFrom1xBitmap(decoded_image); |
| 466 SetImageFromCamera(user_photo_); | 461 SetImageFromCamera(user_photo_); |
| 467 } | 462 } |
| 468 | 463 |
| 469 void ChangePictureOptionsHandler::OnDecodeImageFailed() { | 464 void ChangePictureOptionsHandler::OnDecodeImageFailed() { |
| 470 NOTREACHED() << "Failed to decode PNG image from WebUI"; | 465 NOTREACHED() << "Failed to decode PNG image from WebUI"; |
| 471 } | 466 } |
| 472 | 467 |
| 473 const user_manager::User* ChangePictureOptionsHandler::GetUser() const { | 468 const user_manager::User* ChangePictureOptionsHandler::GetUser() const { |
| 474 Profile* profile = Profile::FromWebUI(web_ui()); | 469 Profile* profile = Profile::FromWebUI(web_ui()); |
| 475 const user_manager::User* user = | 470 const user_manager::User* user = |
| 476 ProfileHelper::Get()->GetUserByProfile(profile); | 471 ProfileHelper::Get()->GetUserByProfile(profile); |
| 477 if (!user) | 472 if (!user) |
| 478 return user_manager::UserManager::Get()->GetActiveUser(); | 473 return user_manager::UserManager::Get()->GetActiveUser(); |
| 479 return user; | 474 return user; |
| 480 } | 475 } |
| 481 | 476 |
| 482 } // namespace options | 477 } // namespace options |
| 483 } // namespace chromeos | 478 } // namespace chromeos |
| OLD | NEW |