OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_DEVICE_SETTINGS_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DEVICE_SETTINGS_PROVIDER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DEVICE_SETTINGS_PROVIDER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DEVICE_SETTINGS_PROVIDER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 22 matching lines...) Expand all Loading... |
33 explicit DeviceSettingsProvider(const NotifyObserversCallback& notify_cb); | 33 explicit DeviceSettingsProvider(const NotifyObserversCallback& notify_cb); |
34 virtual ~DeviceSettingsProvider(); | 34 virtual ~DeviceSettingsProvider(); |
35 | 35 |
36 // CrosSettingsProvider implementation. | 36 // CrosSettingsProvider implementation. |
37 virtual const base::Value* Get(const std::string& path) const OVERRIDE; | 37 virtual const base::Value* Get(const std::string& path) const OVERRIDE; |
38 virtual bool GetTrusted(const std::string& path, | 38 virtual bool GetTrusted(const std::string& path, |
39 const base::Closure& callback) OVERRIDE; | 39 const base::Closure& callback) OVERRIDE; |
40 virtual bool HandlesSetting(const std::string& path) const OVERRIDE; | 40 virtual bool HandlesSetting(const std::string& path) const OVERRIDE; |
41 virtual void Reload() OVERRIDE; | 41 virtual void Reload() OVERRIDE; |
42 | 42 |
| 43 protected: |
| 44 // Constructor that does the real initialization and can also be used by tests |
| 45 // to mock the low level servers of this class. |
| 46 DeviceSettingsProvider(const NotifyObserversCallback& notify_cb, |
| 47 SignedSettingsHelper* signed_settings_helper, |
| 48 OwnershipService::Status ownership_service); |
| 49 |
| 50 void set_ownership_status(OwnershipService::Status status) { |
| 51 ownership_status_ = status; |
| 52 } |
| 53 |
43 private: | 54 private: |
| 55 void Initialize(); |
| 56 |
44 // CrosSettingsProvider implementation: | 57 // CrosSettingsProvider implementation: |
45 virtual void DoSet(const std::string& path, | 58 virtual void DoSet(const std::string& path, |
46 const base::Value& value) OVERRIDE; | 59 const base::Value& value) OVERRIDE; |
47 | 60 |
48 // content::NotificationObserver implementation: | 61 // content::NotificationObserver implementation: |
49 virtual void Observe(int type, | 62 virtual void Observe(int type, |
50 const content::NotificationSource& source, | 63 const content::NotificationSource& source, |
51 const content::NotificationDetails& details) OVERRIDE; | 64 const content::NotificationDetails& details) OVERRIDE; |
52 | 65 |
53 const enterprise_management::PolicyData policy() const; | 66 const enterprise_management::PolicyData policy() const; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 void OnStorePolicyCompleted(SignedSettings::ReturnCode code); | 132 void OnStorePolicyCompleted(SignedSettings::ReturnCode code); |
120 | 133 |
121 // Callback of RetrievePolicyOp for ordinary policy [re]loads. | 134 // Callback of RetrievePolicyOp for ordinary policy [re]loads. |
122 void OnRetrievePolicyCompleted( | 135 void OnRetrievePolicyCompleted( |
123 SignedSettings::ReturnCode code, | 136 SignedSettings::ReturnCode code, |
124 const enterprise_management::PolicyFetchResponse& policy); | 137 const enterprise_management::PolicyFetchResponse& policy); |
125 | 138 |
126 // Pending callbacks that need to be invoked after settings verification. | 139 // Pending callbacks that need to be invoked after settings verification. |
127 std::vector<base::Closure> callbacks_; | 140 std::vector<base::Closure> callbacks_; |
128 | 141 |
| 142 SignedSettingsHelper* signed_settings_helper_; |
129 OwnershipService::Status ownership_status_; | 143 OwnershipService::Status ownership_status_; |
130 mutable scoped_ptr<SignedSettingsMigrationHelper> migration_helper_; | 144 mutable scoped_ptr<SignedSettingsMigrationHelper> migration_helper_; |
131 | 145 |
132 content::NotificationRegistrar registrar_; | 146 content::NotificationRegistrar registrar_; |
133 | 147 |
134 // In order to guard against occasional failure to fetch a property | 148 // In order to guard against occasional failure to fetch a property |
135 // we allow for some number of retries. | 149 // we allow for some number of retries. |
136 int retries_left_; | 150 int retries_left_; |
137 | 151 |
138 enterprise_management::PolicyData policy_; | 152 enterprise_management::PolicyData policy_; |
139 bool trusted_; | 153 bool trusted_; |
140 | 154 |
141 PrefValueMap values_cache_; | 155 PrefValueMap values_cache_; |
142 | 156 |
143 // This is a queue for set requests, because those need to be sequential. | 157 // This is a queue for set requests, because those need to be sequential. |
144 typedef std::pair<std::string, base::Value*> PendingQueueElement; | 158 typedef std::pair<std::string, base::Value*> PendingQueueElement; |
145 std::vector<PendingQueueElement> pending_changes_; | 159 std::vector<PendingQueueElement> pending_changes_; |
146 | 160 |
| 161 friend class DeviceSettingsProviderTest; |
| 162 FRIEND_TEST_ALL_PREFIXES(DeviceSettingsProviderTest, |
| 163 InitializationTestUnowned); |
147 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsProvider); | 164 DISALLOW_COPY_AND_ASSIGN(DeviceSettingsProvider); |
148 }; | 165 }; |
149 | 166 |
150 } // namespace chromeos | 167 } // namespace chromeos |
151 | 168 |
152 #endif // CHROME_BROWSER_CHROMEOS_DEVICE_SETTINGS_PROVIDER_H_ | 169 #endif // CHROME_BROWSER_CHROMEOS_DEVICE_SETTINGS_PROVIDER_H_ |
OLD | NEW |