Fix infinite recursion on hiding panel when created during fullscreen mode.
[chromium-blink-merge.git] / chrome / browser / chromeos / background / ash_user_wallpaper_delegate.cc
blobe86e2235a3b10d1ff6cb57ef7820af7e36f38258
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.
5 #include "chrome/browser/chromeos/background/ash_user_wallpaper_delegate.h"
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/user.h"
16 #include "chrome/browser/chromeos/login/user_manager.h"
17 #include "chrome/browser/chromeos/login/wallpaper_manager.h"
18 #include "chrome/browser/chromeos/login/wizard_controller.h"
19 #include "chromeos/chromeos_switches.h"
20 #include "chromeos/login/login_state.h"
21 #include "content/public/browser/notification_service.h"
23 namespace chromeos {
25 namespace {
27 bool IsNormalWallpaperChange() {
28 if (chromeos::LoginState::Get()->IsUserLoggedIn() ||
29 !CommandLine::ForCurrentProcess()->HasSwitch(
30 switches::kFirstExecAfterBoot) ||
31 WizardController::IsZeroDelayEnabled() ||
32 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kLoginManager)) {
33 return true;
36 return false;
39 class UserWallpaperDelegate : public ash::UserWallpaperDelegate {
40 public:
41 UserWallpaperDelegate()
42 : boot_animation_finished_(false),
43 animation_duration_override_in_ms_(0) {
46 virtual ~UserWallpaperDelegate() {
49 virtual int GetAnimationType() OVERRIDE {
50 return ShouldShowInitialAnimation() ?
51 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE :
52 static_cast<int>(wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
55 virtual int GetAnimationDurationOverride() OVERRIDE {
56 return animation_duration_override_in_ms_;
59 virtual void SetAnimationDurationOverride(
60 int animation_duration_in_ms) OVERRIDE {
61 animation_duration_override_in_ms_ = animation_duration_in_ms;
64 virtual bool ShouldShowInitialAnimation() OVERRIDE {
65 if (IsNormalWallpaperChange() || boot_animation_finished_)
66 return false;
68 // It is a first boot case now. If kDisableBootAnimation flag
69 // is passed, it only disables any transition after OOBE.
70 bool is_registered = StartupUtils::IsDeviceRegistered();
71 const CommandLine* command_line = CommandLine::ForCurrentProcess();
72 bool disable_boot_animation = command_line->
73 HasSwitch(switches::kDisableBootAnimation);
74 if (is_registered && disable_boot_animation)
75 return false;
77 return true;
80 virtual void UpdateWallpaper(bool clear_cache) OVERRIDE {
81 chromeos::WallpaperManager::Get()->UpdateWallpaper(clear_cache);
84 virtual void InitializeWallpaper() OVERRIDE {
85 chromeos::WallpaperManager::Get()->InitializeWallpaper();
88 virtual void OpenSetWallpaperPage() OVERRIDE {
89 wallpaper_manager_util::OpenWallpaperManager();
92 virtual bool CanOpenSetWallpaperPage() OVERRIDE {
93 if (!LoginState::Get()->IsUserAuthenticated())
94 return false;
95 const User* user = chromeos::UserManager::Get()->GetActiveUser();
96 if (!user)
97 return false;
98 if (chromeos::WallpaperManager::Get()->IsPolicyControlled(user->email()))
99 return false;
100 return true;
103 virtual void OnWallpaperAnimationFinished() OVERRIDE {
104 content::NotificationService::current()->Notify(
105 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED,
106 content::NotificationService::AllSources(),
107 content::NotificationService::NoDetails());
110 virtual void OnWallpaperBootAnimationFinished() OVERRIDE {
111 // Make sure that boot animation type is used only once.
112 boot_animation_finished_ = true;
115 private:
116 bool boot_animation_finished_;
118 // The animation duration to show a new wallpaper if an animation is required.
119 int animation_duration_override_in_ms_;
121 DISALLOW_COPY_AND_ASSIGN(UserWallpaperDelegate);
124 } // namespace
126 ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() {
127 return new chromeos::UserWallpaperDelegate();
130 } // namespace chromeos