Chromium Code Reviews| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 const std::string& user_id, | 107 const std::string& user_id, |
| 106 const std::string& user_id_hash) { | 108 const std::string& user_id_hash) { |
| 107 base::FilePath base_path = GetCustomWallpaperDir(sub_dir); | 109 base::FilePath base_path = GetCustomWallpaperDir(sub_dir); |
| 108 base::FilePath to_path = base_path.Append(user_id_hash); | 110 base::FilePath to_path = base_path.Append(user_id_hash); |
| 109 base::FilePath from_path = base_path.Append(user_id); | 111 base::FilePath from_path = base_path.Append(user_id); |
| 110 if (base::PathExists(from_path)) | 112 if (base::PathExists(from_path)) |
| 111 return base::Move(from_path, to_path); | 113 return base::Move(from_path, to_path); |
| 112 return false; | 114 return false; |
| 113 } | 115 } |
| 114 | 116 |
| 117 void CheckCustomizedWallpaperFilesExist( | |
| 118 const base::FilePath& downloaded_file, | |
| 119 const chromeos::WallpaperManager::CustomizedWallpaperRescaledFiles* | |
| 120 rescaled_files, | |
| 121 chromeos::WallpaperManager::CustomizedWallpaperFilesExist* exist) { | |
| 122 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | |
| 123 DCHECK(rescaled_files); | |
| 124 DCHECK(exist); | |
| 125 exist->dowloaded = base::PathExists(downloaded_file); | |
| 126 exist->rescaled_original = | |
| 127 base::PathExists(rescaled_files->path_rescaled_original); | |
| 128 exist->rescaled_small = base::PathExists(rescaled_files->path_rescaled_small); | |
| 129 exist->rescaled_large = base::PathExists(rescaled_files->path_rescaled_large); | |
| 130 } | |
| 131 | |
| 115 } // namespace | 132 } // namespace |
| 116 | 133 |
| 117 namespace chromeos { | 134 namespace chromeos { |
|
Daniel Erat
2014/03/25 21:58:29
nit: put the above anonymous namespace within the
Alexander Alekseev
2014/03/27 00:28:37
Done.
| |
| 118 | 135 |
| 119 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence"; | 136 const char kWallpaperSequenceTokenName[] = "wallpaper-sequence"; |
| 120 | 137 |
| 121 const char kSmallWallpaperSuffix[] = "_small"; | 138 const char kSmallWallpaperSuffix[] = "_small"; |
| 122 const char kLargeWallpaperSuffix[] = "_large"; | 139 const char kLargeWallpaperSuffix[] = "_large"; |
| 123 | 140 |
| 141 // This is used for customized default wallpaper only. | |
| 142 const char kOriginalWallpaperSuffix[] = "_original"; | |
| 143 | |
| 124 const char kSmallWallpaperSubDir[] = "small"; | 144 const char kSmallWallpaperSubDir[] = "small"; |
| 125 const char kLargeWallpaperSubDir[] = "large"; | 145 const char kLargeWallpaperSubDir[] = "large"; |
| 126 const char kOriginalWallpaperSubDir[] = "original"; | 146 const char kOriginalWallpaperSubDir[] = "original"; |
| 127 const char kThumbnailWallpaperSubDir[] = "thumb"; | 147 const char kThumbnailWallpaperSubDir[] = "thumb"; |
| 128 | 148 |
| 129 static WallpaperManager* g_wallpaper_manager = NULL; | 149 static WallpaperManager* g_wallpaper_manager = NULL; |
| 130 | 150 |
| 131 // This object is passed between several threads while wallpaper is being | 151 // This object is passed between several threads while wallpaper is being |
| 132 // loaded. It will notify callback when last reference to it is removed | 152 // loaded. It will notify callback when last reference to it is removed |
| 133 // (thus indicating that the last load action has finished). | 153 // (thus indicating that the last load action has finished). |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 i != manager->loading_.end(); | 279 i != manager->loading_.end(); |
| 260 ++i) | 280 ++i) |
| 261 if (i->get() == this) { | 281 if (i->get() == this) { |
| 262 manager->loading_.erase(i); | 282 manager->loading_.erase(i); |
| 263 break; | 283 break; |
| 264 } | 284 } |
| 265 } | 285 } |
| 266 | 286 |
| 267 // WallpaperManager, public: --------------------------------------------------- | 287 // WallpaperManager, public: --------------------------------------------------- |
| 268 | 288 |
| 289 WallpaperManager::CustomizedWallpaperRescaledFiles:: | |
| 290 CustomizedWallpaperRescaledFiles( | |
| 291 const base::FilePath& path_rescaled_original, | |
| 292 const base::FilePath& path_rescaled_small, | |
| 293 const base::FilePath& path_rescaled_large) | |
| 294 : path_rescaled_original(path_rescaled_original), | |
| 295 path_rescaled_small(path_rescaled_small), | |
| 296 path_rescaled_large(path_rescaled_large) { | |
| 297 } | |
| 298 | |
| 299 WallpaperManager::CustomizedWallpaperFilesExist::CustomizedWallpaperFilesExist() | |
| 300 : dowloaded(false), | |
| 301 rescaled_original(false), | |
| 302 rescaled_small(false), | |
| 303 rescaled_large(false) { | |
| 304 } | |
| 305 | |
| 306 bool WallpaperManager::CustomizedWallpaperFilesExist::AllRescaledExist() const { | |
| 307 return rescaled_original && rescaled_small && rescaled_large; | |
| 308 } | |
| 309 | |
| 269 // TestApi. For testing purpose | 310 // TestApi. For testing purpose |
| 270 WallpaperManager::TestApi::TestApi(WallpaperManager* wallpaper_manager) | 311 WallpaperManager::TestApi::TestApi(WallpaperManager* wallpaper_manager) |
| 271 : wallpaper_manager_(wallpaper_manager) { | 312 : wallpaper_manager_(wallpaper_manager) { |
| 272 } | 313 } |
| 273 | 314 |
| 274 WallpaperManager::TestApi::~TestApi() { | 315 WallpaperManager::TestApi::~TestApi() { |
| 275 } | 316 } |
| 276 | 317 |
| 277 base::FilePath WallpaperManager::TestApi::current_wallpaper_path() { | 318 base::FilePath WallpaperManager::TestApi::current_wallpaper_path() { |
| 278 return wallpaper_manager_->current_wallpaper_path_; | 319 return wallpaper_manager_->current_wallpaper_path_; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 299 g_wallpaper_manager = new WallpaperManager(); | 340 g_wallpaper_manager = new WallpaperManager(); |
| 300 return g_wallpaper_manager; | 341 return g_wallpaper_manager; |
| 301 } | 342 } |
| 302 | 343 |
| 303 WallpaperManager::WallpaperManager() | 344 WallpaperManager::WallpaperManager() |
| 304 : loaded_wallpapers_(0), | 345 : loaded_wallpapers_(0), |
| 305 command_line_for_testing_(NULL), | 346 command_line_for_testing_(NULL), |
| 306 should_cache_wallpaper_(false), | 347 should_cache_wallpaper_(false), |
| 307 weak_factory_(this), | 348 weak_factory_(this), |
| 308 pending_inactive_(NULL) { | 349 pending_inactive_(NULL) { |
| 350 SetDefaultWallpaperPathFromCommandLine( | |
| 351 base::CommandLine::ForCurrentProcess()); | |
| 309 registrar_.Add(this, | 352 registrar_.Add(this, |
| 310 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 353 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 311 content::NotificationService::AllSources()); | 354 content::NotificationService::AllSources()); |
| 312 registrar_.Add(this, | 355 registrar_.Add(this, |
| 313 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 356 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| 314 content::NotificationService::AllSources()); | 357 content::NotificationService::AllSources()); |
| 315 registrar_.Add(this, | 358 registrar_.Add(this, |
| 316 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, | 359 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, |
| 317 content::NotificationService::AllSources()); | 360 content::NotificationService::AllSources()); |
| 318 sequence_token_ = BrowserThread::GetBlockingPool()-> | 361 sequence_token_ = BrowserThread::GetBlockingPool()-> |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 } | 468 } |
| 426 | 469 |
| 427 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(), | 470 return GetUserWallpaperInfo(UserManager::Get()->GetLoggedInUser()->email(), |
| 428 info); | 471 info); |
| 429 } | 472 } |
| 430 | 473 |
| 431 void WallpaperManager::InitializeWallpaper() { | 474 void WallpaperManager::InitializeWallpaper() { |
| 432 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 475 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 433 UserManager* user_manager = UserManager::Get(); | 476 UserManager* user_manager = UserManager::Get(); |
| 434 | 477 |
| 478 // Apply device customization. | |
| 479 if (ShouldUseCustomizedDefaultWallpaper()) { | |
| 480 SetDefaultWallpaperPath( | |
| 481 GetCustomizedWallpaperDefaultRescaledFileName(kSmallWallpaperSuffix), | |
| 482 GetCustomizedWallpaperDefaultRescaledFileName(kLargeWallpaperSuffix)); | |
| 483 } | |
| 484 | |
| 435 CommandLine* command_line = GetComandLine(); | 485 CommandLine* command_line = GetComandLine(); |
| 436 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) { | 486 if (command_line->HasSwitch(chromeos::switches::kGuestSession)) { |
| 437 // Guest wallpaper should be initialized when guest login. | 487 // Guest wallpaper should be initialized when guest login. |
| 438 // Note: This maybe called before login. So IsLoggedInAsGuest can not be | 488 // Note: This maybe called before login. So IsLoggedInAsGuest can not be |
| 439 // used here to determine if current user is guest. | 489 // used here to determine if current user is guest. |
| 440 return; | 490 return; |
| 441 } | 491 } |
| 442 | 492 |
| 443 if (command_line->HasSwitch(::switches::kTestType)) | 493 if (command_line->HasSwitch(::switches::kTestType)) |
| 444 WizardController::SetZeroDelays(); | 494 WizardController::SetZeroDelays(); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 gfx::JPEGCodec::Encode( | 613 gfx::JPEGCodec::Encode( |
| 564 reinterpret_cast<unsigned char*>(image.getAddr32(0, 0)), | 614 reinterpret_cast<unsigned char*>(image.getAddr32(0, 0)), |
| 565 gfx::JPEGCodec::FORMAT_SkBitmap, | 615 gfx::JPEGCodec::FORMAT_SkBitmap, |
| 566 image.width(), | 616 image.width(), |
| 567 image.height(), | 617 image.height(), |
| 568 image.width() * image.bytesPerPixel(), | 618 image.width() * image.bytesPerPixel(), |
| 569 kDefaultEncodingQuality, &(*output)->data()); | 619 kDefaultEncodingQuality, &(*output)->data()); |
| 570 return true; | 620 return true; |
| 571 } | 621 } |
| 572 | 622 |
| 573 void WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, | 623 bool WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, |
| 574 const base::FilePath& path, | 624 const base::FilePath& path, |
| 575 ash::WallpaperLayout layout, | 625 ash::WallpaperLayout layout, |
| 576 int preferred_width, | 626 int preferred_width, |
| 577 int preferred_height) const { | 627 int preferred_height) const { |
| 578 if (layout == ash::WALLPAPER_LAYOUT_CENTER) { | 628 if (layout == ash::WALLPAPER_LAYOUT_CENTER) { |
| 579 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. | 629 // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. |
| 580 if (base::PathExists(path)) | 630 if (base::PathExists(path)) |
| 581 base::DeleteFile(path, false); | 631 base::DeleteFile(path, false); |
| 582 return; | 632 return false; |
| 583 } | 633 } |
| 584 scoped_refptr<base::RefCountedBytes> data; | 634 scoped_refptr<base::RefCountedBytes> data; |
| 585 if (ResizeWallpaper(wallpaper, layout, preferred_width, preferred_height, | 635 if (ResizeWallpaper(wallpaper, layout, preferred_width, preferred_height, |
| 586 &data)) { | 636 &data)) { |
| 587 SaveWallpaperInternal(path, | 637 return SaveWallpaperInternal( |
| 588 reinterpret_cast<const char*>(data->front()), | 638 path, reinterpret_cast<const char*>(data->front()), data->size()); |
| 589 data->size()); | |
| 590 } | 639 } |
| 640 return false; | |
| 591 } | 641 } |
| 592 | 642 |
| 593 bool WallpaperManager::IsPolicyControlled(const std::string& user_id) const { | 643 bool WallpaperManager::IsPolicyControlled(const std::string& user_id) const { |
| 594 chromeos::WallpaperInfo info; | 644 chromeos::WallpaperInfo info; |
| 595 if (!GetUserWallpaperInfo(user_id, &info)) | 645 if (!GetUserWallpaperInfo(user_id, &info)) |
| 596 return false; | 646 return false; |
| 597 return info.type == chromeos::User::POLICY; | 647 return info.type == chromeos::User::POLICY; |
| 598 } | 648 } |
| 599 | 649 |
| 600 void WallpaperManager::OnPolicySet(const std::string& policy, | 650 void WallpaperManager::OnPolicySet(const std::string& policy, |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 735 // There is no visible background in kiosk mode. | 785 // There is no visible background in kiosk mode. |
| 736 if (UserManager::Get()->IsLoggedInAsKioskApp()) | 786 if (UserManager::Get()->IsLoggedInAsKioskApp()) |
| 737 return; | 787 return; |
| 738 current_wallpaper_path_.clear(); | 788 current_wallpaper_path_.clear(); |
| 739 wallpaper_cache_.erase(user_id); | 789 wallpaper_cache_.erase(user_id); |
| 740 // Some browser tests do not have a shell instance. As no wallpaper is needed | 790 // 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 | 791 // in these tests anyway, avoid loading one, preventing crashes and speeding |
| 742 // up the tests. | 792 // up the tests. |
| 743 if (!ash::Shell::HasInstance()) | 793 if (!ash::Shell::HasInstance()) |
| 744 return; | 794 return; |
| 745 if (ash::Shell::GetInstance()->desktop_background_controller()-> | 795 |
| 746 SetDefaultWallpaper(UserManager::Get()->IsLoggedInAsGuest())) | 796 const bool is_guest = UserManager::Get()->IsLoggedInAsGuest(); |
| 747 loaded_wallpapers_++; | 797 |
| 798 if (is_guest) { | |
| 799 loaded_wallpapers_ += | |
| 800 ash::Shell::GetInstance() | |
| 801 ->desktop_background_controller() | |
| 802 ->SetDefaultWallpaper(guest_default_small_wallpaper_file_, | |
| 803 guest_default_large_wallpaper_file_); | |
| 804 } else { | |
| 805 loaded_wallpapers_ += | |
| 806 ash::Shell::GetInstance() | |
| 807 ->desktop_background_controller() | |
| 808 ->SetDefaultWallpaper(default_small_wallpaper_file_, | |
| 809 default_large_wallpaper_file_); | |
| 810 } | |
| 748 } | 811 } |
| 749 | 812 |
| 750 void WallpaperManager::InitInitialUserWallpaper(const std::string& user_id, | 813 void WallpaperManager::InitInitialUserWallpaper(const std::string& user_id, |
| 751 bool is_persistent) { | 814 bool is_persistent) { |
| 752 current_user_wallpaper_info_.file = ""; | 815 current_user_wallpaper_info_.file = ""; |
| 753 current_user_wallpaper_info_.layout = ash::WALLPAPER_LAYOUT_CENTER_CROPPED; | 816 current_user_wallpaper_info_.layout = ash::WALLPAPER_LAYOUT_CENTER_CROPPED; |
| 754 current_user_wallpaper_info_.type = User::DEFAULT; | 817 current_user_wallpaper_info_.type = User::DEFAULT; |
| 755 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight(); | 818 current_user_wallpaper_info_.date = base::Time::Now().LocalMidnight(); |
| 756 | 819 |
| 757 WallpaperInfo info = current_user_wallpaper_info_; | 820 WallpaperInfo info = current_user_wallpaper_info_; |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1063 dir = GetCustomWallpaperDir(kOriginalWallpaperSubDir); | 1126 dir = GetCustomWallpaperDir(kOriginalWallpaperSubDir); |
| 1064 dir = dir.Append(user_id_hash); | 1127 dir = dir.Append(user_id_hash); |
| 1065 if (!base::PathExists(dir)) | 1128 if (!base::PathExists(dir)) |
| 1066 base::CreateDirectory(dir); | 1129 base::CreateDirectory(dir); |
| 1067 dir = GetCustomWallpaperDir(kThumbnailWallpaperSubDir); | 1130 dir = GetCustomWallpaperDir(kThumbnailWallpaperSubDir); |
| 1068 dir = dir.Append(user_id_hash); | 1131 dir = dir.Append(user_id_hash); |
| 1069 if (!base::PathExists(dir)) | 1132 if (!base::PathExists(dir)) |
| 1070 base::CreateDirectory(dir); | 1133 base::CreateDirectory(dir); |
| 1071 } | 1134 } |
| 1072 | 1135 |
| 1136 void WallpaperManager::set_command_line_for_testing( | |
| 1137 base::CommandLine* command_line) { | |
| 1138 command_line_for_testing_ = command_line; | |
| 1139 SetDefaultWallpaperPathFromCommandLine(command_line); | |
| 1140 } | |
| 1141 | |
| 1073 CommandLine* WallpaperManager::GetComandLine() { | 1142 CommandLine* WallpaperManager::GetComandLine() { |
| 1074 CommandLine* command_line = command_line_for_testing_ ? | 1143 CommandLine* command_line = command_line_for_testing_ ? |
| 1075 command_line_for_testing_ : CommandLine::ForCurrentProcess(); | 1144 command_line_for_testing_ : CommandLine::ForCurrentProcess(); |
| 1076 return command_line; | 1145 return command_line; |
| 1077 } | 1146 } |
| 1078 | 1147 |
| 1079 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { | 1148 void WallpaperManager::InitializeRegisteredDeviceWallpaper() { |
| 1080 if (UserManager::Get()->IsUserLoggedIn()) | 1149 if (UserManager::Get()->IsUserLoggedIn()) |
| 1081 return; | 1150 return; |
| 1082 | 1151 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1371 ash::kLargeWallpaperMaxWidth, | 1440 ash::kLargeWallpaperMaxWidth, |
| 1372 ash::kLargeWallpaperMaxHeight); | 1441 ash::kLargeWallpaperMaxHeight); |
| 1373 DeleteAllExcept(large_wallpaper_path); | 1442 DeleteAllExcept(large_wallpaper_path); |
| 1374 } | 1443 } |
| 1375 | 1444 |
| 1376 void WallpaperManager::RecordUma(User::WallpaperType type, int index) const { | 1445 void WallpaperManager::RecordUma(User::WallpaperType type, int index) const { |
| 1377 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", type, | 1446 UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", type, |
| 1378 User::WALLPAPER_TYPE_COUNT); | 1447 User::WALLPAPER_TYPE_COUNT); |
| 1379 } | 1448 } |
| 1380 | 1449 |
| 1381 void WallpaperManager::SaveWallpaperInternal(const base::FilePath& path, | 1450 bool WallpaperManager::SaveWallpaperInternal(const base::FilePath& path, |
| 1382 const char* data, | 1451 const char* data, |
| 1383 int size) const { | 1452 int size) const { |
| 1384 int written_bytes = base::WriteFile(path, data, size); | 1453 int written_bytes = base::WriteFile(path, data, size); |
| 1385 DCHECK(written_bytes == size); | 1454 return written_bytes == size; |
| 1386 } | 1455 } |
| 1387 | 1456 |
| 1388 void WallpaperManager::StartLoad(const std::string& user_id, | 1457 void WallpaperManager::StartLoad(const std::string& user_id, |
| 1389 const WallpaperInfo& info, | 1458 const WallpaperInfo& info, |
| 1390 bool update_wallpaper, | 1459 bool update_wallpaper, |
| 1391 const base::FilePath& wallpaper_path, | 1460 const base::FilePath& wallpaper_path, |
| 1392 MovableOnDestroyCallbackHolder on_finish) { | 1461 MovableOnDestroyCallbackHolder on_finish) { |
| 1393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1394 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); | 1463 TRACE_EVENT_ASYNC_BEGIN0("ui", "LoadAndDecodeWallpaper", this); |
| 1395 | 1464 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1448 if (!pending_inactive_) { | 1517 if (!pending_inactive_) { |
| 1449 loading_.push_back(new WallpaperManager::PendingWallpaper( | 1518 loading_.push_back(new WallpaperManager::PendingWallpaper( |
| 1450 (delayed ? GetWallpaperLoadDelay() | 1519 (delayed ? GetWallpaperLoadDelay() |
| 1451 : base::TimeDelta::FromMilliseconds(0)), | 1520 : base::TimeDelta::FromMilliseconds(0)), |
| 1452 user_id)); | 1521 user_id)); |
| 1453 pending_inactive_ = loading_.back(); | 1522 pending_inactive_ = loading_.back(); |
| 1454 } | 1523 } |
| 1455 return pending_inactive_; | 1524 return pending_inactive_; |
| 1456 } | 1525 } |
| 1457 | 1526 |
| 1527 // static | |
| 1528 base::FilePath WallpaperManager::GetCustomizedWallpaperDefaultRescaledFileName( | |
| 1529 const char* suffix) { | |
| 1530 const base::FilePath default_downloaded_file_name = | |
| 1531 ServicesCustomizationDocument::GetCustomizedWallpaperDownloadedFileName(); | |
| 1532 const base::FilePath default_cache_dir = | |
| 1533 ServicesCustomizationDocument::GetCustomizedWallpaperCacheDir(); | |
| 1534 if (default_downloaded_file_name.empty() || default_cache_dir.empty()) | |
| 1535 return base::FilePath(); | |
| 1536 return default_cache_dir.Append( | |
| 1537 default_downloaded_file_name.BaseName().value() + suffix); | |
| 1538 } | |
| 1539 | |
| 1540 void WallpaperManager::SetCustomizedDefaultWallpaper( | |
| 1541 const GURL& wallpaper_url, | |
| 1542 const base::FilePath& downloaded_file, | |
| 1543 const base::FilePath& resized_directory) { | |
| 1544 // Should fail if this ever happens in tests. | |
| 1545 DCHECK(wallpaper_url.is_valid() || wallpaper_url.is_empty()); | |
| 1546 if (!wallpaper_url.is_valid()) { | |
| 1547 if (!wallpaper_url.is_empty()) { | |
| 1548 LOG(WARNING) << "Invalid Customized Wallpaper URL."; | |
| 1549 } | |
| 1550 return; | |
| 1551 } | |
| 1552 std::string downloaded_file_name = downloaded_file.BaseName().value(); | |
| 1553 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files( | |
| 1554 new CustomizedWallpaperRescaledFiles( | |
| 1555 resized_directory.Append(downloaded_file_name + | |
| 1556 kOriginalWallpaperSuffix), | |
| 1557 resized_directory.Append(downloaded_file_name + | |
| 1558 kSmallWallpaperSuffix), | |
| 1559 resized_directory.Append(downloaded_file_name + | |
| 1560 kLargeWallpaperSuffix))); | |
| 1561 scoped_ptr<CustomizedWallpaperFilesExist> exist( | |
| 1562 new CustomizedWallpaperFilesExist); | |
| 1563 | |
| 1564 base::Closure check_file_exists = | |
| 1565 base::Bind(&CheckCustomizedWallpaperFilesExist, | |
| 1566 downloaded_file, | |
| 1567 base::Unretained(rescaled_files.get()), | |
| 1568 base::Unretained(exist.get())); | |
| 1569 base::Closure on_checked_closure = | |
| 1570 base::Bind(&WallpaperManager::SetCustomizedDefaultWallpaperAfterCheck, | |
| 1571 weak_factory_.GetWeakPtr(), | |
| 1572 wallpaper_url, | |
| 1573 downloaded_file, | |
| 1574 base::Passed(rescaled_files.Pass()), | |
| 1575 base::Passed(exist.Pass())); | |
| 1576 if (!content::BrowserThread::PostBlockingPoolTaskAndReply( | |
| 1577 FROM_HERE, check_file_exists, on_checked_closure)) { | |
| 1578 LOG(WARNING) << "Failed to start check CheckCustomizedWallpaperFilesExist."; | |
| 1579 } | |
| 1580 } | |
| 1581 | |
| 1582 void WallpaperManager::ResizeCustomizedDefaultWallpaper( | |
| 1583 scoped_ptr<gfx::ImageSkia> image, | |
| 1584 const UserImage::RawImage& raw_image, | |
| 1585 const CustomizedWallpaperRescaledFiles* rescaled_files, | |
| 1586 bool* success) { | |
| 1587 DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( | |
| 1588 sequence_token_)); | |
| 1589 UserImage wallpaper(*image.get(), raw_image); | |
| 1590 | |
| 1591 *success = false; | |
| 1592 | |
| 1593 // Re-encode orginal file to jpeg format and save the result for debug | |
|
Daniel Erat
2014/03/25 21:58:29
i don't understand the "for debug" here. how likel
Alexander Alekseev
2014/03/27 00:28:37
No, I never compare the results. It just seems use
| |
| 1594 // (if downloaded file was corrupted, path_rescaled_original will be | |
| 1595 // different from the downloaded). | |
| 1596 *success |= ResizeAndSaveWallpaper(wallpaper, | |
|
Daniel Erat
2014/03/25 21:58:29
shouldn't all of the resizes need to succeed for t
Alexander Alekseev
2014/03/27 00:28:37
Done.
| |
| 1597 rescaled_files->path_rescaled_original, | |
| 1598 ash::WALLPAPER_LAYOUT_STRETCH, | |
| 1599 wallpaper.image().width(), | |
| 1600 wallpaper.image().height()); | |
| 1601 | |
| 1602 *success |= ResizeAndSaveWallpaper(wallpaper, | |
| 1603 rescaled_files->path_rescaled_small, | |
| 1604 ash::WALLPAPER_LAYOUT_STRETCH, | |
| 1605 ash::kSmallWallpaperMaxWidth, | |
| 1606 ash::kSmallWallpaperMaxHeight); | |
| 1607 | |
| 1608 *success |= ResizeAndSaveWallpaper(wallpaper, | |
| 1609 rescaled_files->path_rescaled_large, | |
| 1610 ash::WALLPAPER_LAYOUT_STRETCH, | |
| 1611 ash::kLargeWallpaperMaxWidth, | |
| 1612 ash::kLargeWallpaperMaxHeight); | |
| 1613 } | |
| 1614 | |
| 1615 void WallpaperManager::OnCustomizedDefaultWallpaperResized( | |
| 1616 const GURL& wallpaper_url, | |
| 1617 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | |
| 1618 scoped_ptr<bool> success) { | |
| 1619 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1620 DCHECK(rescaled_files.get()); | |
| 1621 DCHECK(success.get()); | |
| 1622 if (!*success) { | |
| 1623 LOG(WARNING) << "Failed to save Resized Customized Default Wallpaper"; | |
| 1624 return; | |
| 1625 } | |
| 1626 PrefService* prefService = g_browser_process->local_state(); | |
|
Daniel Erat
2014/03/25 21:58:29
s/prefService/pref_service/
Alexander Alekseev
2014/03/27 00:28:37
Done.
| |
| 1627 prefService->SetString(prefs::kCustomizationDefaultWallpaperURL, | |
| 1628 wallpaper_url.spec()); | |
| 1629 SetDefaultWallpaperPath(rescaled_files->path_rescaled_small, | |
| 1630 rescaled_files->path_rescaled_large); | |
| 1631 VLOG(1) << "Customized Default Wallpaper applied."; | |
| 1632 } | |
| 1633 | |
| 1634 void WallpaperManager::OnCustomizedDefaultWallpaperDecoded( | |
| 1635 const GURL& wallpaper_url, | |
| 1636 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | |
| 1637 const UserImage& wallpaper) { | |
| 1638 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1639 | |
| 1640 // If decoded wallpaper is empty, we have probably failed to decode the file. | |
| 1641 if (wallpaper.image().isNull()) { | |
| 1642 LOG(WARNING) << "Failed to decode customized wallpaper."; | |
| 1643 return; | |
| 1644 } | |
| 1645 | |
| 1646 wallpaper.image().EnsureRepsForSupportedScales(); | |
| 1647 scoped_ptr<gfx::ImageSkia> deep_copy(wallpaper.image().DeepCopy()); | |
| 1648 | |
| 1649 scoped_ptr<bool> success(new bool(false)); | |
| 1650 | |
| 1651 // TODO(bshe): This may break if RawImage becomes RefCountedMemory. | |
| 1652 base::Closure resize_closure = | |
| 1653 base::Bind(&WallpaperManager::ResizeCustomizedDefaultWallpaper, | |
| 1654 base::Unretained(this), | |
| 1655 base::Passed(&deep_copy), | |
| 1656 wallpaper.raw_image(), | |
| 1657 base::Unretained(rescaled_files.get()), | |
| 1658 base::Unretained(success.get())); | |
| 1659 base::Closure on_resized_closure = | |
| 1660 base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperResized, | |
| 1661 weak_factory_.GetWeakPtr(), | |
| 1662 wallpaper_url, | |
| 1663 base::Passed(rescaled_files.Pass()), | |
| 1664 base::Passed(success.Pass())); | |
| 1665 | |
| 1666 if (!task_runner_->PostTaskAndReply( | |
| 1667 FROM_HERE, resize_closure, on_resized_closure)) { | |
| 1668 LOG(WARNING) << "Failed to start Customized Wallpaper resize."; | |
| 1669 } | |
| 1670 } | |
| 1671 | |
| 1672 void WallpaperManager::SetCustomizedDefaultWallpaperAfterCheck( | |
| 1673 const GURL& wallpaper_url, | |
| 1674 const base::FilePath& downloaded_file, | |
| 1675 scoped_ptr<CustomizedWallpaperRescaledFiles> rescaled_files, | |
| 1676 scoped_ptr<CustomizedWallpaperFilesExist> exist) { | |
| 1677 PrefService* prefService = g_browser_process->local_state(); | |
|
Daniel Erat
2014/03/25 21:58:29
s/prefService/pref_service/
Alexander Alekseev
2014/03/27 00:28:37
Done.
| |
| 1678 | |
| 1679 std::string current_url = | |
| 1680 prefService->GetString(prefs::kCustomizationDefaultWallpaperURL); | |
| 1681 if ((current_url != wallpaper_url.spec()) || (!exist->AllRescaledExist())) { | |
|
Daniel Erat
2014/03/25 21:58:29
nit: remove unnecessary parentheses
Alexander Alekseev
2014/03/27 00:28:37
Done.
| |
| 1682 DCHECK(exist->dowloaded); | |
| 1683 // Need rescale | |
| 1684 wallpaper_loader_->Start( | |
| 1685 downloaded_file.value(), | |
| 1686 0, // Do not crop. | |
| 1687 base::Bind(&WallpaperManager::OnCustomizedDefaultWallpaperDecoded, | |
| 1688 weak_factory_.GetWeakPtr(), | |
| 1689 wallpaper_url, | |
| 1690 base::Passed(rescaled_files.Pass()))); | |
| 1691 } else { | |
| 1692 SetDefaultWallpaperPath(rescaled_files->path_rescaled_small, | |
| 1693 rescaled_files->path_rescaled_large); | |
| 1694 } | |
| 1695 } | |
| 1696 | |
| 1697 // static | |
| 1698 bool WallpaperManager::ShouldUseCustomizedDefaultWallpaper() { | |
| 1699 PrefService* prefService = g_browser_process->local_state(); | |
|
Daniel Erat
2014/03/25 21:58:29
s/prefService/pref_service/
Alexander Alekseev
2014/03/27 00:28:37
Done.
| |
| 1700 | |
| 1701 return !(prefService->FindPreference(prefs::kCustomizationDefaultWallpaperURL) | |
| 1702 ->IsDefaultValue()); | |
| 1703 } | |
| 1704 | |
| 1705 void WallpaperManager::SetDefaultWallpaperPathFromCommandLine( | |
| 1706 base::CommandLine* command_line) { | |
| 1707 default_small_wallpaper_file_ = command_line->GetSwitchValuePath( | |
| 1708 ash::switches::kAshDefaultWallpaperSmall); | |
| 1709 default_large_wallpaper_file_ = command_line->GetSwitchValuePath( | |
| 1710 ash::switches::kAshDefaultWallpaperLarge); | |
| 1711 guest_default_small_wallpaper_file_ = | |
| 1712 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperSmall); | |
| 1713 guest_default_large_wallpaper_file_ = | |
| 1714 command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperLarge); | |
| 1715 } | |
| 1716 | |
| 1717 void WallpaperManager::SetDefaultWallpaperPath( | |
| 1718 const base::FilePath& default_small_wallpaper_file, | |
| 1719 const base::FilePath& default_large_wallpaper_file) { | |
| 1720 ash::DesktopBackgroundController* dbc = | |
| 1721 ash::Shell::GetInstance()->desktop_background_controller(); | |
| 1722 const bool need_reset = dbc->IsUsingDefaultWallpaper(); | |
|
Daniel Erat
2014/03/25 21:58:29
nit: you can just inline this below now:
if (db
Alexander Alekseev
2014/03/27 00:28:37
Done.
| |
| 1723 default_small_wallpaper_file_ = default_small_wallpaper_file; | |
| 1724 default_large_wallpaper_file_ = default_large_wallpaper_file; | |
| 1725 if (need_reset) { | |
| 1726 dbc->SetDefaultWallpaper(default_small_wallpaper_file, | |
| 1727 default_large_wallpaper_file); | |
| 1728 } | |
| 1729 } | |
| 1730 | |
| 1458 } // namespace chromeos | 1731 } // namespace chromeos |
| OLD | NEW |