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

Side by Side Diff: chrome/browser/chromeos/system/device_disabling_manager.cc

Issue 692383005: Add DeviceDisablingManager to manage device disabling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@f_3_425574_disable_header_bar
Patch Set: Add destructor required by clang. Created 6 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright 2014 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 "chrome/browser/chromeos/system/device_disabling_manager.h"
6
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/logging.h"
10 #include "base/prefs/pref_service.h"
11 #include "base/values.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
14 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
15 #include "chrome/browser/chromeos/policy/server_backed_device_state.h"
16 #include "chrome/common/pref_names.h"
17 #include "chromeos/chromeos_switches.h"
18 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
19
20 namespace chromeos {
21 namespace system {
22
23 DeviceDisablingManager::DeviceDisablingManager(
24 policy::BrowserPolicyConnectorChromeOS* browser_policy_connector)
25 : browser_policy_connector_(browser_policy_connector),
26 weak_factory_(this) {
27 }
28
29 DeviceDisablingManager::~DeviceDisablingManager() {
30 }
31
32 void DeviceDisablingManager::CheckWhetherDeviceDisabledDuringOOBE(
33 const DeviceDisabledCheckCallback& callback) {
34 if (policy::GetRestoreMode() != policy::RESTORE_MODE_DISABLED ||
35 CommandLine::ForCurrentProcess()->HasSwitch(
36 switches::kDisableDeviceDisabling)) {
37 // Indicate that the device is not disabled if it is not marked as such in
38 // local state or device disabling has been turned off by flag.
39 callback.Run(false);
40 return;
41 }
42
43 if (browser_policy_connector_->GetDeviceMode() ==
44 policy::DEVICE_MODE_PENDING) {
45 // If the device mode is not known yet, request to be called back once it
46 // becomes known.
47 browser_policy_connector_->GetInstallAttributes()->ReadImmutableAttributes(
48 base::Bind(
49 &DeviceDisablingManager::CheckWhetherDeviceDisabledDuringOOBE,
50 weak_factory_.GetWeakPtr(),
51 callback));
52 return;
53 }
54
55 if (browser_policy_connector_->GetDeviceMode() !=
56 policy::DEVICE_MODE_NOT_SET) {
57 // If the device is owned already, this method must have been called after
58 // OOBE, which is an error. Indicate that the device is not disabled to
59 // prevent spurious disabling. Actual device disabling after OOBE will be
60 // handled elsewhere, by checking for disabled state in cros settings.
61 LOG(ERROR) << "CheckWhetherDeviceDisabledDuringOOBE() called after OOBE.";
62 callback.Run(false);
63 return;
64 }
65
66 // The device is marked as disabled in local state (based on the device state
67 // retrieved early during OOBE). Since device disabling has not been turned
68 // off by flag and the device is still unowned, we honor the information in
69 // local state and consider the device disabled.
70
71 // Cache the disabled message.
72 disabled_message_.clear();
73 g_browser_process->local_state()->GetDictionary(
74 prefs::kServerBackedDeviceState)->GetString(
75 policy::kDeviceStateDisabledMessage,
76 &disabled_message_);
77
78 // Indicate that the device is disabled.
79 callback.Run(true);
80 }
81
82 } // namespace system
83 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698