Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / power / power_button_observer.cc
blobf7b407b37f7b35eea58254f74f5fce3d81629426
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/power/power_button_observer.h"
7 #include "ash/shell.h"
8 #include "ash/system/tray/system_tray_delegate.h"
9 #include "ash/system/user/login_status.h"
10 #include "ash/wm/power_button_controller.h"
11 #include "base/logging.h"
12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/chromeos/login/screen_locker.h"
14 #include "chrome/browser/chromeos/power/session_state_controller_delegate_chromeos.h"
15 #include "chromeos/dbus/dbus_thread_manager.h"
16 #include "content/public/browser/notification_service.h"
18 namespace chromeos {
20 namespace {
22 ash::user::LoginStatus GetCurrentLoginStatus() {
23 if (!ash::Shell::GetInstance()->system_tray_delegate())
24 return ash::user::LOGGED_IN_NONE;
25 return ash::Shell::GetInstance()->system_tray_delegate()->
26 GetUserLoginStatus();
29 } // namespace
31 PowerButtonObserver::PowerButtonObserver() {
32 ash::Shell::GetInstance()->lock_state_controller()->
33 SetDelegate(new SessionStateControllerDelegateChromeos);
35 registrar_.Add(
36 this,
37 chrome::NOTIFICATION_LOGIN_USER_CHANGED,
38 content::NotificationService::AllSources());
39 registrar_.Add(
40 this,
41 chrome::NOTIFICATION_APP_TERMINATING,
42 content::NotificationService::AllSources());
43 registrar_.Add(
44 this,
45 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED,
46 content::NotificationService::AllSources());
48 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
49 DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this);
51 // Tell the controller about the initial state.
52 ash::Shell::GetInstance()->OnLoginStateChanged(GetCurrentLoginStatus());
54 const ScreenLocker* locker = ScreenLocker::default_screen_locker();
55 bool locked = locker && locker->locked();
56 ash::Shell::GetInstance()->OnLockStateChanged(locked);
59 PowerButtonObserver::~PowerButtonObserver() {
60 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this);
61 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
64 void PowerButtonObserver::Observe(int type,
65 const content::NotificationSource& source,
66 const content::NotificationDetails& details) {
67 switch (type) {
68 case chrome::NOTIFICATION_LOGIN_USER_CHANGED: {
69 ash::Shell::GetInstance()->OnLoginStateChanged(GetCurrentLoginStatus());
70 break;
72 case chrome::NOTIFICATION_APP_TERMINATING:
73 ash::Shell::GetInstance()->OnAppTerminating();
74 break;
75 case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: {
76 bool locked = *content::Details<bool>(details).ptr();
77 ash::Shell::GetInstance()->OnLockStateChanged(locked);
78 break;
80 default:
81 NOTREACHED() << "Unexpected notification " << type;
85 void PowerButtonObserver::PowerButtonEventReceived(
86 bool down, const base::TimeTicks& timestamp) {
87 ash::Shell::GetInstance()->power_button_controller()->
88 OnPowerButtonEvent(down, timestamp);
91 void PowerButtonObserver::LockScreen() {
92 ash::Shell::GetInstance()->lock_state_controller()->OnStartingLock();
95 } // namespace chromeos