OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/resource_cache.h" | 5 #include "chrome/browser/policy/cloud/resource_cache.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 130 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
131 base::FilePath subkey_path; | 131 base::FilePath subkey_path; |
132 if (VerifyKeyPathAndGetSubkeyPath(key, false, subkey, &subkey_path)) | 132 if (VerifyKeyPathAndGetSubkeyPath(key, false, subkey, &subkey_path)) |
133 base::DeleteFile(subkey_path, false); | 133 base::DeleteFile(subkey_path, false); |
134 // Delete() does nothing if the directory given to it is not empty. Hence, the | 134 // Delete() does nothing if the directory given to it is not empty. Hence, the |
135 // call below deletes the directory representing |key| if its last subkey was | 135 // call below deletes the directory representing |key| if its last subkey was |
136 // just removed and does nothing otherwise. | 136 // just removed and does nothing otherwise. |
137 base::DeleteFile(subkey_path.DirName(), false); | 137 base::DeleteFile(subkey_path.DirName(), false); |
138 } | 138 } |
139 | 139 |
| 140 void ResourceCache::Clear(const std::string& key) { |
| 141 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 142 base::FilePath key_path; |
| 143 if (VerifyKeyPath(key, false, &key_path)) |
| 144 base::DeleteFile(key_path, true); |
| 145 } |
| 146 |
140 void ResourceCache::FilterSubkeys(const std::string& key, | 147 void ResourceCache::FilterSubkeys(const std::string& key, |
141 const SubkeyFilter& test) { | 148 const SubkeyFilter& test) { |
142 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 149 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
143 | 150 |
144 base::FilePath key_path; | 151 base::FilePath key_path; |
145 if (!VerifyKeyPath(key, false, &key_path)) | 152 if (!VerifyKeyPath(key, false, &key_path)) |
146 return; | 153 return; |
147 | 154 |
148 base::FileEnumerator enumerator(key_path, false, base::FileEnumerator::FILES); | 155 base::FileEnumerator enumerator(key_path, false, base::FileEnumerator::FILES); |
149 for (base::FilePath subkey_path = enumerator.Next(); | 156 for (base::FilePath subkey_path = enumerator.Next(); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 if (!VerifyKeyPath(key, allow_create_key, &key_path) || | 231 if (!VerifyKeyPath(key, allow_create_key, &key_path) || |
225 !Base64Encode(subkey, &encoded)) { | 232 !Base64Encode(subkey, &encoded)) { |
226 return false; | 233 return false; |
227 } | 234 } |
228 *path = key_path.AppendASCII(encoded); | 235 *path = key_path.AppendASCII(encoded); |
229 return true; | 236 return true; |
230 } | 237 } |
231 | 238 |
232 | 239 |
233 } // namespace policy | 240 } // namespace policy |
OLD | NEW |