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 <string> | 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/containers/scoped_ptr_hash_map.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/values.h" |
13 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 15 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
14 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 16 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
15 #include "chromeos/dbus/session_manager_client.h" | 17 #include "chromeos/dbus/session_manager_client.h" |
16 #include "components/keyed_service/core/keyed_service.h" | 18 #include "components/keyed_service/core/keyed_service.h" |
17 #include "components/ownership/owner_key_util.h" | 19 #include "components/ownership/owner_key_util.h" |
18 #include "components/ownership/owner_settings_service.h" | 20 #include "components/ownership/owner_settings_service.h" |
19 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
20 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
21 | 23 |
22 class Profile; | 24 class Profile; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 const std::string& user_id, | 78 const std::string& user_id, |
77 const enterprise_management::PolicyData* policy_data, | 79 const enterprise_management::PolicyData* policy_data, |
78 const enterprise_management::ChromeDeviceSettingsProto* settings); | 80 const enterprise_management::ChromeDeviceSettingsProto* settings); |
79 | 81 |
80 // Updates device |settings|. | 82 // Updates device |settings|. |
81 static void UpdateDeviceSettings( | 83 static void UpdateDeviceSettings( |
82 const std::string& path, | 84 const std::string& path, |
83 const base::Value& value, | 85 const base::Value& value, |
84 enterprise_management::ChromeDeviceSettingsProto& settings); | 86 enterprise_management::ChromeDeviceSettingsProto& settings); |
85 | 87 |
86 bool has_pending_changes() const { return has_pending_changes_; } | 88 bool has_pending_changes() const { |
| 89 return !pending_changes_.empty() || tentative_settings_.get(); |
| 90 } |
87 | 91 |
88 private: | 92 private: |
89 friend class OwnerSettingsServiceChromeOSFactory; | 93 friend class OwnerSettingsServiceChromeOSFactory; |
90 | 94 |
91 OwnerSettingsServiceChromeOS( | 95 OwnerSettingsServiceChromeOS( |
92 DeviceSettingsService* device_settings_service, | 96 DeviceSettingsService* device_settings_service, |
93 Profile* profile, | 97 Profile* profile, |
94 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); | 98 const scoped_refptr<ownership::OwnerKeyUtil>& owner_key_util); |
95 | 99 |
96 // OwnerSettingsService protected interface overrides: | 100 // OwnerSettingsService protected interface overrides: |
97 | 101 |
98 // Reloads private key from profile's NSS slots, responds via |callback|. | 102 // Reloads private key from profile's NSS slots, responds via |callback|. |
99 virtual void ReloadKeypairImpl(const base::Callback< | 103 virtual void ReloadKeypairImpl(const base::Callback< |
100 void(const scoped_refptr<ownership::PublicKey>& public_key, | 104 void(const scoped_refptr<ownership::PublicKey>& public_key, |
101 const scoped_refptr<ownership::PrivateKey>& private_key)>& callback) | 105 const scoped_refptr<ownership::PrivateKey>& private_key)>& callback) |
102 override; | 106 override; |
103 | 107 |
104 // Possibly notifies DeviceSettingsService that owner's keypair is loaded. | 108 // Possibly notifies DeviceSettingsService that owner's keypair is loaded. |
105 virtual void OnPostKeypairLoadedActions() override; | 109 virtual void OnPostKeypairLoadedActions() override; |
106 | 110 |
107 // Tries to sign store current device settings if there're pending | 111 // Tries to apply recent changes to device settings proto, sign it and store. |
108 // changes in device settings and no active previous call to | 112 void StorePendingChanges(); |
109 // DeviceSettingsService::Store(). | |
110 void StoreDeviceSettings(); | |
111 | 113 |
112 // Called when current device settings are successfully signed. | 114 // Called when current device settings are successfully signed. |
113 // Sends signed settings for storage. | 115 // Sends signed settings for storage. |
114 void OnPolicyAssembledAndSigned( | 116 void OnPolicyAssembledAndSigned( |
115 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_response); | 117 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_response); |
116 | 118 |
117 // Called by DeviceSettingsService when modified and signed device | 119 // Called by DeviceSettingsService when modified and signed device |
118 // settings are stored. Notifies observers and tries to store device | 120 // settings are stored. Notifies observers and tries to store device |
119 // settings again. | 121 // settings again. |
120 void OnSignedPolicyStored(bool success); | 122 void OnSignedPolicyStored(bool success); |
121 | 123 |
122 // Fetches device settings from DeviceSettingsService and merges | |
123 // them with local device settings. | |
124 bool UpdateFromService(); | |
125 | |
126 DeviceSettingsService* device_settings_service_; | 124 DeviceSettingsService* device_settings_service_; |
127 | 125 |
128 // Profile this service instance belongs to. | 126 // Profile this service instance belongs to. |
129 Profile* profile_; | 127 Profile* profile_; |
130 | 128 |
131 // User ID this service instance belongs to. | 129 // User ID this service instance belongs to. |
132 std::string user_id_; | 130 std::string user_id_; |
133 | 131 |
134 // Whether profile still needs to be initialized. | 132 // Whether profile still needs to be initialized. |
135 bool waiting_for_profile_creation_; | 133 bool waiting_for_profile_creation_; |
136 | 134 |
137 // Whether TPM token still needs to be initialized. | 135 // Whether TPM token still needs to be initialized. |
138 bool waiting_for_tpm_token_; | 136 bool waiting_for_tpm_token_; |
139 | 137 |
140 // The device settings. This may be different from the actual | 138 // A set of pending changes to device settings. |
141 // current device settings (which can be obtained from | 139 base::ScopedPtrHashMap<std::string, base::Value> pending_changes_; |
142 // DeviceSettingsService) in case the device does not have an owner | |
143 // yet or there are pending changes that have not yet been written | |
144 // to session_manager. | |
145 enterprise_management::ChromeDeviceSettingsProto device_settings_; | |
146 | 140 |
147 // True if some settings were changed but not stored. | 141 // A protobuf containing pending changes to device settings. |
148 bool has_pending_changes_; | 142 scoped_ptr<enterprise_management::ChromeDeviceSettingsProto> |
| 143 tentative_settings_; |
149 | 144 |
150 content::NotificationRegistrar registrar_; | 145 content::NotificationRegistrar registrar_; |
151 | 146 |
152 base::WeakPtrFactory<OwnerSettingsServiceChromeOS> weak_factory_; | 147 base::WeakPtrFactory<OwnerSettingsServiceChromeOS> weak_factory_; |
153 | 148 |
154 base::WeakPtrFactory<OwnerSettingsServiceChromeOS> store_settings_factory_; | 149 base::WeakPtrFactory<OwnerSettingsServiceChromeOS> store_settings_factory_; |
155 | 150 |
156 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOS); | 151 DISALLOW_COPY_AND_ASSIGN(OwnerSettingsServiceChromeOS); |
157 }; | 152 }; |
158 | 153 |
159 } // namespace chromeos | 154 } // namespace chromeos |
160 | 155 |
161 #endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_ | 156 #endif // CHROME_BROWSER_CHROMEOS_OWNERSHIP_OWNER_SETTINGS_SERVICE_CHROMEOS_H_ |
OLD | NEW |