summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi
diff options
context:
space:
mode:
authordmikurube@google.com <dmikurube@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-12 06:06:07 +0000
committerdmikurube@google.com <dmikurube@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-12 06:06:07 +0000
commit6ff1705e9060188d029df60c7542126679202537 (patch)
tree5496e0777b7000f493b26891f0836417ed279bd9 /webkit/fileapi
parent33a6c77c9d5961c8b4ce8ff17041687a1cd8344a (diff)
downloadchromium_src-6ff1705e9060188d029df60c7542126679202537.zip
chromium_src-6ff1705e9060188d029df60c7542126679202537.tar.gz
chromium_src-6ff1705e9060188d029df60c7542126679202537.tar.bz2
Change the usage cache not to include meta data, such as the the size of usage cache itself.
BUG=86114 TEST=FileSystemQuotaClientTest.*, BrowsingDataFileSystemHelperTest.* Review URL: http://codereview.chromium.org/7278016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92112 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi')
-rw-r--r--webkit/fileapi/file_system_quota_client_unittest.cc144
-rw-r--r--webkit/fileapi/file_system_usage_cache.cc3
-rw-r--r--webkit/fileapi/obfuscated_file_system_file_util.cc19
-rw-r--r--webkit/fileapi/obfuscated_file_system_file_util.h9
-rw-r--r--webkit/fileapi/sandbox_mount_point_provider.cc48
5 files changed, 148 insertions, 75 deletions
diff --git a/webkit/fileapi/file_system_quota_client_unittest.cc b/webkit/fileapi/file_system_quota_client_unittest.cc
index a98cdc6..8b14b6c 100644
--- a/webkit/fileapi/file_system_quota_client_unittest.cc
+++ b/webkit/fileapi/file_system_quota_client_unittest.cc
@@ -12,6 +12,7 @@
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/fileapi/file_system_context.h"
+#include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/file_system_quota_client.h"
#include "webkit/fileapi/file_system_types.h"
#include "webkit/fileapi/file_system_usage_cache.h"
@@ -29,7 +30,6 @@ const char kDummyURL3[] = "http://www.bleh";
// Declared to shorten the variable names.
const quota::StorageType kTemporary = quota::kStorageTypeTemporary;
const quota::StorageType kPersistent = quota::kStorageTypePersistent;
-const int kUsageFileSize = FileSystemUsageCache::kUsageFileSize;
class MockFileSystemPathManager : public FileSystemPathManager {
public:
@@ -129,53 +129,77 @@ class FileSystemQuotaClientTest : public testing::Test {
GURL(origin_url), QuotaStorageTypeToFileSystemType(type), true);
}
- bool CreateFileSystemDirectory(const char* dir_name,
+ FileSystemOperationContext* CreateFileSystemOperationContext(
+ FileSystemFileUtil* file_util,
+ const FilePath& virtual_path,
+ const char* origin_url,
+ quota::StorageType type) {
+ FileSystemOperationContext* context =
+ new FileSystemOperationContext(file_system_context_, file_util);
+ context->set_src_origin_url(GURL(origin_url));
+ context->set_src_virtual_path(virtual_path);
+ context->set_src_type(QuotaStorageTypeToFileSystemType(type));
+ context->set_allowed_bytes_growth(100000000);
+ return context;
+ }
+
+ bool CreateFileSystemDirectory(const FilePath& path,
const char* origin_url,
quota::StorageType type) {
- FilePath origin_base_path = GetOriginBasePath(origin_url, type);
- FilePath dir_path;
- if (dir_name != NULL)
- dir_path = origin_base_path.AppendASCII(dir_name);
- else
- dir_path = origin_base_path;
- if (dir_path.empty())
- return false;
+ FileSystemFileUtil* file_util =
+ file_system_context_->path_manager()->GetFileSystemFileUtil(
+ QuotaStorageTypeToFileSystemType(type));
- return file_util::CreateDirectory(dir_path);
+ scoped_ptr<FileSystemOperationContext> context(
+ CreateFileSystemOperationContext(file_util, path, origin_url, type));
+
+ base::PlatformFileError result =
+ file_util->CreateDirectory(context.get(), path, false, false);
+ if (result != base::PLATFORM_FILE_OK)
+ return false;
+ return true;
}
- bool CreateFileSystemFile(const char* file_name,
+ bool CreateFileSystemFile(const FilePath& path,
int64 file_size,
const char* origin_url,
quota::StorageType type) {
- FilePath origin_base_path = GetOriginBasePath(origin_url, type);
- FilePath file_path = origin_base_path.AppendASCII(file_name);
-
- if (file_path.empty())
+ if (path.empty())
return false;
- int file_flags = base::PLATFORM_FILE_CREATE_ALWAYS |
- base::PLATFORM_FILE_WRITE;
- base::PlatformFileError error_code;
- base::PlatformFile file =
- base::CreatePlatformFile(file_path, file_flags, NULL, &error_code);
- if (error_code != base::PLATFORM_FILE_OK)
- return false;
+ FileSystemFileUtil* file_util = file_system_context_->path_manager()->
+ sandbox_provider()->GetFileSystemFileUtil();
+
+ scoped_ptr<FileSystemOperationContext> context(
+ CreateFileSystemOperationContext(file_util, path, origin_url, type));
- bool succeeded;
- succeeded = base::TruncatePlatformFile(file, file_size);
- succeeded = succeeded && base::ClosePlatformFile(file);
- return succeeded;
+ bool created = false;
+ if (base::PLATFORM_FILE_OK !=
+ file_util->EnsureFileExists(context.get(), path, &created))
+ return false;
+ EXPECT_TRUE(created);
+ if (base::PLATFORM_FILE_OK !=
+ file_util->Truncate(context.get(), path, file_size))
+ return false;
+ return true;
}
- void CreateFiles(const TestFile* files, int num_files) {
+ void InitializeOriginFiles(FileSystemQuotaClient* quota_client,
+ const TestFile* files,
+ int num_files) {
for (int i = 0; i < num_files; i++) {
+ FilePath path = FilePath().AppendASCII(files[i].name);
if (files[i].isDirectory) {
ASSERT_TRUE(CreateFileSystemDirectory(
- files[i].name, files[i].origin_url, files[i].type));
+ path, files[i].origin_url, files[i].type));
+ if (path.empty()) {
+ // Create the usage cache.
+ ASSERT_EQ(0, GetOriginUsage(
+ quota_client, files[i].origin_url, files[i].type));
+ }
} else {
ASSERT_TRUE(CreateFileSystemFile(
- files[i].name, files[i].size, files[i].origin_url, files[i].type));
+ path, files[i].size, files[i].origin_url, files[i].type));
}
}
}
@@ -236,10 +260,10 @@ TEST_F(FileSystemQuotaClientTest, NoFileTest) {
const TestFile kFiles[] = {
{true, NULL, 0, kDummyURL1, kTemporary},
};
- CreateFiles(kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
for (int i = 0; i < 2; i++) {
- EXPECT_EQ(kUsageFileSize,
+ EXPECT_EQ(0,
GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
}
}
@@ -250,10 +274,10 @@ TEST_F(FileSystemQuotaClientTest, OneFileTest) {
{true, NULL, 0, kDummyURL1, kTemporary},
{false, "foo", 4921, kDummyURL1, kTemporary},
};
- CreateFiles(kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
for (int i = 0; i < 2; i++) {
- EXPECT_EQ(4921 + kUsageFileSize,
+ EXPECT_EQ(4921,
GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
}
}
@@ -265,10 +289,10 @@ TEST_F(FileSystemQuotaClientTest, TwoFilesTest) {
{false, "foo", 10310, kDummyURL1, kTemporary},
{false, "bar", 41, kDummyURL1, kTemporary},
};
- CreateFiles(kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
for (int i = 0; i < 2; i++) {
- EXPECT_EQ(10310 + 41 + kUsageFileSize,
+ EXPECT_EQ(10310 + 41,
GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
}
}
@@ -281,10 +305,10 @@ TEST_F(FileSystemQuotaClientTest, EmptyFilesTest) {
{false, "bar", 0, kDummyURL1, kTemporary},
{false, "baz", 0, kDummyURL1, kTemporary},
};
- CreateFiles(kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
for (int i = 0; i < 2; i++) {
- EXPECT_EQ(kUsageFileSize,
+ EXPECT_EQ(0,
GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
}
}
@@ -297,10 +321,10 @@ TEST_F(FileSystemQuotaClientTest, SubDirectoryTest) {
{false, "dirtest/foo", 11921, kDummyURL1, kTemporary},
{false, "bar", 4814, kDummyURL1, kTemporary},
};
- CreateFiles(kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
for (int i = 0; i < 2; i++) {
- EXPECT_EQ(11921 + 4814 + kUsageFileSize,
+ EXPECT_EQ(11921 + 4814,
GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
}
}
@@ -317,12 +341,12 @@ TEST_F(FileSystemQuotaClientTest, MultiTypeTest) {
{false, "dirtest/foo", 193, kDummyURL1, kPersistent},
{false, "bar", 9, kDummyURL1, kPersistent},
};
- CreateFiles(kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
for (int i = 0; i < 2; i++) {
- EXPECT_EQ(133 + 14 + kUsageFileSize,
+ EXPECT_EQ(133 + 14,
GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
- EXPECT_EQ(193 + 9 + kUsageFileSize,
+ EXPECT_EQ(193 + 9,
GetOriginUsage(quota_client.get(), kDummyURL1, kPersistent));
}
}
@@ -347,16 +371,16 @@ TEST_F(FileSystemQuotaClientTest, MultiDomainTest) {
{false, "dom/fan", 2013, kDummyURL2, kPersistent},
{false, "baz", 18, kDummyURL2, kPersistent},
};
- CreateFiles(kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
for (int i = 0; i < 2; i++) {
- EXPECT_EQ(1331 + 134 + kUsageFileSize,
+ EXPECT_EQ(1331 + 134,
GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
- EXPECT_EQ(1903 + 19 + kUsageFileSize,
+ EXPECT_EQ(1903 + 19,
GetOriginUsage(quota_client.get(), kDummyURL1, kPersistent));
- EXPECT_EQ(1319 + 113 + kUsageFileSize,
+ EXPECT_EQ(1319 + 113,
GetOriginUsage(quota_client.get(), kDummyURL2, kTemporary));
- EXPECT_EQ(2013 + 18 + kUsageFileSize,
+ EXPECT_EQ(2013 + 18,
GetOriginUsage(quota_client.get(), kDummyURL2, kPersistent));
}
}
@@ -368,7 +392,7 @@ TEST_F(FileSystemQuotaClientTest, GetUsage_MultipleTasks) {
{false, "foo", 11, kDummyURL1, kTemporary},
{false, "bar", 22, kDummyURL1, kTemporary},
};
- CreateFiles(kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
// Dispatching three GetUsage tasks.
set_additional_callback_count(0);
@@ -376,7 +400,7 @@ TEST_F(FileSystemQuotaClientTest, GetUsage_MultipleTasks) {
RunAdditionalOriginUsageTask(quota_client.get(), kDummyURL1, kTemporary);
RunAdditionalOriginUsageTask(quota_client.get(), kDummyURL1, kTemporary);
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(11 + 22 + kUsageFileSize, usage());
+ EXPECT_EQ(11 + 22, usage());
EXPECT_EQ(2, additional_callback_count());
// Once more, in a different order.
@@ -385,7 +409,7 @@ TEST_F(FileSystemQuotaClientTest, GetUsage_MultipleTasks) {
GetOriginUsageAsync(quota_client.get(), kDummyURL1, kTemporary);
RunAdditionalOriginUsageTask(quota_client.get(), kDummyURL1, kTemporary);
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(11 + 22 + kUsageFileSize, usage());
+ EXPECT_EQ(11 + 22, usage());
EXPECT_EQ(2, additional_callback_count());
}
@@ -396,7 +420,7 @@ TEST_F(FileSystemQuotaClientTest, GetOriginsForType) {
{true, NULL, 0, kDummyURL2, kTemporary},
{true, NULL, 0, kDummyURL3, kPersistent},
};
- CreateFiles(kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
std::set<GURL> origins = GetOriginsForType(quota_client.get(), kTemporary);
EXPECT_EQ(2U, origins.size());
@@ -419,7 +443,7 @@ TEST_F(FileSystemQuotaClientTest, GetOriginsForHost) {
{true, NULL, 0, kURL4, kTemporary},
{true, NULL, 0, kURL5, kPersistent},
};
- CreateFiles(kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
std::set<GURL> origins = GetOriginsForHost(
quota_client.get(), kTemporary, "foo.com");
@@ -437,7 +461,7 @@ TEST_F(FileSystemQuotaClientTest, IncognitoTest) {
{true, NULL, 0, kDummyURL1, kTemporary},
{false, "foo", 10, kDummyURL1, kTemporary},
};
- CreateFiles(kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
// Having files in the usual directory wouldn't affect the result
// queried in incognito mode.
@@ -468,7 +492,7 @@ TEST_F(FileSystemQuotaClientTest, DeleteOriginTest) {
{true, NULL, 0, "https://bar.com/", kTemporary},
{false, "g", 64, "https://bar.com/", kTemporary},
};
- CreateFiles(kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
DeleteOriginData(quota_client.get(), "http://foo.com/", kTemporary);
MessageLoop::current()->RunAllPending();
@@ -489,23 +513,23 @@ TEST_F(FileSystemQuotaClientTest, DeleteOriginTest) {
EXPECT_EQ(0, GetOriginUsage(
quota_client.get(), "http://buz.com/", kTemporary));
- EXPECT_EQ(2 + kUsageFileSize,
+ EXPECT_EQ(2,
GetOriginUsage(quota_client.get(),
"https://foo.com/",
kTemporary));
- EXPECT_EQ(4 + kUsageFileSize,
+ EXPECT_EQ(4,
GetOriginUsage(quota_client.get(),
"http://foo.com/",
kPersistent));
- EXPECT_EQ(8 + kUsageFileSize,
+ EXPECT_EQ(8,
GetOriginUsage(quota_client.get(),
"http://bar.com/",
kTemporary));
- EXPECT_EQ(32 + kUsageFileSize,
+ EXPECT_EQ(32,
GetOriginUsage(quota_client.get(),
"https://bar.com/",
kPersistent));
- EXPECT_EQ(64 + kUsageFileSize,
+ EXPECT_EQ(64,
GetOriginUsage(quota_client.get(),
"https://bar.com/",
kTemporary));
diff --git a/webkit/fileapi/file_system_usage_cache.cc b/webkit/fileapi/file_system_usage_cache.cc
index 5d970b3..1f93c40 100644
--- a/webkit/fileapi/file_system_usage_cache.cc
+++ b/webkit/fileapi/file_system_usage_cache.cc
@@ -11,7 +11,7 @@
namespace fileapi {
const char FileSystemUsageCache::kUsageFileName[] = ".usage";
-const char FileSystemUsageCache::kUsageFileHeader[] = "FSU1";
+const char FileSystemUsageCache::kUsageFileHeader[] = "FSU2";
const int FileSystemUsageCache::kUsageFileHeaderSize = 4;
const int FileSystemUsageCache::kUsageFileSize =
sizeof(Pickle::Header) +
@@ -71,6 +71,7 @@ int FileSystemUsageCache::AtomicUpdateUsageByDelta(
const FilePath& usage_file_path, int64 delta) {
uint32 dirty = 0;
int64 fs_usage;
+ // TODO(dmikurube): Make sure that usage_file_path is available.
fs_usage = Read(usage_file_path, &dirty);
return Write(usage_file_path, dirty, fs_usage + delta);
diff --git a/webkit/fileapi/obfuscated_file_system_file_util.cc b/webkit/fileapi/obfuscated_file_system_file_util.cc
index a143171..b28dc92 100644
--- a/webkit/fileapi/obfuscated_file_system_file_util.cc
+++ b/webkit/fileapi/obfuscated_file_system_file_util.cc
@@ -846,6 +846,20 @@ FilePath ObfuscatedFileSystemFileUtil::GetDirectoryForOrigin(
return path;
}
+bool ObfuscatedFileSystemFileUtil::DeleteDirectoryForOriginAndType(
+ const GURL& origin, FileSystemType type) {
+ FilePath path_for_origin = GetDirectoryForOriginAndType(origin, type, false);
+ if (!file_util::PathExists(path_for_origin))
+ return true;
+
+ // TODO(dmikurube): Consider the return value of DestroyDirectoryDatabase.
+ // We ignore its error now since 1) it doesn't matter the final result, and
+ // 2) it always returns false in Windows because of LevelDB's implementation.
+ // Information about failure would be useful for debugging.
+ DestroyDirectoryDatabase(origin, type);
+ return file_util::Delete(path_for_origin, true /* recursive */);
+}
+
bool ObfuscatedFileSystemFileUtil::MigrateFromOldSandbox(
const GURL& origin_url, FileSystemType type, const FilePath& src_root) {
if (!DestroyDirectoryDatabase(origin_url, type))
@@ -1008,8 +1022,11 @@ bool ObfuscatedFileSystemFileUtil::DestroyDirectoryDatabase(
}
std::string key = GetOriginIdentifierFromURL(origin) + type_string;
DirectoryMap::iterator iter = directories_.find(key);
- if (iter != directories_.end())
+ if (iter != directories_.end()) {
+ FileSystemDirectoryDatabase* database = iter->second;
directories_.erase(iter);
+ delete database;
+ }
FilePath path = GetDirectoryForOriginAndType(origin, type, false);
if (path.empty())
diff --git a/webkit/fileapi/obfuscated_file_system_file_util.h b/webkit/fileapi/obfuscated_file_system_file_util.h
index 9f819fc..fecc898 100644
--- a/webkit/fileapi/obfuscated_file_system_file_util.h
+++ b/webkit/fileapi/obfuscated_file_system_file_util.h
@@ -139,6 +139,10 @@ class ObfuscatedFileSystemFileUtil : public FileSystemFileUtil,
// contain both the filesystem type subdirectories.
FilePath GetDirectoryForOrigin(const GURL& origin, bool create);
+ // Deletes the topmost directory specific to this origin and type. This will
+ // delete its directory database.
+ bool DeleteDirectoryForOriginAndType(const GURL& origin, FileSystemType type);
+
// This will migrate a filesystem from the old passthrough sandbox into the
// new obfuscated one. It won't obfuscate the old filenames [it will maintain
// the old structure, but move it to a new root], but any new files created
@@ -179,6 +183,10 @@ class ObfuscatedFileSystemFileUtil : public FileSystemFileUtil,
FileSystemOperationContext* context,
const FilePath& root_path) OVERRIDE;
+ // Deletes a directory database from the database list in the ObfuscatedFSFU
+ // and destroys the database on the disk.
+ bool DestroyDirectoryDatabase(const GURL& origin, FileSystemType type);
+
private:
typedef FileSystemDirectoryDatabase::FileId FileId;
typedef FileSystemDirectoryDatabase::FileInfo FileInfo;
@@ -222,7 +230,6 @@ class ObfuscatedFileSystemFileUtil : public FileSystemFileUtil,
const GURL& origin_url, FileSystemType type, bool create);
void MarkUsed();
void DropDatabases();
- bool DestroyDirectoryDatabase(const GURL& origin, FileSystemType type);
bool InitOriginDatabase(bool create);
typedef std::map<std::string, FileSystemDirectoryDatabase*> DirectoryMap;
diff --git a/webkit/fileapi/sandbox_mount_point_provider.cc b/webkit/fileapi/sandbox_mount_point_provider.cc
index 792b77d..e00e5b4 100644
--- a/webkit/fileapi/sandbox_mount_point_provider.cc
+++ b/webkit/fileapi/sandbox_mount_point_provider.cc
@@ -15,6 +15,7 @@
#include "base/stringprintf.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_util.h"
+#include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/file_system_path_manager.h"
#include "webkit/fileapi/file_system_types.h"
#include "webkit/fileapi/file_system_usage_cache.h"
@@ -478,13 +479,12 @@ FilePath SandboxMountPointProvider::GetBaseDirectoryForOriginAndType(
bool SandboxMountPointProvider::DeleteOriginDataOnFileThread(
QuotaManagerProxy* proxy, const GURL& origin_url,
fileapi::FileSystemType type) {
- FilePath path_for_origin =
- GetBaseDirectoryForOriginAndType(origin_url, type, false);
- if (!file_util::PathExists(path_for_origin))
- return true;
+ MigrateIfNeeded(sandbox_file_util_, old_base_path());
int64 usage = GetOriginUsageOnFileThread(origin_url, type);
- bool result = file_util::Delete(path_for_origin, true /* recursive */);
+
+ bool result =
+ sandbox_file_util_->DeleteDirectoryForOriginAndType(origin_url, type);
if (result && proxy) {
proxy->NotifyStorageModified(
quota::QuotaClient::kFileSystem,
@@ -529,8 +529,7 @@ int64 SandboxMountPointProvider::GetOriginUsageOnFileThread(
type == fileapi::kFileSystemTypePersistent);
FilePath base_path =
GetBaseDirectoryForOriginAndType(origin_url, type, false);
- if (base_path.empty() || !file_util::DirectoryExists(base_path))
- return 0;
+ if (base_path.empty() || !file_util::DirectoryExists(base_path)) return 0;
FilePath usage_file_path =
base_path.AppendASCII(FileSystemUsageCache::kUsageFileName);
@@ -544,11 +543,35 @@ int64 SandboxMountPointProvider::GetOriginUsageOnFileThread(
}
// The usage cache has not been initialized or the cache is dirty.
// Get the directory size now and update the cache.
- if (FileSystemUsageCache::Exists(usage_file_path))
- FileSystemUsageCache::Delete(usage_file_path);
- int64 usage = file_util::ComputeDirectorySize(base_path);
- // The result of ComputeDirectorySize does not include .usage file size.
- usage += FileSystemUsageCache::kUsageFileSize;
+ FileSystemUsageCache::Delete(usage_file_path);
+
+ FileSystemOperationContext context(NULL, sandbox_file_util_);
+ context.set_src_origin_url(origin_url);
+ context.set_src_type(type);
+ scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> enumerator(
+ sandbox_file_util_->CreateFileEnumerator(&context, FilePath()));
+
+ FilePath file_path_each;
+ int64 usage = 0;
+
+ // TODO(ericu): This could be made much more efficient if the
+ // AbstractFileEnumerator also had an interface to tell you the size of the
+ // file. ObfuscatedFileSystemFileEnumerator has already looked up the data,
+ // and it's a big waste to look it up again. The other implementers could
+ // easily add it on-demand, so as not to waste time when it's not needed.
+ while (!(file_path_each = enumerator->Next()).empty()) {
+ base::PlatformFileInfo file_info;
+ FilePath platform_file_path;
+ if (!enumerator->IsDirectory()) {
+ base::PlatformFileError error = sandbox_file_util_->GetFileInfo(
+ &context, file_path_each, &file_info, &platform_file_path);
+ if (error != base::PLATFORM_FILE_OK)
+ NOTREACHED();
+ else
+ usage += file_info.size;
+ }
+ // TODO(dmikurube): Add some cost as described at crbug.com/86114.
+ }
// This clears the dirty flag too.
FileSystemUsageCache::UpdateUsage(usage_file_path, usage);
return usage;
@@ -575,6 +598,7 @@ void SandboxMountPointProvider::UpdateOriginUsageOnFileThread(
FilePath usage_file_path = GetUsageCachePathForOriginAndType(
origin_url, type);
DCHECK(!usage_file_path.empty());
+ // TODO(dmikurbe): Make sure that usage_file_path is available.
FileSystemUsageCache::AtomicUpdateUsageByDelta(usage_file_path, delta);
if (proxy) {
proxy->NotifyStorageModified(