ash_user_wallpaper_delegate.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chromeos/background/ash_user_wallpaper_delegate.h"
6
7#include "ash/shell.h"
8#include "ash/desktop_background/user_wallpaper_delegate.h"
9#include "ash/wm/window_animations.h"
10#include "base/command_line.h"
11#include "base/logging.h"
12#include "chrome/browser/chrome_notification_types.h"
13#include "chrome/browser/chromeos/extensions/wallpaper_manager_util.h"
14#include "chrome/browser/chromeos/login/startup_utils.h"
15#include "chrome/browser/chromeos/login/wallpaper_manager.h"
16#include "chrome/browser/chromeos/login/wizard_controller.h"
17#include "chrome/browser/profiles/profile_manager.h"
18#include "chrome/browser/ui/browser.h"
19#include "chrome/browser/ui/browser_finder.h"
20#include "chrome/browser/ui/chrome_pages.h"
21#include "chromeos/chromeos_switches.h"
22#include "chromeos/login/login_state.h"
23#include "content/public/browser/notification_service.h"
24
25namespace chromeos {
26
27namespace {
28
29bool IsNormalWallpaperChange() {
30  if (chromeos::LoginState::Get()->IsUserLoggedIn() ||
31      !CommandLine::ForCurrentProcess()->HasSwitch(
32          switches::kFirstExecAfterBoot) ||
33      WizardController::IsZeroDelayEnabled() ||
34      !CommandLine::ForCurrentProcess()->HasSwitch(switches::kLoginManager)) {
35    return true;
36  }
37
38  return false;
39}
40
41class UserWallpaperDelegate : public ash::UserWallpaperDelegate {
42 public:
43  UserWallpaperDelegate()
44      : boot_animation_finished_(false),
45        animation_duration_override_in_ms_(0) {
46  }
47
48  virtual ~UserWallpaperDelegate() {
49  }
50
51  virtual int GetAnimationType() OVERRIDE {
52    return ShouldShowInitialAnimation() ?
53        ash::WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE :
54        static_cast<int>(views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
55  }
56
57  virtual int GetAnimationDurationOverride() OVERRIDE {
58    return animation_duration_override_in_ms_;
59  }
60
61  virtual void SetAnimationDurationOverride(
62      int animation_duration_in_ms) OVERRIDE {
63    animation_duration_override_in_ms_ = animation_duration_in_ms;
64  }
65
66  virtual bool ShouldShowInitialAnimation() OVERRIDE {
67    if (IsNormalWallpaperChange() || boot_animation_finished_)
68      return false;
69
70    // It is a first boot case now. If kDisableBootAnimation flag
71    // is passed, it only disables any transition after OOBE.
72    // |kDisableOobeAnimation| disables OOBE animation for slow hardware.
73    bool is_registered = StartupUtils::IsDeviceRegistered();
74    const CommandLine* command_line = CommandLine::ForCurrentProcess();
75    bool disable_boot_animation = command_line->
76        HasSwitch(switches::kDisableBootAnimation);
77    bool disable_oobe_animation = command_line->
78        HasSwitch(switches::kDisableOobeAnimation);
79    if ((!is_registered && disable_oobe_animation) ||
80        (is_registered && disable_boot_animation))
81      return false;
82
83    return true;
84  }
85
86  virtual void UpdateWallpaper() OVERRIDE {
87    chromeos::WallpaperManager::Get()->UpdateWallpaper();
88  }
89
90  virtual void InitializeWallpaper() OVERRIDE {
91    chromeos::WallpaperManager::Get()->InitializeWallpaper();
92  }
93
94  virtual void OpenSetWallpaperPage() OVERRIDE {
95    wallpaper_manager_util::OpenWallpaperManager();
96  }
97
98  virtual bool CanOpenSetWallpaperPage() OVERRIDE {
99    return LoginState::Get()->IsUserAuthenticated();
100  }
101
102  virtual void OnWallpaperAnimationFinished() OVERRIDE {
103    content::NotificationService::current()->Notify(
104        chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED,
105        content::NotificationService::AllSources(),
106        content::NotificationService::NoDetails());
107  }
108
109  virtual void OnWallpaperBootAnimationFinished() OVERRIDE {
110    // Make sure that boot animation type is used only once.
111    boot_animation_finished_ = true;
112  }
113
114 private:
115  bool boot_animation_finished_;
116
117  // The animation duration to show a new wallpaper if an animation is required.
118  int animation_duration_override_in_ms_;
119
120  DISALLOW_COPY_AND_ASSIGN(UserWallpaperDelegate);
121};
122
123}  // namespace
124
125ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() {
126  return new chromeos::UserWallpaperDelegate();
127}
128
129}  // namespace chromeos
130