Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / background / ash_user_wallpaper_delegate.cc
blob10dd3e1527937329e9c78a5d67182cd47d9ca6b3
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/desktop_background/user_wallpaper_delegate.h"
8 #include "ash/shell.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/users/wallpaper/wallpaper_manager.h"
16 #include "chrome/browser/chromeos/login/wizard_controller.h"
17 #include "chromeos/chromeos_switches.h"
18 #include "chromeos/login/login_state.h"
19 #include "components/user_manager/user.h"
20 #include "components/user_manager/user_manager.h"
21 #include "content/public/browser/notification_service.h"
23 namespace chromeos {
25 namespace {
27 bool IsNormalWallpaperChange() {
28 if (chromeos::LoginState::Get()->IsUserLoggedIn() ||
29 !base::CommandLine::ForCurrentProcess()->HasSwitch(
30 switches::kFirstExecAfterBoot) ||
31 WizardController::IsZeroDelayEnabled() ||
32 !base::CommandLine::ForCurrentProcess()->HasSwitch(
33 switches::kLoginManager)) {
34 return true;
37 return false;
40 class UserWallpaperDelegate : public ash::UserWallpaperDelegate {
41 public:
42 UserWallpaperDelegate()
43 : boot_animation_finished_(false),
44 animation_duration_override_in_ms_(0) {
47 ~UserWallpaperDelegate() override {}
49 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 int GetAnimationDurationOverride() override {
56 return animation_duration_override_in_ms_;
59 void SetAnimationDurationOverride(int animation_duration_in_ms) override {
60 animation_duration_override_in_ms_ = animation_duration_in_ms;
63 bool ShouldShowInitialAnimation() override {
64 if (IsNormalWallpaperChange() || boot_animation_finished_)
65 return false;
67 // It is a first boot case now. If kDisableBootAnimation flag
68 // is passed, it only disables any transition after OOBE.
69 bool is_registered = StartupUtils::IsDeviceRegistered();
70 const base::CommandLine* command_line =
71 base::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 void UpdateWallpaper(bool clear_cache) override {
81 chromeos::WallpaperManager::Get()->UpdateWallpaper(clear_cache);
84 void InitializeWallpaper() override {
85 chromeos::WallpaperManager::Get()->InitializeWallpaper();
88 void OpenSetWallpaperPage() override {
89 if (CanOpenSetWallpaperPage())
90 wallpaper_manager_util::OpenWallpaperManager();
93 bool CanOpenSetWallpaperPage() override {
94 const LoginState* login_state = LoginState::Get();
95 const LoginState::LoggedInUserType user_type =
96 login_state->GetLoggedInUserType();
97 if (!login_state->IsUserLoggedIn())
98 return false;
100 // Whitelist user types that are allowed to change their wallpaper. (Guest
101 // users are not, see crosbug 26900.)
102 if (user_type != LoginState::LOGGED_IN_USER_REGULAR &&
103 user_type != LoginState::LOGGED_IN_USER_OWNER &&
104 user_type != LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT &&
105 user_type != LoginState::LOGGED_IN_USER_SUPERVISED) {
106 return false;
108 const user_manager::User* user =
109 user_manager::UserManager::Get()->GetActiveUser();
110 if (!user)
111 return false;
112 if (chromeos::WallpaperManager::Get()->IsPolicyControlled(user->email()))
113 return false;
114 return true;
117 void OnWallpaperAnimationFinished() override {
118 content::NotificationService::current()->Notify(
119 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED,
120 content::NotificationService::AllSources(),
121 content::NotificationService::NoDetails());
124 void OnWallpaperBootAnimationFinished() override {
125 // Make sure that boot animation type is used only once.
126 boot_animation_finished_ = true;
129 private:
130 bool boot_animation_finished_;
132 // The animation duration to show a new wallpaper if an animation is required.
133 int animation_duration_override_in_ms_;
135 DISALLOW_COPY_AND_ASSIGN(UserWallpaperDelegate);
138 } // namespace
140 ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() {
141 return new chromeos::UserWallpaperDelegate();
144 } // namespace chromeos