Commit 10b22614 authored by bshe@chromium.org's avatar bshe@chromium.org

Restore to user selected wallpaper after browser crash

After browser crash, the wallpaper was reverted to the default wallpaper. This
CL fix the bug.

BUG=118751
TEST=Test on any chromeos device
select a wallpaper different than the default one
go to about:inducebrowsercrashforrealz, the browser will crash and restart
verify if the wallpaper reverted to the default wallpaper after restart.

Review URL: https://chromiumcodereview.appspot.com/9764012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128232 0039d316-1c4b-4281-b951-d872f2087c98
parent 1e330021
......@@ -166,7 +166,7 @@ bool HandleToggleDesktopBackgroundMode() {
ash::DesktopBackgroundController::BACKGROUND_IMAGE)
desktop_background_controller->SetDesktopBackgroundSolidColorMode();
else
desktop_background_controller->SetPreviousDesktopBackgroundImage();
desktop_background_controller->OnDesktopBackgroundChanged();
return true;
}
......
......@@ -21,24 +21,24 @@
namespace ash {
DesktopBackgroundController::DesktopBackgroundController() :
previous_wallpaper_index_(GetDefaultWallpaperIndex()),
desktop_background_mode_(BACKGROUND_IMAGE) {
}
DesktopBackgroundController::~DesktopBackgroundController() {
}
void DesktopBackgroundController::OnDesktopBackgroundChanged(int index) {
void DesktopBackgroundController::OnDesktopBackgroundChanged() {
internal::RootWindowLayoutManager* root_window_layout =
Shell::GetInstance()->root_window_layout();
if (desktop_background_mode_ == BACKGROUND_SOLID_COLOR)
return;
int index = Shell::GetInstance()->user_wallpaper_delegate()->
GetUserWallpaperIndex();
DCHECK(root_window_layout->background_widget()->widget_delegate());
static_cast<internal::DesktopBackgroundView*>(
root_window_layout->background_widget()->widget_delegate())->
SetWallpaper(GetWallpaper(index));
previous_wallpaper_index_ = index;
}
void DesktopBackgroundController::SetDesktopBackgroundImageMode(
......@@ -51,14 +51,6 @@ void DesktopBackgroundController::SetDesktopBackgroundImageMode(
desktop_background_mode_ = BACKGROUND_IMAGE;
}
void DesktopBackgroundController::SetDefaultDesktopBackgroundImage() {
SetDesktopBackgroundImageMode(GetWallpaper(GetDefaultWallpaperIndex()));
}
void DesktopBackgroundController::SetPreviousDesktopBackgroundImage() {
SetDesktopBackgroundImageMode(GetWallpaper(previous_wallpaper_index_));
}
void DesktopBackgroundController::SetDesktopBackgroundSolidColorMode() {
// Set a solid black background.
// TODO(derat): Remove this in favor of having the compositor only clear the
......
......@@ -13,6 +13,14 @@ class SkBitmap;
namespace ash {
class UserWallpaperDelegate {
public:
virtual ~UserWallpaperDelegate() {}
// Gets the index of user selected wallpaper
virtual const int GetUserWallpaperIndex() = 0;
};
// A class to listen for login and desktop background change events and set the
// corresponding default wallpaper in Aura shell.
class ASH_EXPORT DesktopBackgroundController {
......@@ -30,31 +38,18 @@ class ASH_EXPORT DesktopBackgroundController {
return desktop_background_mode_;
}
// Change the desktop background image to wallpaper with |index|.
void OnDesktopBackgroundChanged(int index);
// Change the desktop background image to user selected wallpaper.
void OnDesktopBackgroundChanged();
// Sets the desktop background to image mode and create a new background
// widget with |wallpaper|.
void SetDesktopBackgroundImageMode(const SkBitmap& wallpaper);
// Sets the desktop background to image mode and create a new background
// widget with default wallpaper.
void SetDefaultDesktopBackgroundImage();
// Sets the desktop background to image mode and create a new background
// widget with previous selected wallpaper at run time.
void SetPreviousDesktopBackgroundImage();
// Sets the desktop background to solid color mode and create a solid color
// layout.
void SetDesktopBackgroundSolidColorMode();
private:
// We need to cache the previously used wallpaper index. So when users switch
// desktop background color mode at run time, we can directly switch back to
// the user selected wallpaper in image mode.
int previous_wallpaper_index_;
// Can change at runtime.
BackgroundMode desktop_background_mode_;
......
......@@ -229,6 +229,22 @@ void CreateSpecialContainers(aura::RootWindow* root_window) {
lock_screen_related_containers);
}
// This dummy class is used for shell unit tests. We dont have chrome delegate
// in these tests.
class DummyUserWallpaperDelegate: public UserWallpaperDelegate {
public:
DummyUserWallpaperDelegate() {}
virtual ~DummyUserWallpaperDelegate() {}
const int GetUserWallpaperIndex() {
return 0;
}
private:
DISALLOW_COPY_AND_ASSIGN(DummyUserWallpaperDelegate);
};
class DummySystemTrayDelegate : public SystemTrayDelegate {
public:
DummySystemTrayDelegate()
......@@ -638,6 +654,10 @@ void Shell::Init() {
// This controller needs to be set before SetupManagedWindowMode.
desktop_background_controller_.reset(new DesktopBackgroundController);
if (delegate_.get())
user_wallpaper_delegate_.reset(delegate_->CreateUserWallpaperDelegate());
if (!user_wallpaper_delegate_.get())
user_wallpaper_delegate_.reset(new DummyUserWallpaperDelegate());
InitLayoutManagers();
......@@ -798,8 +818,11 @@ void Shell::InitLayoutManagers() {
new internal::WorkspaceController(default_container));
workspace_controller_->workspace_manager()->set_shelf(shelf_layout_manager);
// Create the desktop background image.
desktop_background_controller_->SetDefaultDesktopBackgroundImage();
// Create desktop background widget.
// TODO(bshe): We should be able to use OnDesktopBackgroundChanged function
// here after issue 117244 got fixed.
desktop_background_controller_->SetDesktopBackgroundImageMode(
GetWallpaper(user_wallpaper_delegate_->GetUserWallpaperIndex()));
}
void Shell::DisableWorkspaceGridLayout() {
......
......@@ -51,6 +51,7 @@ class ShellDelegate;
class ShellObserver;
class SystemTrayDelegate;
class SystemTray;
class UserWallpaperDelegate;
class VideoDetector;
class WindowCycleController;
......@@ -196,6 +197,9 @@ class ASH_EXPORT Shell {
ShellDelegate* delegate() { return delegate_.get(); }
SystemTrayDelegate* tray_delegate() { return tray_delegate_.get(); }
UserWallpaperDelegate* user_wallpaper_delegate() {
return user_wallpaper_delegate_.get();
}
Launcher* launcher() { return launcher_.get(); }
......@@ -259,6 +263,7 @@ class ASH_EXPORT Shell {
scoped_ptr<ShellDelegate> delegate_;
scoped_ptr<SystemTrayDelegate> tray_delegate_;
scoped_ptr<UserWallpaperDelegate> user_wallpaper_delegate_;
scoped_ptr<Launcher> launcher_;
......
......@@ -234,6 +234,10 @@ class ShellDelegateImpl : public ash::ShellDelegate {
return NULL;
}
virtual ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() {
return NULL;
}
private:
// Used to update Launcher. Owned by main.
WindowWatcher* watcher_;
......
......@@ -30,6 +30,7 @@ struct LauncherItem;
class ScreenshotDelegate;
class SystemTray;
class SystemTrayDelegate;
class UserWallpaperDelegate;
// Delegate of the Shell.
class ASH_EXPORT ShellDelegate {
......@@ -84,6 +85,9 @@ class ASH_EXPORT ShellDelegate {
// Creates a system-tray delegate. Shell takes ownership of the delegate.
virtual SystemTrayDelegate* CreateSystemTrayDelegate(SystemTray* tray) = 0;
// Creates a user wallpaper delegate. Shell takes ownership of the delegate.
virtual UserWallpaperDelegate* CreateUserWallpaperDelegate() = 0;
};
} // namespace ash
......
......@@ -69,5 +69,9 @@ SystemTrayDelegate* TestShellDelegate::CreateSystemTrayDelegate(
return NULL;
}
UserWallpaperDelegate* TestShellDelegate::CreateUserWallpaperDelegate() {
return NULL;
}
} // namespace test
} // namespace ash
......@@ -32,6 +32,7 @@ class TestShellDelegate : public ShellDelegate {
virtual LauncherDelegate* CreateLauncherDelegate(
ash::LauncherModel* model) OVERRIDE;
virtual SystemTrayDelegate* CreateSystemTrayDelegate(SystemTray* t) OVERRIDE;
virtual UserWallpaperDelegate* CreateUserWallpaperDelegate() OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(TestShellDelegate);
......
......@@ -14,6 +14,40 @@
namespace chromeos {
namespace {
class UserWallpaperDelegate: public ash::UserWallpaperDelegate {
public:
UserWallpaperDelegate() {
}
virtual ~UserWallpaperDelegate() {
}
virtual const int GetUserWallpaperIndex() OVERRIDE {
chromeos::UserManager* user_manager = chromeos::UserManager::Get();
// If at login screen or logged in as a guest/incognito user, then use the
// default wallpaper.
if (user_manager->IsLoggedInAsGuest() || !user_manager->IsUserLoggedIn())
return ash::GetDefaultWallpaperIndex();
const chromeos::User& user = user_manager->GetLoggedInUser();
DCHECK(!user.email().empty());
int index = user_manager->GetUserWallpaper(user.email());
DCHECK(index >=0 && index < ash::GetWallpaperCount());
return index;
}
private:
DISALLOW_COPY_AND_ASSIGN(UserWallpaperDelegate);
};
} // namespace
ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() {
return new chromeos::UserWallpaperDelegate();
}
DesktopBackgroundObserver::DesktopBackgroundObserver() {
registrar_.Add(
this,
......@@ -24,25 +58,13 @@ DesktopBackgroundObserver::DesktopBackgroundObserver() {
DesktopBackgroundObserver::~DesktopBackgroundObserver() {
}
int DesktopBackgroundObserver::GetUserWallpaperIndex() {
chromeos::UserManager* user_manager = chromeos::UserManager::Get();
// Guest/incognito user do not have an email address.
if (user_manager->IsLoggedInAsGuest())
return ash::GetDefaultWallpaperIndex();
const chromeos::User& user = user_manager->GetLoggedInUser();
DCHECK(!user.email().empty());
int index = user_manager->GetUserWallpaper(user.email());
DCHECK(index >=0 && index < ash::GetWallpaperCount());
return index;
}
void DesktopBackgroundObserver::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_LOGIN_USER_CHANGED: {
ash::Shell::GetInstance()->desktop_background_controller()->
OnDesktopBackgroundChanged(GetUserWallpaperIndex());
OnDesktopBackgroundChanged();
break;
}
default:
......
......@@ -9,18 +9,22 @@
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
namespace ash {
class UserWallpaperDelegate;
}
namespace chromeos {
ash::UserWallpaperDelegate* CreateUserWallpaperDelegate();
// Listens for background change events and passes them to the Aura shell's
// DesktopBackgroundController class.
class DesktopBackgroundObserver : public content::NotificationObserver{
class DesktopBackgroundObserver : public content::NotificationObserver {
public:
DesktopBackgroundObserver();
virtual ~DesktopBackgroundObserver();
private:
// Returns the index of user selected wallpaper from a default wallpaper list.
int GetUserWallpaperIndex();
// content::NotificationObserver implementation.
virtual void Observe(int type,
......
......@@ -923,7 +923,7 @@ void UserManagerImpl::SaveWallpaperDefaultIndex(const std::string& username,
wallpapers_update->SetWithoutPathExpansion(username,
new base::FundamentalValue(wallpaper_index));
ash::Shell::GetInstance()->desktop_background_controller()->
OnDesktopBackgroundChanged(wallpaper_index);
OnDesktopBackgroundChanged();
}
void UserManagerImpl::SetUserImage(const std::string& username,
......
......@@ -23,6 +23,7 @@
#if defined(OS_CHROMEOS)
#include "base/chromeos/chromeos_version.h"
#include "chrome/browser/chromeos/background/desktop_background_observer.h"
#include "chrome/browser/chromeos/dbus/dbus_thread_manager.h"
#include "chrome/browser/chromeos/dbus/power_manager_client.h"
#include "chrome/browser/chromeos/login/user_manager.h"
......@@ -135,6 +136,14 @@ ash::SystemTrayDelegate* ChromeShellDelegate::CreateSystemTrayDelegate(
#endif
}
ash::UserWallpaperDelegate* ChromeShellDelegate::CreateUserWallpaperDelegate() {
#if defined(OS_CHROMEOS)
return chromeos::CreateUserWallpaperDelegate();
#else
return NULL;
#endif
}
void ChromeShellDelegate::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
......
......@@ -54,6 +54,7 @@ class ChromeShellDelegate : public ash::ShellDelegate,
ash::LauncherModel* model) OVERRIDE;
virtual ash::SystemTrayDelegate* CreateSystemTrayDelegate(
ash::SystemTray* tray) OVERRIDE;
virtual ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() OVERRIDE;
// content::NotificationObserver override:
virtual void Observe(int type,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment