blob: fb6b85f74829daa00fe08fe5f1441b6b04af7f39 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/power/suspend_observer.h"
#include "ash/shell.h"
#include "ash/wm/user_activity_detector.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/extensions/api/system_private/system_private_api.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/pref_names.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/display/output_configurator.h"
namespace chromeos {
SuspendObserver::SuspendObserver()
: power_client_(DBusThreadManager::Get()->GetPowerManagerClient()),
session_client_(DBusThreadManager::Get()->GetSessionManagerClient()),
screen_locked_(false) {
power_client_->AddObserver(this);
session_client_->AddObserver(this);
}
SuspendObserver::~SuspendObserver() {
session_client_->RemoveObserver(this);
session_client_ = NULL;
power_client_->RemoveObserver(this);
power_client_ = NULL;
}
void SuspendObserver::SuspendImminent() {
// If the lock-before-suspending pref is set, get a callback to block
// suspend and ask the session manager to lock the screen.
Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
if (profile && profile->GetPrefs()->GetBoolean(prefs::kEnableScreenLock) &&
UserManager::Get()->CanCurrentUserLock() && !screen_locked_) {
screen_lock_callback_ = power_client_->GetSuspendReadinessCallback();
// TODO(antrim) : additional logging for crbug/173178
LOG(WARNING) << "Requesting screen lock from SuspendObserver";
session_client_->RequestLockScreen();
}
ash::Shell::GetInstance()->user_activity_detector()->OnDisplayPowerChanging();
ash::Shell::GetInstance()->output_configurator()->SuspendDisplays();
}
void SuspendObserver::ScreenIsLocked() {
screen_locked_ = true;
// Stop blocking suspend after the screen is locked.
if (!screen_lock_callback_.is_null()) {
LOG(WARNING) << "Locking screen due to suspend.";
// Run the callback asynchronously. ScreenIsLocked() is currently
// called asynchronously after RequestLockScreen(), but this guards
// against it being made synchronous later.
MessageLoop::current()->PostTask(FROM_HERE, screen_lock_callback_);
screen_lock_callback_.Reset();
} else {
LOG(WARNING) << "Locking screen without suspend.";
}
}
void SuspendObserver::ScreenIsUnlocked() {
screen_locked_ = false;
}
} // namespace chromeos
|