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