| 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_CROS_USER_POLICY_CACHE_H_ | |
| 6 #define CHROME_BROWSER_POLICY_CROS_USER_POLICY_CACHE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/file_path.h" | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "chrome/browser/policy/cloud_policy_cache_base.h" | |
| 16 #include "chrome/browser/policy/user_policy_disk_cache.h" | |
| 17 #include "chrome/browser/policy/user_policy_token_cache.h" | |
| 18 | |
| 19 namespace chromeos { | |
| 20 class SessionManagerClient; | |
| 21 } | |
| 22 | |
| 23 namespace policy { | |
| 24 | |
| 25 class CloudPolicyDataStore; | |
| 26 | |
| 27 // User policy cache that talks to the ChromeOS login library in order to store | |
| 28 // and fetch policy data. | |
| 29 class CrosUserPolicyCache : public CloudPolicyCacheBase, | |
| 30 public UserPolicyTokenCache::Delegate, | |
| 31 public UserPolicyDiskCache::Delegate { | |
| 32 public: | |
| 33 CrosUserPolicyCache(chromeos::SessionManagerClient* session_manager_client, | |
| 34 CloudPolicyDataStore* data_store, | |
| 35 bool wait_for_policy_fetch, | |
| 36 const FilePath& legacy_token_cache_file, | |
| 37 const FilePath& legacy_policy_cache_file); | |
| 38 virtual ~CrosUserPolicyCache(); | |
| 39 | |
| 40 // CloudPolicyCacheBase implementation. | |
| 41 virtual void Load() OVERRIDE; | |
| 42 virtual bool SetPolicy( | |
| 43 const enterprise_management::PolicyFetchResponse& policy) OVERRIDE; | |
| 44 virtual void SetUnmanaged() OVERRIDE; | |
| 45 virtual void SetFetchingDone() OVERRIDE; | |
| 46 | |
| 47 protected: | |
| 48 virtual bool DecodePolicyData( | |
| 49 const enterprise_management::PolicyData& policy_data, | |
| 50 PolicyMap* policies) OVERRIDE; | |
| 51 | |
| 52 private: | |
| 53 class StorePolicyOperation; | |
| 54 class RetrievePolicyOperation; | |
| 55 | |
| 56 // UserPolicyTokenLoader::Delegate: | |
| 57 virtual void OnTokenLoaded(const std::string& token, | |
| 58 const std::string& device_id) OVERRIDE; | |
| 59 | |
| 60 // UserPolicyDiskCache::Delegate: | |
| 61 virtual void OnDiskCacheLoaded( | |
| 62 UserPolicyDiskCache::LoadResult result, | |
| 63 const enterprise_management::CachedCloudPolicyResponse& policy) OVERRIDE; | |
| 64 | |
| 65 // Used as a callback for the policy store operation. | |
| 66 void OnPolicyStored(bool result); | |
| 67 | |
| 68 // Callback for the initial policy load. Installs the policy and passes the | |
| 69 // loaded token and device ID to the data store. | |
| 70 void OnPolicyLoadDone( | |
| 71 bool result, | |
| 72 const enterprise_management::PolicyFetchResponse& policy); | |
| 73 | |
| 74 // Callback for the policy retrieval operation run to reload the policy after | |
| 75 // new policy has been successfully stored. Installs the new policy in the | |
| 76 // cache and publishes it if successful. | |
| 77 void OnPolicyReloadDone( | |
| 78 bool result, | |
| 79 const enterprise_management::PolicyFetchResponse& policy); | |
| 80 | |
| 81 void CancelStore(); | |
| 82 void CancelRetrieve(); | |
| 83 | |
| 84 // Checks whether the disk cache and (if requested) the policy fetch | |
| 85 // (including the DBus roundtrips) has completed and generates ready or | |
| 86 // fetching done notifications if this is the case. | |
| 87 void CheckIfDone(); | |
| 88 | |
| 89 // Installs legacy policy, mangling it to remove any public keys, public key | |
| 90 // versions and signatures. This is done so on the next policy fetch the | |
| 91 // server ships down a new policy to be sent down to session_manager. | |
| 92 void InstallLegacyPolicy( | |
| 93 const enterprise_management::PolicyFetchResponse& policy); | |
| 94 | |
| 95 // Removes the legacy cache dir. | |
| 96 static void RemoveLegacyCacheDir(const FilePath& dir); | |
| 97 | |
| 98 chromeos::SessionManagerClient* session_manager_client_; | |
| 99 CloudPolicyDataStore* data_store_; | |
| 100 | |
| 101 // Whether a policy fetch is pending before readiness is asserted. | |
| 102 bool pending_policy_fetch_; | |
| 103 bool pending_disk_cache_load_; | |
| 104 | |
| 105 // Storage and retrieval operations that are currently in flight. | |
| 106 StorePolicyOperation* store_operation_; | |
| 107 RetrievePolicyOperation* retrieve_operation_; | |
| 108 | |
| 109 // TODO(mnissler): Remove all the legacy policy support members below after | |
| 110 // the number of pre-M20 clients drops back to zero. | |
| 111 FilePath legacy_cache_dir_; | |
| 112 | |
| 113 base::WeakPtrFactory<UserPolicyTokenCache::Delegate> | |
| 114 legacy_token_cache_delegate_factory_; | |
| 115 scoped_refptr<UserPolicyTokenLoader> legacy_token_loader_; | |
| 116 | |
| 117 base::WeakPtrFactory<UserPolicyDiskCache::Delegate> | |
| 118 legacy_policy_cache_delegate_factory_; | |
| 119 scoped_refptr<UserPolicyDiskCache> legacy_policy_cache_; | |
| 120 | |
| 121 DISALLOW_COPY_AND_ASSIGN(CrosUserPolicyCache); | |
| 122 }; | |
| 123 | |
| 124 } // namespace policy | |
| 125 | |
| 126 #endif // CHROME_BROWSER_POLICY_CROS_USER_POLICY_CACHE_H_ | |
| OLD | NEW |