Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: content/browser/storage_partition_impl_map.cc

Issue 16392011: Move FileEnumerator to its own file, do some refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix incorrect includes Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "content/browser/storage_partition_impl_map.h" 5 #include "content/browser/storage_partition_impl_map.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.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_path.h" 11 #include "base/files/file_path.h"
11 #include "base/stl_util.h" 12 #include "base/stl_util.h"
12 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
13 #include "base/string_util.h" 14 #include "base/string_util.h"
14 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
15 #include "base/threading/sequenced_worker_pool.h" 16 #include "base/threading/sequenced_worker_pool.h"
16 #include "content/browser/appcache/chrome_appcache_service.h" 17 #include "content/browser/appcache/chrome_appcache_service.h"
17 #include "content/browser/fileapi/browser_file_system_helper.h" 18 #include "content/browser/fileapi/browser_file_system_helper.h"
18 #include "content/browser/fileapi/chrome_blob_storage_context.h" 19 #include "content/browser/fileapi/chrome_blob_storage_context.h"
19 #include "content/browser/loader/resource_request_info_impl.h" 20 #include "content/browser/loader/resource_request_info_impl.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // 176 //
176 // An average partition domain is likely to have less than 10 unique 177 // An average partition domain is likely to have less than 10 unique
177 // partition names which is far lower than 75. 178 // partition names which is far lower than 75.
178 // 179 //
179 // Note, that for 4 9s of reliability, the limit is 237 partition names per 180 // Note, that for 4 9s of reliability, the limit is 237 partition names per
180 // partition domain. 181 // partition domain.
181 const int kPartitionNameHashBytes = 6; 182 const int kPartitionNameHashBytes = 6;
182 183
183 // Needed for selecting all files in ObliterateOneDirectory() below. 184 // Needed for selecting all files in ObliterateOneDirectory() below.
184 #if defined(OS_POSIX) 185 #if defined(OS_POSIX)
185 const int kAllFileTypes = file_util::FileEnumerator::FILES | 186 const int kAllFileTypes = base::FileEnumerator::FILES |
186 file_util::FileEnumerator::DIRECTORIES | 187 base::FileEnumerator::DIRECTORIES |
187 file_util::FileEnumerator::SHOW_SYM_LINKS; 188 base::FileEnumerator::SHOW_SYM_LINKS;
188 #else 189 #else
189 const int kAllFileTypes = file_util::FileEnumerator::FILES | 190 const int kAllFileTypes = base::FileEnumerator::FILES |
190 file_util::FileEnumerator::DIRECTORIES; 191 base::FileEnumerator::DIRECTORIES;
191 #endif 192 #endif
192 193
193 base::FilePath GetStoragePartitionDomainPath( 194 base::FilePath GetStoragePartitionDomainPath(
194 const std::string& partition_domain) { 195 const std::string& partition_domain) {
195 CHECK(IsStringUTF8(partition_domain)); 196 CHECK(IsStringUTF8(partition_domain));
196 197
197 return base::FilePath(kStoragePartitionDirname).Append(kExtensionsDirname) 198 return base::FilePath(kStoragePartitionDirname).Append(kExtensionsDirname)
198 .Append(base::FilePath::FromUTF8Unsafe(partition_domain)); 199 .Append(base::FilePath::FromUTF8Unsafe(partition_domain));
199 } 200 }
200 201
201 // Helper function for doing a depth-first deletion of the data on disk. 202 // Helper function for doing a depth-first deletion of the data on disk.
202 // Examines paths directly in |current_dir| (no recursion) and tries to 203 // Examines paths directly in |current_dir| (no recursion) and tries to
203 // delete from disk anything that is in, or isn't a parent of something in 204 // delete from disk anything that is in, or isn't a parent of something in
204 // |paths_to_keep|. Paths that need further expansion are added to 205 // |paths_to_keep|. Paths that need further expansion are added to
205 // |paths_to_consider|. 206 // |paths_to_consider|.
206 void ObliterateOneDirectory(const base::FilePath& current_dir, 207 void ObliterateOneDirectory(const base::FilePath& current_dir,
207 const std::vector<base::FilePath>& paths_to_keep, 208 const std::vector<base::FilePath>& paths_to_keep,
208 std::vector<base::FilePath>* paths_to_consider) { 209 std::vector<base::FilePath>* paths_to_consider) {
209 CHECK(current_dir.IsAbsolute()); 210 CHECK(current_dir.IsAbsolute());
210 211
211 file_util::FileEnumerator enumerator(current_dir, false, kAllFileTypes); 212 base::FileEnumerator enumerator(current_dir, false, kAllFileTypes);
212 for (base::FilePath to_delete = enumerator.Next(); !to_delete.empty(); 213 for (base::FilePath to_delete = enumerator.Next(); !to_delete.empty();
213 to_delete = enumerator.Next()) { 214 to_delete = enumerator.Next()) {
214 // Enum tracking which of the 3 possible actions to take for |to_delete|. 215 // Enum tracking which of the 3 possible actions to take for |to_delete|.
215 enum { kSkip, kEnqueue, kDelete } action = kDelete; 216 enum { kSkip, kEnqueue, kDelete } action = kDelete;
216 217
217 for (std::vector<base::FilePath>::const_iterator to_keep = 218 for (std::vector<base::FilePath>::const_iterator to_keep =
218 paths_to_keep.begin(); 219 paths_to_keep.begin();
219 to_keep != paths_to_keep.end(); 220 to_keep != paths_to_keep.end();
220 ++to_keep) { 221 ++to_keep) {
221 if (to_delete == *to_keep) { 222 if (to_delete == *to_keep) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // there is not necessarily a guaranteed case where the logic may succeed. 316 // there is not necessarily a guaranteed case where the logic may succeed.
316 // 317 //
317 // This function is still named BlockingGarbageCollect() because it does 318 // This function is still named BlockingGarbageCollect() because it does
318 // execute a few filesystem operations synchronously. 319 // execute a few filesystem operations synchronously.
319 void BlockingGarbageCollect( 320 void BlockingGarbageCollect(
320 const base::FilePath& storage_root, 321 const base::FilePath& storage_root,
321 const scoped_refptr<base::TaskRunner>& file_access_runner, 322 const scoped_refptr<base::TaskRunner>& file_access_runner,
322 scoped_ptr<base::hash_set<base::FilePath> > active_paths) { 323 scoped_ptr<base::hash_set<base::FilePath> > active_paths) {
323 CHECK(storage_root.IsAbsolute()); 324 CHECK(storage_root.IsAbsolute());
324 325
325 file_util::FileEnumerator enumerator(storage_root, false, kAllFileTypes); 326 base::FileEnumerator enumerator(storage_root, false, kAllFileTypes);
326 base::FilePath trash_directory; 327 base::FilePath trash_directory;
327 if (!file_util::CreateTemporaryDirInDir(storage_root, kTrashDirname, 328 if (!file_util::CreateTemporaryDirInDir(storage_root, kTrashDirname,
328 &trash_directory)) { 329 &trash_directory)) {
329 // Unable to continue without creating the trash directory so give up. 330 // Unable to continue without creating the trash directory so give up.
330 return; 331 return;
331 } 332 }
332 for (base::FilePath path = enumerator.Next(); !path.empty(); 333 for (base::FilePath path = enumerator.Next(); !path.empty();
333 path = enumerator.Next()) { 334 path = enumerator.Next()) {
334 if (active_paths->find(path) == active_paths->end() && 335 if (active_paths->find(path) == active_paths->end() &&
335 path != trash_directory) { 336 path != trash_directory) {
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 579
579 // We do not call InitializeURLRequestContext() for media contexts because, 580 // We do not call InitializeURLRequestContext() for media contexts because,
580 // other than the HTTP cache, the media contexts share the same backing 581 // other than the HTTP cache, the media contexts share the same backing
581 // objects as their associated "normal" request context. Thus, the previous 582 // objects as their associated "normal" request context. Thus, the previous
582 // call serves to initialize the media request context for this storage 583 // call serves to initialize the media request context for this storage
583 // partition as well. 584 // partition as well.
584 } 585 }
585 } 586 }
586 587
587 } // namespace content 588 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698