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

Side by Side Diff: net/disk_cache/simple/simple_index_file_posix.cc

Issue 22927018: Avoid fragmenting the heap too much while reconstructing the index. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/disk_cache/simple/simple_index_file.h"
6
7 #include <dirent.h>
8 #include <sys/stat.h>
9 #include <sys/types.h>
10 #include <unistd.h>
11
12 #include <string>
13
14 #include "base/callback.h"
15 #include "base/logging.h"
16 #include "base/memory/scoped_ptr.h"
17
18 namespace disk_cache {
19 namespace {
20
21 struct DirCloser {
22 void operator()(DIR* dir) { closedir(dir); }
23 };
24
25 typedef scoped_ptr<DIR, DirCloser> ScopedDir;
26
27 } // namespace
28
29 // static
30 bool SimpleIndexFile::TraverseCacheDirectory(
31 const std::string& cache_path,
32 const EntryFileCallback& entry_file_callback) {
33 const ScopedDir dir(opendir(cache_path.c_str()));
34 if (!dir) {
35 PLOG(ERROR) << "opendir " << cache_path;
36 return false;
37 }
38 std::string file_name;
39 dirent entry, *result;
40 while (readdir_r(dir.get(), &entry, &result) == 0) {
41 if (!result)
42 return true; // The traversal completed successfully.
43 file_name.assign(result->d_name);
44 if (file_name == "." || file_name == "..")
45 continue;
46 entry_file_callback.Run(file_name);
47 }
48 PLOG(ERROR) << "readdir_r " << cache_path;
49 return false;
50 }
51
52 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698