summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-17 11:53:51 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-17 11:53:51 +0000
commite5006b96ad664c9650c3631b4e666147a9c87a91 (patch)
tree29f5d2a4e28ff48da1843e63edfaa7fd0fb5cea8 /webkit/fileapi
parentfb9c4a7f8b369a8f810ac92334ff6f16cea138a6 (diff)
downloadchromium_src-e5006b96ad664c9650c3631b4e666147a9c87a91.zip
chromium_src-e5006b96ad664c9650c3631b4e666147a9c87a91.tar.gz
chromium_src-e5006b96ad664c9650c3631b4e666147a9c87a91.tar.bz2
Switch usage cache code to use FileSystemQuotaUtil in FileWriterDelegate
patch based on: http://codereview.chromium.org/6973005/ BUG=74841 TEST=FileWriterDelegate.* Review URL: http://codereview.chromium.org/7012037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85622 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi')
-rw-r--r--webkit/fileapi/file_system_operation.cc3
-rw-r--r--webkit/fileapi/file_system_operation.h2
-rw-r--r--webkit/fileapi/file_system_quota_util.cc65
-rw-r--r--webkit/fileapi/file_system_quota_util.h37
-rw-r--r--webkit/fileapi/file_writer_delegate.cc102
-rw-r--r--webkit/fileapi/file_writer_delegate.h13
-rw-r--r--webkit/fileapi/file_writer_delegate_unittest.cc162
-rw-r--r--webkit/fileapi/sandbox_mount_point_provider.cc4
-rw-r--r--webkit/fileapi/sandbox_mount_point_provider.h5
-rw-r--r--webkit/fileapi/webkit_fileapi.gypi3
10 files changed, 257 insertions, 139 deletions
diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc
index ac9ef88..de86b6f 100644
--- a/webkit/fileapi/file_system_operation.cc
+++ b/webkit/fileapi/file_system_operation.cc
@@ -728,8 +728,7 @@ void FileSystemOperation::OnFileOpenedForWrite(
delete this;
return;
}
- file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get(),
- file_system_operation_context_);
+ file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get());
}
bool FileSystemOperation::VerifyFileSystemPathForRead(
diff --git a/webkit/fileapi/file_system_operation.h b/webkit/fileapi/file_system_operation.h
index 08f7528..f7d8e7b 100644
--- a/webkit/fileapi/file_system_operation.h
+++ b/webkit/fileapi/file_system_operation.h
@@ -100,8 +100,10 @@ class FileSystemOperation {
FileSystemOperationContext* file_system_operation_context() {
return &file_system_operation_context_;
}
+
friend class FileSystemOperationTest;
friend class FileSystemOperationWriteTest;
+ friend class FileWriterDelegateTest;
bool GetUsageAndQuotaThenCallback(
const GURL& origin_url,
diff --git a/webkit/fileapi/file_system_quota_util.cc b/webkit/fileapi/file_system_quota_util.cc
new file mode 100644
index 0000000..3d0fab4
--- /dev/null
+++ b/webkit/fileapi/file_system_quota_util.cc
@@ -0,0 +1,65 @@
+// Copyright (c) 2011 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 "webkit/fileapi/file_system_quota_util.h"
+
+#include "base/compiler_specific.h"
+#include "base/message_loop_proxy.h"
+
+namespace fileapi {
+
+void FileSystemQuotaUtil::Proxy::UpdateOriginUsage(
+ quota::QuotaManagerProxy* proxy, const GURL& origin_url,
+ fileapi::FileSystemType type, int64 delta) {
+ if (!file_thread_->BelongsToCurrentThread()) {
+ file_thread_->PostTask(FROM_HERE, NewRunnableMethod(
+ this, &Proxy::UpdateOriginUsage, proxy, origin_url, type, delta));
+ return;
+ }
+ if (quota_util_)
+ quota_util_->UpdateOriginUsageOnFileThread(proxy, origin_url, type, delta);
+}
+
+void FileSystemQuotaUtil::Proxy::StartUpdateOrigin(
+ const GURL& origin_url, fileapi::FileSystemType type) {
+ if (!file_thread_->BelongsToCurrentThread()) {
+ file_thread_->PostTask(FROM_HERE, NewRunnableMethod(
+ this, &Proxy::StartUpdateOrigin, origin_url, type));
+ return;
+ }
+ if (quota_util_)
+ quota_util_->StartUpdateOriginOnFileThread(origin_url, type);
+}
+
+void FileSystemQuotaUtil::Proxy::EndUpdateOrigin(
+ const GURL& origin_url, fileapi::FileSystemType type) {
+ if (!file_thread_->BelongsToCurrentThread()) {
+ file_thread_->PostTask(FROM_HERE, NewRunnableMethod(
+ this, &Proxy::EndUpdateOrigin, origin_url, type));
+ return;
+ }
+ if (quota_util_)
+ quota_util_->EndUpdateOriginOnFileThread(origin_url, type);
+}
+
+FileSystemQuotaUtil::Proxy::Proxy(
+ FileSystemQuotaUtil* quota_util,
+ base::MessageLoopProxy* file_thread)
+ : quota_util_(quota_util),
+ file_thread_(file_thread) {
+ DCHECK(quota_util);
+}
+
+FileSystemQuotaUtil::Proxy::~Proxy() {
+}
+
+FileSystemQuotaUtil::FileSystemQuotaUtil(base::MessageLoopProxy* file_thread)
+ : proxy_(new Proxy(ALLOW_THIS_IN_INITIALIZER_LIST(this), file_thread)) {
+}
+
+FileSystemQuotaUtil::~FileSystemQuotaUtil() {
+ proxy_->quota_util_ = NULL;
+}
+
+} // namespace fileapi
diff --git a/webkit/fileapi/file_system_quota_util.h b/webkit/fileapi/file_system_quota_util.h
index 73e3373..c7b70df 100644
--- a/webkit/fileapi/file_system_quota_util.h
+++ b/webkit/fileapi/file_system_quota_util.h
@@ -9,9 +9,14 @@
#include <string>
#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
#include "googleurl/src/gurl.h"
#include "webkit/fileapi/file_system_types.h"
+namespace base {
+class MessageLoopProxy;
+}
+
namespace quota {
class QuotaManagerProxy;
}
@@ -25,6 +30,30 @@ namespace fileapi {
// the thread that the method name implies.
class FileSystemQuotaUtil {
public:
+ // Methods of this class can be called on any thread.
+ class Proxy : public base::RefCountedThreadSafe<Proxy> {
+ public:
+ void UpdateOriginUsage(quota::QuotaManagerProxy* proxy,
+ const GURL& origin_url,
+ fileapi::FileSystemType type,
+ int64 delta);
+ void StartUpdateOrigin(const GURL& origin_url,
+ fileapi::FileSystemType type);
+ void EndUpdateOrigin(const GURL& origin_url,
+ fileapi::FileSystemType type);
+
+ private:
+ friend class FileSystemQuotaUtil;
+ friend class base::RefCountedThreadSafe<Proxy>;
+ Proxy(FileSystemQuotaUtil* quota_handler,
+ base::MessageLoopProxy* file_thread);
+ ~Proxy();
+
+ FileSystemQuotaUtil* quota_util_; // Accessed only on the FILE thread.
+ scoped_refptr<base::MessageLoopProxy> file_thread_;
+ DISALLOW_COPY_AND_ASSIGN(Proxy);
+ };
+
// Called by quota client.
virtual void GetOriginsForTypeOnFileThread(fileapi::FileSystemType type,
std::set<GURL>* origins) = 0;
@@ -63,8 +92,14 @@ class FileSystemQuotaUtil {
virtual void EndUpdateOriginOnFileThread(const GURL& origin_url,
fileapi::FileSystemType type) = 0;
+ Proxy* proxy() { return proxy_.get(); }
+
protected:
- virtual ~FileSystemQuotaUtil() {}
+ explicit FileSystemQuotaUtil(base::MessageLoopProxy* file_thread);
+ virtual ~FileSystemQuotaUtil();
+
+ private:
+ scoped_refptr<Proxy> proxy_;
};
} // namespace fileapi
diff --git a/webkit/fileapi/file_writer_delegate.cc b/webkit/fileapi/file_writer_delegate.cc
index 1f80620..38e7260 100644
--- a/webkit/fileapi/file_writer_delegate.cc
+++ b/webkit/fileapi/file_writer_delegate.cc
@@ -10,8 +10,9 @@
#include "net/base/net_errors.h"
#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_operation.h"
+#include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/file_system_path_manager.h"
-#include "webkit/fileapi/file_system_usage_cache.h"
+#include "webkit/fileapi/file_system_quota_util.h"
#include "webkit/fileapi/quota_file_util.h"
namespace fileapi {
@@ -20,16 +21,15 @@ static const int kReadBufSize = 32768;
namespace {
-typedef Callback3<base::PlatformFileError /* error code */,
- const base::PlatformFileInfo& /* file_info */,
- const FilePath& /* usage_file_path */
+typedef Callback2<base::PlatformFileError /* error code */,
+ const base::PlatformFileInfo& /* file_info */
>::Type InitializeTaskCallback;
class InitializeTask : public base::RefCountedThreadSafe<InitializeTask> {
public:
InitializeTask(
base::PlatformFile file,
- const FileSystemOperationContext& context,
+ FileSystemOperationContext* context,
InitializeTaskCallback* callback)
: origin_message_loop_proxy_(
base::MessageLoopProxy::CreateForCurrentThread()),
@@ -50,24 +50,21 @@ class InitializeTask : public base::RefCountedThreadSafe<InitializeTask> {
friend class base::RefCountedThreadSafe<InitializeTask>;
void RunCallback() {
- callback_->Run(error_code_, file_info_, usage_file_path_);
+ callback_->Run(error_code_, file_info_);
delete callback_;
}
void ProcessOnTargetThread() {
- FilePath base_path = context_.file_system_context()->path_manager()->
- ValidateFileSystemRootAndGetPathOnFileThread(
- context_.src_origin_url(), context_.src_type(), FilePath(), false);
- usage_file_path_ = base_path.AppendASCII(
- FileSystemUsageCache::kUsageFileName);
- if (!usage_file_path_.empty()) {
- // Increment the dirty when the Write operation starts.
- FileSystemUsageCache::IncrementDirty(usage_file_path_);
+ DCHECK(context_->file_system_context());
+ FileSystemQuotaUtil* quota_util = context_->file_system_context()->
+ GetQuotaUtil(context_->src_type());
+ if (quota_util) {
+ DCHECK(quota_util->proxy());
+ quota_util->proxy()->StartUpdateOrigin(
+ context_->src_origin_url(), context_->src_type());
}
-
if (!base::GetPlatformFileInfo(file_, &file_info_))
error_code_ = base::PLATFORM_FILE_ERROR_FAILED;
-
origin_message_loop_proxy_->PostTask(FROM_HERE, NewRunnableMethod(this,
&InitializeTask::RunCallback));
}
@@ -76,11 +73,10 @@ class InitializeTask : public base::RefCountedThreadSafe<InitializeTask> {
base::PlatformFileError error_code_;
base::PlatformFile file_;
- FileSystemOperationContext context_;
+ FileSystemOperationContext* context_;
InitializeTaskCallback* callback_;
base::PlatformFileInfo file_info_;
- FilePath usage_file_path_;
};
} // namespace (anonymous)
@@ -107,31 +103,34 @@ FileWriterDelegate::FileWriterDelegate(
FileWriterDelegate::~FileWriterDelegate() {
}
-void FileWriterDelegate::OnGetFileInfoAndPrepareUsageFile(
+void FileWriterDelegate::OnGetFileInfoAndCallStartUpdate(
base::PlatformFileError error,
- const base::PlatformFileInfo& file_info,
- const FilePath& usage_file_path) {
+ const base::PlatformFileInfo& file_info) {
+ if (error) {
+ OnError(error);
+ return;
+ }
if (allowed_bytes_growth_ != QuotaFileUtil::kNoLimit)
allowed_bytes_to_write_ = file_info.size - offset_ + allowed_bytes_growth_;
else
allowed_bytes_to_write_ = QuotaFileUtil::kNoLimit;
file_stream_.reset(new net::FileStream(file_,
base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE |
- base::PLATFORM_FILE_ASYNC));
- usage_file_path_ = usage_file_path;
+ base::PLATFORM_FILE_ASYNC));
request_->Start();
}
void FileWriterDelegate::Start(base::PlatformFile file,
- net::URLRequest* request,
- const FileSystemOperationContext& context) {
+ net::URLRequest* request) {
file_ = file;
request_ = request;
- allowed_bytes_growth_ = context.allowed_bytes_growth();
+ allowed_bytes_growth_ =
+ file_system_operation_context()->allowed_bytes_growth();
- scoped_refptr<InitializeTask> relay = new InitializeTask(file_, context,
+ scoped_refptr<InitializeTask> relay = new InitializeTask(
+ file_, file_system_operation_context(),
callback_factory_.NewCallback(
- &FileWriterDelegate::OnGetFileInfoAndPrepareUsageFile));
+ &FileWriterDelegate::OnGetFileInfoAndCallStartUpdate));
relay->Start(proxy_, FROM_HERE);
}
@@ -252,20 +251,23 @@ void FileWriterDelegate::OnError(base::PlatformFileError error) {
request_->set_delegate(NULL);
request_->Cancel();
- if (!usage_file_path_.empty()) {
- // Decrement the dirty when the Write operation finishes.
- proxy_->PostTask(FROM_HERE, NewRunnableFunction(
- &FileSystemUsageCache::DecrementDirty, usage_file_path_));
+ if (quota_util()) {
+ quota_util()->proxy()->EndUpdateOrigin(
+ file_system_operation_context()->src_origin_url(),
+ file_system_operation_context()->src_type());
}
+
file_system_operation_->DidWrite(error, 0, true);
}
void FileWriterDelegate::OnProgress(int bytes_read, bool done) {
DCHECK(bytes_read + bytes_read_backlog_ >= bytes_read_backlog_);
- if (bytes_read > 0 && !usage_file_path_.empty()) {
- proxy_->PostTask(FROM_HERE, NewRunnableFunction(
- &FileSystemUsageCache::AtomicUpdateUsageByDelta,
- usage_file_path_, bytes_read));
+ if (bytes_read > 0 && quota_util()) {
+ quota_util()->proxy()->UpdateOriginUsage(
+ file_system_operation_->file_system_context()->quota_manager_proxy(),
+ file_system_operation_context()->src_origin_url(),
+ file_system_operation_context()->src_type(),
+ bytes_read);
}
static const int kMinProgressDelayMS = 200;
base::Time currentTime = base::Time::Now();
@@ -275,16 +277,32 @@ void FileWriterDelegate::OnProgress(int bytes_read, bool done) {
bytes_read += bytes_read_backlog_;
last_progress_event_time_ = currentTime;
bytes_read_backlog_ = 0;
- if (done && !usage_file_path_.empty()) {
- // Decrement the dirty when the Write operation finishes.
- proxy_->PostTask(FROM_HERE, NewRunnableFunction(
- &FileSystemUsageCache::DecrementDirty, usage_file_path_));
+ if (done && quota_util()) {
+ if (quota_util()) {
+ quota_util()->proxy()->EndUpdateOrigin(
+ file_system_operation_context()->src_origin_url(),
+ file_system_operation_context()->src_type());
+ }
}
- file_system_operation_->DidWrite(
- base::PLATFORM_FILE_OK, bytes_read, done);
+ file_system_operation_->DidWrite(base::PLATFORM_FILE_OK, bytes_read, done);
return;
}
bytes_read_backlog_ += bytes_read;
}
+FileSystemOperationContext*
+FileWriterDelegate::file_system_operation_context() const {
+ DCHECK(file_system_operation_);
+ DCHECK(file_system_operation_->file_system_operation_context());
+ return file_system_operation_->file_system_operation_context();
+}
+
+FileSystemQuotaUtil* FileWriterDelegate::quota_util() const {
+ DCHECK(file_system_operation_);
+ DCHECK(file_system_operation_->file_system_context());
+ DCHECK(file_system_operation_->file_system_operation_context());
+ return file_system_operation_->file_system_context()->GetQuotaUtil(
+ file_system_operation_context()->src_type());
+}
+
} // namespace fileapi
diff --git a/webkit/fileapi/file_writer_delegate.h b/webkit/fileapi/file_writer_delegate.h
index d95cc42..cf59e5a 100644
--- a/webkit/fileapi/file_writer_delegate.h
+++ b/webkit/fileapi/file_writer_delegate.h
@@ -22,6 +22,7 @@ namespace fileapi {
class FileSystemOperation;
class FileSystemOperationContext;
+class FileSystemQuotaUtil;
class FileWriterDelegate : public net::URLRequest::Delegate {
public:
@@ -32,8 +33,7 @@ class FileWriterDelegate : public net::URLRequest::Delegate {
virtual ~FileWriterDelegate();
void Start(base::PlatformFile file,
- net::URLRequest* request,
- const FileSystemOperationContext& context);
+ net::URLRequest* request);
base::PlatformFile file() {
return file_;
}
@@ -50,10 +50,9 @@ class FileWriterDelegate : public net::URLRequest::Delegate {
virtual void OnReadCompleted(net::URLRequest* request, int bytes_read);
private:
- void OnGetFileInfoAndPrepareUsageFile(
+ void OnGetFileInfoAndCallStartUpdate(
base::PlatformFileError error,
- const base::PlatformFileInfo& file_info,
- const FilePath& usage_file_path);
+ const base::PlatformFileInfo& file_info);
void Read();
void OnDataReceived(int bytes_read);
void Write();
@@ -61,6 +60,9 @@ class FileWriterDelegate : public net::URLRequest::Delegate {
void OnError(base::PlatformFileError error);
void OnProgress(int bytes_read, bool done);
+ FileSystemOperationContext* file_system_operation_context() const;
+ FileSystemQuotaUtil* quota_util() const;
+
FileSystemOperation* file_system_operation_;
base::PlatformFile file_;
base::PlatformFileInfo file_info_;
@@ -70,7 +72,6 @@ class FileWriterDelegate : public net::URLRequest::Delegate {
int bytes_read_backlog_;
int bytes_written_;
int bytes_read_;
- FilePath usage_file_path_;
int64 total_bytes_written_;
int64 allowed_bytes_growth_;
int64 allowed_bytes_to_write_;
diff --git a/webkit/fileapi/file_writer_delegate_unittest.cc b/webkit/fileapi/file_writer_delegate_unittest.cc
index d56c7ae..80e6299 100644
--- a/webkit/fileapi/file_writer_delegate_unittest.cc
+++ b/webkit/fileapi/file_writer_delegate_unittest.cc
@@ -9,6 +9,7 @@
//
#include <string>
+#include <vector>
#include "base/file_util_proxy.h"
#include "base/memory/scoped_temp_dir.h"
@@ -26,31 +27,13 @@
#include "webkit/fileapi/file_system_path_manager.h"
#include "webkit/fileapi/file_system_usage_cache.h"
#include "webkit/fileapi/file_writer_delegate.h"
+#include "webkit/fileapi/sandbox_mount_point_provider.h"
#include "webkit/fileapi/quota_file_util.h"
namespace fileapi {
namespace {
-class MockFileSystemPathManager : public FileSystemPathManager {
- public:
- MockFileSystemPathManager(const FilePath& filesystem_path)
- : FileSystemPathManager(base::MessageLoopProxy::CreateForCurrentThread(),
- filesystem_path, NULL, false, true),
- test_filesystem_path_(filesystem_path) {}
-
- virtual FilePath ValidateFileSystemRootAndGetPathOnFileThread(
- const GURL& origin_url,
- FileSystemType type,
- const FilePath& virtual_path,
- bool create) {
- return test_filesystem_path_;
- }
-
- private:
- FilePath test_filesystem_path_;
-};
-
class Result {
public:
Result()
@@ -86,7 +69,8 @@ class Result {
class FileWriterDelegateTest : public PlatformTest {
public:
FileWriterDelegateTest()
- : loop_(MessageLoop::TYPE_IO) {}
+ : loop_(MessageLoop::TYPE_IO),
+ origin_url_("http://foo") {}
protected:
virtual void SetUp();
@@ -96,21 +80,30 @@ class FileWriterDelegateTest : public PlatformTest {
return FileSystemUsageCache::GetUsage(usage_file_path_);
}
+ FileSystemOperation* CreateNewOperation(Result* result, int64 quota);
+
+ FileSystemContext* file_system_context() {
+ return file_system_context_.get();
+ }
+
static net::URLRequest::ProtocolFactory Factory;
scoped_ptr<FileWriterDelegate> file_writer_delegate_;
scoped_ptr<net::URLRequest> request_;
- scoped_ptr<FileSystemOperationContext> context_;
scoped_ptr<Result> result_;
+ scoped_refptr<FileSystemContext> file_system_context_;
MessageLoop loop_;
ScopedTempDir dir_;
- FilePath filesystem_dir_;
FilePath usage_file_path_;
FilePath file_path_;
PlatformFile file_;
+ const GURL origin_url_;
+
+ static const char* content_;
};
+const char* FileWriterDelegateTest::content_ = NULL;
namespace {
@@ -144,7 +137,7 @@ class FileWriterDelegateTestJob : public net::URLRequestJob {
return true;
}
-private:
+ private:
std::string content_;
int remaining_bytes_;
int cursor_;
@@ -152,7 +145,7 @@ private:
class MockDispatcher : public FileSystemCallbackDispatcher {
public:
- MockDispatcher(Result* result) : result_(result) { }
+ explicit MockDispatcher(Result* result) : result_(result) {}
virtual void DidFail(base::PlatformFileError status) {
result_->set_failure_status(status);
@@ -195,26 +188,31 @@ class MockDispatcher : public FileSystemCallbackDispatcher {
net::URLRequestJob* FileWriterDelegateTest::Factory(
net::URLRequest* request,
const std::string& scheme) {
- return new FileWriterDelegateTestJob(request, g_content);
+ return new FileWriterDelegateTestJob(
+ request, FileWriterDelegateTest::content_);
}
void FileWriterDelegateTest::SetUp() {
ASSERT_TRUE(dir_.CreateUniqueTempDir());
- filesystem_dir_ = dir_.path().AppendASCII("filesystem");
- file_util::CreateDirectory(filesystem_dir_);
- ASSERT_TRUE(file_util::CreateTemporaryFileInDir(filesystem_dir_,
- &file_path_));
-
- context_.reset(new FileSystemOperationContext(
- new FileSystemContext(base::MessageLoopProxy::CreateForCurrentThread(),
- base::MessageLoopProxy::CreateForCurrentThread(),
- NULL, NULL, FilePath(), false /* is_incognito */,
- true, true,
- new MockFileSystemPathManager(filesystem_dir_)),
- NULL));
-
- usage_file_path_ =
- filesystem_dir_.AppendASCII(FileSystemUsageCache::kUsageFileName);
+ FilePath base_dir = dir_.path().AppendASCII("filesystem");
+ file_system_context_ = new FileSystemContext(
+ base::MessageLoopProxy::CreateForCurrentThread(),
+ base::MessageLoopProxy::CreateForCurrentThread(),
+ NULL, NULL, base_dir, false,
+ true, true, NULL);
+
+ // NOTE: this test assumes the filesystem implementation uses
+ // sandbox provider for temporary filesystem.
+ SandboxMountPointProvider* sandbox_provider =
+ file_system_context_->path_manager()->sandbox_provider();
+ FilePath filesystem_dir = sandbox_provider->GetBaseDirectoryForOriginAndType(
+ origin_url_, kFileSystemTypeTemporary);
+ ASSERT_TRUE(file_util::CreateDirectory(filesystem_dir));
+ ASSERT_TRUE(file_util::CreateTemporaryFileInDir(
+ filesystem_dir, &file_path_));
+
+ usage_file_path_ = sandbox_provider->GetUsageCachePathForOriginAndType(
+ origin_url_, kFileSystemTypeTemporary);
FileSystemUsageCache::UpdateUsage(usage_file_path_, 0);
bool created;
@@ -233,23 +231,36 @@ void FileWriterDelegateTest::SetUp() {
void FileWriterDelegateTest::TearDown() {
net::URLRequest::RegisterProtocolFactory("blob", NULL);
- result_.reset(NULL);
+ result_.reset();
base::ClosePlatformFile(file_);
- context_.reset(NULL);
+}
+
+FileSystemOperation* FileWriterDelegateTest::CreateNewOperation(
+ Result* result, int64 quota) {
+ FileSystemOperation* operation =
+ new FileSystemOperation(new MockDispatcher(result), NULL,
+ file_system_context_.get(),
+ QuotaFileUtil::GetInstance());
+ FileSystemOperationContext* context =
+ operation->file_system_operation_context();
+ context->set_src_origin_url(origin_url_);
+ context->set_src_type(kFileSystemTypeTemporary);
+ context->set_dest_origin_url(origin_url_);
+ context->set_dest_type(kFileSystemTypeTemporary);
+ context->set_allowed_bytes_growth(quota);
+ return operation;
}
TEST_F(FileWriterDelegateTest, WriteSuccessWithoutQuotaLimit) {
GURL blob_url("blob:nolimit");
- g_content = std::string("The quick brown fox jumps over the lazy dog.\n");
+ content_ = "The quick brown fox jumps over the lazy dog.\n";
file_writer_delegate_.reset(new FileWriterDelegate(
- new FileSystemOperation(new MockDispatcher(result_.get()), NULL, NULL,
- QuotaFileUtil::GetInstance()),
+ CreateNewOperation(result_.get(), QuotaFileUtil::kNoLimit),
0, base::MessageLoopProxy::CreateForCurrentThread()));
request_.reset(new net::URLRequest(blob_url, file_writer_delegate_.get()));
ASSERT_EQ(0, GetCachedUsage());
- context_->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
- file_writer_delegate_->Start(file_, request_.get(), *context_);
+ file_writer_delegate_->Start(file_, request_.get());
MessageLoop::current()->Run();
ASSERT_EQ(45, GetCachedUsage());
@@ -257,25 +268,23 @@ TEST_F(FileWriterDelegateTest, WriteSuccessWithoutQuotaLimit) {
EXPECT_EQ(base::PLATFORM_FILE_OK, result_->status());
EXPECT_TRUE(result_->complete());
- file_writer_delegate_.reset(NULL);
+ file_writer_delegate_.reset();
}
TEST_F(FileWriterDelegateTest, WriteSuccessWithJustQuota) {
GURL blob_url("blob:just");
- g_content = std::string("The quick brown fox jumps over the lazy dog.\n");
+ content_ = "The quick brown fox jumps over the lazy dog.\n";
file_writer_delegate_.reset(new FileWriterDelegate(
- new FileSystemOperation(new MockDispatcher(result_.get()), NULL, NULL,
- QuotaFileUtil::GetInstance()),
+ CreateNewOperation(result_.get(), 45),
0, base::MessageLoopProxy::CreateForCurrentThread()));
request_.reset(new net::URLRequest(blob_url, file_writer_delegate_.get()));
ASSERT_EQ(0, GetCachedUsage());
- context_->set_allowed_bytes_growth(45);
- file_writer_delegate_->Start(file_, request_.get(), *context_);
+ file_writer_delegate_->Start(file_, request_.get());
MessageLoop::current()->Run();
ASSERT_EQ(45, GetCachedUsage());
- file_writer_delegate_.reset(NULL);
+ file_writer_delegate_.reset();
EXPECT_EQ(45, result_->bytes_written());
EXPECT_EQ(base::PLATFORM_FILE_OK, result_->status());
@@ -284,20 +293,18 @@ TEST_F(FileWriterDelegateTest, WriteSuccessWithJustQuota) {
TEST_F(FileWriterDelegateTest, WriteFailureByQuota) {
GURL blob_url("blob:failure");
- g_content = std::string("The quick brown fox jumps over the lazy dog.\n");
+ content_ = "The quick brown fox jumps over the lazy dog.\n";
file_writer_delegate_.reset(new FileWriterDelegate(
- new FileSystemOperation(new MockDispatcher(result_.get()), NULL, NULL,
- QuotaFileUtil::GetInstance()),
+ CreateNewOperation(result_.get(), 44),
0, base::MessageLoopProxy::CreateForCurrentThread()));
request_.reset(new net::URLRequest(blob_url, file_writer_delegate_.get()));
ASSERT_EQ(0, GetCachedUsage());
- context_->set_allowed_bytes_growth(44);
- file_writer_delegate_->Start(file_, request_.get(), *context_);
+ file_writer_delegate_->Start(file_, request_.get());
MessageLoop::current()->Run();
ASSERT_EQ(44, GetCachedUsage());
- file_writer_delegate_.reset(NULL);
+ file_writer_delegate_.reset();
EXPECT_EQ(44, result_->bytes_written());
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, result_->status());
@@ -306,20 +313,18 @@ TEST_F(FileWriterDelegateTest, WriteFailureByQuota) {
TEST_F(FileWriterDelegateTest, WriteZeroBytesSuccessfullyWithZeroQuota) {
GURL blob_url("blob:zero");
- g_content = std::string("");
+ content_ = "";
file_writer_delegate_.reset(new FileWriterDelegate(
- new FileSystemOperation(new MockDispatcher(result_.get()), NULL, NULL,
- QuotaFileUtil::GetInstance()),
+ CreateNewOperation(result_.get(), 0),
0, base::MessageLoopProxy::CreateForCurrentThread()));
request_.reset(new net::URLRequest(blob_url, file_writer_delegate_.get()));
ASSERT_EQ(0, GetCachedUsage());
- context_->set_allowed_bytes_growth(0);
- file_writer_delegate_->Start(file_, request_.get(), *context_);
+ file_writer_delegate_->Start(file_, request_.get());
MessageLoop::current()->Run();
ASSERT_EQ(0, GetCachedUsage());
- file_writer_delegate_.reset(NULL);
+ file_writer_delegate_.reset();
EXPECT_EQ(0, result_->bytes_written());
EXPECT_EQ(base::PLATFORM_FILE_OK, result_->status());
@@ -327,7 +332,6 @@ TEST_F(FileWriterDelegateTest, WriteZeroBytesSuccessfullyWithZeroQuota) {
}
TEST_F(FileWriterDelegateTest, WriteSuccessWithoutQuotaLimitConcurrent) {
- scoped_ptr<FileSystemOperationContext> context2;
scoped_ptr<FileWriterDelegate> file_writer_delegate2;
scoped_ptr<net::URLRequest> request2;
scoped_ptr<Result> result2;
@@ -342,41 +346,29 @@ TEST_F(FileWriterDelegateTest, WriteSuccessWithoutQuotaLimitConcurrent) {
&created, &error_code);
ASSERT_EQ(base::PLATFORM_FILE_OK, error_code);
- context2.reset(new FileSystemOperationContext(
- new FileSystemContext(base::MessageLoopProxy::CreateForCurrentThread(),
- base::MessageLoopProxy::CreateForCurrentThread(),
- NULL, NULL, FilePath(), false /* is_incognito */,
- true, true,
- new MockFileSystemPathManager(filesystem_dir_)),
- NULL));
-
result2.reset(new Result());
GURL blob_url("blob:nolimitconcurrent");
GURL blob_url2("blob:nolimitconcurrent2");
- g_content = std::string("The quick brown fox jumps over the lazy dog.\n");
+ content_ = "The quick brown fox jumps over the lazy dog.\n";
file_writer_delegate_.reset(new FileWriterDelegate(
- new FileSystemOperation(new MockDispatcher(result_.get()), NULL, NULL,
- QuotaFileUtil::GetInstance()),
+ CreateNewOperation(result_.get(), QuotaFileUtil::kNoLimit),
0, base::MessageLoopProxy::CreateForCurrentThread()));
file_writer_delegate2.reset(new FileWriterDelegate(
- new FileSystemOperation(new MockDispatcher(result2.get()), NULL, NULL,
- QuotaFileUtil::GetInstance()),
+ CreateNewOperation(result2.get(), QuotaFileUtil::kNoLimit),
0, base::MessageLoopProxy::CreateForCurrentThread()));
request_.reset(new net::URLRequest(blob_url, file_writer_delegate_.get()));
request2.reset(new net::URLRequest(blob_url2, file_writer_delegate2.get()));
ASSERT_EQ(0, GetCachedUsage());
- context_->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
- context2->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
- file_writer_delegate_->Start(file_, request_.get(), *context_);
- file_writer_delegate2->Start(file2, request2.get(), *context2);
+ file_writer_delegate_->Start(file_, request_.get());
+ file_writer_delegate2->Start(file2, request2.get());
MessageLoop::current()->Run();
if (!result_->complete() || !result2->complete())
MessageLoop::current()->Run();
ASSERT_EQ(90, GetCachedUsage());
- file_writer_delegate_.reset(NULL);
+ file_writer_delegate_.reset();
EXPECT_EQ(45, result_->bytes_written());
EXPECT_EQ(base::PLATFORM_FILE_OK, result_->status());
diff --git a/webkit/fileapi/sandbox_mount_point_provider.cc b/webkit/fileapi/sandbox_mount_point_provider.cc
index 8f6d776..8ac594c 100644
--- a/webkit/fileapi/sandbox_mount_point_provider.cc
+++ b/webkit/fileapi/sandbox_mount_point_provider.cc
@@ -21,6 +21,7 @@
#include "webkit/fileapi/file_system_path_manager.h"
#include "webkit/fileapi/file_system_usage_cache.h"
#include "webkit/fileapi/file_system_util.h"
+#include "webkit/fileapi/obfuscated_file_system_file_util.h"
#include "webkit/fileapi/sandbox_mount_point_provider.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/quota/quota_manager.h"
@@ -173,7 +174,8 @@ SandboxMountPointProvider::SandboxMountPointProvider(
FileSystemPathManager* path_manager,
scoped_refptr<base::MessageLoopProxy> file_message_loop,
const FilePath& profile_path)
- : path_manager_(path_manager),
+ : FileSystemQuotaUtil(file_message_loop),
+ path_manager_(path_manager),
file_message_loop_(file_message_loop),
base_path_(profile_path.Append(kFileSystemDirectory)),
sandbox_file_util_(new ObfuscatedFileSystemFileUtil(base_path_)) {
diff --git a/webkit/fileapi/sandbox_mount_point_provider.h b/webkit/fileapi/sandbox_mount_point_provider.h
index 3dd8140..22b9f29 100644
--- a/webkit/fileapi/sandbox_mount_point_provider.h
+++ b/webkit/fileapi/sandbox_mount_point_provider.h
@@ -14,7 +14,6 @@
#include "googleurl/src/gurl.h"
#include "webkit/fileapi/file_system_mount_point_provider.h"
#include "webkit/fileapi/file_system_quota_util.h"
-#include "webkit/fileapi/obfuscated_file_system_file_util.h"
namespace base {
class MessageLoopProxy;
@@ -26,6 +25,8 @@ class QuotaManagerProxy;
namespace fileapi {
+class ObfuscatedFileSystemFileUtil;
+
// An interface to construct or crack sandboxed filesystem paths.
// Currently each sandboxed filesystem path looks like (soon will be changed):
// <profile_dir>/FileSystem/<origin_identifier>/<type>/chrome-<unique>/...
@@ -162,6 +163,8 @@ class SandboxMountPointProvider
class GetFileSystemRootPathTask;
+ friend class FileWriterDelegateTest;
+
// The path_manager_ isn't owned by this instance; this instance is owned by
// the path_manager_, and they have the same lifetime.
FileSystemPathManager* path_manager_;
diff --git a/webkit/fileapi/webkit_fileapi.gypi b/webkit/fileapi/webkit_fileapi.gypi
index d23a1f9..aaae064 100644
--- a/webkit/fileapi/webkit_fileapi.gypi
+++ b/webkit/fileapi/webkit_fileapi.gypi
@@ -37,9 +37,10 @@
'file_system_origin_database.h',
'file_system_path_manager.cc',
'file_system_path_manager.h',
- 'file_system_quota_util.h',
'file_system_quota_client.cc',
'file_system_quota_client.h',
+ 'file_system_quota_util.cc',
+ 'file_system_quota_util.h',
'file_system_types.h',
'file_system_url_request_job.cc',
'file_system_url_request_job.h',