| Index: ash/desktop_background/desktop_background_controller.cc
|
| diff --git a/ash/desktop_background/desktop_background_controller.cc b/ash/desktop_background/desktop_background_controller.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1aaa0b6af865f166d975063abe6e74982ca4718d
|
| --- /dev/null
|
| +++ b/ash/desktop_background/desktop_background_controller.cc
|
| @@ -0,0 +1,69 @@
|
| +// 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 "ash/desktop_background/desktop_background_controller.h"
|
| +
|
| +#include "ash/desktop_background/desktop_background_resources.h"
|
| +#include "ash/shell.h"
|
| +#include "base/logging.h"
|
| +#include "chrome/browser/chromeos/login/user_manager.h"
|
| +#include "chrome/common/chrome_notification_types.h"
|
| +#include "content/public/browser/notification_service.h"
|
| +#include "grit/ui_resources.h"
|
| +#include "ui/gfx/image/image.h"
|
| +#include "ui/base/resource/resource_bundle.h"
|
| +
|
| +namespace ash {
|
| +
|
| +DesktopBackgroundController::DesktopBackgroundController(){
|
| + registrar_.Add(
|
| + this,
|
| + chrome::NOTIFICATION_DESKTOP_BACKGROUND_CHANGED,
|
| + content::NotificationService::AllSources());
|
| + registrar_.Add(
|
| + this,
|
| + chrome::NOTIFICATION_LOGIN_USER_CHANGED,
|
| + content::NotificationService::AllSources());
|
| +}
|
| +
|
| +DesktopBackgroundController::~DesktopBackgroundController() {
|
| +}
|
| +
|
| +void DesktopBackgroundController::OnDesktopBackgroundChange(
|
| + const SkBitmap& wallpaper) {
|
| + Shell::GetInstance()->SetDesktopBackgroundWallpaper(wallpaper);
|
| +}
|
| +
|
| +const SkBitmap& DesktopBackgroundController::GetPresetWallpaper() {
|
| + return GetDefaultWallpaper(internal::kPresetWallpaperIndex);
|
| +}
|
| +
|
| +const SkBitmap& DesktopBackgroundController::GetUserWallpaper() {
|
| + chromeos::UserManager* user_manager = chromeos::UserManager::Get();
|
| + const chromeos::User& user = user_manager->logged_in_user();
|
| + DCHECK(!user.email().empty());
|
| + int index = user_manager->GetUserWallpaper(user.email());
|
| + DCHECK(index >=0 && index < internal::kDefaultWallpaperCount);
|
| + return GetDefaultWallpaper(index);
|
| +}
|
| +
|
| +void DesktopBackgroundController::Observe(int type,
|
| + const content::NotificationSource& source,
|
| + const content::NotificationDetails& details) {
|
| + switch (type) {
|
| + case chrome::NOTIFICATION_DESKTOP_BACKGROUND_CHANGED: {
|
| + int index = *content::Details<int>(details).ptr();
|
| + OnDesktopBackgroundChange(GetDefaultWallpaper(index));
|
| + break;
|
| + }
|
| + case chrome::NOTIFICATION_LOGIN_USER_CHANGED: {
|
| + OnDesktopBackgroundChange(GetUserWallpaper());
|
| + break;
|
| + }
|
| + default:
|
| + NOTREACHED();
|
| + }
|
| +}
|
| +
|
| +} // namespace ash
|
|
|