Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: chrome/browser/chromeos/background/ash_user_wallpaper_delegate.cc

Issue 2271373002: mash: Port mojo:ash_sysui's ContextMenuMus to mojo:ash. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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/common/wm/window_animation_types.h"
8 #include "ash/desktop_background/user_wallpaper_delegate.h"
9 #include "ash/shell.h"
10 #include "ash/wm/window_animations.h"
11 #include "base/command_line.h"
12 #include "base/logging.h"
13 #include "base/macros.h"
14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/chromeos/extensions/wallpaper_manager_util.h"
16 #include "chrome/browser/chromeos/login/startup_utils.h"
17 #include "chrome/browser/chromeos/login/users/wallpaper/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 "components/user_manager/user.h"
22 #include "components/user_manager/user_manager.h"
23 #include "content/public/browser/notification_service.h"
24
25 namespace chromeos {
26
27 namespace {
28
29 bool IsNormalWallpaperChange() {
30 if (chromeos::LoginState::Get()->IsUserLoggedIn() ||
31 !base::CommandLine::ForCurrentProcess()->HasSwitch(
32 switches::kFirstExecAfterBoot) ||
33 WizardController::IsZeroDelayEnabled() ||
34 !base::CommandLine::ForCurrentProcess()->HasSwitch(
35 switches::kLoginManager)) {
36 return true;
37 }
38
39 return false;
40 }
41
42 class UserWallpaperDelegate : public ash::UserWallpaperDelegate {
43 public:
44 UserWallpaperDelegate()
45 : boot_animation_finished_(false),
46 animation_duration_override_in_ms_(0) {
47 }
48
49 ~UserWallpaperDelegate() override {}
50
51 int GetAnimationType() override {
52 return ShouldShowInitialAnimation()
53 ? ash::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE
54 : static_cast<int>(::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
55 }
56
57 int GetAnimationDurationOverride() override {
58 return animation_duration_override_in_ms_;
59 }
60
61 void SetAnimationDurationOverride(int animation_duration_in_ms) override {
62 animation_duration_override_in_ms_ = animation_duration_in_ms;
63 }
64
65 bool ShouldShowInitialAnimation() override {
66 if (IsNormalWallpaperChange() || boot_animation_finished_)
67 return false;
68
69 // It is a first boot case now. If kDisableBootAnimation flag
70 // is passed, it only disables any transition after OOBE.
71 bool is_registered = StartupUtils::IsDeviceRegistered();
72 const base::CommandLine* command_line =
73 base::CommandLine::ForCurrentProcess();
74 bool disable_boot_animation = command_line->
75 HasSwitch(switches::kDisableBootAnimation);
76 if (is_registered && disable_boot_animation)
77 return false;
78
79 return true;
80 }
81
82 void UpdateWallpaper(bool clear_cache) override {
83 chromeos::WallpaperManager::Get()->UpdateWallpaper(clear_cache);
84 }
85
86 void InitializeWallpaper() override {
87 chromeos::WallpaperManager::Get()->InitializeWallpaper();
88 }
89
90 void OpenSetWallpaperPage() override {
91 if (CanOpenSetWallpaperPage())
92 wallpaper_manager_util::OpenWallpaperManager();
93 }
94
95 bool CanOpenSetWallpaperPage() override {
96 const LoginState* login_state = LoginState::Get();
97 const LoginState::LoggedInUserType user_type =
98 login_state->GetLoggedInUserType();
99 if (!login_state->IsUserLoggedIn())
100 return false;
101
102 // Whitelist user types that are allowed to change their wallpaper. (Guest
103 // users are not, see crosbug 26900.)
104 if (user_type != LoginState::LOGGED_IN_USER_REGULAR &&
105 user_type != LoginState::LOGGED_IN_USER_OWNER &&
106 user_type != LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT &&
107 user_type != LoginState::LOGGED_IN_USER_SUPERVISED) {
108 return false;
109 }
110 const user_manager::User* user =
111 user_manager::UserManager::Get()->GetActiveUser();
112 if (!user)
113 return false;
114 if (chromeos::WallpaperManager::Get()->IsPolicyControlled(
115 user->GetAccountId()))
116 return false;
117 return true;
118 }
119
120 void OnWallpaperAnimationFinished() override {
121 content::NotificationService::current()->Notify(
122 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED,
123 content::NotificationService::AllSources(),
124 content::NotificationService::NoDetails());
125 }
126
127 void OnWallpaperBootAnimationFinished() override {
128 // Make sure that boot animation type is used only once.
129 boot_animation_finished_ = true;
130 }
131
132 private:
133 bool boot_animation_finished_;
134
135 // The animation duration to show a new wallpaper if an animation is required.
136 int animation_duration_override_in_ms_;
137
138 DISALLOW_COPY_AND_ASSIGN(UserWallpaperDelegate);
139 };
140
141 } // namespace
142
143 ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() {
144 return new chromeos::UserWallpaperDelegate();
145 }
146
147 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698