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 #ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_DEVICE_DISABLING_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_SYSTEM_DEVICE_DISABLING_MANAGER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_SYSTEM_DEVICE_DISABLING_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_SYSTEM_DEVICE_DISABLING_MANAGER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/observer_list.h" |
| 15 #include "chrome/browser/chromeos/settings/cros_settings.h" |
13 | 16 |
14 namespace policy { | 17 namespace policy { |
15 class BrowserPolicyConnectorChromeOS; | 18 class BrowserPolicyConnectorChromeOS; |
16 } | 19 } |
17 | 20 |
| 21 namespace user_manager { |
| 22 class UserManager; |
| 23 } |
| 24 |
18 namespace chromeos { | 25 namespace chromeos { |
19 namespace system { | 26 namespace system { |
20 | 27 |
21 // If an enrolled device is lost or stolen, it can be remotely disabled by its | 28 // If an enrolled device is lost or stolen, it can be remotely disabled by its |
22 // owner. The disabling is triggered in two different ways, depending on the | 29 // owner. The disabling is triggered in two different ways, depending on the |
23 // state the device is in: | 30 // state the device is in: |
24 // - If the device has been wiped, it will perform a hash dance during OOBE to | 31 // - If the device has been wiped, it will perform a hash dance during OOBE to |
25 // find out whether any persistent state has been stored for it on the server. | 32 // find out whether any persistent state has been stored for it on the server. |
26 // If so, persistent state is retrieved as a |DeviceStateRetrievalResponse| | 33 // If so, persistent state is retrieved as a |DeviceStateRetrievalResponse| |
27 // protobuf, parsed and written to the |prefs::kServerBackedDeviceState| local | 34 // protobuf, parsed and written to the |prefs::kServerBackedDeviceState| local |
28 // state pref. At the appropriate place in the OOBE flow, the | 35 // state pref. At the appropriate place in the OOBE flow, the |
29 // |WizardController| will call CheckWhetherDeviceDisabledDuringOOBE() to find | 36 // |WizardController| will call CheckWhetherDeviceDisabledDuringOOBE() to find |
30 // out whether the device is disabled, causing it to either show or skip the | 37 // out whether the device is disabled, causing it to either show or skip the |
31 // device disabled screen. | 38 // device disabled screen. |
32 // - If the device has not been wiped, the disabled state is retrieved with | 39 // - If the device has not been wiped, the disabled state is retrieved with |
33 // every device policy fetch as part of the |PolicyData| protobuf, parsed and | 40 // every device policy fetch as part of the |PolicyData| protobuf, parsed and |
34 // written to the |chromeos::kDeviceDisabled| cros setting. | 41 // written to the |chromeos::kDeviceDisabled| cros setting. This class |
35 // | 42 // monitors the cros setting. When the device becomes disabled, one of two |
36 // TODO(bartfab): Make this class subscribe to the cros setting and trigger | 43 // actions is taken: |
37 // the device disabled screen. http://crbug.com/425574 | 44 // 1) If no session is in progress, the device disabled screen is shown |
| 45 // immediately. |
| 46 // 2) If a session is in progress, the session is terminated. After Chrome has |
| 47 // restarted on the login screen, the disabled screen is shown per 1). |
| 48 // This ensures that when a device is disabled, there is never any user |
| 49 // session running in the backround. |
| 50 // When the device is re-enabled, Chrome is restarted once more to resume the |
| 51 // regular login screen flows from a known-good point. |
38 class DeviceDisablingManager { | 52 class DeviceDisablingManager { |
39 public: | 53 public: |
40 using DeviceDisabledCheckCallback = base::Callback<void(bool)>; | 54 using DeviceDisabledCheckCallback = base::Callback<void(bool)>; |
41 | 55 |
42 explicit DeviceDisablingManager( | 56 class Observer { |
43 policy::BrowserPolicyConnectorChromeOS* browser_policy_connector); | 57 public: |
| 58 virtual ~Observer(); |
| 59 |
| 60 virtual void OnDisabledMessageChanged( |
| 61 const std::string& disabled_message) = 0; |
| 62 |
| 63 private: |
| 64 DISALLOW_ASSIGN(Observer); |
| 65 }; |
| 66 |
| 67 class Delegate { |
| 68 public: |
| 69 virtual ~Delegate(); |
| 70 |
| 71 // Terminate the current session (if any) and restart Chrome to show the |
| 72 // login screen. |
| 73 virtual void RestartToLoginScreen() = 0; |
| 74 |
| 75 // Show the device disabled screen. |
| 76 virtual void ShowDeviceDisabledScreen() = 0; |
| 77 |
| 78 private: |
| 79 DISALLOW_ASSIGN(Delegate); |
| 80 }; |
| 81 |
| 82 // |delegate| must outlive |this|. |
| 83 DeviceDisablingManager(Delegate* delegate, |
| 84 CrosSettings* cros_settings, |
| 85 user_manager::UserManager* user_manager); |
44 ~DeviceDisablingManager(); | 86 ~DeviceDisablingManager(); |
45 | 87 |
| 88 void AddObserver(Observer* observer); |
| 89 void RemoveObserver(Observer* observer); |
| 90 |
46 // Returns the cached disabled message. The message is only guaranteed to be | 91 // Returns the cached disabled message. The message is only guaranteed to be |
47 // up to date if the disabled screen was triggered. | 92 // up to date if the disabled screen was triggered. |
48 const std::string& disabled_message() const { return disabled_message_; } | 93 const std::string& disabled_message() const { return disabled_message_; } |
49 | 94 |
50 // Checks whether the device is disabled. |callback| will be invoked with the | 95 // Performs a check whether the device is disabled during OOBE. |callback| |
51 // result of the check. | 96 // will be invoked with the result of the check. |
52 void CheckWhetherDeviceDisabledDuringOOBE( | 97 void CheckWhetherDeviceDisabledDuringOOBE( |
53 const DeviceDisabledCheckCallback& callback); | 98 const DeviceDisabledCheckCallback& callback); |
54 | 99 |
| 100 // Whenever trusted cros settings indicate that the device is disabled, this |
| 101 // method should be used to check whether the device disabling is to be |
| 102 // honored. If this method returns false, the device should not be disabled. |
| 103 static bool HonorDeviceDisablingDuringNormalOperation(); |
| 104 |
55 private: | 105 private: |
| 106 void Init(); |
| 107 |
| 108 // Cache the disabled message and inform observers if it changed. |
| 109 void CacheDisabledMessageAndNotify(const std::string& disabled_message); |
| 110 |
| 111 void UpdateFromCrosSettings(); |
| 112 |
| 113 Delegate* delegate_; |
56 policy::BrowserPolicyConnectorChromeOS* browser_policy_connector_; | 114 policy::BrowserPolicyConnectorChromeOS* browser_policy_connector_; |
| 115 CrosSettings* cros_settings_; |
| 116 user_manager::UserManager* user_manager_; |
| 117 |
| 118 ObserverList<Observer> observers_; |
| 119 |
| 120 scoped_ptr<CrosSettings::ObserverSubscription> device_disabled_subscription_; |
| 121 scoped_ptr<CrosSettings::ObserverSubscription> disabled_message_subscription_; |
| 122 |
| 123 // Indicates whether the device was disabled when the cros settings were last |
| 124 // read. |
| 125 bool device_disabled_; |
57 | 126 |
58 // A cached copy of the message to show on the device disabled screen. | 127 // A cached copy of the message to show on the device disabled screen. |
59 std::string disabled_message_; | 128 std::string disabled_message_; |
60 | 129 |
61 base::WeakPtrFactory<DeviceDisablingManager> weak_factory_; | 130 base::WeakPtrFactory<DeviceDisablingManager> weak_factory_; |
62 | 131 |
63 DISALLOW_COPY_AND_ASSIGN(DeviceDisablingManager); | 132 DISALLOW_COPY_AND_ASSIGN(DeviceDisablingManager); |
64 }; | 133 }; |
65 | 134 |
66 } // namespace system | 135 } // namespace system |
67 } // namespace chromeos | 136 } // namespace chromeos |
68 | 137 |
69 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_DEVICE_DISABLING_MANAGER_H_ | 138 #endif // CHROME_BROWSER_CHROMEOS_SYSTEM_DEVICE_DISABLING_MANAGER_H_ |
OLD | NEW |