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_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_ |
6 #define CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_ | 6 #define CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_ |
7 | 7 |
8 #include <deque> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
12 #include "base/compiler_specific.h" | |
13 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
14 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 14 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
15 #include "chromeos/dbus/session_manager_client.h" | 15 #include "chromeos/dbus/session_manager_client.h" |
16 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
17 #include "components/ownership/owner_key_util.h" | 17 #include "components/ownership/owner_key_util.h" |
18 #include "components/ownership/owner_settings_service.h" | 18 #include "components/ownership/owner_settings_service.h" |
19 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
20 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
21 | 21 |
22 class Profile; | 22 class Profile; |
23 | 23 |
24 namespace ownership { | 24 namespace ownership { |
25 class OwnerKeyUtil; | 25 class OwnerKeyUtil; |
26 } | 26 } |
27 | 27 |
28 namespace chromeos { | 28 namespace chromeos { |
29 | 29 |
30 class SessionManagerOperation; | |
31 | |
32 // The class is a profile-keyed service which holds public/private | 30 // The class is a profile-keyed service which holds public/private |
33 // keypair corresponds to a profile. The keypair is reloaded automatically when | 31 // keypair corresponds to a profile. The keypair is reloaded automatically when |
34 // profile is created and TPM token is ready. Note that the private part of a | 32 // profile is created and TPM token is ready. Note that the private part of a |
35 // key can be loaded only for the owner. | 33 // key can be loaded only for the owner. |
36 // | 34 // |
37 // TODO (ygorshenin@): move write path for device settings here | 35 // TODO (ygorshenin@): move write path for device settings here |
38 // (crbug.com/230018). | 36 // (crbug.com/230018). |
39 class OwnerSettingsServiceChromeOS : public ownership::OwnerSettingsService, | 37 class OwnerSettingsServiceChromeOS : public ownership::OwnerSettingsService, |
40 public content::NotificationObserver, | 38 public content::NotificationObserver, |
41 public SessionManagerClient::Observer { | 39 public SessionManagerClient::Observer, |
| 40 public DeviceSettingsService::Observer { |
42 public: | 41 public: |
43 virtual ~OwnerSettingsServiceChromeOS(); | 42 virtual ~OwnerSettingsServiceChromeOS(); |
44 | 43 |
45 void OnTPMTokenReady(bool tpm_token_enabled); | 44 void OnTPMTokenReady(bool tpm_token_enabled); |
46 | 45 |
47 // ownership::OwnerSettingsService implementation: | 46 // ownership::OwnerSettingsService implementation: |
48 virtual void SignAndStorePolicyAsync( | 47 virtual bool HandlesSetting(const std::string& setting) override; |
49 scoped_ptr<enterprise_management::PolicyData> policy, | 48 virtual bool Set(const std::string& setting, |
50 const base::Closure& callback) override; | 49 const base::Value& value) override; |
51 | 50 |
52 // NotificationObserver implementation: | 51 // NotificationObserver implementation: |
53 virtual void Observe(int type, | 52 virtual void Observe(int type, |
54 const content::NotificationSource& source, | 53 const content::NotificationSource& source, |
55 const content::NotificationDetails& details) override; | 54 const content::NotificationDetails& details) override; |
56 | 55 |
57 // SessionManagerClient::Observer: | 56 // SessionManagerClient::Observer: |
58 virtual void OwnerKeySet(bool success) override; | 57 virtual void OwnerKeySet(bool success) override; |
59 | 58 |
| 59 // DeviceSettingsService::Observer: |
| 60 virtual void OwnershipStatusChanged() override; |
| 61 virtual void DeviceSettingsUpdated() override; |
| 62 |
60 // Checks if the user is the device owner, without the user profile having to | 63 // Checks if the user is the device owner, without the user profile having to |
61 // been initialized. Should be used only if login state is in safe mode. | 64 // been initialized. Should be used only if login state is in safe mode. |
62 static void IsOwnerForSafeModeAsync( | 65 static void IsOwnerForSafeModeAsync( |
63 const std::string& user_hash, | 66 const std::string& user_hash, |
64 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util, | 67 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util, |
65 const IsOwnerCallback& callback); | 68 const IsOwnerCallback& callback); |
66 | 69 |
67 static void SetDeviceSettingsServiceForTesting( | 70 // Assembles PolicyData based on |settings|, |policy_data| and |
68 DeviceSettingsService* device_settings_service); | 71 // |user_id|. |
| 72 static scoped_ptr<enterprise_management::PolicyData> AssemblePolicy( |
| 73 const std::string& user_id, |
| 74 const enterprise_management::PolicyData* policy_data, |
| 75 const enterprise_management::ChromeDeviceSettingsProto* settings); |
| 76 |
| 77 // Updates device |settings|. |
| 78 static void UpdateDeviceSettings( |
| 79 const std::string& path, |
| 80 const base::Value& value, |
| 81 enterprise_management::ChromeDeviceSettingsProto& settings); |
| 82 |
| 83 bool has_pending_changes() const { return has_pending_changes_; } |
69 | 84 |
70 private: | 85 private: |
71 friend class OwnerSettingsServiceChromeOSFactory; | 86 friend class OwnerSettingsServiceChromeOSFactory; |
72 | 87 |
73 OwnerSettingsServiceChromeOS( | 88 OwnerSettingsServiceChromeOS( |
| 89 DeviceSettingsService* device_settings_service, |
74 Profile* profile, | 90 Profile* profile, |
75 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); | 91 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); |
76 | 92 |
77 // OwnerSettingsService protected interface overrides: | 93 // OwnerSettingsService protected interface overrides: |
78 | 94 |
79 // Reloads private key from profile's NSS slots, responds via |callback|. | 95 // Reloads private key from profile's NSS slots, responds via |callback|. |
80 virtual void ReloadKeypairImpl(const base::Callback< | 96 virtual void ReloadKeypairImpl(const base::Callback< |
81 void(const scoped_refptr<ownership::PublicKey>& public_key, | 97 void(const scoped_refptr<ownership::PublicKey>& public_key, |
82 const scoped_refptr<ownership::PrivateKey>& private_key)>& callback) | 98 const scoped_refptr<ownership::PrivateKey>& private_key)>& callback) |
83 override; | 99 override; |
84 | 100 |
85 // Possibly notifies DeviceSettingsService that owner's keypair is loaded. | 101 // Possibly notifies DeviceSettingsService that owner's keypair is loaded. |
86 virtual void OnPostKeypairLoadedActions() override; | 102 virtual void OnPostKeypairLoadedActions() override; |
87 | 103 |
88 // Performs next operation in the queue. | 104 // Tries to sign store current device settings if there're pending |
89 void StartNextOperation(); | 105 // changes in device settings and no active previous call to |
| 106 // DeviceSettingsService::Store(). |
| 107 void StoreDeviceSettings(); |
90 | 108 |
91 // Called when sign-and-store operation completes it's work. | 109 // Called when current device settings are successfully signed. |
92 void HandleCompletedOperation(const base::Closure& callback, | 110 // Sends signed settings for storage. |
93 SessionManagerOperation* operation, | 111 void OnPolicyAssembledAndSigned( |
94 DeviceSettingsService::Status status); | 112 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_response); |
| 113 |
| 114 // Called by DeviceSettingsService when modified and signed device |
| 115 // settings are stored. Notifies observers and tries to store device |
| 116 // settings again. |
| 117 void OnSignedPolicyStored(bool success); |
| 118 |
| 119 // Fetches device settings from DeviceSettingsService and merges |
| 120 // them with local device settings. |
| 121 bool UpdateFromService(); |
| 122 |
| 123 DeviceSettingsService* device_settings_service_; |
95 | 124 |
96 // Profile this service instance belongs to. | 125 // Profile this service instance belongs to. |
97 Profile* profile_; | 126 Profile* profile_; |
98 | 127 |
99 // User ID this service instance belongs to. | 128 // User ID this service instance belongs to. |
100 std::string user_id_; | 129 std::string user_id_; |
101 | 130 |
102 // Whether profile still needs to be initialized. | 131 // Whether profile still needs to be initialized. |
103 bool waiting_for_profile_creation_; | 132 bool waiting_for_profile_creation_; |
104 | 133 |
105 // Whether TPM token still needs to be initialized. | 134 // Whether TPM token still needs to be initialized. |
106 bool waiting_for_tpm_token_; | 135 bool waiting_for_tpm_token_; |
107 | 136 |
108 // The queue of pending sign-and-store operations. The first operation on the | 137 // The device settings. This may be different from the actual |
109 // queue is currently active; it gets removed and destroyed once it completes. | 138 // current device settings (which can be obtained from |
110 std::deque<SessionManagerOperation*> pending_operations_; | 139 // DeviceSettingsService) in case the device does not have an owner |
| 140 // yet or there are pending changes that have not yet been written |
| 141 // to session_manager. |
| 142 enterprise_management::ChromeDeviceSettingsProto device_settings_; |
| 143 |
| 144 // True if some settings were changed but not stored. |
| 145 bool has_pending_changes_; |
111 | 146 |
112 content::NotificationRegistrar registrar_; | 147 content::NotificationRegistrar registrar_; |
113 | 148 |
114 base::WeakPtrFactory<OwnerSettingsServiceChromeOS> weak_factory_; | 149 base::WeakPtrFactory<OwnerSettingsServiceChromeOS> weak_factory_; |
115 | 150 |
| 151 base::WeakPtrFactory<OwnerSettingsServiceChromeOS> store_settings_factory_; |
| 152 |
116 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOS); | 153 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOS); |
117 }; | 154 }; |
118 | 155 |
119 } // namespace chromeos | 156 } // namespace chromeos |
120 | 157 |
121 #endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_ | 158 #endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_ |
OLD | NEW |