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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: net/disk_cache/simple/simple_index_file_posix.cc
diff --git a/net/disk_cache/simple/simple_index_file_posix.cc b/net/disk_cache/simple/simple_index_file_posix.cc
new file mode 100644
index 0000000000000000000000000000000000000000..287bed84b1b24d53ff8c7d8f2da7a418a694ca6b
--- /dev/null
+++ b/net/disk_cache/simple/simple_index_file_posix.cc
@@ -0,0 +1,52 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/disk_cache/simple/simple_index_file.h"
+
+#include <dirent.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <string>
+
+#include "base/callback.h"
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+
+namespace disk_cache {
+namespace {
+
+struct DirCloser {
+ void operator()(DIR* dir) { closedir(dir); }
+};
+
+typedef scoped_ptr<DIR, DirCloser> ScopedDir;
+
+} // namespace
+
+// static
+bool SimpleIndexFile::TraverseCacheDirectory(
+ const std::string& cache_path,
+ const EntryFileCallback& entry_file_callback) {
+ const ScopedDir dir(opendir(cache_path.c_str()));
+ if (!dir) {
+ PLOG(ERROR) << "opendir " << cache_path;
+ return false;
+ }
+ std::string file_name;
+ dirent entry, *result;
+ while (readdir_r(dir.get(), &entry, &result) == 0) {
+ if (!result)
+ return true; // The traversal completed successfully.
+ file_name.assign(result->d_name);
+ if (file_name == "." || file_name == "..")
+ continue;
+ entry_file_callback.Run(file_name);
+ }
+ PLOG(ERROR) << "readdir_r " << cache_path;
+ return false;
+}
+
+} // namespace disk_cache

Powered by Google App Engine
This is Rietveld 408576698