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_POLICY_USER_CLOUD_POLICY_STORE_CHROMEOS_H_ | 5 #ifndef CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_STORE_CHROMEOS_H_ |
6 #define CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_STORE_CHROMEOS_H_ | 6 #define CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_STORE_CHROMEOS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | |
10 | 9 |
11 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
13 #include "base/file_path.h" | 12 #include "base/file_path.h" |
14 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
16 #include "chrome/browser/policy/cloud_policy_validator.h" | 15 #include "chrome/browser/policy/cloud_policy_validator.h" |
17 #include "chrome/browser/policy/user_cloud_policy_store_base.h" | 16 #include "chrome/browser/policy/user_cloud_policy_store_base.h" |
18 #include "chromeos/dbus/dbus_method_call_status.h" | |
19 | 17 |
20 namespace chromeos { | 18 namespace chromeos { |
21 class CryptohomeClient; | |
22 class SessionManagerClient; | 19 class SessionManagerClient; |
23 } | 20 } |
24 | 21 |
25 namespace policy { | 22 namespace policy { |
26 | 23 |
27 class LegacyPolicyCacheLoader; | 24 class LegacyPolicyCacheLoader; |
28 | 25 |
29 // Implements a cloud policy store backed by the Chrome OS' session_manager, | 26 // Implements a cloud policy store backed by the Chrome OS' session_manager, |
30 // which takes care of persisting policy to disk and is accessed via DBus calls | 27 // which takes care of persisting policy to disk and is accessed via DBus calls |
31 // through SessionManagerClient. | 28 // through SessionManagerClient. |
32 // | 29 // |
33 // Additionally, this class drives legacy UserPolicyTokenCache and | 30 // Additionally, this class drives legacy UserPolicyTokenCache and |
34 // UserPolicyDiskCache instances, migrating policy from these to session_manager | 31 // UserPolicyDiskCache instances, migrating policy from these to session_manager |
35 // storage on the fly. | 32 // storage on the fly. |
36 class UserCloudPolicyStoreChromeOS : public UserCloudPolicyStoreBase { | 33 class UserCloudPolicyStoreChromeOS : public UserCloudPolicyStoreBase { |
37 public: | 34 public: |
38 UserCloudPolicyStoreChromeOS( | 35 UserCloudPolicyStoreChromeOS( |
39 chromeos::CryptohomeClient* cryptohome_client, | |
40 chromeos::SessionManagerClient* session_manager_client, | 36 chromeos::SessionManagerClient* session_manager_client, |
41 const std::string& username, | 37 const std::string& username, |
42 const base::FilePath& user_policy_key_dir, | |
43 const base::FilePath& legacy_token_cache_file, | 38 const base::FilePath& legacy_token_cache_file, |
44 const base::FilePath& legacy_policy_cache_file); | 39 const base::FilePath& legacy_policy_cache_file); |
45 virtual ~UserCloudPolicyStoreChromeOS(); | 40 virtual ~UserCloudPolicyStoreChromeOS(); |
46 | 41 |
47 // CloudPolicyStore: | 42 // CloudPolicyStore: |
48 virtual void Store( | 43 virtual void Store( |
49 const enterprise_management::PolicyFetchResponse& policy) OVERRIDE; | 44 const enterprise_management::PolicyFetchResponse& policy) OVERRIDE; |
50 virtual void Load() OVERRIDE; | 45 virtual void Load() OVERRIDE; |
51 | 46 |
52 private: | 47 private: |
53 // Starts validation of |policy| before storing it. | 48 // Called back from SessionManagerClient for policy load operations. |
54 void ValidatePolicyForStore( | 49 void OnPolicyRetrieved(const std::string& policy_blob); |
55 scoped_ptr<enterprise_management::PolicyFetchResponse> policy); | |
56 | 50 |
57 // Completion handler for policy validation on the Store() path. | 51 // Completion handler for policy validation on the Load() path. Installs the |
58 // Starts a store operation if the validation succeeded. | 52 // policy and publishes it if validation succeeded. |
| 53 void OnRetrievedPolicyValidated(UserCloudPolicyValidator* validator); |
| 54 |
| 55 // Completion handler for policy validation on the Load() path. Starts a store |
| 56 // operation if the validation succeeded. |
59 void OnPolicyToStoreValidated(UserCloudPolicyValidator* validator); | 57 void OnPolicyToStoreValidated(UserCloudPolicyValidator* validator); |
60 | 58 |
61 // Called back from SessionManagerClient for policy store operations. | 59 // Called back from SessionManagerClient for policy store operations. |
62 void OnPolicyStored(bool); | 60 void OnPolicyStored(bool); |
63 | 61 |
64 // Called back from SessionManagerClient for policy load operations. | 62 // Starts policy blob validation. |
65 void OnPolicyRetrieved(const std::string& policy_blob); | 63 void Validate( |
66 | 64 scoped_ptr<enterprise_management::PolicyFetchResponse> policy, |
67 // Starts validation of the loaded |policy| before installing it. | 65 const UserCloudPolicyValidator::CompletionCallback& callback); |
68 void ValidateRetrievedPolicy( | |
69 scoped_ptr<enterprise_management::PolicyFetchResponse> policy); | |
70 | |
71 // Completion handler for policy validation on the Load() path. Installs the | |
72 // policy and publishes it if validation succeeded. | |
73 void OnRetrievedPolicyValidated(UserCloudPolicyValidator* validator); | |
74 | 66 |
75 // Callback for loading legacy caches. | 67 // Callback for loading legacy caches. |
76 void OnLegacyLoadFinished( | 68 void OnLegacyLoadFinished( |
77 const std::string& dm_token, | 69 const std::string& dm_token, |
78 const std::string& device_id, | 70 const std::string& device_id, |
79 Status status, | 71 Status status, |
80 scoped_ptr<enterprise_management::PolicyFetchResponse>); | 72 scoped_ptr<enterprise_management::PolicyFetchResponse>); |
81 | 73 |
82 // Completion callback for legacy policy validation. | 74 // Completion callback for legacy policy validation. |
83 void OnLegacyPolicyValidated(const std::string& dm_token, | 75 void OnLegacyPolicyValidated(const std::string& dm_token, |
84 const std::string& device_id, | 76 const std::string& device_id, |
85 UserCloudPolicyValidator* validator); | 77 UserCloudPolicyValidator* validator); |
86 | 78 |
87 // Installs legacy tokens. | 79 // Installs legacy tokens. |
88 void InstallLegacyTokens(const std::string& dm_token, | 80 void InstallLegacyTokens(const std::string& dm_token, |
89 const std::string& device_id); | 81 const std::string& device_id); |
90 | 82 |
91 // Removes the passed-in legacy cache directory. | 83 // Removes the passed-in legacy cache directory. |
92 static void RemoveLegacyCacheDir(const base::FilePath& dir); | 84 static void RemoveLegacyCacheDir(const base::FilePath& dir); |
93 | 85 |
94 // Invokes |callback| after reloading |policy_key_|. | |
95 void ReloadPolicyKey(const base::Closure& callback); | |
96 | |
97 // Reads the contents of |path| into |key|. | |
98 static void LoadPolicyKey(const FilePath& path, std::vector<uint8>* key); | |
99 | |
100 // Callback for the key reloading. | |
101 void OnPolicyKeyReloaded(std::vector<uint8>* key, | |
102 const base::Closure& callback); | |
103 | |
104 // Invokes |callback| after creating |policy_key_|, if it hasn't been created | |
105 // yet; otherwise invokes |callback| immediately. | |
106 void EnsurePolicyKeyLoaded(const base::Closure& callback); | |
107 | |
108 // Callback for getting the sanitized username from |cryptohome_client_|. | |
109 void OnGetSanitizedUsername(const base::Closure& callback, | |
110 chromeos::DBusMethodCallStatus call_status, | |
111 const std::string& sanitized_username); | |
112 | |
113 chromeos::CryptohomeClient* cryptohome_client_; | |
114 chromeos::SessionManagerClient* session_manager_client_; | 86 chromeos::SessionManagerClient* session_manager_client_; |
115 const std::string username_; | 87 const std::string username_; |
116 base::FilePath user_policy_key_dir_; | |
117 | 88 |
118 base::WeakPtrFactory<UserCloudPolicyStoreChromeOS> weak_factory_; | 89 base::WeakPtrFactory<UserCloudPolicyStoreChromeOS> weak_factory_; |
119 | 90 |
120 // TODO(mnissler): Remove all the legacy policy support members below after | 91 // TODO(mnissler): Remove all the legacy policy support members below after |
121 // the number of pre-M20 clients drops back to zero. | 92 // the number of pre-M20 clients drops back to zero. |
122 base::FilePath legacy_cache_dir_; | 93 base::FilePath legacy_cache_dir_; |
123 scoped_ptr<LegacyPolicyCacheLoader> legacy_loader_; | 94 scoped_ptr<LegacyPolicyCacheLoader> legacy_loader_; |
124 bool legacy_caches_loaded_; | 95 bool legacy_caches_loaded_; |
125 | 96 |
126 bool policy_key_loaded_; | |
127 FilePath policy_key_path_; | |
128 std::vector<uint8> policy_key_; | |
129 | |
130 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyStoreChromeOS); | 97 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyStoreChromeOS); |
131 }; | 98 }; |
132 | 99 |
133 } // namespace policy | 100 } // namespace policy |
134 | 101 |
135 #endif // CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_STORE_CHROMEOS_H_ | 102 #endif // CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_STORE_CHROMEOS_H_ |
OLD | NEW |