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

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

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

Powered by Google App Engine
This is Rietveld 408576698