Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Unified Diff: chrome/browser/chromeos/login/wallpaper_manager.cc

Issue 11415015: Remove use of index in wallpaper picker code and some refactor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Please review this patch Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 153ba8bcc9f354db6f45c294a0659d93a35fb4f0..7934a9148666286663c322c29331695075afb969 100644
--- a/chrome/browser/chromeos/login/wallpaper_manager.cc
+++ b/chrome/browser/chromeos/login/wallpaper_manager.cc
@@ -6,8 +6,6 @@
#include <vector>
-#include "ash/desktop_background/desktop_background_controller.h"
-#include "ash/desktop_background/desktop_background_resources.h"
#include "ash/shell.h"
#include "base/command_line.h"
#include "base/logging.h"
@@ -56,16 +54,6 @@ const int kThumbnailHeight = 80;
const int kCacheWallpaperDelayMs = 500;
-// Default wallpaper index used in OOBE (first boot).
-// Defined here because Chromium default index differs.
-// Also see ash::WallpaperInfo kDefaultWallpapers in
-// desktop_background_resources.cc
-#if defined(GOOGLE_CHROME_BUILD)
-const int kDefaultOOBEWallpaperIndex = 1; // IDR_AURA_WALLPAPERS_2_LANDSCAPE8
-#else
-const int kDefaultOOBEWallpaperIndex = 0; // IDR_AURA_WALLPAPERS_5_GRADIENT5
-#endif
-
// A dictionary pref that maps usernames to wallpaper properties.
const char kUserWallpapersProperties[] = "UserWallpapersProperties";
@@ -114,8 +102,6 @@ WallpaperManager* WallpaperManager::Get() {
WallpaperManager::WallpaperManager()
: loaded_wallpapers_(0),
- ALLOW_THIS_IN_INITIALIZER_LIST(current_default_wallpaper_index_(
- ash::GetInvalidWallpaperIndex())),
ALLOW_THIS_IN_INITIALIZER_LIST(wallpaper_loader_(
new UserImageLoader(ImageDecoder::ROBUST_JPEG_CODEC))),
should_cache_wallpaper_(false),
@@ -244,7 +230,7 @@ void WallpaperManager::InitializeWallpaper() {
if (!user_manager->IsUserLoggedIn()) {
if (!disable_new_oobe) {
if (!WizardController::IsDeviceRegistered()) {
- SetDefaultWallpaper(kDefaultOOBEWallpaperIndex);
+ SetDefaultWallpaper();
} else {
bool show_users = true;
bool result = CrosSettings::Get()->GetBoolean(
@@ -254,7 +240,7 @@ void WallpaperManager::InitializeWallpaper() {
const chromeos::UserList& users = user_manager->GetUsers();
if (!show_users || users.empty()) {
// Boot into sign in form, preload default wallpaper.
- SetDefaultWallpaper(kDefaultOOBEWallpaperIndex);
+ SetDefaultWallpaper();
return;
}
@@ -406,7 +392,7 @@ void WallpaperManager::SetCustomWallpaper(const std::string& username,
// If decoded wallpaper is empty, we are probably failed to decode the file.
// Use default wallpaper in this case.
if (wallpaper.image().isNull()) {
- SetDefaultWallpaper(ash::GetDefaultWallpaperIndex());
+ SetDefaultWallpaper();
return;
}
@@ -448,15 +434,26 @@ void WallpaperManager::SetCustomWallpaper(const std::string& username,
SetUserWallpaperInfo(username, info, is_persistent);
}
-void WallpaperManager::SetDefaultWallpaper(int index) {
+void WallpaperManager::SetDefaultWallpaper() {
+ ash::DesktopBackgroundController* controller =
+ ash::Shell::GetInstance()->desktop_background_controller();
+ ash::WallpaperResolution resolution = controller->GetAppropriateResolution();
+ ash::WallpaperInfo info;
+ if (UserManager::Get()->IsLoggedInAsGuest()) {
+ info = (resolution == ash::LARGE) ? ash::kGuestLargeWallpaper :
+ ash::kGuestSmallWallpaper;
+ } else {
+ info = (resolution == ash::LARGE) ? ash::kDefaultLargeWallpaper :
+ ash::kDefaultSmallWallpaper;
+ }
+
// Prevents loading of the same wallpaper as the currently loading/loaded one.
- if (current_default_wallpaper_index_ == index)
+ if (controller->GetWallpaperIDR() == info.idr)
return;
- current_default_wallpaper_index_ = index;
+
current_wallpaper_path_ = FilePath("");
loaded_wallpapers_++;
- ash::Shell::GetInstance()->desktop_background_controller()->
- SetDefaultWallpaper(index);
+ controller->SetDefaultWallpaper(info);
}
void WallpaperManager::SetInitialUserWallpaper(const std::string& username,
@@ -472,12 +469,8 @@ void WallpaperManager::SetInitialUserWallpaper(const std::string& username,
// Some browser tests do not have shell instance. And it is not necessary to
// create a wallpaper for these tests. Add HasInstance check to prevent tests
// crash and speed up the tests by avoid loading wallpaper.
- if (ash::Shell::HasInstance()) {
- if (username == kGuestUser)
- SetDefaultWallpaper(ash::GetGuestWallpaperIndex());
- else
- SetDefaultWallpaper(ash::GetDefaultWallpaperIndex());
- }
+ if (ash::Shell::HasInstance())
+ SetDefaultWallpaper();
}
void WallpaperManager::SetUserWallpaperInfo(const std::string& username,
@@ -509,7 +502,7 @@ void WallpaperManager::SetLastSelectedUser(
void WallpaperManager::SetUserWallpaper(const std::string& email) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (email == kGuestUser) {
- SetDefaultWallpaper(ash::GetGuestWallpaperIndex());
+ SetDefaultWallpaper();
return;
}
@@ -534,7 +527,6 @@ void WallpaperManager::SetUserWallpaper(const std::string& email) {
if (current_wallpaper_path_ == wallpaper_path)
return;
current_wallpaper_path_ = wallpaper_path;
- current_default_wallpaper_index_ = ash::GetInvalidWallpaperIndex();
loaded_wallpapers_++;
BrowserThread::PostTask(
@@ -548,7 +540,7 @@ void WallpaperManager::SetUserWallpaper(const std::string& email) {
if (info.file.empty()) {
// Uses default built-in wallpaper when file is empty. Eventually, we
// will only ship one built-in wallpaper in ChromeOS image.
- SetDefaultWallpaper(ash::GetDefaultWallpaperIndex());
+ SetDefaultWallpaper();
return;
}
@@ -560,10 +552,6 @@ void WallpaperManager::SetUserWallpaper(const std::string& email) {
}
}
-void WallpaperManager::SetSigninWallpaper() {
- SetDefaultWallpaper(kDefaultOOBEWallpaperIndex);
-}
-
void WallpaperManager::SetWallpaperFromImageSkia(
const gfx::ImageSkia& wallpaper,
ash::WallpaperLayout layout) {
@@ -699,10 +687,8 @@ void WallpaperManager::LoadWallpaper(const std::string& email,
wallpaper_path = wallpaper_dir.Append(file_name);
if (current_wallpaper_path_ == wallpaper_path)
return;
- if (update_wallpaper) {
+ if (update_wallpaper)
current_wallpaper_path_ = wallpaper_path;
- current_default_wallpaper_index_ = ash::GetInvalidWallpaperIndex();
- }
loaded_wallpapers_++;
StartLoad(email, info, update_wallpaper, wallpaper_path);
} else {
@@ -822,12 +808,8 @@ void WallpaperManager::OnWallpaperDecoded(const std::string& email,
};
SetUserWallpaperInfo(email, info, true);
- if (update_wallpaper) {
- SetDefaultWallpaper(ash::GetDefaultWallpaperIndex());
- } else {
- ash::Shell::GetInstance()->desktop_background_controller()->
- CacheDefaultWallpaper(ash::GetDefaultWallpaperIndex());
- }
+ if (update_wallpaper)
+ SetDefaultWallpaper();
return;
}
// Generate all reps before passing to another thread.
@@ -898,13 +880,6 @@ void WallpaperManager::SaveCustomWallpaper(const std::string& email,
void WallpaperManager::RecordUma(User::WallpaperType type, int index) {
UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.Type", type,
User::WALLPAPER_TYPE_COUNT);
- if (type == User::DEFAULT) {
- if (index >= 0) {
- // TODO(sschmitz): Remove "if" when the index for new UI is available.
- UMA_HISTOGRAM_ENUMERATION("Ash.Wallpaper.DefaultIndex", index,
- ash::GetWallpaperCount());
- }
- }
}
void WallpaperManager::SaveWallpaperInternal(const FilePath& path,

Powered by Google App Engine
This is Rietveld 408576698