OLD | NEW |
---|---|
(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/prefs/pref_service.h" | |
10 #include "base/values.h" | |
11 #include "chrome/browser/browser_process.h" | |
12 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | |
13 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | |
14 #include "chrome/browser/chromeos/policy/server_backed_device_state.h" | |
15 #include "chrome/common/pref_names.h" | |
16 #include "chromeos/chromeos_switches.h" | |
17 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | |
18 | |
19 namespace chromeos { | |
20 namespace system { | |
21 | |
22 DeviceDisablingManager::DeviceDisablingManager( | |
23 policy::BrowserPolicyConnectorChromeOS* browser_policy_connector) | |
24 : browser_policy_connector_(browser_policy_connector), | |
25 weak_factory_(this) { | |
26 } | |
27 | |
28 const std::string& DeviceDisablingManager::GetDisabledMessage() const { | |
29 return disabled_message_; | |
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 callback.Run(false); | |
62 return; | |
63 } | |
64 | |
Denis Kuznetsov (DE-MUC)
2014/11/06 16:34:29
Add a comment/DCHECK explicitly stating condition
bartfab (slow)
2014/11/06 17:08:15
Done.
| |
65 // Cache the disabled message. | |
66 disabled_message_.clear(); | |
67 g_browser_process->local_state()->GetDictionary( | |
68 prefs::kServerBackedDeviceState)->GetString( | |
69 policy::kDeviceStateDisabledMessage, | |
70 &disabled_message_); | |
71 | |
72 // Indicate that the device is disabled. | |
73 callback.Run(true); | |
74 } | |
75 | |
76 } // namespace system | |
77 } // namespace chromeos | |
OLD | NEW |