Chromium Code Reviews| Index: chrome/browser/chromeos/login/wallpaper_manager.cc |
| diff --git a/chrome/browser/chromeos/login/wallpaper_manager.cc b/chrome/browser/chromeos/login/wallpaper_manager.cc |
| index a036ca9064fdbf43a1a63d07eba4e94046c9fc0f..6d430963d786160ceeed0aecd086bc12603c8074 100644 |
| --- a/chrome/browser/chromeos/login/wallpaper_manager.cc |
| +++ b/chrome/browser/chromeos/login/wallpaper_manager.cc |
| @@ -7,6 +7,8 @@ |
| #include <numeric> |
| #include <vector> |
| +#include "ash/ash_switches.h" |
| +#include "ash/desktop_background/desktop_background_controller.h" |
| #include "ash/shell.h" |
| #include "base/command_line.h" |
| #include "base/debug/trace_event.h" |
| @@ -27,6 +29,7 @@ |
| #include "base/values.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/chrome_notification_types.h" |
| +#include "chrome/browser/chromeos/customization_document.h" |
|
Daniel Erat
2014/03/31 22:25:46
did you mean to add this include in the next chang
Alexander Alekseev
2014/04/03 19:15:44
Done.
|
| #include "chrome/browser/chromeos/login/startup_utils.h" |
| #include "chrome/browser/chromeos/login/user.h" |
| #include "chrome/browser/chromeos/login/user_manager.h" |
| @@ -46,6 +49,8 @@ |
| using content::BrowserThread; |
| +namespace chromeos { |
| + |
| namespace { |
| // The amount of delay before starts to move custom wallpapers to the new place. |
| @@ -114,8 +119,6 @@ bool MoveCustomWallpaperDirectory(const char* sub_dir, |
| } // namespace |
| -namespace chromeos { |
| - |
| const char kWallpaperSequenceTokenName[] = "wallpaper-sequence"; |
| const char kSmallWallpaperSuffix[] = "_small"; |
| @@ -208,9 +211,8 @@ void WallpaperManager::PendingWallpaper::ProcessRequest() { |
| if (default_) { |
| manager->DoSetDefaultWallpaper(user_id_, on_finish_.Pass()); |
| } else if (!user_wallpaper_.isNull()) { |
| - ash::Shell::GetInstance()-> |
| - desktop_background_controller()-> |
| - SetCustomWallpaper(user_wallpaper_, info_.layout); |
| + ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaper( |
| + user_wallpaper_, info_.layout); |
| } else if (!wallpaper_path_.empty()) { |
| manager->task_runner_->PostTask( |
| FROM_HERE, |
| @@ -306,6 +308,8 @@ WallpaperManager::WallpaperManager() |
| should_cache_wallpaper_(false), |
| weak_factory_(this), |
| pending_inactive_(NULL) { |
| + SetDefaultWallpaperPathFromCommandLine( |
| + base::CommandLine::ForCurrentProcess()); |
| registrar_.Add(this, |
| chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| content::NotificationService::AllSources()); |
| @@ -520,7 +524,8 @@ bool WallpaperManager::ResizeWallpaper( |
| ash::WallpaperLayout layout, |
| int preferred_width, |
| int preferred_height, |
| - scoped_refptr<base::RefCountedBytes>* output) const { |
| + scoped_refptr<base::RefCountedBytes>* output, |
| + gfx::ImageSkia* output_skia) const { |
| DCHECK(BrowserThread::GetBlockingPool()-> |
| IsRunningSequenceOnCurrentThread(sequence_token_)); |
| int width = wallpaper.image().width(); |
| @@ -567,27 +572,38 @@ bool WallpaperManager::ResizeWallpaper( |
| image.height(), |
| image.width() * image.bytesPerPixel(), |
| kDefaultEncodingQuality, &(*output)->data()); |
| + |
| + if (output_skia) { |
| + resized_image.MakeThreadSafe(); |
| + *output_skia = resized_image; |
| + } |
| + |
| return true; |
| } |
| -void WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, |
| +bool WallpaperManager::ResizeAndSaveWallpaper(const UserImage& wallpaper, |
| const base::FilePath& path, |
| ash::WallpaperLayout layout, |
| int preferred_width, |
| - int preferred_height) const { |
| + int preferred_height, |
| + gfx::ImageSkia* result) const { |
| if (layout == ash::WALLPAPER_LAYOUT_CENTER) { |
| // TODO(bshe): Generates cropped custom wallpaper for CENTER layout. |
| if (base::PathExists(path)) |
| base::DeleteFile(path, false); |
| - return; |
| + return false; |
| } |
| scoped_refptr<base::RefCountedBytes> data; |
| - if (ResizeWallpaper(wallpaper, layout, preferred_width, preferred_height, |
| - &data)) { |
| - SaveWallpaperInternal(path, |
| - reinterpret_cast<const char*>(data->front()), |
| - data->size()); |
| + if (ResizeWallpaper(wallpaper, |
| + layout, |
| + preferred_width, |
| + preferred_height, |
| + &data, |
| + result)) { |
| + return SaveWallpaperInternal( |
| + path, reinterpret_cast<const char*>(data->front()), data->size()); |
| } |
| + return false; |
| } |
| bool WallpaperManager::IsPolicyControlled(const std::string& user_id) const { |
| @@ -729,6 +745,31 @@ void WallpaperManager::SetDefaultWallpaperDelayed(const std::string& user_id) { |
| GetPendingWallpaper(user_id, true)->ResetSetDefaultWallpaper(); |
| } |
| +void WallpaperManager::OnDefaultWallpaperDecoded( |
| + const base::FilePath& path, |
| + scoped_ptr<gfx::ImageSkia>* result, |
| + MovableOnDestroyCallbackHolder on_finish, |
| + const UserImage& wallpaper) { |
| + result->reset(new gfx::ImageSkia); |
| + (**result) = wallpaper.image(); |
| + ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaper( |
| + wallpaper.image(), ash::WALLPAPER_LAYOUT_STRETCH); |
| +} |
| + |
| +void WallpaperManager::StartLoadAndSetDefaultWallpaper( |
| + const base::FilePath& path, |
| + scoped_ptr<gfx::ImageSkia>* result, |
| + MovableOnDestroyCallbackHolder on_finish) { |
|
bshe
2014/04/01 15:32:56
I dont see anywhere using wallpaper that packed in
Alexander Alekseev
2014/04/03 19:15:44
Done.
|
| + wallpaper_loader_->Start( |
| + path.value(), |
| + 0, // Do not crop. |
| + base::Bind(&WallpaperManager::OnDefaultWallpaperDecoded, |
| + base::Unretained(this), |
| + path, |
| + base::Unretained(result), |
| + base::Passed(on_finish.Pass()))); |
| +} |
| + |
| void WallpaperManager::DoSetDefaultWallpaper( |
| const std::string& user_id, |
| MovableOnDestroyCallbackHolder on_finish) { |
| @@ -742,9 +783,56 @@ void WallpaperManager::DoSetDefaultWallpaper( |
| // up the tests. |
| if (!ash::Shell::HasInstance()) |
| return; |
| - if (ash::Shell::GetInstance()->desktop_background_controller()-> |
| - SetDefaultWallpaper(UserManager::Get()->IsLoggedInAsGuest())) |
| - loaded_wallpapers_++; |
| + |
| + const bool is_guest = UserManager::Get()->IsLoggedInAsGuest(); |
| + |
| + gfx::ImageSkia image; |
| + |
| + ash::WallpaperResolution resolution = ash::Shell::GetInstance() |
| + ->desktop_background_controller() |
| + ->GetAppropriateResolution(); |
| + const bool use_small = (resolution == ash::WALLPAPER_RESOLUTION_SMALL); |
| + |
| + if (is_guest) { |
| + if (use_small) { |
| + if (guest_default_small_wallpaper_image_.get() == NULL) { |
|
Daniel Erat
2014/03/31 22:25:46
nit: just do "if (!guest_default_small_wallpaper_i
Alexander Alekseev
2014/04/03 19:15:44
Done.
|
| + StartLoadAndSetDefaultWallpaper(guest_default_small_wallpaper_file_, |
| + &guest_default_small_wallpaper_image_, |
| + on_finish.Pass()); |
| + return; |
| + } |
| + image = *guest_default_small_wallpaper_image_; |
| + } else { |
| + if (guest_default_large_wallpaper_image_.get() == NULL) { |
|
Daniel Erat
2014/03/31 22:25:46
there's a lot of duplicated code here. how about d
Alexander Alekseev
2014/04/03 19:15:44
Done.
|
| + StartLoadAndSetDefaultWallpaper(guest_default_large_wallpaper_file_, |
| + &guest_default_large_wallpaper_image_, |
| + on_finish.Pass()); |
| + return; |
| + } |
| + image = *guest_default_large_wallpaper_image_; |
| + } |
| + } else { |
| + // not guest |
| + if (use_small) { |
| + if (default_small_wallpaper_image_.get() == NULL) { |
| + StartLoadAndSetDefaultWallpaper(default_small_wallpaper_file_, |
| + &default_small_wallpaper_image_, |
| + on_finish.Pass()); |
| + return; |
| + } |
| + image = *default_small_wallpaper_image_; |
| + } else { |
| + if (default_large_wallpaper_image_.get() == NULL) { |
| + StartLoadAndSetDefaultWallpaper(default_large_wallpaper_file_, |
| + &default_large_wallpaper_image_, |
| + on_finish.Pass()); |
| + return; |
| + } |
| + image = *default_large_wallpaper_image_; |
| + } |
| + } |
| + ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaper( |
| + image, ash::WALLPAPER_LAYOUT_STRETCH); |
| } |
| void WallpaperManager::InitInitialUserWallpaper(const std::string& user_id, |
| @@ -1070,6 +1158,12 @@ void WallpaperManager::EnsureCustomWallpaperDirectories( |
| base::CreateDirectory(dir); |
| } |
| +void WallpaperManager::set_command_line_for_testing( |
| + base::CommandLine* command_line) { |
| + command_line_for_testing_ = command_line; |
| + SetDefaultWallpaperPathFromCommandLine(command_line); |
| +} |
| + |
| CommandLine* WallpaperManager::GetComandLine() { |
|
Daniel Erat
2014/03/31 22:25:46
s/Comand/Command/ (please fix this typo elsewhere
Alexander Alekseev
2014/04/03 19:15:44
Done.
|
| CommandLine* command_line = command_line_for_testing_ ? |
| command_line_for_testing_ : CommandLine::ForCurrentProcess(); |
| @@ -1321,8 +1415,8 @@ void WallpaperManager::OnWallpaperDecoded( |
| } |
| if (update_wallpaper) { |
| - ash::Shell::GetInstance()->desktop_background_controller()-> |
| - SetCustomWallpaper(wallpaper.image(), layout); |
| + ash::Shell::GetInstance()->desktop_background_controller()->SetWallpaper( |
| + wallpaper.image(), layout); |
| } |
| } |
| @@ -1357,19 +1451,27 @@ void WallpaperManager::SaveCustomWallpaper(const std::string& user_id_hash, |
| // Re-encode orginal file to jpeg format and saves the result in case that |
| // resized wallpaper is not generated (i.e. chrome shutdown before resized |
| // wallpaper is saved). |
| - ResizeAndSaveWallpaper(wallpaper, original_path, |
| + ResizeAndSaveWallpaper(wallpaper, |
| + original_path, |
| ash::WALLPAPER_LAYOUT_STRETCH, |
| wallpaper.image().width(), |
| - wallpaper.image().height()); |
| + wallpaper.image().height(), |
| + NULL); |
| DeleteAllExcept(original_path); |
| - ResizeAndSaveWallpaper(wallpaper, small_wallpaper_path, layout, |
| + ResizeAndSaveWallpaper(wallpaper, |
| + small_wallpaper_path, |
| + layout, |
| ash::kSmallWallpaperMaxWidth, |
| - ash::kSmallWallpaperMaxHeight); |
| + ash::kSmallWallpaperMaxHeight, |
| + NULL); |
| DeleteAllExcept(small_wallpaper_path); |
| - ResizeAndSaveWallpaper(wallpaper, large_wallpaper_path, layout, |
| + ResizeAndSaveWallpaper(wallpaper, |
| + large_wallpaper_path, |
| + layout, |
| ash::kLargeWallpaperMaxWidth, |
| - ash::kLargeWallpaperMaxHeight); |
| + ash::kLargeWallpaperMaxHeight, |
| + NULL); |
| DeleteAllExcept(large_wallpaper_path); |
| } |
| @@ -1378,11 +1480,11 @@ void WallpaperManager::RecordUma(User::WallpaperType type, int index) const { |
| User::WALLPAPER_TYPE_COUNT); |
| } |
| -void WallpaperManager::SaveWallpaperInternal(const base::FilePath& path, |
| +bool WallpaperManager::SaveWallpaperInternal(const base::FilePath& path, |
| const char* data, |
| int size) const { |
| int written_bytes = base::WriteFile(path, data, size); |
| - DCHECK(written_bytes == size); |
| + return written_bytes == size; |
| } |
| void WallpaperManager::StartLoad(const std::string& user_id, |
| @@ -1455,4 +1557,16 @@ WallpaperManager::PendingWallpaper* WallpaperManager::GetPendingWallpaper( |
| return pending_inactive_; |
| } |
| +void WallpaperManager::SetDefaultWallpaperPathFromCommandLine( |
| + base::CommandLine* command_line) { |
| + default_small_wallpaper_file_ = command_line->GetSwitchValuePath( |
| + ash::switches::kAshDefaultWallpaperSmall); |
| + default_large_wallpaper_file_ = command_line->GetSwitchValuePath( |
| + ash::switches::kAshDefaultWallpaperLarge); |
| + guest_default_small_wallpaper_file_ = |
| + command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperSmall); |
| + guest_default_large_wallpaper_file_ = |
| + command_line->GetSwitchValuePath(ash::switches::kAshGuestWallpaperLarge); |
| +} |
| + |
| } // namespace chromeos |