Chromium Code Reviews| 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 #include "chrome/browser/policy/cloud/user_cloud_policy_store.h" | 5 #include "chrome/browser/policy/cloud/user_cloud_policy_store.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" | 9 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" |
| 10 #include "chrome/browser/policy/proto/cloud/device_management_local.pb.h" | 10 #include "chrome/browser/policy/proto/cloud/device_management_local.pb.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 return result; | 63 return result; |
| 64 } | 64 } |
| 65 | 65 |
| 66 result.status = policy::LOAD_RESULT_SUCCESS; | 66 result.status = policy::LOAD_RESULT_SUCCESS; |
| 67 return result; | 67 return result; |
| 68 } | 68 } |
| 69 | 69 |
| 70 // Stores policy to the backing file (must be called via a task on | 70 // Stores policy to the backing file (must be called via a task on |
| 71 // the FILE thread). | 71 // the FILE thread). |
| 72 void StorePolicyToDiskOnFileThread(const base::FilePath& path, | 72 void StorePolicyToDiskOnFileThread(const base::FilePath& path, |
| 73 const em::PolicyFetchResponse& policy) { | 73 const em::PolicyFetchResponse& policy) { |
|
Joao da Silva
2013/07/23 20:44:47
This is chromium style :-)
You may give clang-for
Steve Condie
2013/07/24 01:42:04
Whoops, didn't mean to change that. In a previous
| |
| 74 DVLOG(1) << "Storing policy to " << path.value(); | 74 DVLOG(1) << "Storing policy to " << path.value(); |
| 75 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 75 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 76 std::string data; | 76 std::string data; |
| 77 if (!policy.SerializeToString(&data)) { | 77 if (!policy.SerializeToString(&data)) { |
| 78 DLOG(WARNING) << "Failed to serialize policy data"; | 78 DLOG(WARNING) << "Failed to serialize policy data"; |
| 79 return; | 79 return; |
| 80 } | 80 } |
| 81 | 81 |
| 82 if (!file_util::CreateDirectory(path.DirName())) { | 82 if (!file_util::CreateDirectory(path.DirName())) { |
| 83 DLOG(WARNING) << "Failed to create directory " << path.DirName().value(); | 83 DLOG(WARNING) << "Failed to create directory " << path.DirName().value(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 } | 120 } |
| 121 | 121 |
| 122 void UserCloudPolicyStore::Clear() { | 122 void UserCloudPolicyStore::Clear() { |
| 123 content::BrowserThread::PostTask( | 123 content::BrowserThread::PostTask( |
| 124 content::BrowserThread::FILE, FROM_HERE, | 124 content::BrowserThread::FILE, FROM_HERE, |
| 125 base::Bind(base::IgnoreResult(&base::DeleteFile), | 125 base::Bind(base::IgnoreResult(&base::DeleteFile), |
| 126 backing_file_path_, | 126 backing_file_path_, |
| 127 false)); | 127 false)); |
| 128 policy_.reset(); | 128 policy_.reset(); |
| 129 policy_map_.Clear(); | 129 policy_map_.Clear(); |
| 130 SetPolicyHashValue(0); | |
|
Joao da Silva
2013/07/23 20:44:47
NotifyStoreLoaded() could compute this
Steve Condie
2013/07/24 01:42:04
Done.
| |
| 130 NotifyStoreLoaded(); | 131 NotifyStoreLoaded(); |
| 131 } | 132 } |
| 132 | 133 |
| 133 void UserCloudPolicyStore::Load() { | 134 void UserCloudPolicyStore::Load() { |
| 134 DVLOG(1) << "Initiating policy load from disk"; | 135 DVLOG(1) << "Initiating policy load from disk"; |
| 135 // Cancel any pending Load/Store/Validate operations. | 136 // Cancel any pending Load/Store/Validate operations. |
| 136 weak_factory_.InvalidateWeakPtrs(); | 137 weak_factory_.InvalidateWeakPtrs(); |
| 137 | 138 |
| 138 // Start a new Load operation and have us get called back when it is | 139 // Start a new Load operation and have us get called back when it is |
| 139 // complete. | 140 // complete. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 DVLOG(1) << "Validation failed: status=" << validation_status_; | 182 DVLOG(1) << "Validation failed: status=" << validation_status_; |
| 182 status_ = STATUS_VALIDATION_ERROR; | 183 status_ = STATUS_VALIDATION_ERROR; |
| 183 NotifyStoreError(); | 184 NotifyStoreError(); |
| 184 return; | 185 return; |
| 185 } | 186 } |
| 186 | 187 |
| 187 DVLOG(1) << "Validation succeeded - installing policy with dm_token: " << | 188 DVLOG(1) << "Validation succeeded - installing policy with dm_token: " << |
| 188 validator->policy_data()->request_token(); | 189 validator->policy_data()->request_token(); |
| 189 DVLOG(1) << "Device ID: " << validator->policy_data()->device_id(); | 190 DVLOG(1) << "Device ID: " << validator->policy_data()->device_id(); |
| 190 | 191 |
| 191 InstallPolicy(validator->policy_data().Pass(), validator->payload().Pass()); | 192 InstallPolicy( |
| 193 validator->policy_data().Pass(), | |
| 194 validator->payload().Pass(), | |
| 195 validator->hash_value()); | |
|
Joao da Silva
2013/07/23 20:44:47
NotifyStoreLoaded can do this :-)
Steve Condie
2013/07/24 01:42:04
Done.
| |
| 192 status_ = STATUS_OK; | 196 status_ = STATUS_OK; |
| 193 NotifyStoreLoaded(); | 197 NotifyStoreLoaded(); |
| 194 } | 198 } |
| 195 | 199 |
| 196 void UserCloudPolicyStore::Store(const em::PolicyFetchResponse& policy) { | 200 void UserCloudPolicyStore::Store(const em::PolicyFetchResponse& policy) { |
| 197 // Stop any pending requests to store policy, then validate the new policy | 201 // Stop any pending requests to store policy, then validate the new policy |
| 198 // before storing it. | 202 // before storing it. |
| 199 weak_factory_.InvalidateWeakPtrs(); | 203 weak_factory_.InvalidateWeakPtrs(); |
| 200 scoped_ptr<em::PolicyFetchResponse> policy_copy( | 204 scoped_ptr<em::PolicyFetchResponse> policy_copy( |
| 201 new em::PolicyFetchResponse(policy)); | 205 new em::PolicyFetchResponse(policy)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 NotifyStoreError(); | 248 NotifyStoreError(); |
| 245 return; | 249 return; |
| 246 } | 250 } |
| 247 | 251 |
| 248 // Persist the validated policy (just fire a task - don't bother getting a | 252 // Persist the validated policy (just fire a task - don't bother getting a |
| 249 // reply because we can't do anything if it fails). | 253 // reply because we can't do anything if it fails). |
| 250 content::BrowserThread::PostTask( | 254 content::BrowserThread::PostTask( |
| 251 content::BrowserThread::FILE, FROM_HERE, | 255 content::BrowserThread::FILE, FROM_HERE, |
| 252 base::Bind(&StorePolicyToDiskOnFileThread, | 256 base::Bind(&StorePolicyToDiskOnFileThread, |
| 253 backing_file_path_, *validator->policy())); | 257 backing_file_path_, *validator->policy())); |
| 254 InstallPolicy(validator->policy_data().Pass(), validator->payload().Pass()); | 258 InstallPolicy( |
| 259 validator->policy_data().Pass(), | |
| 260 validator->payload().Pass(), | |
| 261 validator->hash_value()); | |
|
Joao da Silva
2013/07/23 20:44:47
Same
Steve Condie
2013/07/24 01:42:04
Done.
| |
| 255 status_ = STATUS_OK; | 262 status_ = STATUS_OK; |
| 256 NotifyStoreLoaded(); | 263 NotifyStoreLoaded(); |
| 257 } | 264 } |
| 258 | 265 |
| 259 } // namespace policy | 266 } // namespace policy |
| OLD | NEW |