diff options
16 files changed, 292 insertions, 63 deletions
diff --git a/ash/desktop_background/desktop_background_resources.cc b/ash/desktop_background/desktop_background_resources.cc index 8219624..64392e5 100644 --- a/ash/desktop_background/desktop_background_resources.cc +++ b/ash/desktop_background/desktop_background_resources.cc @@ -244,14 +244,6 @@ const int kGuestWallpaperIndex = kDefaultWallpaperIndex; namespace ash { -int GetSolidColorIndex() { - return kSolidColorIndex; -} - -int GetInvalidWallpaperIndex() { - return kInvalidWallpaperIndex; -} - int GetDefaultWallpaperIndex() { DCHECK(kDefaultWallpaperIndex < kDefaultWallpaperCount); return std::min(kDefaultWallpaperIndex, kDefaultWallpaperCount - 1); @@ -262,10 +254,17 @@ int GetGuestWallpaperIndex() { return std::min(kGuestWallpaperIndex, kDefaultWallpaperCount - 1); } -int GetRandomWallpaperIndex() { +int GetInvalidWallpaperIndex() { + return kInvalidWallpaperIndex; +} + +int GetNextWallpaperIndex(int index) { DCHECK(kLastRandomWallpaperIndex < kDefaultWallpaperCount); - return base::RandInt(0, - std::min(kLastRandomWallpaperIndex, kDefaultWallpaperCount - 1)); + return (index + 1) % (kLastRandomWallpaperIndex + 1); +} + +int GetSolidColorIndex() { + return kSolidColorIndex; } int GetWallpaperCount() { diff --git a/ash/desktop_background/desktop_background_resources.h b/ash/desktop_background/desktop_background_resources.h index a25afa2..7c14ce6 100644 --- a/ash/desktop_background/desktop_background_resources.h +++ b/ash/desktop_background/desktop_background_resources.h @@ -29,11 +29,11 @@ struct ASH_EXPORT WallpaperInfo { const SkColor kLoginWallpaperColor = 0xFEFEFE; -ASH_EXPORT int GetSolidColorIndex(); -ASH_EXPORT int GetInvalidWallpaperIndex(); ASH_EXPORT int GetDefaultWallpaperIndex(); ASH_EXPORT int GetGuestWallpaperIndex(); -ASH_EXPORT int GetRandomWallpaperIndex(); +ASH_EXPORT int GetInvalidWallpaperIndex(); +ASH_EXPORT int GetNextWallpaperIndex(int index); +ASH_EXPORT int GetSolidColorIndex(); ASH_EXPORT int GetWallpaperCount(); ASH_EXPORT const WallpaperInfo& GetWallpaperInfo(int index); diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index ba3aad2..ce447a7 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -13655,8 +13655,8 @@ Press any key to continue exploring. <message name="IDS_OPTIONS_SET_WALLPAPER_AUTHOR_TEXT" desc="Author label."> Photo by </message> - <message name="IDS_OPTIONS_SET_WALLPAPER_RANDOM" desc="Label for option to randomly choose wallpaper at login."> - I'm feeling lucky + <message name="IDS_OPTIONS_SET_WALLPAPER_DAILY" desc="Label for option to change wallpaper daily."> + Change wallpaper daily </message> <message name="IDS_OPTIONS_WALLPAPER_CENTER_LAYOUT" desc="Label for option to center a customized wallpaper."> Center diff --git a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc index 04b51e3..280082a 100644 --- a/chrome/browser/chromeos/chrome_browser_main_chromeos.cc +++ b/chrome/browser/chromeos/chrome_browser_main_chromeos.cc @@ -36,6 +36,7 @@ #include "chrome/browser/chromeos/login/screen_locker.h" #include "chrome/browser/chromeos/login/session_manager_observer.h" #include "chrome/browser/chromeos/login/user_manager.h" +#include "chrome/browser/chromeos/login/wallpaper_manager.h" #include "chrome/browser/chromeos/low_memory_observer.h" #include "chrome/browser/chromeos/net/cros_network_change_notifier_factory.h" #include "chrome/browser/chromeos/net/network_change_notifier_chromeos.h" @@ -262,6 +263,10 @@ void ChromeBrowserMainPartsChromeos::PostMainMessageLoopStart() { // Initialize DBusThreadManager for the browser. This must be done after // the main message loop is started, as it uses the message loop. chromeos::DBusThreadManager::Initialize(); + // Add PowerManagerClient observer for WallpaperManager. WallpaperManager + // is initialized before DBusThreadManager. + chromeos::WallpaperManager::Get()->AddPowerManagerClientObserver(); + chromeos::CrosDBusService::Initialize(); // Initialize the session manager observer so that we'll take actions diff --git a/chrome/browser/chromeos/login/mock_user_manager.h b/chrome/browser/chromeos/login/mock_user_manager.h index 71db774..134e93c 100644 --- a/chrome/browser/chromeos/login/mock_user_manager.h +++ b/chrome/browser/chromeos/login/mock_user_manager.h @@ -40,8 +40,9 @@ class MockUserManager : public UserManager { MOCK_CONST_METHOD1(GetUserDisplayName, string16(const std::string&)); MOCK_METHOD2(SaveUserDisplayEmail, void(const std::string&, const std::string&)); - MOCK_METHOD2(GetLoggedInUserWallpaperProperties, void(User::WallpaperType*, - int*)); + MOCK_METHOD3(GetLoggedInUserWallpaperProperties, void(User::WallpaperType*, + int*, + base::Time*)); MOCK_METHOD2(SaveLoggedInUserWallpaperProperties, void(User::WallpaperType, int)); MOCK_CONST_METHOD1(GetUserDisplayEmail, std::string(const std::string&)); diff --git a/chrome/browser/chromeos/login/user.h b/chrome/browser/chromeos/login/user.h index a4377ab..a5c0cfb 100644 --- a/chrome/browser/chromeos/login/user.h +++ b/chrome/browser/chromeos/login/user.h @@ -43,7 +43,7 @@ class User { static const int kInvalidImageIndex = -3; enum WallpaperType { - RANDOM = 0, + DAILY = 0, CUSTOMIZED = 1, DEFAULT = 2, UNKNOWN = 3 diff --git a/chrome/browser/chromeos/login/user_manager.h b/chrome/browser/chromeos/login/user_manager.h index fe3f539..1b6712b 100644 --- a/chrome/browser/chromeos/login/user_manager.h +++ b/chrome/browser/chromeos/login/user_manager.h @@ -10,6 +10,7 @@ #include "ash/desktop_background/desktop_background_resources.h" #include "base/memory/singleton.h" +#include "base/time.h" #include "chrome/browser/chromeos/login/user.h" #include "chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.h" @@ -174,7 +175,8 @@ class UserManager { // Sets |type| and |index| to the value saved in local state for logged in // user. virtual void GetLoggedInUserWallpaperProperties(User::WallpaperType* type, - int* index) = 0; + int* index, + base::Time* last_modification_date) = 0; // Saves |type| and |index| chose by logged in user to Local State. virtual void SaveLoggedInUserWallpaperProperties(User::WallpaperType type, diff --git a/chrome/browser/chromeos/login/user_manager_impl.cc b/chrome/browser/chromeos/login/user_manager_impl.cc index d74b410..c22ef19 100644 --- a/chrome/browser/chromeos/login/user_manager_impl.cc +++ b/chrome/browser/chromeos/login/user_manager_impl.cc @@ -19,6 +19,7 @@ #include "base/path_service.h" #include "base/rand_util.h" #include "base/stl_util.h" +#include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/stringprintf.h" #include "base/time.h" @@ -79,6 +80,7 @@ const char kImageURLNodeName[] = "url"; const char kWallpaperTypeNodeName[] = "type"; const char kWallpaperIndexNodeName[] = "index"; +const char kWallpaperDateNodeName[] = "date"; // Default wallpaper index used in OOBE (first boot). // Defined here because Chromium default index differs. @@ -442,12 +444,11 @@ void UserManagerImpl::UserSelected(const std::string& email) { if (IsKnownUser(email)) { User::WallpaperType type; int index; - GetUserWallpaperProperties(email, &type, &index); - if (type == User::RANDOM) { - // Generate a new random wallpaper index if the selected user chose - // RANDOM wallpaper. - index = ash::GetRandomWallpaperIndex(); - SaveUserWallpaperProperties(email, User::RANDOM, index); + base::Time date; + GetUserWallpaperProperties(email, &type, &index, &date); + if (type == User::DAILY && date != base::Time::Now().LocalMidnight()) { + index = ash::GetNextWallpaperIndex(index); + SaveUserWallpaperProperties(email, User::DAILY, index); } else if (type == User::CUSTOMIZED) { std::string wallpaper_path = GetWallpaperPathForUser(email, false).value(); @@ -463,6 +464,7 @@ void UserManagerImpl::UserSelected(const std::string& email) { } ash::Shell::GetInstance()->desktop_background_controller()-> SetDefaultWallpaper(index); + WallpaperManager::Get()->SetLastSelectedUser(email); } } @@ -946,7 +948,8 @@ void UserManagerImpl::EnsureUsersLoaded() { void UserManagerImpl::EnsureLoggedInUserWallpaperLoaded() { User::WallpaperType type; int index; - GetLoggedInUserWallpaperProperties(&type, &index); + base::Time last_modification_date; + GetLoggedInUserWallpaperProperties(&type, &index, &last_modification_date); if (type != current_user_wallpaper_type_ || index != current_user_wallpaper_index_) @@ -1118,7 +1121,8 @@ void UserManagerImpl::MigrateWallpaperData() { void UserManagerImpl::GetLoggedInUserWallpaperProperties( User::WallpaperType* type, - int* index) { + int* index, + base::Time* last_modification_date) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(logged_in_user_); @@ -1128,7 +1132,10 @@ void UserManagerImpl::GetLoggedInUserWallpaperProperties( return; } - GetUserWallpaperProperties(GetLoggedInUser().email(), type, index); + GetUserWallpaperProperties(GetLoggedInUser().email(), + type, + index, + last_modification_date); } void UserManagerImpl::SaveLoggedInUserWallpaperProperties( @@ -1170,8 +1177,9 @@ void UserManagerImpl::SetUserImage(const std::string& username, } void UserManagerImpl::GetUserWallpaperProperties(const std::string& username, - User::WallpaperType* type, - int* index) { + User::WallpaperType* type, + int* index, + base::Time* last_modification_date) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // Default to the values cached in memory. @@ -1191,6 +1199,13 @@ void UserManagerImpl::GetUserWallpaperProperties(const std::string& username, wallpaper_properties->GetInteger(kWallpaperTypeNodeName, reinterpret_cast<int*>(type)); wallpaper_properties->GetInteger(kWallpaperIndexNodeName, index); + std::string date_string; + int64 val; + if (!(wallpaper_properties->GetString(kWallpaperDateNodeName, + &date_string) && + base::StringToInt64(date_string, &val))) + val = 0; + *last_modification_date = base::Time::FromInternalValue(val); } } } @@ -1217,6 +1232,8 @@ void UserManagerImpl::SaveUserWallpaperProperties(const std::string& username, new base::FundamentalValue(type)); wallpaper_properties->Set(kWallpaperIndexNodeName, new base::FundamentalValue(index)); + wallpaper_properties->SetString(kWallpaperDateNodeName, + base::Int64ToString(base::Time::Now().LocalMidnight().ToInternalValue())); wallpaper_update->SetWithoutPathExpansion(username, wallpaper_properties); } diff --git a/chrome/browser/chromeos/login/user_manager_impl.h b/chrome/browser/chromeos/login/user_manager_impl.h index d3df8a3..6a2d03a 100644 --- a/chrome/browser/chromeos/login/user_manager_impl.h +++ b/chrome/browser/chromeos/login/user_manager_impl.h @@ -20,6 +20,7 @@ #include "chrome/browser/chromeos/login/user.h" #include "chrome/browser/chromeos/login/user_image_loader.h" #include "chrome/browser/chromeos/login/user_manager.h" +#include "chrome/browser/chromeos/login/wallpaper_manager.h" #include "chrome/browser/profiles/profile_downloader_delegate.h" #include "chrome/browser/sync/profile_sync_service_observer.h" #include "content/public/browser/notification_observer.h" @@ -73,7 +74,8 @@ class UserManagerImpl : public UserManager, virtual std::string GetUserDisplayEmail( const std::string& username) const OVERRIDE; virtual void GetLoggedInUserWallpaperProperties(User::WallpaperType* type, - int* index) OVERRIDE; + int* index, + base::Time* last_modification_date) OVERRIDE; virtual void SaveLoggedInUserWallpaperProperties(User::WallpaperType type, int index) OVERRIDE; virtual void SaveUserDefaultImageIndex(const std::string& username, @@ -126,6 +128,7 @@ class UserManagerImpl : public UserManager, private: friend class UserManagerImplWrapper; friend class UserManagerTest; + friend class WallpaperManager; // Loads |users_| from Local State if the list has not been loaded yet. // Subsequent calls have no effect. Must be called on the UI thread. @@ -174,7 +177,7 @@ class UserManagerImpl : public UserManager, // Migrate the old wallpaper index to a new wallpaper structure. // The new wallpaper structure is: - // { WallpaperType: RANDOM|CUSTOMIZED|DEFAULT, + // { WallpaperType: DAILY|CUSTOMIZED|DEFAULT, // index: index of the default wallpapers } void MigrateWallpaperData(); @@ -186,9 +189,14 @@ class UserManagerImpl : public UserManager, const GURL& image_url, const UserImage& user_image); + // Get wallpaper |type|, |index| and |last_modification_date| of |username| + // from local state. void GetUserWallpaperProperties(const std::string& username, User::WallpaperType* type, - int* index); + int* index, + base::Time* last_modification_date); + + // Set |username|'s wallpaper |type|, |index| and local date to local state. void SaveUserWallpaperProperties(const std::string& username, User::WallpaperType type, int index); @@ -339,6 +347,9 @@ class UserManagerImpl : public UserManager, // |false| if the value has not been read from trusted device policy yet. bool ephemeral_users_enabled_; + // True if user pod row is showed at login screen. + bool show_users_; + // Cached name of device owner. Defaults to empty string if the value has not // been read from trusted device policy yet. std::string owner_email_; diff --git a/chrome/browser/chromeos/login/wallpaper_manager.cc b/chrome/browser/chromeos/login/wallpaper_manager.cc new file mode 100644 index 0000000..95a3cb5 --- /dev/null +++ b/chrome/browser/chromeos/login/wallpaper_manager.cc @@ -0,0 +1,118 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/login/wallpaper_manager.h" + +#include "ash/desktop_background/desktop_background_resources.h" +#include "base/logging.h" +#include "base/time.h" +#include "base/values.h" +#include "chrome/browser/browser_process.h" +#include "chrome/browser/chromeos/cros_settings.h" +#include "chrome/browser/chromeos/login/user.h" +#include "chrome/browser/chromeos/login/user_manager.h" +#include "chrome/browser/chromeos/login/user_manager_impl.h" +#include "chrome/browser/prefs/pref_service.h" +#include "chromeos/dbus/dbus_thread_manager.h" +#include "chromeos/dbus/power_manager_client.h" + +namespace { +const int kWallpaperUpdateIntervalSec = 24 * 60 * 60; +} // namespace + +namespace chromeos { + +static WallpaperManager* g_wallpaper_manager = NULL; + +WallpaperManager::WallpaperManager() : last_selected_user_("") { + system::TimezoneSettings::GetInstance()->AddObserver(this); + RestartTimer(); +} + +WallpaperManager::~WallpaperManager() { + DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); + system::TimezoneSettings::GetInstance()->RemoveObserver(this); +} + +void WallpaperManager::SetLastSelectedUser(std::string last_selected_user) { + last_selected_user_ = last_selected_user; +} + +void WallpaperManager::AddPowerManagerClientObserver() { + if (!DBusThreadManager::Get()->GetPowerManagerClient()->HasObserver(this)) + DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); +} + +void WallpaperManager::RestartTimer() { + timer_.Stop(); + base::Time midnight = base::Time::Now().LocalMidnight(); + base::TimeDelta interval = base::Time::Now() - midnight; + int64 remaining_seconds = kWallpaperUpdateIntervalSec - interval.InSeconds(); + if (remaining_seconds <= 0) { + BatchUpdateWallpaper(); + } else { + // Set up a one shot timer which will batch update wallpaper at midnight. + timer_.Start(FROM_HERE, + base::TimeDelta::FromSeconds(remaining_seconds), + this, + &WallpaperManager::BatchUpdateWallpaper); + } +} + +void WallpaperManager::TimezoneChanged(const icu::TimeZone& timezone) { + RestartTimer(); +} + +void WallpaperManager::SystemResumed() { + BatchUpdateWallpaper(); +} + +void WallpaperManager::BatchUpdateWallpaper() { + PrefService* local_state = g_browser_process->local_state(); + UserManager* user_manager = UserManager::Get(); + bool show_users = true; + CrosSettings::Get()->GetBoolean( + kAccountsPrefShowUserNamesOnSignIn, &show_users); + if (local_state) { + User::WallpaperType type; + int index = 0; + base::Time last_modification_date; + const UserList& users = user_manager->GetUsers(); + for (UserList::const_iterator it = users.begin(); + it != users.end(); ++it) { + std::string email = (*it)->email(); + // TODO(bshe): Move GetUserWallpaperProperties() to this class. + static_cast<UserManagerImpl*>(user_manager)-> + GetUserWallpaperProperties(email, &type, &index, + &last_modification_date); + base::Time current_date = base::Time::Now().LocalMidnight(); + if (type == User::DAILY && current_date != last_modification_date) { + index = ash::GetNextWallpaperIndex(index); + // TODO(bshe): Move SaveUserWallpaperProperties() to this class. + static_cast<UserManagerImpl*>(user_manager)-> + SaveUserWallpaperProperties(email, type, index); + } + // Force a wallpaper update for logged in / last selected user. + // TODO(bshe): Notify lock screen, wallpaper picker UI to update wallpaper + // as well. + if (user_manager->IsUserLoggedIn() && + email == user_manager->GetLoggedInUser().email()) { + user_manager->UserSelected(email); + } else if (show_users && + email == last_selected_user_) { + user_manager->UserSelected(email); + } + } + } + RestartTimer(); +} + +// static +WallpaperManager* WallpaperManager::Get() { + if(!g_wallpaper_manager) + g_wallpaper_manager = new WallpaperManager(); + return g_wallpaper_manager; +} + +} // chromeos diff --git a/chrome/browser/chromeos/login/wallpaper_manager.h b/chrome/browser/chromeos/login/wallpaper_manager.h new file mode 100644 index 0000000..0c7062f --- /dev/null +++ b/chrome/browser/chromeos/login/wallpaper_manager.h @@ -0,0 +1,62 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ +#define CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ +#pragma once + +#include <string> + +#include "base/timer.h" +#include "chrome/browser/chromeos/power/resume_observer.h" +#include "chrome/browser/chromeos/system/timezone_settings.h" +#include "unicode/timezone.h" + +namespace chromeos { + +// This class maintains wallpapers for users who have logged into this Chrome +// OS device. +class WallpaperManager: public system::TimezoneSettings::Observer, + public chromeos::ResumeObserver { + public: + WallpaperManager(); + + static WallpaperManager* Get(); + + // Sets last selected user on user pod row. + void SetLastSelectedUser(std::string last_selected_user); + + // Adds PowerManagerClient observer. It needs to be added after + // PowerManagerClient initialized. + void AddPowerManagerClientObserver(); + + // Starts a one shot timer which calls BatchUpdateWallpaper at next midnight. + // Cancel any previous timer if any. + void RestartTimer(); + + private: + virtual ~WallpaperManager(); + + // Overridden from system::TimezoneSettings::Observer. + virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE; + + // Overridden from chromeos::ResumeObserver + virtual void SystemResumed() OVERRIDE; + + // Change the wallpapers for users who choose DAILY wallpaper type. Updates + // current wallpaper if it changed. This function should be called at exactly + // at 0am if chromeos device is on. + void BatchUpdateWallpaper(); + + // The last selected user on user pod row. + std::string last_selected_user_; + + base::OneShotTimer<WallpaperManager> timer_; + + DISALLOW_COPY_AND_ASSIGN(WallpaperManager); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_LOGIN_WALLPAPER_MANAGER_H_ diff --git a/chrome/browser/resources/options2/chromeos/set_wallpaper_options.html b/chrome/browser/resources/options2/chromeos/set_wallpaper_options.html index 2148a96..99e8b00 100644 --- a/chrome/browser/resources/options2/chromeos/set_wallpaper_options.html +++ b/chrome/browser/resources/options2/chromeos/set_wallpaper_options.html @@ -16,8 +16,8 @@ <div id="wallpaper-action-area" class="action-area"> <div class="checkbox" guest-visibility="disabled"> <label> - <input id="use-random-wallpaper" type="checkbox"> - <span i18n-content="randomCheckbox"></span> + <input id="use-daily-wallpaper" type="checkbox"> + <span i18n-content="dailyWallpaperLabel"></span> </label> </div> <div class="spacer"></div> diff --git a/chrome/browser/resources/options2/chromeos/set_wallpaper_options.js b/chrome/browser/resources/options2/chromeos/set_wallpaper_options.js index 8e9791b..57ad71c 100644 --- a/chrome/browser/resources/options2/chromeos/set_wallpaper_options.js +++ b/chrome/browser/resources/options2/chromeos/set_wallpaper_options.js @@ -51,7 +51,7 @@ cr.define('options', function() { $('set-wallpaper-layout').addEventListener('change', this.handleLayoutChange_); $('set-custom-wallpaper').onclick = this.handleChooseFile_; - $('use-random-wallpaper').onclick = this.handleCheckboxClick_.bind(this); + $('use-daily-wallpaper').onclick = this.handleCheckboxClick_.bind(this); $('set-wallpaper-overlay-confirm').onclick = function() { OptionsPage.closeOverlay(); }; @@ -188,10 +188,10 @@ cr.define('options', function() { */ handleCheckboxClick_: function() { var wallpaperGrid = $('wallpaper-grid'); - if ($('use-random-wallpaper').checked) { + if ($('use-daily-wallpaper').checked) { wallpaperGrid.disabled = true; $('attribution-label').hidden = false; - chrome.send('selectRandomWallpaper'); + chrome.send('selectDailyWallpaper'); wallpaperGrid.classList.add('grayout'); $('set-wallpaper-layout').hidden = true; } else { @@ -204,20 +204,19 @@ cr.define('options', function() { /** * Selects corresponding wallpaper thumbnail with the given URL and toggle - * the "I'm feeling lucky" checkbox. + * the "Change wallpaper daily..." checkbox. * @param {string} url URL of the wallpaper thumbnail to select. - * @param {boolean} isRandom True if user checked "I'm feeling lucky" + * @param {boolean} isDaily True if user checked "Change wallpaper daily..." * checkbox. * @private */ - setSelectedImage_: function(url, isRandom) { + setSelectedImage_: function(url, isDaily) { var wallpaperGrid = $('wallpaper-grid'); wallpaperGrid.selectedItemUrl = url; this.setWallpaperAttribution_(url); - if (isRandom) { - // Do not call chrome.send('selectRandomWallpaper'), it is not - // neccessary to generate a new random index here. - $('use-random-wallpaper').checked = true; + if (isDaily) { + // Do not call chrome.send('selectDailyWallpaper'). + $('use-daily-wallpaper').checked = true; wallpaperGrid.disabled = true; wallpaperGrid.classList.add('grayout'); } @@ -242,14 +241,14 @@ cr.define('options', function() { }, /** - * Display layout drop down box and disable random mode if enabled. Called + * Display layout drop down box and disable daily mode if enabled. Called * when user select a valid file from file system. */ didSelectFile_: function() { $('set-wallpaper-layout').hidden = false; var wallpaperGrid = $('wallpaper-grid'); - if ($('use-random-wallpaper').checked) { - $('use-random-wallpaper').checked = false; + if ($('use-daily-wallpaper').checked) { + $('use-daily-wallpaper').checked = false; wallpaperGrid.disabled = false; wallpaperGrid.classList.remove('grayout'); } diff --git a/chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.cc b/chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.cc index a7f7c78..ecef6d7 100644 --- a/chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.cc +++ b/chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.cc @@ -65,8 +65,8 @@ void SetWallpaperOptionsHandler::GetLocalizedValues( l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_DIALOG_TEXT)); localized_strings->SetString("setWallpaperAuthor", l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_AUTHOR_TEXT)); - localized_strings->SetString("randomCheckbox", - l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_RANDOM)); + localized_strings->SetString("dailyWallpaperLabel", + l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_DAILY)); localized_strings->SetString("customWallpaper", l10n_util::GetStringUTF16(IDS_OPTIONS_CUSTOME_WALLPAPER)); } @@ -81,8 +81,8 @@ void SetWallpaperOptionsHandler::RegisterMessages() { web_ui()->RegisterMessageCallback("selectDefaultWallpaper", base::Bind(&SetWallpaperOptionsHandler::HandleDefaultWallpaper, base::Unretained(this))); - web_ui()->RegisterMessageCallback("selectRandomWallpaper", - base::Bind(&SetWallpaperOptionsHandler::HandleRandomWallpaper, + web_ui()->RegisterMessageCallback("selectDailyWallpaper", + base::Bind(&SetWallpaperOptionsHandler::HandleDailyWallpaper, base::Unretained(this))); web_ui()->RegisterMessageCallback("chooseWallpaper", base::Bind(&SetWallpaperOptionsHandler::HandleChooseFile, @@ -161,9 +161,17 @@ void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) { DCHECK(args && args->empty()); User::WallpaperType type; int index; - UserManager::Get()->GetLoggedInUserWallpaperProperties(&type, &index); + base::Time date; + UserManager::Get()->GetLoggedInUserWallpaperProperties(&type, &index, &date); + if (type == User::DAILY && date != base::Time::Now().LocalMidnight()) { + index = ash::GetNextWallpaperIndex(index); + UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DAILY, + index); + ash::Shell::GetInstance()->user_wallpaper_delegate()-> + InitializeWallpaper(); + } base::StringValue image_url(GetDefaultWallpaperThumbnailURL(index)); - base::FundamentalValue is_random(type == User::RANDOM); + base::FundamentalValue is_daily(type == User::DAILY); if (type == User::CUSTOMIZED) { ash::WallpaperLayout layout = static_cast<ash::WallpaperLayout>(index); SendLayoutOptions(layout); @@ -171,7 +179,7 @@ void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) { } else { SendLayoutOptions(ash::CENTER_CROPPED); web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage", - image_url, is_random); + image_url, is_daily); } } @@ -224,15 +232,20 @@ void SetWallpaperOptionsHandler::HandleDefaultWallpaper(const ListValue* args) { } } -void SetWallpaperOptionsHandler::HandleRandomWallpaper(const ListValue* args) { - int index = ash::GetRandomWallpaperIndex(); - UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::RANDOM, index); +void SetWallpaperOptionsHandler::HandleDailyWallpaper(const ListValue* args) { + User::WallpaperType type; + int index; + base::Time date; + UserManager::Get()->GetLoggedInUserWallpaperProperties(&type, &index, &date); + if (date != base::Time::Now().LocalMidnight()) + index = ash::GetNextWallpaperIndex(index); + UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DAILY, index); ash::Shell::GetInstance()->desktop_background_controller()-> SetDefaultWallpaper(index); base::StringValue image_url(GetDefaultWallpaperThumbnailURL(index)); - base::FundamentalValue is_random(true); + base::FundamentalValue is_daily(true); web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage", - image_url, is_random); + image_url, is_daily); } gfx::NativeWindow SetWallpaperOptionsHandler::GetBrowserWindow() const { diff --git a/chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.h b/chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.h index 6bcf981..6c8907e 100644 --- a/chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.h +++ b/chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.h @@ -76,8 +76,8 @@ class SetWallpaperOptionsHandler : public ::options2::OptionsPageUIHandler, // Selects one of the available default wallpapers. void HandleDefaultWallpaper(const base::ListValue* args); - // Sets user wallpaper to a random one from the default wallpapers. - void HandleRandomWallpaper(const base::ListValue* args); + // Sets user wallpaper to the next one in the list of default wallpapers. + void HandleDailyWallpaper(const base::ListValue* args); // Returns handle to browser window or NULL if it can't be found. gfx::NativeWindow GetBrowserWindow() const; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 4da3d6b..a797d39 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -758,6 +758,8 @@ 'browser/chromeos/login/version_info_updater.cc', 'browser/chromeos/login/version_info_updater.h', 'browser/chromeos/login/view_screen.h', + 'browser/chromeos/login/wallpaper_manager.cc', + 'browser/chromeos/login/wallpaper_manager.h', 'browser/chromeos/login/web_page_screen.cc', 'browser/chromeos/login/web_page_screen.h', 'browser/chromeos/login/web_page_view.cc', |