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 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "chrome/browser/policy/cloud_policy_validator.h" | 15 #include "chrome/browser/policy/cloud_policy_validator.h" |
16 #include "chrome/browser/policy/user_cloud_policy_store_base.h" | 16 #include "chrome/browser/policy/user_cloud_policy_store_base.h" |
| 17 #include "chromeos/dbus/dbus_method_call_status.h" |
17 | 18 |
18 namespace chromeos { | 19 namespace chromeos { |
| 20 class CryptohomeClient; |
19 class SessionManagerClient; | 21 class SessionManagerClient; |
20 } | 22 } |
21 | 23 |
22 namespace policy { | 24 namespace policy { |
23 | 25 |
24 class LegacyPolicyCacheLoader; | 26 class LegacyPolicyCacheLoader; |
| 27 class UserPolicyKey; |
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, |
38 const FilePath& legacy_token_cache_file, | 42 const FilePath& legacy_token_cache_file, |
39 const FilePath& legacy_policy_cache_file); | 43 const FilePath& legacy_policy_cache_file); |
40 virtual ~UserCloudPolicyStoreChromeOS(); | 44 virtual ~UserCloudPolicyStoreChromeOS(); |
41 | 45 |
42 // CloudPolicyStore: | 46 // CloudPolicyStore: |
43 virtual void Store( | 47 virtual void Store( |
44 const enterprise_management::PolicyFetchResponse& policy) OVERRIDE; | 48 const enterprise_management::PolicyFetchResponse& policy) OVERRIDE; |
45 virtual void Load() OVERRIDE; | 49 virtual void Load() OVERRIDE; |
46 | 50 |
47 private: | 51 private: |
| 52 // Starts validation of |policy| before storing it. |
| 53 void ValidatePolicyForStore( |
| 54 scoped_ptr<enterprise_management::PolicyFetchResponse> policy); |
| 55 |
| 56 // Completion handler for policy validation on the Store() path. |
| 57 // Starts a store operation if the validation succeeded. |
| 58 void OnPolicyToStoreValidated(UserCloudPolicyValidator* validator); |
| 59 |
| 60 // Called back from SessionManagerClient for policy store operations. |
| 61 void OnPolicyStored(bool); |
| 62 |
48 // Called back from SessionManagerClient for policy load operations. | 63 // Called back from SessionManagerClient for policy load operations. |
49 void OnPolicyRetrieved(const std::string& policy_blob); | 64 void OnPolicyRetrieved(const std::string& policy_blob); |
50 | 65 |
| 66 // Starts validation of the loaded |policy| before installing it. |
| 67 void ValidateRetrievedPolicy( |
| 68 scoped_ptr<enterprise_management::PolicyFetchResponse> policy); |
| 69 |
51 // Completion handler for policy validation on the Load() path. Installs the | 70 // Completion handler for policy validation on the Load() path. Installs the |
52 // policy and publishes it if validation succeeded. | 71 // policy and publishes it if validation succeeded. |
53 void OnRetrievedPolicyValidated(UserCloudPolicyValidator* validator); | 72 void OnRetrievedPolicyValidated(UserCloudPolicyValidator* validator); |
54 | 73 |
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. | 74 // Callback for loading legacy caches. |
68 void OnLegacyLoadFinished( | 75 void OnLegacyLoadFinished( |
69 const std::string& dm_token, | 76 const std::string& dm_token, |
70 const std::string& device_id, | 77 const std::string& device_id, |
71 Status status, | 78 Status status, |
72 scoped_ptr<enterprise_management::PolicyFetchResponse>); | 79 scoped_ptr<enterprise_management::PolicyFetchResponse>); |
73 | 80 |
74 // Completion callback for legacy policy validation. | 81 // Completion callback for legacy policy validation. |
75 void OnLegacyPolicyValidated(const std::string& dm_token, | 82 void OnLegacyPolicyValidated(const std::string& dm_token, |
76 const std::string& device_id, | 83 const std::string& device_id, |
77 UserCloudPolicyValidator* validator); | 84 UserCloudPolicyValidator* validator); |
78 | 85 |
79 // Installs legacy tokens. | 86 // Installs legacy tokens. |
80 void InstallLegacyTokens(const std::string& dm_token, | 87 void InstallLegacyTokens(const std::string& dm_token, |
81 const std::string& device_id); | 88 const std::string& device_id); |
82 | 89 |
83 // Removes the passed-in legacy cache directory. | 90 // Removes the passed-in legacy cache directory. |
84 static void RemoveLegacyCacheDir(const FilePath& dir); | 91 static void RemoveLegacyCacheDir(const FilePath& dir); |
85 | 92 |
| 93 void EnsurePolicyKeyLoaded(const base::Closure& callback); |
| 94 |
| 95 // Callback for getting the sanitized username from |cryptohome_client_|. |
| 96 void OnGetSanitizedUsername(const base::Closure& callback, |
| 97 chromeos::DBusMethodCallStatus call_status, |
| 98 const std::string& sanitized_username); |
| 99 |
| 100 chromeos::CryptohomeClient* cryptohome_client_; |
86 chromeos::SessionManagerClient* session_manager_client_; | 101 chromeos::SessionManagerClient* session_manager_client_; |
87 const std::string username_; | 102 const std::string username_; |
88 | 103 |
89 base::WeakPtrFactory<UserCloudPolicyStoreChromeOS> weak_factory_; | 104 base::WeakPtrFactory<UserCloudPolicyStoreChromeOS> weak_factory_; |
90 | 105 |
91 // TODO(mnissler): Remove all the legacy policy support members below after | 106 // TODO(mnissler): Remove all the legacy policy support members below after |
92 // the number of pre-M20 clients drops back to zero. | 107 // the number of pre-M20 clients drops back to zero. |
93 FilePath legacy_cache_dir_; | 108 FilePath legacy_cache_dir_; |
94 scoped_ptr<LegacyPolicyCacheLoader> legacy_loader_; | 109 scoped_ptr<LegacyPolicyCacheLoader> legacy_loader_; |
95 bool legacy_caches_loaded_; | 110 bool legacy_caches_loaded_; |
96 | 111 |
| 112 scoped_ptr<UserPolicyKey> policy_key_; |
| 113 |
97 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyStoreChromeOS); | 114 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyStoreChromeOS); |
98 }; | 115 }; |
99 | 116 |
100 } // namespace policy | 117 } // namespace policy |
101 | 118 |
102 #endif // CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_STORE_CHROMEOS_H_ | 119 #endif // CHROME_BROWSER_POLICY_USER_CLOUD_POLICY_STORE_CHROMEOS_H_ |
OLD | NEW |