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

Side by Side Diff: ash/system/chromeos/power/suspend_observer.cc

Issue 26692002: chromeos: More power-related cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/system/chromeos/power/suspend_observer.h"
6
7 #include "ash/session_state_delegate.h"
8 #include "ash/shell.h"
9 #include "ash/wm/user_activity_detector.h"
10 #include "base/prefs/pref_service.h"
11 #include "chromeos/dbus/dbus_thread_manager.h"
12 #include "chromeos/display/output_configurator.h"
13
14 namespace ash {
15 namespace internal {
16
17 SuspendObserver::SuspendObserver()
18 : power_client_(
19 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()),
20 session_client_(
21 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()),
22 screen_locked_(false) {
23 power_client_->AddObserver(this);
24 session_client_->AddObserver(this);
25 }
26
27 SuspendObserver::~SuspendObserver() {
28 session_client_->RemoveObserver(this);
29 session_client_ = NULL;
30 power_client_->RemoveObserver(this);
31 power_client_ = NULL;
32 }
33
34 void SuspendObserver::SuspendImminent() {
35 Shell* shell = Shell::GetInstance();
36 SessionStateDelegate* delegate = shell->session_state_delegate();
37
38 // If the lock-before-suspending pref is set, get a callback to block
39 // suspend and ask the session manager to lock the screen.
40 if (!screen_locked_ && delegate->ShouldLockScreenBeforeSuspending() &&
41 delegate->CanLockScreen()) {
42 screen_lock_callback_ = power_client_->GetSuspendReadinessCallback();
43 VLOG(1) << "Requesting screen lock from SuspendObserver";
44 session_client_->RequestLockScreen();
45 }
46
47 shell->user_activity_detector()->OnDisplayPowerChanging();
48 shell->output_configurator()->SuspendDisplays();
49 }
50
51 void SuspendObserver::ScreenIsLocked() {
52 screen_locked_ = true;
53
54 // Stop blocking suspend after the screen is locked.
55 if (!screen_lock_callback_.is_null()) {
56 VLOG(1) << "Screen locked due to suspend";
57 // Run the callback asynchronously. ScreenIsLocked() is currently
58 // called asynchronously after RequestLockScreen(), but this guards
59 // against it being made synchronous later.
60 base::MessageLoop::current()->PostTask(FROM_HERE, screen_lock_callback_);
61 screen_lock_callback_.Reset();
62 } else {
63 VLOG(1) << "Screen locked without suspend";
64 }
65 }
66
67 void SuspendObserver::ScreenIsUnlocked() {
68 screen_locked_ = false;
69 }
70
71 } // namespace internal
72 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698