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 "ash/audio/sounds.h" | 7 #include "ash/audio/sounds.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
17 #include "chrome/browser/chromeos/camera_presence_notifier.h" | 17 #include "chrome/browser/chromeos/camera_presence_notifier.h" |
18 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager.h" | 18 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager.h" |
19 #include "chrome/browser/chromeos/login/users/user_manager.h" | 19 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
20 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
21 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
22 #include "chrome/browser/ui/browser_window.h" | 22 #include "chrome/browser/ui/browser_window.h" |
23 #include "chrome/browser/ui/chrome_select_file_policy.h" | 23 #include "chrome/browser/ui/chrome_select_file_policy.h" |
24 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
27 #include "chromeos/audio/chromeos_sounds.h" | 27 #include "chromeos/audio/chromeos_sounds.h" |
28 #include "components/user_manager/user.h" | 28 #include "components/user_manager/user.h" |
29 #include "components/user_manager/user_image/default_user_images.h" | 29 #include "components/user_manager/user_image/default_user_images.h" |
30 #include "components/user_manager/user_image/user_image.h" | 30 #include "components/user_manager/user_image/user_image.h" |
| 31 #include "components/user_manager/user_manager.h" |
31 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
33 #include "content/public/browser/web_ui.h" | 34 #include "content/public/browser/web_ui.h" |
34 #include "content/public/common/url_constants.h" | 35 #include "content/public/common/url_constants.h" |
35 #include "grit/browser_resources.h" | 36 #include "grit/browser_resources.h" |
36 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
37 #include "grit/theme_resources.h" | 38 #include "grit/theme_resources.h" |
38 #include "net/base/data_url.h" | 39 #include "net/base/data_url.h" |
39 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
40 #include "ui/base/resource/resource_bundle.h" | 41 #include "ui/base/resource/resource_bundle.h" |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 void ChangePictureOptionsHandler::SendProfileImage(const gfx::ImageSkia& image, | 306 void ChangePictureOptionsHandler::SendProfileImage(const gfx::ImageSkia& image, |
306 bool should_select) { | 307 bool should_select) { |
307 base::StringValue data_url(webui::GetBitmapDataUrl(*image.bitmap())); | 308 base::StringValue data_url(webui::GetBitmapDataUrl(*image.bitmap())); |
308 base::FundamentalValue select(should_select); | 309 base::FundamentalValue select(should_select); |
309 web_ui()->CallJavascriptFunction("ChangePictureOptions.setProfileImage", | 310 web_ui()->CallJavascriptFunction("ChangePictureOptions.setProfileImage", |
310 data_url, select); | 311 data_url, select); |
311 } | 312 } |
312 | 313 |
313 void ChangePictureOptionsHandler::UpdateProfileImage() { | 314 void ChangePictureOptionsHandler::UpdateProfileImage() { |
314 UserImageManager* user_image_manager = | 315 UserImageManager* user_image_manager = |
315 UserManager::Get()->GetUserImageManager(GetUser()->email()); | 316 ChromeUserManager::Get()->GetUserImageManager(GetUser()->email()); |
316 // If we have a downloaded profile image and haven't sent it in | 317 // If we have a downloaded profile image and haven't sent it in |
317 // |SendSelectedImage|, send it now (without selecting). | 318 // |SendSelectedImage|, send it now (without selecting). |
318 if (previous_image_index_ != user_manager::User::USER_IMAGE_PROFILE && | 319 if (previous_image_index_ != user_manager::User::USER_IMAGE_PROFILE && |
319 !user_image_manager->DownloadedProfileImage().isNull()) | 320 !user_image_manager->DownloadedProfileImage().isNull()) |
320 SendProfileImage(user_image_manager->DownloadedProfileImage(), false); | 321 SendProfileImage(user_image_manager->DownloadedProfileImage(), false); |
321 | 322 |
322 user_image_manager->DownloadProfileImage(kProfileDownloadReason); | 323 user_image_manager->DownloadProfileImage(kProfileDownloadReason); |
323 } | 324 } |
324 | 325 |
325 void ChangePictureOptionsHandler::SendOldImage(const std::string& image_url) { | 326 void ChangePictureOptionsHandler::SendOldImage(const std::string& image_url) { |
(...skipping 10 matching lines...) Expand all Loading... |
336 args->GetSize() != 2 || | 337 args->GetSize() != 2 || |
337 !args->GetString(0, &image_url) || | 338 !args->GetString(0, &image_url) || |
338 !args->GetString(1, &image_type)) { | 339 !args->GetString(1, &image_type)) { |
339 NOTREACHED(); | 340 NOTREACHED(); |
340 return; | 341 return; |
341 } | 342 } |
342 DCHECK(!image_url.empty()); | 343 DCHECK(!image_url.empty()); |
343 DCHECK(!image_type.empty()); | 344 DCHECK(!image_type.empty()); |
344 | 345 |
345 UserImageManager* user_image_manager = | 346 UserImageManager* user_image_manager = |
346 UserManager::Get()->GetUserImageManager(GetUser()->email()); | 347 ChromeUserManager::Get()->GetUserImageManager(GetUser()->email()); |
347 int image_index = user_manager::User::USER_IMAGE_INVALID; | 348 int image_index = user_manager::User::USER_IMAGE_INVALID; |
348 bool waiting_for_camera_photo = false; | 349 bool waiting_for_camera_photo = false; |
349 | 350 |
350 if (image_type == "old") { | 351 if (image_type == "old") { |
351 // Previous image (from camera or manually uploaded) re-selected. | 352 // Previous image (from camera or manually uploaded) re-selected. |
352 DCHECK(!previous_image_.isNull()); | 353 DCHECK(!previous_image_.isNull()); |
353 user_image_manager->SaveUserImage( | 354 user_image_manager->SaveUserImage( |
354 user_manager::UserImage::CreateAndEncode(previous_image_)); | 355 user_manager::UserImage::CreateAndEncode(previous_image_)); |
355 | 356 |
356 UMA_HISTOGRAM_ENUMERATION("UserImage.ChangeChoice", | 357 UMA_HISTOGRAM_ENUMERATION("UserImage.ChangeChoice", |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 } | 397 } |
397 | 398 |
398 // Ignore the result of the previous decoding if it's no longer needed. | 399 // Ignore the result of the previous decoding if it's no longer needed. |
399 if (!waiting_for_camera_photo && image_decoder_.get()) | 400 if (!waiting_for_camera_photo && image_decoder_.get()) |
400 image_decoder_->set_delegate(NULL); | 401 image_decoder_->set_delegate(NULL); |
401 } | 402 } |
402 | 403 |
403 void ChangePictureOptionsHandler::FileSelected(const base::FilePath& path, | 404 void ChangePictureOptionsHandler::FileSelected(const base::FilePath& path, |
404 int index, | 405 int index, |
405 void* params) { | 406 void* params) { |
406 UserManager* user_manager = UserManager::Get(); | 407 ChromeUserManager::Get() |
407 user_manager->GetUserImageManager(GetUser()->email())-> | 408 ->GetUserImageManager(GetUser()->email()) |
408 SaveUserImageFromFile(path); | 409 ->SaveUserImageFromFile(path); |
409 UMA_HISTOGRAM_ENUMERATION("UserImage.ChangeChoice", | 410 UMA_HISTOGRAM_ENUMERATION("UserImage.ChangeChoice", |
410 user_manager::kHistogramImageFromFile, | 411 user_manager::kHistogramImageFromFile, |
411 user_manager::kHistogramImagesCount); | 412 user_manager::kHistogramImagesCount); |
412 VLOG(1) << "Selected image from file"; | 413 VLOG(1) << "Selected image from file"; |
413 } | 414 } |
414 | 415 |
415 void ChangePictureOptionsHandler::SetImageFromCamera( | 416 void ChangePictureOptionsHandler::SetImageFromCamera( |
416 const gfx::ImageSkia& photo) { | 417 const gfx::ImageSkia& photo) { |
417 UserManager* user_manager = UserManager::Get(); | 418 ChromeUserManager::Get() |
418 user_manager->GetUserImageManager(GetUser()->email()) | 419 ->GetUserImageManager(GetUser()->email()) |
419 ->SaveUserImage(user_manager::UserImage::CreateAndEncode(photo)); | 420 ->SaveUserImage(user_manager::UserImage::CreateAndEncode(photo)); |
420 UMA_HISTOGRAM_ENUMERATION("UserImage.ChangeChoice", | 421 UMA_HISTOGRAM_ENUMERATION("UserImage.ChangeChoice", |
421 user_manager::kHistogramImageFromCamera, | 422 user_manager::kHistogramImageFromCamera, |
422 user_manager::kHistogramImagesCount); | 423 user_manager::kHistogramImagesCount); |
423 VLOG(1) << "Selected camera photo"; | 424 VLOG(1) << "Selected camera photo"; |
424 } | 425 } |
425 | 426 |
426 void ChangePictureOptionsHandler::SetCameraPresent(bool present) { | 427 void ChangePictureOptionsHandler::SetCameraPresent(bool present) { |
427 base::FundamentalValue present_value(present); | 428 base::FundamentalValue present_value(present); |
428 | 429 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 | 469 |
469 void ChangePictureOptionsHandler::OnDecodeImageFailed( | 470 void ChangePictureOptionsHandler::OnDecodeImageFailed( |
470 const ImageDecoder* decoder) { | 471 const ImageDecoder* decoder) { |
471 NOTREACHED() << "Failed to decode PNG image from WebUI"; | 472 NOTREACHED() << "Failed to decode PNG image from WebUI"; |
472 } | 473 } |
473 | 474 |
474 user_manager::User* ChangePictureOptionsHandler::GetUser() const { | 475 user_manager::User* ChangePictureOptionsHandler::GetUser() const { |
475 Profile* profile = Profile::FromWebUI(web_ui()); | 476 Profile* profile = Profile::FromWebUI(web_ui()); |
476 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile); | 477 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile); |
477 if (!user) | 478 if (!user) |
478 return UserManager::Get()->GetActiveUser(); | 479 return user_manager::UserManager::Get()->GetActiveUser(); |
479 return user; | 480 return user; |
480 } | 481 } |
481 | 482 |
482 } // namespace options | 483 } // namespace options |
483 } // namespace chromeos | 484 } // namespace chromeos |
OLD | NEW |