OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_POLICY_DEVICE_POLICY_CACHE_H_ | |
6 #define CHROME_BROWSER_POLICY_DEVICE_POLICY_CACHE_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/compiler_specific.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "chrome/browser/chromeos/settings/device_settings_service.h" | |
14 #include "chrome/browser/policy/cloud_policy_cache_base.h" | |
15 | |
16 namespace policy { | |
17 | |
18 class CloudPolicyDataStore; | |
19 class EnterpriseInstallAttributes; | |
20 class PolicyMap; | |
21 | |
22 // CloudPolicyCacheBase implementation that persists policy information | |
23 // to ChromeOS' session manager (via DeviceSettingsService). | |
24 class DevicePolicyCache : public CloudPolicyCacheBase, | |
25 public chromeos::DeviceSettingsService::Observer { | |
26 public: | |
27 DevicePolicyCache(CloudPolicyDataStore* data_store, | |
28 EnterpriseInstallAttributes* install_attributes); | |
29 virtual ~DevicePolicyCache(); | |
30 | |
31 // CloudPolicyCacheBase implementation: | |
32 virtual void Load() OVERRIDE; | |
33 virtual bool SetPolicy( | |
34 const enterprise_management::PolicyFetchResponse& policy) OVERRIDE; | |
35 virtual void SetUnmanaged() OVERRIDE; | |
36 virtual void SetFetchingDone() OVERRIDE; | |
37 | |
38 // DeviceSettingsService::Observer implementation: | |
39 virtual void OwnershipStatusChanged() OVERRIDE; | |
40 virtual void DeviceSettingsUpdated() OVERRIDE; | |
41 | |
42 private: | |
43 friend class DevicePolicyCacheTest; | |
44 friend class DevicePolicyCacheTestHelper; | |
45 | |
46 // Alternate c'tor allowing tests to mock out the DeviceSettingsService | |
47 // singleton. | |
48 DevicePolicyCache( | |
49 CloudPolicyDataStore* data_store, | |
50 EnterpriseInstallAttributes* install_attributes, | |
51 chromeos::DeviceSettingsService* device_settings_service); | |
52 | |
53 // CloudPolicyCacheBase implementation: | |
54 virtual bool DecodePolicyData( | |
55 const enterprise_management::PolicyData& policy_data, | |
56 PolicyMap* policies) OVERRIDE; | |
57 | |
58 // Handles completion of policy store operations. | |
59 void PolicyStoreOpCompleted(); | |
60 | |
61 // Checks with immutable attributes whether this is an enterprise device and | |
62 // read the registration user if this is the case. | |
63 void CheckImmutableAttributes(); | |
64 | |
65 // Tries to install the initial device policy retrieved from signed settings. | |
66 // Fills in |device_token| if it could be extracted from the loaded protobuf. | |
67 void InstallInitialPolicy( | |
68 chromeos::DeviceSettingsService::Status status, | |
69 const enterprise_management::PolicyData* policy_data, | |
70 std::string* device_token); | |
71 | |
72 // Ensures that CrosSettings has established trust on the reporting prefs and | |
73 // publishes the |device_token| loaded from the cache. It's important that we | |
74 // have fully-initialized device settings s.t. device status uploads get the | |
75 // correct reporting policy flags. | |
76 void SetTokenAndFlagReady(const std::string& device_token); | |
77 | |
78 // Checks whether a policy fetch is pending and sends out a notification if | |
79 // that is the case. | |
80 void CheckFetchingDone(); | |
81 | |
82 CloudPolicyDataStore* data_store_; | |
83 EnterpriseInstallAttributes* install_attributes_; | |
84 | |
85 chromeos::DeviceSettingsService* device_settings_service_; | |
86 | |
87 base::WeakPtrFactory<DevicePolicyCache> weak_ptr_factory_; | |
88 | |
89 bool policy_fetch_pending_; | |
90 | |
91 DISALLOW_COPY_AND_ASSIGN(DevicePolicyCache); | |
92 }; | |
93 | |
94 } // namespace policy | |
95 | |
96 #endif // CHROME_BROWSER_POLICY_DEVICE_POLICY_CACHE_H_ | |
OLD | NEW |