| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_POLICY_USER_POLICY_CACHE_H_ | 5 #ifndef CHROME_BROWSER_POLICY_USER_POLICY_CACHE_H_ |
| 6 #define CHROME_BROWSER_POLICY_USER_POLICY_CACHE_H_ | 6 #define CHROME_BROWSER_POLICY_USER_POLICY_CACHE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 namespace em = enterprise_management; | 30 namespace em = enterprise_management; |
| 31 | 31 |
| 32 class PolicyMap; | 32 class PolicyMap; |
| 33 | 33 |
| 34 // CloudPolicyCacheBase implementation that persists policy information | 34 // CloudPolicyCacheBase implementation that persists policy information |
| 35 // into the file specified by the c'tor parameter |backing_file_path|. | 35 // into the file specified by the c'tor parameter |backing_file_path|. |
| 36 class UserPolicyCache : public CloudPolicyCacheBase, | 36 class UserPolicyCache : public CloudPolicyCacheBase, |
| 37 public UserPolicyDiskCache::Delegate { | 37 public UserPolicyDiskCache::Delegate { |
| 38 public: | 38 public: |
| 39 explicit UserPolicyCache(const FilePath& backing_file_path); | 39 // |backing_file_path| is the path to the cache file. |
| 40 // |wait_for_policy_fetch| is true if the cache should be ready only after |
| 41 // an attempt was made to fetch user policy. |
| 42 UserPolicyCache(const FilePath& backing_file_path, |
| 43 bool wait_for_policy_fetch); |
| 40 virtual ~UserPolicyCache(); | 44 virtual ~UserPolicyCache(); |
| 41 | 45 |
| 42 // CloudPolicyCacheBase implementation: | 46 // CloudPolicyCacheBase implementation: |
| 43 virtual void Load() OVERRIDE; | 47 virtual void Load() OVERRIDE; |
| 44 virtual void SetPolicy(const em::PolicyFetchResponse& policy) OVERRIDE; | 48 virtual void SetPolicy(const em::PolicyFetchResponse& policy) OVERRIDE; |
| 45 virtual void SetUnmanaged() OVERRIDE; | 49 virtual void SetUnmanaged() OVERRIDE; |
| 50 virtual void SetFetchingDone() OVERRIDE; |
| 46 | 51 |
| 47 private: | 52 private: |
| 48 class DiskCache; | 53 class DiskCache; |
| 49 | 54 |
| 50 // UserPolicyDiskCache::Delegate implementation: | 55 // UserPolicyDiskCache::Delegate implementation: |
| 51 virtual void OnDiskCacheLoaded( | 56 virtual void OnDiskCacheLoaded( |
| 52 UserPolicyDiskCache::LoadResult result, | 57 UserPolicyDiskCache::LoadResult result, |
| 53 const em::CachedCloudPolicyResponse& cached_response) OVERRIDE; | 58 const em::CachedCloudPolicyResponse& cached_response) OVERRIDE; |
| 54 | 59 |
| 55 // CloudPolicyCacheBase implementation: | 60 // CloudPolicyCacheBase implementation: |
| 56 virtual bool DecodePolicyData(const em::PolicyData& policy_data, | 61 virtual bool DecodePolicyData(const em::PolicyData& policy_data, |
| 57 PolicyMap* mandatory, | 62 PolicyMap* mandatory, |
| 58 PolicyMap* recommended) OVERRIDE; | 63 PolicyMap* recommended) OVERRIDE; |
| 59 | 64 |
| 65 // Checks if this cache is ready, and invokes SetReady() if so. |
| 66 void CheckIfReady(); |
| 67 |
| 60 // <Old-style policy support> | 68 // <Old-style policy support> |
| 61 // The following member functions are needed to support old-style policy and | 69 // The following member functions are needed to support old-style policy and |
| 62 // can be removed once all server-side components (CPanel, D3) have been | 70 // can be removed once all server-side components (CPanel, D3) have been |
| 63 // migrated to providing the new policy format. | 71 // migrated to providing the new policy format. |
| 64 | 72 |
| 65 // If |mandatory| and |recommended| are both empty, and |policy_data| | 73 // If |mandatory| and |recommended| are both empty, and |policy_data| |
| 66 // contains a field named "repeated GenericNamedValue named_value = 2;", | 74 // contains a field named "repeated GenericNamedValue named_value = 2;", |
| 67 // this field is decoded into |mandatory|. | 75 // this field is decoded into |mandatory|. |
| 68 void MaybeDecodeOldstylePolicy(const std::string& policy_data, | 76 void MaybeDecodeOldstylePolicy(const std::string& policy_data, |
| 69 PolicyMap* mandatory, | 77 PolicyMap* mandatory, |
| 70 PolicyMap* recommended); | 78 PolicyMap* recommended); |
| 71 | 79 |
| 72 Value* DecodeIntegerValue(google::protobuf::int64 value) const; | 80 Value* DecodeIntegerValue(google::protobuf::int64 value) const; |
| 73 Value* DecodeValue(const em::GenericValue& value) const; | 81 Value* DecodeValue(const em::GenericValue& value) const; |
| 74 | 82 |
| 75 // </Old-style policy support> | 83 // </Old-style policy support> |
| 76 | 84 |
| 77 // Manages the cache file. | 85 // Manages the cache file. |
| 78 scoped_refptr<UserPolicyDiskCache> disk_cache_; | 86 scoped_refptr<UserPolicyDiskCache> disk_cache_; |
| 79 | 87 |
| 80 // Used for constructing the weak ptr passed to |disk_cache_|. | 88 // Used for constructing the weak ptr passed to |disk_cache_|. |
| 81 base::WeakPtrFactory<UserPolicyDiskCache::Delegate> weak_ptr_factory_; | 89 base::WeakPtrFactory<UserPolicyDiskCache::Delegate> weak_ptr_factory_; |
| 82 | 90 |
| 91 // True if the disk cache has been loaded. |
| 92 bool disk_cache_ready_; |
| 93 |
| 94 // True if at least one attempt was made to refresh the cache with a freshly |
| 95 // fetched policy, or if there is no need to wait for that. |
| 96 bool fetch_ready_; |
| 97 |
| 83 DISALLOW_COPY_AND_ASSIGN(UserPolicyCache); | 98 DISALLOW_COPY_AND_ASSIGN(UserPolicyCache); |
| 84 }; | 99 }; |
| 85 | 100 |
| 86 } // namespace policy | 101 } // namespace policy |
| 87 | 102 |
| 88 #endif // CHROME_BROWSER_POLICY_USER_POLICY_CACHE_H_ | 103 #endif // CHROME_BROWSER_POLICY_USER_POLICY_CACHE_H_ |
| OLD | NEW |