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

Side by Side Diff: ash/system/power/power_event_observer.cc

Issue 2916733002: cros: Suspend media sessions on SuspendImminent
Patch Set: PowerEventObserver Created 3 years, 6 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
« no previous file with comments | « ash/system/power/power_event_observer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/system/power/power_event_observer.h" 5 #include "ash/system/power/power_event_observer.h"
6 6
7 #include "ash/public/cpp/config.h" 7 #include "ash/public/cpp/config.h"
8 #include "ash/session/session_controller.h" 8 #include "ash/session/session_controller.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/shell_delegate.h"
10 #include "ash/shell_port.h" 11 #include "ash/shell_port.h"
11 #include "ash/system/tray/system_tray_notifier.h" 12 #include "ash/system/tray/system_tray_notifier.h"
12 #include "ash/wm/power_button_controller.h" 13 #include "ash/wm/power_button_controller.h"
13 #include "chromeos/dbus/dbus_thread_manager.h" 14 #include "chromeos/dbus/dbus_thread_manager.h"
14 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
15 #include "ui/aura/window_tree_host.h" 16 #include "ui/aura/window_tree_host.h"
16 #include "ui/base/user_activity/user_activity_detector.h" 17 #include "ui/base/user_activity/user_activity_detector.h"
17 #include "ui/compositor/compositor.h" 18 #include "ui/compositor/compositor.h"
18 #include "ui/display/manager/chromeos/display_configurator.h" 19 #include "ui/display/manager/chromeos/display_configurator.h"
19 20
(...skipping 17 matching lines...) Expand all
37 window->GetHost()->compositor()->SetVisible(true); 38 window->GetHost()->compositor()->SetVisible(true);
38 } 39 }
39 40
40 void OnSuspendDisplaysCompleted(const base::Closure& suspend_callback, 41 void OnSuspendDisplaysCompleted(const base::Closure& suspend_callback,
41 bool status) { 42 bool status) {
42 suspend_callback.Run(); 43 suspend_callback.Run();
43 } 44 }
44 45
45 } // namespace 46 } // namespace
46 47
47 PowerEventObserver::PowerEventObserver() 48 PowerEventObserver::PowerEventObserver() {
48 : screen_locked_(false), waiting_for_lock_screen_animations_(false) {
49 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( 49 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(
50 this); 50 this);
51 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver( 51 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(
52 this); 52 this);
53 } 53 }
54 54
55 PowerEventObserver::~PowerEventObserver() { 55 PowerEventObserver::~PowerEventObserver() {
56 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( 56 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(
57 this); 57 this);
58 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver( 58 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 if (!screen_locked_ && controller->ShouldLockScreenAutomatically() && 95 if (!screen_locked_ && controller->ShouldLockScreenAutomatically() &&
96 controller->CanLockScreen()) { 96 controller->CanLockScreen()) {
97 screen_lock_callback_ = chromeos::DBusThreadManager::Get() 97 screen_lock_callback_ = chromeos::DBusThreadManager::Get()
98 ->GetPowerManagerClient() 98 ->GetPowerManagerClient()
99 ->GetSuspendReadinessCallback(); 99 ->GetSuspendReadinessCallback();
100 VLOG(1) << "Requesting screen lock from PowerEventObserver"; 100 VLOG(1) << "Requesting screen lock from PowerEventObserver";
101 chromeos::DBusThreadManager::Get() 101 chromeos::DBusThreadManager::Get()
102 ->GetSessionManagerClient() 102 ->GetSessionManagerClient()
103 ->RequestLockScreen(); 103 ->RequestLockScreen();
104 } else if (waiting_for_lock_screen_animations_) { 104 } else if (waiting_for_lock_screen_animations_) {
105 // The lock-before-suspending pref has been set and the lock screen is ready 105 // The auto-screen-lock pref has been set and the lock screen is ready but
106 // but the animations have not completed yet. This can happen if a suspend 106 // the animations have not completed yet. This can happen if a suspend
107 // request is canceled after the lock screen is ready but before the 107 // request is canceled after the lock screen is ready but before the
108 // animations have completed and then another suspend request is immediately 108 // animations have completed and then another suspend request is immediately
109 // started. In practice, it is highly unlikely that this will ever happen 109 // started. In practice, it is highly unlikely that this will ever happen
110 // but it's better to be safe since the cost of not dealing with it properly 110 // but it's better to be safe since the cost of not dealing with it properly
111 // is a memory leak in the GPU and weird artifacts on the screen. 111 // is a memory leak in the GPU and weird artifacts on the screen.
112 screen_lock_callback_ = chromeos::DBusThreadManager::Get() 112 screen_lock_callback_ = chromeos::DBusThreadManager::Get()
113 ->GetPowerManagerClient() 113 ->GetPowerManagerClient()
114 ->GetSuspendReadinessCallback(); 114 ->GetSuspendReadinessCallback();
115 } else { 115 } else {
116 // The lock-before-suspending pref is not set or the screen has already been 116 // The auto-screen-lock pref is not set or the screen has already been
117 // locked and the animations have completed. Rendering can be stopped now. 117 // locked and the animations have completed. Rendering can be stopped now.
118 StopRenderingRequests(); 118 StopRenderingRequests();
119 } 119 }
120 120
121 ui::UserActivityDetector::Get()->OnDisplayPowerChanging(); 121 ui::UserActivityDetector::Get()->OnDisplayPowerChanging();
122 122
123 // TODO(derat): After mus exposes a method for suspending displays, call it 123 // TODO(derat): After mus exposes a method for suspending displays, call it
124 // here: http://crbug.com/692193 124 // here: http://crbug.com/692193
125 if (Shell::GetAshConfig() != Config::MASH) { 125 if (Shell::GetAshConfig() != Config::MASH) {
126 Shell::Get()->display_configurator()->SuspendDisplays(base::Bind( 126 Shell::Get()->display_configurator()->SuspendDisplays(base::Bind(
(...skipping 19 matching lines...) Expand all
146 ResumeRenderingRequests(); 146 ResumeRenderingRequests();
147 } 147 }
148 148
149 void PowerEventObserver::ScreenIsLocked() { 149 void PowerEventObserver::ScreenIsLocked() {
150 screen_locked_ = true; 150 screen_locked_ = true;
151 waiting_for_lock_screen_animations_ = true; 151 waiting_for_lock_screen_animations_ = true;
152 152
153 // The screen is now locked but the pending suspend, if any, will be blocked 153 // The screen is now locked but the pending suspend, if any, will be blocked
154 // until all the animations have completed. 154 // until all the animations have completed.
155 if (!screen_lock_callback_.is_null()) { 155 if (!screen_lock_callback_.is_null()) {
156 Shell::Get()->shell_delegate()->SuspendMediaSessions();
156 VLOG(1) << "Screen locked due to suspend"; 157 VLOG(1) << "Screen locked due to suspend";
157 } else { 158 } else {
158 VLOG(1) << "Screen locked without suspend"; 159 VLOG(1) << "Screen locked without suspend";
159 } 160 }
160 } 161 }
161 162
162 void PowerEventObserver::ScreenIsUnlocked() { 163 void PowerEventObserver::ScreenIsUnlocked() {
163 screen_locked_ = false; 164 screen_locked_ = false;
164 } 165 }
165 166
166 } // namespace ash 167 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/power/power_event_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698