summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/power/session_state_controller_delegate_chromeos.cc
blob: 299db3fb7643217031da5d75258cf6f373b3b580 (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
// Copyright (c) 2012 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/session_state_controller_delegate_chromeos.h"

#include "base/logging.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/power_manager_client.h"
#include "chromeos/dbus/session_manager_client.h"
#include "chromeos/settings/cros_settings_names.h"
#include "chromeos/settings/cros_settings_provider.h"

namespace chromeos {

SessionStateControllerDelegateChromeos::SessionStateControllerDelegateChromeos()
    : weak_factory_(this) {
}

SessionStateControllerDelegateChromeos::
    ~SessionStateControllerDelegateChromeos() {
}

void SessionStateControllerDelegateChromeos::RequestLockScreen() {
  // TODO(antrim) : additional logging for crbug/173178
  LOG(WARNING) << "Requesting screen lock from SessionStateControllerDelegate";
  DBusThreadManager::Get()->GetSessionManagerClient()->RequestLockScreen();
}

void SessionStateControllerDelegateChromeos::RequestShutdown() {
  CrosSettings* cros_settings = CrosSettings::Get();
  CrosSettingsProvider::TrustedStatus status =
      cros_settings->PrepareTrustedValues(base::Bind(
          &SessionStateControllerDelegateChromeos::RequestShutdown,
          weak_factory_.GetWeakPtr()));
  if (status != CrosSettingsProvider::TRUSTED)
    return;

  // Get the updated policy.
  bool reboot_on_shutdown = false;
  cros_settings->GetBoolean(kRebootOnShutdown, &reboot_on_shutdown);

  if (reboot_on_shutdown)
    DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart();
  else
    DBusThreadManager::Get()->GetPowerManagerClient()->RequestShutdown();
}

}  // namespace chromeos