| 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/chromeos/login/wallpaper_manager.h" | 5 #include "chrome/browser/chromeos/login/wallpaper_manager.h" |
| 6 | 6 |
| 7 #include <numeric> | 7 #include <numeric> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/ash_switches.h" |
| 11 #include "ash/desktop_background/desktop_background_controller.h" |
| 10 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 11 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 12 #include "base/debug/trace_event.h" | 14 #include "base/debug/trace_event.h" |
| 13 #include "base/file_util.h" | 15 #include "base/file_util.h" |
| 14 #include "base/files/file_enumerator.h" | 16 #include "base/files/file_enumerator.h" |
| 15 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 16 #include "base/logging.h" | 18 #include "base/logging.h" |
| 17 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
| 18 #include "base/path_service.h" | 20 #include "base/path_service.h" |
| 19 #include "base/prefs/pref_registry_simple.h" | 21 #include "base/prefs/pref_registry_simple.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 32 #include "chrome/browser/chromeos/login/user_manager.h" | 34 #include "chrome/browser/chromeos/login/user_manager.h" |
| 33 #include "chrome/browser/chromeos/login/wizard_controller.h" | 35 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 34 #include "chrome/browser/chromeos/settings/cros_settings.h" | 36 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 35 #include "chrome/common/chrome_paths.h" | 37 #include "chrome/common/chrome_paths.h" |
| 36 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
| 37 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
| 38 #include "chromeos/chromeos_switches.h" | 40 #include "chromeos/chromeos_switches.h" |
| 39 #include "chromeos/dbus/dbus_thread_manager.h" | 41 #include "chromeos/dbus/dbus_thread_manager.h" |
| 40 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
| 41 #include "content/public/browser/notification_service.h" | 43 #include "content/public/browser/notification_service.h" |
| 44 #include "grit/ash_resources.h" |
| 42 #include "ui/base/resource/resource_bundle.h" | 45 #include "ui/base/resource/resource_bundle.h" |
| 43 #include "ui/gfx/codec/jpeg_codec.h" | 46 #include "ui/gfx/codec/jpeg_codec.h" |
| 44 #include "ui/gfx/image/image_skia_operations.h" | 47 #include "ui/gfx/image/image_skia_operations.h" |
| 45 #include "ui/gfx/skia_util.h" | 48 #include "ui/gfx/skia_util.h" |
| 46 | 49 |
| 47 using content::BrowserThread; | 50 using content::BrowserThread; |
| 48 | 51 |
| 52 namespace chromeos { |
| 53 |
| 49 namespace { | 54 namespace { |
| 50 | 55 |
| 51 // The amount of delay before starts to move custom wallpapers to the new place. | 56 // The amount of delay before starts to move custom wallpapers to the new place. |
| 52 const int kMoveCustomWallpaperDelaySeconds = 30; | 57 const int kMoveCustomWallpaperDelaySeconds = 30; |
| 53 | 58 |
| 54 // Default quality for encoding wallpaper. | 59 // Default quality for encoding wallpaper. |
| 55 const int kDefaultEncodingQuality = 90; | 60 const int kDefaultEncodingQuality = 90; |
| 56 | 61 |
| 57 // A dictionary pref that maps usernames to file paths to their wallpapers. | 62 // A dictionary pref that maps usernames to file paths to their wallpapers. |
| 58 // Deprecated. Will remove this const char after done migration. | 63 // Deprecated. Will remove this const char after done migration. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 base::FilePath base_path = GetCustomWallpaperDir(sub_dir); | 112 base::FilePath base_path = GetCustomWallpaperDir(sub_dir); |
| 108 base::FilePath to_path = base_path.Append(user_id_hash); | 113 base::FilePath to_path = base_path.Append(user_id_hash); |
| 109 base::FilePath from_path = base_path.Append(user_id); | 114 base::FilePath from_path = base_path.Append(user_id); |
| 110 if (base::PathExists(from_path)) | 115 if (base::PathExists(from_path)) |
| 111 return base::Move(from_path, to_path); | 116 return base::Move(from_path, to_path); |
| 112 return false; | 117 return false; |
| 113 } | 118 } |
| 114 | 119 |
| 115 } // namespace | 120 } // namespace |
| 116 | 121 |
| 117 namespace chromeos { | |
| 118 | |
| 119 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence"; | 122 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence"; |
| 120 | 123 |
| 121 const char kSmallWallpaperSuffix[] = "_small"; | 124 const char kSmallWallpaperSuffix[] = "_small"; |
| 122 const char kLargeWallpaperSuffix[] = "_large"; | 125 const char kLargeWallpaperSuffix[] = "_large"; |
| 123 | 126 |
| 124 const char kSmallWallpaperSubDir[] = "small"; | 127 const char kSmallWallpaperSubDir[] = "small"; |
| 125 const char kLargeWallpaperSubDir[] = "large"; | 128 const char kLargeWallpaperSubDir[] = "large"; |
| 126 const char kOriginalWallpaperSubDir[] = "original"; | 129 const char kOriginalWallpaperSubDir[] = "original"; |
| 127 const char kThumbnailWallpaperSubDir[] = "thumb"; | 130 const char kThumbnailWallpaperSubDir[] = "thumb"; |
| 128 | 131 |
| 132 const int kSmallWallpaperMaxWidth = 1366; |
| 133 const int kSmallWallpaperMaxHeight = 800; |
| 134 const int kLargeWallpaperMaxWidth = 2560; |
| 135 const int kLargeWallpaperMaxHeight = 1700; |
| 136 const int kWallpaperThumbnailWidth = 108; |
| 137 const int kWallpaperThumbnailHeight = 68; |
| 138 |
| 129 static WallpaperManager* g_wallpaper_manager = NULL; | 139 static WallpaperManager* g_wallpaper_manager = NULL; |
| 130 | 140 |
| 131 // This object is passed between several threads while wallpaper is being | 141 // This object is passed between several threads while wallpaper is being |
| 132 // loaded. It will notify callback when last reference to it is removed | 142 // loaded. It will notify callback when last reference to it is removed |
| 133 // (thus indicating that the last load action has finished). | 143 // (thus indicating that the last load action has finished). |
| 134 class MovableOnDestroyCallback { | 144 class MovableOnDestroyCallback { |
| 135 public: | 145 public: |
| 136 explicit MovableOnDestroyCallback(const base::Closure& callback) | 146 explicit MovableOnDestroyCallback(const base::Closure& callback) |
| 137 : callback_(callback) { | 147 : callback_(callback) { |
| 138 } | 148 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 211 |
| 202 WallpaperManager* manager = WallpaperManager::Get(); | 212 WallpaperManager* manager = WallpaperManager::Get(); |
| 203 if (manager->pending_inactive_ == this) | 213 if (manager->pending_inactive_ == this) |
| 204 manager->pending_inactive_ = NULL; | 214 manager->pending_inactive_ = NULL; |
| 205 | 215 |
| 206 started_load_at_ = base::Time::Now(); | 216 started_load_at_ = base::Time::Now(); |
| 207 | 217 |
| 208 if (default_) { | 218 if (default_) { |
| 209 manager->DoSetDefaultWallpaper(user_id_, on_finish_.Pass()); | 219 manager->DoSetDefaultWallpaper(user_id_, on_finish_.Pass()); |
| 210 } else if (!user_wallpaper_.isNull()) { | 220 } else if (!user_wallpaper_.isNull()) { |
| 211 ash::Shell::GetInstance()-> | 221 ash::Shell::GetInstance() |
| 212 desktop_background_controller()-> | 222 ->desktop_background_controller() |
| 213 SetCustomWallpaper(user_wallpaper_, info_.layout); | 223 ->SetWallpaperImage(user_wallpaper_, info_.layout); |
| 214 } else if (!wallpaper_path_.empty()) { | 224 } else if (!wallpaper_path_.empty()) { |
| 215 manager->task_runner_->PostTask( | 225 manager->task_runner_->PostTask( |
| 216 FROM_HERE, | 226 FROM_HERE, |
| 217 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, | 227 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, |
| 218 base::Unretained(manager), | 228 base::Unretained(manager), |
| 219 user_id_, | 229 user_id_, |
| 220 info_, | 230 info_, |
| 221 wallpaper_path_, | 231 wallpaper_path_, |
| 222 true /* update wallpaper */, | 232 true /* update wallpaper */, |
| 223 base::Passed(on_finish_.Pass()))); | 233 base::Passed(on_finish_.Pass()))); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 g_wallpaper_manager = new WallpaperManager(); | 309 g_wallpaper_manager = new WallpaperManager(); |
| 300 return g_wallpaper_manager; | 310 return g_wallpaper_manager; |
| 301 } | 311 } |
| 302 | 312 |
| 303 WallpaperManager::WallpaperManager() | 313 WallpaperManager::WallpaperManager() |
| 304 : loaded_wallpapers_(0), | 314 : loaded_wallpapers_(0), |
| 305 command_line_for_testing_(NULL), | 315 command_line_for_testing_(NULL), |
| 306 should_cache_wallpaper_(false), | 316 should_cache_wallpaper_(false), |
| 307 weak_factory_(this), | 317 weak_factory_(this), |
| 308 pending_inactive_(NULL) { | 318 pending_inactive_(NULL) { |
| 319 SetDefaultWallpaperPathsFromCommandLine( |
| 320 base::CommandLine::ForCurrentProcess()); |
| 309 registrar_.Add(this, | 321 registrar_.Add(this, |
| 310 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 322 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 311 content::NotificationService::AllSources()); | 323 content::NotificationService::AllSources()); |
| 312 registrar_.Add(this, | 324 registrar_.Add(this, |
| 313 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 325 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| 314 content::NotificationService::AllSources()); | 326 content::NotificationService::AllSources()); |
| 315 registrar_.Add(this, | 327 registrar_.Add(this, |
| 316 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, | 328 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, |
| 317 content::NotificationService::AllSources()); | 329 content::NotificationService::AllSources()); |
| 318 sequence_token_ = BrowserThread::GetBlockingPool()-> | 330 sequence_token_ = BrowserThread::GetBlockingPool()-> |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 } | 437 } |
| 426 | 438 |
| 427 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(), | 439 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(), |
| 428 info); | 440 info); |
| 429 } | 441 } |
| 430 | 442 |
| 431 void WallpaperManager::InitializeWallpaper() { | 443 void WallpaperManager::InitializeWallpaper() { |
| 432 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 433 UserManager* user_manager = UserManager::Get(); | 445 UserManager* user_manager = UserManager::Get(); |
| 434 | 446 |
| 435 CommandLine* command_line = GetComandLine(); | 447 CommandLine* command_line = GetCommandLine(); |
| 436 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) { | 448 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) { |
| 437 // Guest wallpaper should be initialized when guest login. | 449 // Guest wallpaper should be initialized when guest login. |
| 438 // Note: This maybe called before login. So IsLoggedInAsGuest can not be | 450 // Note: This maybe called before login. So IsLoggedInAsGuest can not be |
| 439 // used here to determine if current user is guest. | 451 // used here to determine if current user is guest. |
| 440 return; | 452 return; |
| 441 } | 453 } |
| 442 | 454 |
| 443 if (command_line->HasSwitch(::switches::kTestType)) | 455 if (command_line->HasSwitch(::switches::kTestType)) |
| 444 WizardController::SetZeroDelays(); | 456 WizardController::SetZeroDelays(); |
| 445 | 457 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 470 ClearDisposableWallpaperCache(); | 482 ClearDisposableWallpaperCache(); |
| 471 BrowserThread::PostDelayedTask( | 483 BrowserThread::PostDelayedTask( |
| 472 BrowserThread::UI, | 484 BrowserThread::UI, |
| 473 FROM_HERE, | 485 FROM_HERE, |
| 474 base::Bind(&WallpaperManager::MoveLoggedInUserCustomWallpaper, | 486 base::Bind(&WallpaperManager::MoveLoggedInUserCustomWallpaper, |
| 475 weak_factory_.GetWeakPtr()), | 487 weak_factory_.GetWeakPtr()), |
| 476 base::TimeDelta::FromSeconds(kMoveCustomWallpaperDelaySeconds)); | 488 base::TimeDelta::FromSeconds(kMoveCustomWallpaperDelaySeconds)); |
| 477 break; | 489 break; |
| 478 } | 490 } |
| 479 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { | 491 case chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE: { |
| 480 if (!GetComandLine()->HasSwitch(switches::kDisableBootAnimation)) { | 492 if (!GetCommandLine()->HasSwitch(switches::kDisableBootAnimation)) { |
| 481 BrowserThread::PostDelayedTask( | 493 BrowserThread::PostDelayedTask( |
| 482 BrowserThread::UI, FROM_HERE, | 494 BrowserThread::UI, FROM_HERE, |
| 483 base::Bind(&WallpaperManager::CacheUsersWallpapers, | 495 base::Bind(&WallpaperManager::CacheUsersWallpapers, |
| 484 weak_factory_.GetWeakPtr()), | 496 weak_factory_.GetWeakPtr()), |
| 485 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs)); | 497 base::TimeDelta::FromMilliseconds(kCacheWallpaperDelayMs)); |
| 486 } else { | 498 } else { |
| 487 should_cache_wallpaper_ = true; | 499 should_cache_wallpaper_ = true; |
| 488 } | 500 } |
| 489 break; | 501 break; |
| 490 } | 502 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 513 prefs::kUsersWallpaperInfo); | 525 prefs::kUsersWallpaperInfo); |
| 514 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(user_id, NULL); | 526 prefs_wallpapers_info_update->RemoveWithoutPathExpansion(user_id, NULL); |
| 515 DeleteUserWallpapers(user_id, info.file); | 527 DeleteUserWallpapers(user_id, info.file); |
| 516 } | 528 } |
| 517 | 529 |
| 518 bool WallpaperManager::ResizeWallpaper( | 530 bool WallpaperManager::ResizeWallpaper( |
| 519 const UserImage& wallpaper, | 531 const UserImage& wallpaper, |
| 520 ash::WallpaperLayout layout, | 532 ash::WallpaperLayout layout, |
| 521 int preferred_width, | 533 int preferred_width, |
| 522 int preferred_height, | 534 int preferred_height, |
| 523 scoped_refptr<base::RefCountedBytes>* output) const { | 535 scoped_refptr<base::RefCountedBytes>* output, |
| 536 gfx::ImageSkia* output_skia) const { |
| 524 DCHECK(BrowserThread::GetBlockingPool()-> | 537 DCHECK(BrowserThread::GetBlockingPool()-> |
| 525 IsRunningSequenceOnCurrentThread(sequence_token_)); | 538 IsRunningSequenceOnCurrentThread(sequence_token_)); |
| 526 int width = wallpaper.image().width(); | 539 int width = wallpaper.image().width(); |
| 527 int height = wallpaper.image().height(); | 540 int height = wallpaper.image().height(); |
| 528 int resized_width; | 541 int resized_width; |
| 529 int resized_height; | 542 int resized_height; |
| 530 *output = new base::RefCountedBytes(); | 543 *output = new base::RefCountedBytes(); |
| 531 | 544 |
| 532 if (layout == ash::WALLPAPER_LAYOUT_CENTER_CROPPED) { | 545 if (layout == ash::WALLPAPER_LAYOUT_CENTER_CROPPED) { |
| 533 // Do not resize custom wallpaper if it is smaller than preferred size. | 546 // Do not resize custom wallpaper if it is smaller than preferred size. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 560 | 573 |
| 561 SkBitmap image = *(resized_image.bitmap()); | 574 SkBitmap image = *(resized_image.bitmap()); |
| 562 SkAutoLockPixels lock_input(image); | 575 SkAutoLockPixels lock_input(image); |
| 563 gfx::JPEGCodec::Encode( | 576 gfx::JPEGCodec::Encode( |
| 564 reinterpret_cast<unsigned char*>(image.getAddr32(0, 0)), | 577 reinterpret_cast<unsigned char*>(image.getAddr32(0, 0)), |
| 565 gfx::JPEGCodec::FORMAT_SkBitmap, | 578 gfx::JPEGCodec::FORMAT_SkBitmap, |
| 566 image.width(), | 579 image.width(), |
| 567 image.height(), | 580 image.height(), |
| 568 image.width() * image.bytesPerPixel(), | 581 image.width() * image.bytesPerPixel(), |
| 569 kDefaultEncodingQuality, &(*output)->data()); | 582 kDefaultEncodingQuality, &(*output)->data()); |
| 583 |
| 584 if (output_skia) { |
| 585 resized_image.MakeThreadSafe(); |
| 586 *output_skia = resized_image; |
| 587 } |
| 588 |
| 570 return true; | 589 return true; |
| 571 } | 590 } |
| 572 | 591 |
| 573 void WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, | 592 bool WallpaperManager::ResizeAndSaveWallpaper( |
| 574 const base::FilePath& path, | 593 const UserImage& wallpaper, |
| 575 ash::WallpaperLayout layout, | 594 const base::FilePath& path, |
| 576 int preferred_width, | 595 ash::WallpaperLayout layout, |
| 577 int preferred_height) const { | 596 int preferred_width, |
| 597 int preferred_height, |
| 598 gfx::ImageSkia* result_out) const { |
| 578 if (layout == ash::WALLPAPER_LAYOUT_CENTER) { | 599 if (layout == ash::WALLPAPER_LAYOUT_CENTER) { |
| 579 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. | 600 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. |
| 580 if (base::PathExists(path)) | 601 if (base::PathExists(path)) |
| 581 base::DeleteFile(path, false); | 602 base::DeleteFile(path, false); |
| 582 return; | 603 return false; |
| 583 } | 604 } |
| 584 scoped_refptr<base::RefCountedBytes> data; | 605 scoped_refptr<base::RefCountedBytes> data; |
| 585 if (ResizeWallpaper(wallpaper, layout, preferred_width, preferred_height, | 606 if (ResizeWallpaper(wallpaper, |
| 586 &data)) { | 607 layout, |
| 587 SaveWallpaperInternal(path, | 608 preferred_width, |
| 588 reinterpret_cast<const char*>(data->front()), | 609 preferred_height, |
| 589 data->size()); | 610 &data, |
| 611 result_out)) { |
| 612 return SaveWallpaperInternal( |
| 613 path, reinterpret_cast<const char*>(data->front()), data->size()); |
| 590 } | 614 } |
| 615 return false; |
| 591 } | 616 } |
| 592 | 617 |
| 593 bool WallpaperManager::IsPolicyControlled(const std::string& user_id) const { | 618 bool WallpaperManager::IsPolicyControlled(const std::string& user_id) const { |
| 594 chromeos::WallpaperInfo info; | 619 chromeos::WallpaperInfo info; |
| 595 if (!GetUserWallpaperInfo(user_id, &info)) | 620 if (!GetUserWallpaperInfo(user_id, &info)) |
| 596 return false; | 621 return false; |
| 597 return info.type == chromeos::User::POLICY; | 622 return info.type == chromeos::User::POLICY; |
| 598 } | 623 } |
| 599 | 624 |
| 600 void WallpaperManager::OnPolicySet(const std::string& policy, | 625 void WallpaperManager::OnPolicySet(const std::string& policy, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 621 return; | 646 return; |
| 622 | 647 |
| 623 wallpaper_loader_->Start( | 648 wallpaper_loader_->Start( |
| 624 data.Pass(), | 649 data.Pass(), |
| 625 0, // Do not crop. | 650 0, // Do not crop. |
| 626 base::Bind(&WallpaperManager::SetPolicyControlledWallpaper, | 651 base::Bind(&WallpaperManager::SetPolicyControlledWallpaper, |
| 627 weak_factory_.GetWeakPtr(), | 652 weak_factory_.GetWeakPtr(), |
| 628 user_id)); | 653 user_id)); |
| 629 } | 654 } |
| 630 | 655 |
| 656 // static |
| 657 WallpaperManager::WallpaperResolution |
| 658 WallpaperManager::GetAppropriateResolution() { |
| 659 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 660 gfx::Size size = |
| 661 ash::DesktopBackgroundController::GetMaxDisplaySizeInNative(); |
| 662 return (size.width() > kSmallWallpaperMaxWidth || |
| 663 size.height() > kSmallWallpaperMaxHeight) |
| 664 ? WALLPAPER_RESOLUTION_LARGE |
| 665 : WALLPAPER_RESOLUTION_SMALL; |
| 666 } |
| 667 |
| 631 void WallpaperManager::SetPolicyControlledWallpaper( | 668 void WallpaperManager::SetPolicyControlledWallpaper( |
| 632 const std::string& user_id, | 669 const std::string& user_id, |
| 633 const UserImage& wallpaper) { | 670 const UserImage& wallpaper) { |
| 634 const User *user = chromeos::UserManager::Get()->FindUser(user_id); | 671 const User *user = chromeos::UserManager::Get()->FindUser(user_id); |
| 635 if (!user) { | 672 if (!user) { |
| 636 NOTREACHED() << "Unknown user."; | 673 NOTREACHED() << "Unknown user."; |
| 637 return; | 674 return; |
| 638 } | 675 } |
| 639 SetCustomWallpaper(user_id, | 676 SetCustomWallpaper(user_id, |
| 640 user->username_hash(), | 677 user->username_hash(), |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 // There is no visible background in kiosk mode. | 772 // There is no visible background in kiosk mode. |
| 736 if (UserManager::Get()->IsLoggedInAsKioskApp()) | 773 if (UserManager::Get()->IsLoggedInAsKioskApp()) |
| 737 return; | 774 return; |
| 738 current_wallpaper_path_.clear(); | 775 current_wallpaper_path_.clear(); |
| 739 wallpaper_cache_.erase(user_id); | 776 wallpaper_cache_.erase(user_id); |
| 740 // Some browser tests do not have a shell instance. As no wallpaper is needed | 777 // Some browser tests do not have a shell instance. As no wallpaper is needed |
| 741 // in these tests anyway, avoid loading one, preventing crashes and speeding | 778 // in these tests anyway, avoid loading one, preventing crashes and speeding |
| 742 // up the tests. | 779 // up the tests. |
| 743 if (!ash::Shell::HasInstance()) | 780 if (!ash::Shell::HasInstance()) |
| 744 return; | 781 return; |
| 745 if (ash::Shell::GetInstance()->desktop_background_controller()-> | 782 |
| 746 SetDefaultWallpaper(UserManager::Get()->IsLoggedInAsGuest())) | 783 WallpaperResolution resolution = GetAppropriateResolution(); |
| 747 loaded_wallpapers_++; | 784 const bool use_small = (resolution == WALLPAPER_RESOLUTION_SMALL); |
| 785 |
| 786 const base::FilePath* file = NULL; |
| 787 |
| 788 if (UserManager::Get()->IsLoggedInAsGuest()) { |
| 789 file = |
| 790 use_small ? &guest_small_wallpaper_file_ : &guest_large_wallpaper_file_; |
| 791 } else { |
| 792 file = use_small ? &default_small_wallpaper_file_ |
| 793 : &default_large_wallpaper_file_; |
| 794 } |
| 795 const ash::WallpaperLayout layout = |
| 796 use_small ? ash::WALLPAPER_LAYOUT_CENTER |
| 797 : ash::WALLPAPER_LAYOUT_CENTER_CROPPED; |
| 798 DCHECK(file); |
| 799 if (!default_wallpaper_image_.get() || |
| 800 default_wallpaper_image_->url().spec() != file->value()) { |
| 801 default_wallpaper_image_.reset(); |
| 802 if (!file->empty()) { |
| 803 loaded_wallpapers_++; |
| 804 StartLoadAndSetDefaultWallpaper( |
| 805 *file, layout, on_finish.Pass(), &default_wallpaper_image_); |
| 806 return; |
| 807 } |
| 808 |
| 809 const int resource_id = use_small ? IDR_AURA_WALLPAPER_DEFAULT_SMALL |
| 810 : IDR_AURA_WALLPAPER_DEFAULT_LARGE; |
| 811 |
| 812 loaded_wallpapers_ += ash::Shell::GetInstance() |
| 813 ->desktop_background_controller() |
| 814 ->SetWallpaperResource(resource_id, layout); |
| 815 return; |
| 816 } |
| 817 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( |
| 818 default_wallpaper_image_->image(), layout); |
| 748 } | 819 } |
| 749 | 820 |
| 750 void WallpaperManager::InitInitialUserWallpaper(const std::string& user_id, | 821 void WallpaperManager::InitInitialUserWallpaper(const std::string& user_id, |
| 751 bool is_persistent) { | 822 bool is_persistent) { |
| 752 current_user_wallpaper_info_.file = ""; | 823 current_user_wallpaper_info_.file = ""; |
| 753 current_user_wallpaper_info_.layout = ash::WALLPAPER_LAYOUT_CENTER_CROPPED; | 824 current_user_wallpaper_info_.layout = ash::WALLPAPER_LAYOUT_CENTER_CROPPED; |
| 754 current_user_wallpaper_info_.type = User::DEFAULT; | 825 current_user_wallpaper_info_.type = User::DEFAULT; |
| 755 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight(); | 826 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight(); |
| 756 | 827 |
| 757 WallpaperInfo info = current_user_wallpaper_info_; | 828 WallpaperInfo info = current_user_wallpaper_info_; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 GetUserWallpaperInfo(user_id, &info); | 893 GetUserWallpaperInfo(user_id, &info); |
| 823 } | 894 } |
| 824 | 895 |
| 825 gfx::ImageSkia user_wallpaper; | 896 gfx::ImageSkia user_wallpaper; |
| 826 current_user_wallpaper_info_ = info; | 897 current_user_wallpaper_info_ = info; |
| 827 if (GetWallpaperFromCache(user_id, &user_wallpaper)) { | 898 if (GetWallpaperFromCache(user_id, &user_wallpaper)) { |
| 828 GetPendingWallpaper(user_id, delayed) | 899 GetPendingWallpaper(user_id, delayed) |
| 829 ->ResetSetWallpaperImage(user_wallpaper, info); | 900 ->ResetSetWallpaperImage(user_wallpaper, info); |
| 830 } else { | 901 } else { |
| 831 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) { | 902 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) { |
| 832 ash::WallpaperResolution resolution = | 903 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); |
| 833 ash::Shell::GetInstance()-> | |
| 834 desktop_background_controller()-> | |
| 835 GetAppropriateResolution(); | |
| 836 const char* sub_dir = (resolution == ash::WALLPAPER_RESOLUTION_SMALL) | |
| 837 ? kSmallWallpaperSubDir | |
| 838 : kLargeWallpaperSubDir; | |
| 839 | |
| 840 // Wallpaper is not resized when layout is ash::WALLPAPER_LAYOUT_CENTER. | 904 // Wallpaper is not resized when layout is ash::WALLPAPER_LAYOUT_CENTER. |
| 841 // Original wallpaper should be used in this case. | 905 // Original wallpaper should be used in this case. |
| 842 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. | 906 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. |
| 843 if (info.layout == ash::WALLPAPER_LAYOUT_CENTER) | 907 if (info.layout == ash::WALLPAPER_LAYOUT_CENTER) |
| 844 sub_dir = kOriginalWallpaperSubDir; | 908 sub_dir = kOriginalWallpaperSubDir; |
| 845 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); | 909 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); |
| 846 wallpaper_path = wallpaper_path.Append(info.file); | 910 wallpaper_path = wallpaper_path.Append(info.file); |
| 847 if (current_wallpaper_path_ == wallpaper_path) | 911 if (current_wallpaper_path_ == wallpaper_path) |
| 848 return; | 912 return; |
| 849 current_wallpaper_path_ = wallpaper_path; | 913 current_wallpaper_path_ = wallpaper_path; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 if (UserManager::IsMultipleProfilesAllowed()) | 945 if (UserManager::IsMultipleProfilesAllowed()) |
| 882 wallpaper_cache_[user_id] = wallpaper; | 946 wallpaper_cache_[user_id] = wallpaper; |
| 883 | 947 |
| 884 if (update_wallpaper) { | 948 if (update_wallpaper) { |
| 885 GetPendingWallpaper(last_selected_user_, false /* Not delayed */) | 949 GetPendingWallpaper(last_selected_user_, false /* Not delayed */) |
| 886 ->ResetSetWallpaperImage(wallpaper, info); | 950 ->ResetSetWallpaperImage(wallpaper, info); |
| 887 } | 951 } |
| 888 } | 952 } |
| 889 | 953 |
| 890 void WallpaperManager::UpdateWallpaper(bool clear_cache) { | 954 void WallpaperManager::UpdateWallpaper(bool clear_cache) { |
| 955 FOR_EACH_OBSERVER(Observer, observers_, OnUpdateWallpaperForTesting()); |
| 891 if (clear_cache) | 956 if (clear_cache) |
| 892 wallpaper_cache_.clear(); | 957 wallpaper_cache_.clear(); |
| 893 current_wallpaper_path_.clear(); | 958 current_wallpaper_path_.clear(); |
| 894 // For GAIA login flow, the last_selected_user_ may not be set before user | 959 // For GAIA login flow, the last_selected_user_ may not be set before user |
| 895 // login. If UpdateWallpaper is called at GAIA login screen, no wallpaper will | 960 // login. If UpdateWallpaper is called at GAIA login screen, no wallpaper will |
| 896 // be set. It could result a black screen on external monitors. | 961 // be set. It could result a black screen on external monitors. |
| 897 // See http://crbug.com/265689 for detail. | 962 // See http://crbug.com/265689 for detail. |
| 898 if (last_selected_user_.empty()) { | 963 if (last_selected_user_.empty()) { |
| 899 SetDefaultWallpaperNow(UserManager::kSignInUser); | 964 SetDefaultWallpaperNow(UserManager::kSignInUser); |
| 900 return; | 965 return; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 } | 1011 } |
| 947 | 1012 |
| 948 void WallpaperManager::CacheUserWallpaper(const std::string& user_id) { | 1013 void WallpaperManager::CacheUserWallpaper(const std::string& user_id) { |
| 949 if (wallpaper_cache_.find(user_id) != wallpaper_cache_.end()) | 1014 if (wallpaper_cache_.find(user_id) != wallpaper_cache_.end()) |
| 950 return; | 1015 return; |
| 951 WallpaperInfo info; | 1016 WallpaperInfo info; |
| 952 if (GetUserWallpaperInfo(user_id, &info)) { | 1017 if (GetUserWallpaperInfo(user_id, &info)) { |
| 953 base::FilePath wallpaper_dir; | 1018 base::FilePath wallpaper_dir; |
| 954 base::FilePath wallpaper_path; | 1019 base::FilePath wallpaper_path; |
| 955 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) { | 1020 if (info.type == User::CUSTOMIZED || info.type == User::POLICY) { |
| 956 ash::WallpaperResolution resolution = ash::Shell::GetInstance()-> | 1021 const char* sub_dir = GetCustomWallpaperSubdirForCurrentResolution(); |
| 957 desktop_background_controller()->GetAppropriateResolution(); | |
| 958 const char* sub_dir = (resolution == ash::WALLPAPER_RESOLUTION_SMALL) ? | |
| 959 kSmallWallpaperSubDir : kLargeWallpaperSubDir; | |
| 960 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); | 1022 base::FilePath wallpaper_path = GetCustomWallpaperDir(sub_dir); |
| 961 wallpaper_path = wallpaper_path.Append(info.file); | 1023 wallpaper_path = wallpaper_path.Append(info.file); |
| 962 task_runner_->PostTask( | 1024 task_runner_->PostTask( |
| 963 FROM_HERE, | 1025 FROM_HERE, |
| 964 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, | 1026 base::Bind(&WallpaperManager::GetCustomWallpaperInternal, |
| 965 base::Unretained(this), | 1027 base::Unretained(this), |
| 966 user_id, | 1028 user_id, |
| 967 info, | 1029 info, |
| 968 wallpaper_path, | 1030 wallpaper_path, |
| 969 false /* do not update wallpaper */, | 1031 false /* do not update wallpaper */, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 dir = GetCustomWallpaperDir(kOriginalWallpaperSubDir); | 1125 dir = GetCustomWallpaperDir(kOriginalWallpaperSubDir); |
| 1064 dir = dir.Append(user_id_hash); | 1126 dir = dir.Append(user_id_hash); |
| 1065 if (!base::PathExists(dir)) | 1127 if (!base::PathExists(dir)) |
| 1066 base::CreateDirectory(dir); | 1128 base::CreateDirectory(dir); |
| 1067 dir = GetCustomWallpaperDir(kThumbnailWallpaperSubDir); | 1129 dir = GetCustomWallpaperDir(kThumbnailWallpaperSubDir); |
| 1068 dir = dir.Append(user_id_hash); | 1130 dir = dir.Append(user_id_hash); |
| 1069 if (!base::PathExists(dir)) | 1131 if (!base::PathExists(dir)) |
| 1070 base::CreateDirectory(dir); | 1132 base::CreateDirectory(dir); |
| 1071 } | 1133 } |
| 1072 | 1134 |
| 1073 CommandLine* WallpaperManager::GetComandLine() { | 1135 void WallpaperManager::SetCommandLineForTesting( |
| 1136 base::CommandLine* command_line) { |
| 1137 command_line_for_testing_ = command_line; |
| 1138 SetDefaultWallpaperPathsFromCommandLine(command_line); |
| 1139 } |
| 1140 |
| 1141 CommandLine* WallpaperManager::GetCommandLine() { |
| 1074 CommandLine* command_line = command_line_for_testing_ ? | 1142 CommandLine* command_line = command_line_for_testing_ ? |
| 1075 command_line_for_testing_ : CommandLine::ForCurrentProcess(); | 1143 command_line_for_testing_ : CommandLine::ForCurrentProcess(); |
| 1076 return command_line; | 1144 return command_line; |
| 1077 } | 1145 } |
| 1078 | 1146 |
| 1079 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { | 1147 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { |
| 1080 if (UserManager::Get()->IsUserLoggedIn()) | 1148 if (UserManager::Get()->IsUserLoggedIn()) |
| 1081 return; | 1149 return; |
| 1082 | 1150 |
| 1083 bool disable_boot_animation = GetComandLine()-> | 1151 bool disable_boot_animation = |
| 1084 HasSwitch(switches::kDisableBootAnimation); | 1152 GetCommandLine()->HasSwitch(switches::kDisableBootAnimation); |
| 1085 bool show_users = true; | 1153 bool show_users = true; |
| 1086 bool result = CrosSettings::Get()->GetBoolean( | 1154 bool result = CrosSettings::Get()->GetBoolean( |
| 1087 kAccountsPrefShowUserNamesOnSignIn, &show_users); | 1155 kAccountsPrefShowUserNamesOnSignIn, &show_users); |
| 1088 DCHECK(result) << "Unable to fetch setting " | 1156 DCHECK(result) << "Unable to fetch setting " |
| 1089 << kAccountsPrefShowUserNamesOnSignIn; | 1157 << kAccountsPrefShowUserNamesOnSignIn; |
| 1090 const chromeos::UserList& users = UserManager::Get()->GetUsers(); | 1158 const chromeos::UserList& users = UserManager::Get()->GetUsers(); |
| 1091 if (!show_users || users.empty()) { | 1159 if (!show_users || users.empty()) { |
| 1092 // Boot into sign in form, preload default wallpaper. | 1160 // Boot into sign in form, preload default wallpaper. |
| 1093 SetDefaultWallpaperDelayed(UserManager::kSignInUser); | 1161 SetDefaultWallpaperDelayed(UserManager::kSignInUser); |
| 1094 return; | 1162 return; |
| 1095 } | 1163 } |
| 1096 | 1164 |
| 1097 if (!disable_boot_animation) { | 1165 if (!disable_boot_animation) { |
| 1098 // Normal boot, load user wallpaper. | 1166 // Normal boot, load user wallpaper. |
| 1099 // If normal boot animation is disabled wallpaper would be set | 1167 // If normal boot animation is disabled wallpaper would be set |
| 1100 // asynchronously once user pods are loaded. | 1168 // asynchronously once user pods are loaded. |
| 1101 SetUserWallpaperDelayed(users[0]->email()); | 1169 SetUserWallpaperDelayed(users[0]->email()); |
| 1102 } | 1170 } |
| 1103 } | 1171 } |
| 1104 | 1172 |
| 1105 void WallpaperManager::LoadWallpaper(const std::string& user_id, | 1173 void WallpaperManager::LoadWallpaper(const std::string& user_id, |
| 1106 const WallpaperInfo& info, | 1174 const WallpaperInfo& info, |
| 1107 bool update_wallpaper, | 1175 bool update_wallpaper, |
| 1108 MovableOnDestroyCallbackHolder on_finish) { | 1176 MovableOnDestroyCallbackHolder on_finish) { |
| 1109 base::FilePath wallpaper_dir; | 1177 base::FilePath wallpaper_dir; |
| 1110 base::FilePath wallpaper_path; | 1178 base::FilePath wallpaper_path; |
| 1111 if (info.type == User::ONLINE) { | 1179 if (info.type == User::ONLINE) { |
| 1112 std::string file_name = GURL(info.file).ExtractFileName(); | 1180 std::string file_name = GURL(info.file).ExtractFileName(); |
| 1113 ash::WallpaperResolution resolution = ash::Shell::GetInstance()-> | 1181 WallpaperResolution resolution = GetAppropriateResolution(); |
| 1114 desktop_background_controller()->GetAppropriateResolution(); | |
| 1115 // Only solid color wallpapers have stretch layout and they have only one | 1182 // Only solid color wallpapers have stretch layout and they have only one |
| 1116 // resolution. | 1183 // resolution. |
| 1117 if (info.layout != ash::WALLPAPER_LAYOUT_STRETCH && | 1184 if (info.layout != ash::WALLPAPER_LAYOUT_STRETCH && |
| 1118 resolution == ash::WALLPAPER_RESOLUTION_SMALL) { | 1185 resolution == WALLPAPER_RESOLUTION_SMALL) { |
| 1119 file_name = base::FilePath(file_name).InsertBeforeExtension( | 1186 file_name = base::FilePath(file_name).InsertBeforeExtension( |
| 1120 kSmallWallpaperSuffix).value(); | 1187 kSmallWallpaperSuffix).value(); |
| 1121 } | 1188 } |
| 1122 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)); | 1189 CHECK(PathService::Get(chrome::DIR_CHROMEOS_WALLPAPERS, &wallpaper_dir)); |
| 1123 wallpaper_path = wallpaper_dir.Append(file_name); | 1190 wallpaper_path = wallpaper_dir.Append(file_name); |
| 1124 if (current_wallpaper_path_ == wallpaper_path) | 1191 if (current_wallpaper_path_ == wallpaper_path) |
| 1125 return; | 1192 return; |
| 1126 | 1193 |
| 1127 if (update_wallpaper) | 1194 if (update_wallpaper) |
| 1128 current_wallpaper_path_ = wallpaper_path; | 1195 current_wallpaper_path_ = wallpaper_path; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 return; | 1381 return; |
| 1315 } | 1382 } |
| 1316 | 1383 |
| 1317 // Only cache the user wallpaper at login screen and for multi profile users. | 1384 // Only cache the user wallpaper at login screen and for multi profile users. |
| 1318 if (!UserManager::Get()->IsUserLoggedIn() || | 1385 if (!UserManager::Get()->IsUserLoggedIn() || |
| 1319 UserManager::IsMultipleProfilesAllowed()) { | 1386 UserManager::IsMultipleProfilesAllowed()) { |
| 1320 wallpaper_cache_[user_id] = wallpaper.image(); | 1387 wallpaper_cache_[user_id] = wallpaper.image(); |
| 1321 } | 1388 } |
| 1322 | 1389 |
| 1323 if (update_wallpaper) { | 1390 if (update_wallpaper) { |
| 1324 ash::Shell::GetInstance()->desktop_background_controller()-> | 1391 ash::Shell::GetInstance() |
| 1325 SetCustomWallpaper(wallpaper.image(), layout); | 1392 ->desktop_background_controller() |
| 1393 ->SetWallpaperImage(wallpaper.image(), layout); |
| 1326 } | 1394 } |
| 1327 } | 1395 } |
| 1328 | 1396 |
| 1329 void WallpaperManager::ProcessCustomWallpaper( | 1397 void WallpaperManager::ProcessCustomWallpaper( |
| 1330 const std::string& user_id_hash, | 1398 const std::string& user_id_hash, |
| 1331 bool persistent, | 1399 bool persistent, |
| 1332 const WallpaperInfo& info, | 1400 const WallpaperInfo& info, |
| 1333 scoped_ptr<gfx::ImageSkia> image, | 1401 scoped_ptr<gfx::ImageSkia> image, |
| 1334 const UserImage::RawImage& raw_image) { | 1402 const UserImage::RawImage& raw_image) { |
| 1335 DCHECK(BrowserThread::GetBlockingPool()-> | 1403 DCHECK(BrowserThread::GetBlockingPool()-> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1350 EnsureCustomWallpaperDirectories(user_id_hash); | 1418 EnsureCustomWallpaperDirectories(user_id_hash); |
| 1351 std::string file_name = original_path.BaseName().value(); | 1419 std::string file_name = original_path.BaseName().value(); |
| 1352 base::FilePath small_wallpaper_path = | 1420 base::FilePath small_wallpaper_path = |
| 1353 GetCustomWallpaperPath(kSmallWallpaperSubDir, user_id_hash, file_name); | 1421 GetCustomWallpaperPath(kSmallWallpaperSubDir, user_id_hash, file_name); |
| 1354 base::FilePath large_wallpaper_path = | 1422 base::FilePath large_wallpaper_path = |
| 1355 GetCustomWallpaperPath(kLargeWallpaperSubDir, user_id_hash, file_name); | 1423 GetCustomWallpaperPath(kLargeWallpaperSubDir, user_id_hash, file_name); |
| 1356 | 1424 |
| 1357 // Re-encode orginal file to jpeg format and saves the result in case that | 1425 // Re-encode orginal file to jpeg format and saves the result in case that |
| 1358 // resized wallpaper is not generated (i.e. chrome shutdown before resized | 1426 // resized wallpaper is not generated (i.e. chrome shutdown before resized |
| 1359 // wallpaper is saved). | 1427 // wallpaper is saved). |
| 1360 ResizeAndSaveWallpaper(wallpaper, original_path, | 1428 ResizeAndSaveWallpaper(wallpaper, |
| 1429 original_path, |
| 1361 ash::WALLPAPER_LAYOUT_STRETCH, | 1430 ash::WALLPAPER_LAYOUT_STRETCH, |
| 1362 wallpaper.image().width(), | 1431 wallpaper.image().width(), |
| 1363 wallpaper.image().height()); | 1432 wallpaper.image().height(), |
| 1433 NULL); |
| 1364 DeleteAllExcept(original_path); | 1434 DeleteAllExcept(original_path); |
| 1365 | 1435 |
| 1366 ResizeAndSaveWallpaper(wallpaper, small_wallpaper_path, layout, | 1436 ResizeAndSaveWallpaper(wallpaper, |
| 1367 ash::kSmallWallpaperMaxWidth, | 1437 small_wallpaper_path, |
| 1368 ash::kSmallWallpaperMaxHeight); | 1438 layout, |
| 1439 kSmallWallpaperMaxWidth, |
| 1440 kSmallWallpaperMaxHeight, |
| 1441 NULL); |
| 1369 DeleteAllExcept(small_wallpaper_path); | 1442 DeleteAllExcept(small_wallpaper_path); |
| 1370 ResizeAndSaveWallpaper(wallpaper, large_wallpaper_path, layout, | 1443 ResizeAndSaveWallpaper(wallpaper, |
| 1371 ash::kLargeWallpaperMaxWidth, | 1444 large_wallpaper_path, |
| 1372 ash::kLargeWallpaperMaxHeight); | 1445 layout, |
| 1446 kLargeWallpaperMaxWidth, |
| 1447 kLargeWallpaperMaxHeight, |
| 1448 NULL); |
| 1373 DeleteAllExcept(large_wallpaper_path); | 1449 DeleteAllExcept(large_wallpaper_path); |
| 1374 } | 1450 } |
| 1375 | 1451 |
| 1376 void WallpaperManager::RecordUma(User::WallpaperType type, int index) const { | 1452 void WallpaperManager::RecordUma(User::WallpaperType type, int index) const { |
| 1377 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", type, | 1453 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", type, |
| 1378 User::WALLPAPER_TYPE_COUNT); | 1454 User::WALLPAPER_TYPE_COUNT); |
| 1379 } | 1455 } |
| 1380 | 1456 |
| 1381 void WallpaperManager::SaveWallpaperInternal(const base::FilePath& path, | 1457 bool WallpaperManager::SaveWallpaperInternal(const base::FilePath& path, |
| 1382 const char* data, | 1458 const char* data, |
| 1383 int size) const { | 1459 int size) const { |
| 1384 int written_bytes = base::WriteFile(path, data, size); | 1460 int written_bytes = base::WriteFile(path, data, size); |
| 1385 DCHECK(written_bytes == size); | 1461 return written_bytes == size; |
| 1386 } | 1462 } |
| 1387 | 1463 |
| 1388 void WallpaperManager::StartLoad(const std::string& user_id, | 1464 void WallpaperManager::StartLoad(const std::string& user_id, |
| 1389 const WallpaperInfo& info, | 1465 const WallpaperInfo& info, |
| 1390 bool update_wallpaper, | 1466 bool update_wallpaper, |
| 1391 const base::FilePath& wallpaper_path, | 1467 const base::FilePath& wallpaper_path, |
| 1392 MovableOnDestroyCallbackHolder on_finish) { | 1468 MovableOnDestroyCallbackHolder on_finish) { |
| 1393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1469 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1394 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); | 1470 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); |
| 1395 | 1471 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1448 if (!pending_inactive_) { | 1524 if (!pending_inactive_) { |
| 1449 loading_.push_back(new WallpaperManager::PendingWallpaper( | 1525 loading_.push_back(new WallpaperManager::PendingWallpaper( |
| 1450 (delayed ? GetWallpaperLoadDelay() | 1526 (delayed ? GetWallpaperLoadDelay() |
| 1451 : base::TimeDelta::FromMilliseconds(0)), | 1527 : base::TimeDelta::FromMilliseconds(0)), |
| 1452 user_id)); | 1528 user_id)); |
| 1453 pending_inactive_ = loading_.back(); | 1529 pending_inactive_ = loading_.back(); |
| 1454 } | 1530 } |
| 1455 return pending_inactive_; | 1531 return pending_inactive_; |
| 1456 } | 1532 } |
| 1457 | 1533 |
| 1534 void WallpaperManager::SetDefaultWallpaperPathsFromCommandLine( |
| 1535 base::CommandLine* command_line) { |
| 1536 default_small_wallpaper_file_ = command_line->GetSwitchValuePath( |
| 1537 ash::switches::kAshDefaultWallpaperSmall); |
| 1538 default_large_wallpaper_file_ = command_line->GetSwitchValuePath( |
| 1539 ash::switches::kAshDefaultWallpaperLarge); |
| 1540 guest_small_wallpaper_file_ = |
| 1541 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperSmall); |
| 1542 guest_large_wallpaper_file_ = |
| 1543 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperLarge); |
| 1544 default_wallpaper_image_.reset(); |
| 1545 } |
| 1546 |
| 1547 void WallpaperManager::OnDefaultWallpaperDecoded( |
| 1548 const base::FilePath& path, |
| 1549 const ash::WallpaperLayout layout, |
| 1550 scoped_ptr<chromeos::UserImage>* result_out, |
| 1551 MovableOnDestroyCallbackHolder on_finish, |
| 1552 const UserImage& wallpaper) { |
| 1553 result_out->reset(new UserImage(wallpaper.image())); |
| 1554 (*result_out)->set_url(GURL(path.value())); |
| 1555 ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( |
| 1556 wallpaper.image(), layout); |
| 1557 } |
| 1558 |
| 1559 void WallpaperManager::StartLoadAndSetDefaultWallpaper( |
| 1560 const base::FilePath& path, |
| 1561 const ash::WallpaperLayout layout, |
| 1562 MovableOnDestroyCallbackHolder on_finish, |
| 1563 scoped_ptr<chromeos::UserImage>* result_out) { |
| 1564 wallpaper_loader_->Start( |
| 1565 path.value(), |
| 1566 0, // Do not crop. |
| 1567 base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded, |
| 1568 weak_factory_.GetWeakPtr(), |
| 1569 path, |
| 1570 layout, |
| 1571 base::Unretained(result_out), |
| 1572 base::Passed(on_finish.Pass()))); |
| 1573 } |
| 1574 |
| 1575 const char* WallpaperManager::GetCustomWallpaperSubdirForCurrentResolution() { |
| 1576 WallpaperResolution resolution = GetAppropriateResolution(); |
| 1577 return resolution == WALLPAPER_RESOLUTION_SMALL ? kSmallWallpaperSubDir |
| 1578 : kLargeWallpaperSubDir; |
| 1579 } |
| 1580 |
| 1458 } // namespace chromeos | 1581 } // namespace chromeos |
| OLD | NEW |