diff options
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r-- | chrome/browser/chromeos/chrome_browser_main_chromeos.cc | 5 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/mock_user_manager.h | 5 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/user.h | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/user_manager.h | 4 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/user_manager_impl.cc | 39 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/user_manager_impl.h | 17 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/wallpaper_manager.cc | 118 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/wallpaper_manager.h | 62 |
8 files changed, 234 insertions, 18 deletions
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_ |