Commit 0408c755 authored by brettw@chromium.org's avatar brettw@chromium.org

Move ComputeDirectorySize to the base namespace.

BUG=
TBR=tfarina

Review URL: https://chromiumcodereview.appspot.com/16950027

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208091 0039d316-1c4b-4281-b951-d872f2087c98
parent 67c88d8a
......@@ -19,8 +19,7 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
using base::FileEnumerator;
using base::FilePath;
namespace base {
namespace {
......@@ -35,9 +34,26 @@ static const int kMaxUniqueFiles = 100;
} // namespace
bool g_bug108724_debug = false;
int64 ComputeDirectorySize(const FilePath& root_path) {
int64 running_size = 0;
FileEnumerator file_iter(root_path, true, FileEnumerator::FILES);
while (!file_iter.Next().empty())
running_size += file_iter.GetInfo().GetSize();
return running_size;
}
} // namespace base
// -----------------------------------------------------------------------------
namespace file_util {
bool g_bug108724_debug = false;
using base::FileEnumerator;
using base::FilePath;
using base::kExtensionSeparator;
using base::kMaxUniqueFiles;
void InsertBeforeExtension(FilePath* path, const FilePath::StringType& suffix) {
FilePath::StringType& value =
......@@ -270,12 +286,4 @@ int GetUniquePathNumber(
return -1;
}
int64 ComputeDirectorySize(const FilePath& root_path) {
int64 running_size = 0;
FileEnumerator file_iter(root_path, true, FileEnumerator::FILES);
while (!file_iter.Next().empty())
running_size += file_iter.GetInfo().GetSize();
return running_size;
}
} // namespace
} // namespace file_util
......@@ -37,28 +37,29 @@
#endif
namespace base {
class Time;
// Returns an absolute version of a relative path. Returns an empty path on
// error. On POSIX, this function fails if the path does not exist. This
// function can result in I/O so it can be slow.
BASE_EXPORT FilePath MakeAbsoluteFilePath(const FilePath& input);
} // namespace base
namespace file_util {
class Time;
extern bool g_bug108724_debug;
//-----------------------------------------------------------------------------
// Functions that involve filesystem access or modification:
// Returns an absolute version of a relative path. Returns an empty path on
// error. On POSIX, this function fails if the path does not exist. This
// function can result in I/O so it can be slow.
BASE_EXPORT FilePath MakeAbsoluteFilePath(const FilePath& input);
// Returns the total number of bytes used by all the files under |root_path|.
// If the path does not exist the function returns 0.
//
// This function is implemented using the FileEnumerator class so it is not
// particularly speedy in any platform.
BASE_EXPORT int64 ComputeDirectorySize(const base::FilePath& root_path);
BASE_EXPORT int64 ComputeDirectorySize(const FilePath& root_path);
} // namespace base
namespace file_util {
// Deletes the given path, whether it's a file or a directory.
// If it's a directory, it's perfectly happy to delete all of the
......
......@@ -336,7 +336,7 @@ TEST_F(FileUtilTest, FileAndDirectorySize) {
FilePath file_03 = subsubdir_path.Append(FPL("The file 03.txt"));
CreateTextFile(file_03, L"123");
int64 computed_size = file_util::ComputeDirectorySize(temp_dir_.path());
int64 computed_size = base::ComputeDirectorySize(temp_dir_.path());
EXPECT_EQ(size_f1 + size_f2 + 3, computed_size);
}
......
......@@ -28,6 +28,7 @@
#include "base/win/windows_version.h"
using base::FilePath;
using base::g_bug108724_debug;
namespace base {
......
......@@ -175,7 +175,7 @@ void ContactDatabase::InitFromTaskRunner(const base::FilePath& database_dir,
VLOG(1) << "Opening " << database_dir.value();
UMA_HISTOGRAM_MEMORY_KB("Contacts.DatabaseSizeBytes",
file_util::ComputeDirectorySize(database_dir));
base::ComputeDirectorySize(database_dir));
*success = false;
HistogramInitResult histogram_result = HISTOGRAM_INIT_RESULT_SUCCESS;
......
......@@ -243,7 +243,7 @@ class PathTest : public DiagnosticTest {
int64 dir_or_file_size = 0;
if (path_info_.is_directory) {
dir_or_file_size = file_util::ComputeDirectorySize(dir_or_file);
dir_or_file_size = base::ComputeDirectorySize(dir_or_file);
} else {
file_util::GetFileSize(dir_or_file, &dir_or_file_size);
}
......
......@@ -318,7 +318,7 @@ int64 IndexedDBContextImpl::ReadUsageFromDisk(const GURL& origin_url) const {
std::string origin_id =
webkit_database::GetIdentifierFromOrigin(origin_url);
base::FilePath file_path = GetIndexedDBFilePath(origin_id);
return file_util::ComputeDirectorySize(file_path);
return base::ComputeDirectorySize(file_path);
}
void IndexedDBContextImpl::EnsureDiskUsageCacheInitialized(
......
......@@ -97,7 +97,7 @@ int64 SandboxFileSystemTestHelper::GetCachedOriginUsage() const {
int64 SandboxFileSystemTestHelper::ComputeCurrentOriginUsage() {
usage_cache()->CloseCacheFiles();
int64 size = file_util::ComputeDirectorySize(GetOriginRootPath());
int64 size = base::ComputeDirectorySize(GetOriginRootPath());
if (file_util::PathExists(GetUsageCachePath()))
size -= FileSystemUsageCache::kUsageFileSize;
return size;
......@@ -105,7 +105,7 @@ int64 SandboxFileSystemTestHelper::ComputeCurrentOriginUsage() {
int64
SandboxFileSystemTestHelper::ComputeCurrentDirectoryDatabaseUsage() {
return file_util::ComputeDirectorySize(
return base::ComputeDirectorySize(
GetOriginRootPath().AppendASCII("Paths"));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment