OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/system/device_disabling_manager.h" | 5 #include "chrome/browser/chromeos/system/device_disabling_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/browser_process_platform_part.h" | |
14 #include "chrome/browser/chromeos/login/existing_user_controller.h" | |
15 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | |
16 #include "chrome/browser/chromeos/login/wizard_controller.h" | |
13 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
14 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 18 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
15 #include "chrome/browser/chromeos/policy/server_backed_device_state.h" | 19 #include "chrome/browser/chromeos/policy/server_backed_device_state.h" |
20 #include "chrome/browser/lifetime/application_lifetime.h" | |
16 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
17 #include "chromeos/chromeos_switches.h" | 22 #include "chromeos/chromeos_switches.h" |
23 #include "chromeos/settings/cros_settings_names.h" | |
24 #include "chromeos/settings/cros_settings_provider.h" | |
18 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 25 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
26 #include "components/user_manager/user_manager.h" | |
19 | 27 |
20 namespace chromeos { | 28 namespace chromeos { |
21 namespace system { | 29 namespace system { |
22 | 30 |
31 namespace { | |
32 | |
33 class DeviceDisablingManagerDefaultDelegate | |
34 : public DeviceDisablingManager::Delegate { | |
35 public: | |
36 DeviceDisablingManagerDefaultDelegate(); | |
37 | |
38 // DeviceDisablingManager::Delegate: | |
achuithb
2014/11/07 00:15:17
make these private
bartfab (slow)
2014/11/07 10:11:37
Done.
| |
39 void RestartToLoginScreen() override; | |
40 void ShowDeviceDisabledScreen() override; | |
41 | |
42 private: | |
43 DISALLOW_COPY_AND_ASSIGN(DeviceDisablingManagerDefaultDelegate); | |
44 }; | |
45 | |
46 DeviceDisablingManagerDefaultDelegate::DeviceDisablingManagerDefaultDelegate() { | |
47 } | |
48 | |
49 void DeviceDisablingManagerDefaultDelegate::RestartToLoginScreen() { | |
50 chrome::AttemptUserExit(); | |
51 } | |
52 | |
53 void DeviceDisablingManagerDefaultDelegate::ShowDeviceDisabledScreen() { | |
54 LoginDisplayHostImpl::default_host()->StartWizard( | |
55 WizardController::kDeviceDisabledScreenName, | |
56 NULL); | |
57 } | |
58 | |
59 } // namespace | |
60 | |
61 DeviceDisablingManager::Observer::~Observer() { | |
62 } | |
63 | |
64 DeviceDisablingManager::Delegate::~Delegate() { | |
65 } | |
66 | |
23 DeviceDisablingManager::DeviceDisablingManager( | 67 DeviceDisablingManager::DeviceDisablingManager( |
24 policy::BrowserPolicyConnectorChromeOS* browser_policy_connector) | 68 Delegate* delegate, |
25 : browser_policy_connector_(browser_policy_connector), | 69 CrosSettings* cros_settings, |
70 user_manager::UserManager* user_manager) | |
71 : delegate_(delegate), | |
72 browser_policy_connector_(g_browser_process->platform_part()-> | |
73 browser_policy_connector_chromeos()), | |
74 cros_settings_(cros_settings), | |
75 user_manager_(user_manager), | |
76 device_disabled_(false), | |
26 weak_factory_(this) { | 77 weak_factory_(this) { |
78 if (!delegate_) { | |
79 owned_delegate_.reset(new DeviceDisablingManagerDefaultDelegate); | |
80 delegate_ = owned_delegate_.get(); | |
81 } | |
82 | |
83 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
84 switches::kDisableDeviceDisabling)) { | |
85 // If device disabling is turned off by flags, do not start monitoring cros | |
86 // settings. | |
87 return; | |
achuithb
2014/11/07 00:15:17
It's a little bit weird to have an early return fr
bartfab (slow)
2014/11/07 10:11:37
Done.
| |
88 } | |
89 | |
90 device_disabled_subscription_ = cros_settings_->AddSettingsObserver( | |
91 kDeviceDisabled, | |
92 base::Bind(&DeviceDisablingManager::UpdateFromCrosSettings, | |
93 weak_factory_.GetWeakPtr())); | |
94 disabled_message_subscription_ = cros_settings_->AddSettingsObserver( | |
95 kDeviceDisabledMessage, | |
96 base::Bind(&DeviceDisablingManager::UpdateFromCrosSettings, | |
97 weak_factory_.GetWeakPtr())); | |
98 | |
99 UpdateFromCrosSettings(); | |
100 } | |
101 | |
102 void DeviceDisablingManager::AddObserver(Observer* observer) { | |
103 observers_.AddObserver(observer); | |
104 } | |
105 | |
106 void DeviceDisablingManager::RemoveObserver(Observer* observer) { | |
107 observers_.RemoveObserver(observer); | |
108 } | |
109 | |
110 void DeviceDisablingManager::CacheDisabledMessageAndNotify( | |
111 const std::string& disabled_message) { | |
112 if (disabled_message == disabled_message_) | |
113 return; | |
114 | |
115 disabled_message_ = disabled_message; | |
116 FOR_EACH_OBSERVER(Observer, | |
117 observers_, | |
118 OnDisabledMessageChanged(disabled_message_)); | |
27 } | 119 } |
28 | 120 |
29 void DeviceDisablingManager::CheckWhetherDeviceDisabledDuringOOBE( | 121 void DeviceDisablingManager::CheckWhetherDeviceDisabledDuringOOBE( |
30 const DeviceDisabledCheckCallback& callback) { | 122 const DeviceDisabledCheckCallback& callback) { |
31 if (policy::GetRestoreMode() != policy::RESTORE_MODE_DISABLED || | 123 if (policy::GetRestoreMode() != policy::RESTORE_MODE_DISABLED || |
32 CommandLine::ForCurrentProcess()->HasSwitch( | 124 CommandLine::ForCurrentProcess()->HasSwitch( |
33 switches::kDisableDeviceDisabling)) { | 125 switches::kDisableDeviceDisabling)) { |
34 // Indicate that the device is not disabled if it is not marked as such in | 126 // Indicate that the device is not disabled if it is not marked as such in |
35 // local state or device disabling has been turned off by flag. | 127 // local state or device disabling has been turned off by flag. |
36 callback.Run(false); | 128 callback.Run(false); |
(...skipping 21 matching lines...) Expand all Loading... | |
58 LOG(ERROR) << "CheckWhetherDeviceDisabledDuringOOBE() called after OOBE."; | 150 LOG(ERROR) << "CheckWhetherDeviceDisabledDuringOOBE() called after OOBE."; |
59 callback.Run(false); | 151 callback.Run(false); |
60 return; | 152 return; |
61 } | 153 } |
62 | 154 |
63 // The device is marked as disabled in local state (based on the device state | 155 // The device is marked as disabled in local state (based on the device state |
64 // retrieved early during OOBE). Since device disabling has not been turned | 156 // retrieved early during OOBE). Since device disabling has not been turned |
65 // off by flag and the device is still unowned, we honor the information in | 157 // off by flag and the device is still unowned, we honor the information in |
66 // local state and consider the device disabled. | 158 // local state and consider the device disabled. |
67 | 159 |
68 // Cache the disabled message. | 160 // Update the disabled message. |
69 disabled_message_.clear(); | 161 std::string disabled_message; |
70 g_browser_process->local_state()->GetDictionary( | 162 g_browser_process->local_state()->GetDictionary( |
71 prefs::kServerBackedDeviceState)->GetString( | 163 prefs::kServerBackedDeviceState)->GetString( |
72 policy::kDeviceStateDisabledMessage, | 164 policy::kDeviceStateDisabledMessage, |
73 &disabled_message_); | 165 &disabled_message); |
166 CacheDisabledMessageAndNotify(disabled_message); | |
74 | 167 |
75 // Indicate that the device is disabled. | 168 // Indicate that the device is disabled. |
76 callback.Run(true); | 169 callback.Run(true); |
77 } | 170 } |
78 | 171 |
172 // static | |
173 bool DeviceDisablingManager::HonorDeviceDisablingDuringNormalOperation() { | |
174 // Device disabling should be honored when the device is enterprise managed | |
175 // and device disabling has not been turned off by flag. | |
176 return g_browser_process->platform_part()-> | |
177 browser_policy_connector_chromeos()->IsEnterpriseManaged() && | |
178 !CommandLine::ForCurrentProcess()->HasSwitch( | |
179 switches::kDisableDeviceDisabling); | |
180 } | |
181 | |
182 void DeviceDisablingManager::UpdateFromCrosSettings() { | |
183 if (cros_settings_->PrepareTrustedValues(base::Bind( | |
184 &DeviceDisablingManager::UpdateFromCrosSettings, | |
185 weak_factory_.GetWeakPtr())) != CrosSettingsProvider::TRUSTED) { | |
186 // If the cros settings are not trusted yet, request to be called back | |
187 // later. | |
188 return; | |
189 } | |
190 | |
191 if (!HonorDeviceDisablingDuringNormalOperation()) { | |
192 // If the device is not enterprise managed or device disabling has been | |
193 // turned of by flag, device disabling is not available. | |
194 return; | |
195 } | |
196 | |
197 bool device_disabled = false; | |
198 if (!cros_settings_->GetBoolean(kDeviceDisabled, &device_disabled) || | |
199 !device_disabled) { | |
200 if (!device_disabled_) { | |
201 // If the device was not disabled and has not been disabled, there is | |
202 // nothing to do. Return. | |
203 return; | |
204 } | |
205 device_disabled_ = false; | |
206 | |
207 // The device was disabled and has been re-enabled. Normal function should | |
208 // be resumed. Since the device disabled screen abruptly interrupts the | |
209 // regular login screen flows, Chrome should be restarted to return to a | |
210 // well-defined state. | |
211 delegate_->RestartToLoginScreen(); | |
212 return; | |
213 } | |
214 | |
215 // Update the disabled message. | |
216 std::string disabled_message; | |
217 cros_settings_->GetString(kDeviceDisabledMessage, &disabled_message); | |
218 CacheDisabledMessageAndNotify(disabled_message); | |
219 | |
220 if (device_disabled_) { | |
221 // If the device was disabled already, updating the disabled message is the | |
222 // only action required. Return. | |
achuithb
2014/11/07 00:15:17
Drop 'Return' since it's pretty obvious that's wha
bartfab (slow)
2014/11/07 10:11:37
Done.
| |
223 return; | |
224 } | |
225 device_disabled_ = true; | |
226 | |
227 const ExistingUserController* existing_user_controller = | |
228 ExistingUserController::current_controller(); | |
229 if (user_manager_->GetActiveUser() || | |
230 (existing_user_controller && | |
231 existing_user_controller->IsSigninInProgress())) { | |
232 // If a session or a login is in progress, restart Chrome and return to the | |
233 // login screen. Chrome will show the device disabled screen after the | |
234 // restart. | |
235 delegate_->RestartToLoginScreen(); | |
236 return; | |
237 } | |
238 | |
239 // If no session or login is in progress, show the device disabled screen. | |
240 delegate_->ShowDeviceDisabledScreen(); | |
241 } | |
242 | |
79 } // namespace system | 243 } // namespace system |
80 } // namespace chromeos | 244 } // namespace chromeos |
OLD | NEW |