diff options
author | nhiroki@chromium.org <nhiroki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-08 08:44:23 +0000 |
---|---|---|
committer | nhiroki@chromium.org <nhiroki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-08 08:44:23 +0000 |
commit | fd511780ba4793a17e1e3564726fdc1797a714b9 (patch) | |
tree | 4844a680713f160454f00a526b592d04ff5c0709 /webkit | |
parent | 741fd682669c569fde6ba5301b5406943ac06130 (diff) | |
download | chromium_src-fd511780ba4793a17e1e3564726fdc1797a714b9.zip chromium_src-fd511780ba4793a17e1e3564726fdc1797a714b9.tar.gz chromium_src-fd511780ba4793a17e1e3564726fdc1797a714b9.tar.bz2 |
Revert 233815 "Quota: Implement QuotaBackendImpl"
This breaks content_unittests on some bots.
http://build.chromium.org/p/chromium.linux/builders/Linux Aura/builds/11164
> Quota: Implement QuotaBackendImpl
>
> This introduces QuotaBackendImpl working as bridge among FileSystemUsageCache,
> QuotaManager and QuotaReservationManager. The backend will be created by
> FileSystemContext and retained by QuotaReservationManager.
>
>
> BUG=303443
> TEST=content_unittests --gtest_filter=QuotaBackendImplTest.*
> TEST=content_unittests --gtest_filter=QuotaReservationManagerTest.*
> TBR=jochen@chromium.org
>
> Review URL: https://codereview.chromium.org/61593002
TBR=nhiroki@chromium.org
Review URL: https://codereview.chromium.org/64883003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233828 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
11 files changed, 54 insertions, 540 deletions
diff --git a/webkit/browser/fileapi/obfuscated_file_util.h b/webkit/browser/fileapi/obfuscated_file_util.h index 05d5530..e25a99e 100644 --- a/webkit/browser/fileapi/obfuscated_file_util.h +++ b/webkit/browser/fileapi/obfuscated_file_util.h @@ -230,7 +230,6 @@ class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE ObfuscatedFileUtil friend class ObfuscatedFileEnumerator; friend class ObfuscatedFileUtilTest; - friend class QuotaBackendImplTest; FRIEND_TEST_ALL_PREFIXES(ObfuscatedFileUtilTest, MaybeDropDatabasesAliveCase); FRIEND_TEST_ALL_PREFIXES(ObfuscatedFileUtilTest, MaybeDropDatabasesAlreadyDeletedCase); diff --git a/webkit/browser/fileapi/quota/quota_backend_impl.cc b/webkit/browser/fileapi/quota/quota_backend_impl.cc deleted file mode 100644 index 70dbd3d..0000000 --- a/webkit/browser/fileapi/quota/quota_backend_impl.cc +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright 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 "webkit/browser/fileapi/quota/quota_backend_impl.h" - -#include <string> - -#include "base/bind.h" -#include "base/callback.h" -#include "base/logging.h" -#include "base/sequenced_task_runner.h" -#include "webkit/browser/fileapi/file_system_usage_cache.h" -#include "webkit/browser/quota/quota_client.h" -#include "webkit/browser/quota/quota_manager.h" -#include "webkit/common/fileapi/file_system_util.h" - -namespace fileapi { - -QuotaBackendImpl::QuotaBackendImpl( - base::SequencedTaskRunner* file_task_runner, - ObfuscatedFileUtil* obfuscated_file_util, - FileSystemUsageCache* file_system_usage_cache, - quota::QuotaManagerProxy* quota_manager_proxy) - : file_task_runner_(file_task_runner), - obfuscated_file_util_(obfuscated_file_util), - file_system_usage_cache_(file_system_usage_cache), - quota_manager_proxy_(quota_manager_proxy), - weak_ptr_factory_(this) { -} - -QuotaBackendImpl::~QuotaBackendImpl() { -} - -void QuotaBackendImpl::ReserveQuota(const GURL& origin, - FileSystemType type, - int64 delta, - const ReserveQuotaCallback& callback) { - DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); - if (!delta) { - callback.Run(base::PLATFORM_FILE_OK); - return; - } - DCHECK(quota_manager_proxy_); - quota_manager_proxy_->GetUsageAndQuota( - file_task_runner_, origin, FileSystemTypeToQuotaStorageType(type), - base::Bind(&QuotaBackendImpl::DidGetUsageAndQuotaForReserveQuota, - weak_ptr_factory_.GetWeakPtr(), - QuotaReservationInfo(origin, type, delta), callback)); -} - -void QuotaBackendImpl::ReleaseReservedQuota(const GURL& origin, - FileSystemType type, - int64 size) { - DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); - DCHECK_LE(0, size); - if (!size) - return; - ReserveQuotaInternal(QuotaReservationInfo(origin, type, -size)); -} - -void QuotaBackendImpl::CommitQuotaUsage(const GURL& origin, - FileSystemType type, - int64 delta) { - DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); - if (!delta) - return; - ReserveQuotaInternal(QuotaReservationInfo(origin, type, delta)); - base::FilePath path; - if (GetUsageCachePath(origin, type, &path) != base::PLATFORM_FILE_OK) - return; - bool result = file_system_usage_cache_->AtomicUpdateUsageByDelta(path, delta); - DCHECK(result); -} - -void QuotaBackendImpl::IncrementDirtyCount(const GURL& origin, - FileSystemType type) { - DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); - base::FilePath path; - if (GetUsageCachePath(origin, type, &path) != base::PLATFORM_FILE_OK) - return; - DCHECK(file_system_usage_cache_); - file_system_usage_cache_->IncrementDirty(path); -} - -void QuotaBackendImpl::DecrementDirtyCount(const GURL& origin, - FileSystemType type) { - DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); - base::FilePath path; - if (GetUsageCachePath(origin, type, &path) != base::PLATFORM_FILE_OK) - return; - DCHECK(file_system_usage_cache_); - file_system_usage_cache_->DecrementDirty(path); -} - -void QuotaBackendImpl::DidGetUsageAndQuotaForReserveQuota( - const QuotaReservationInfo& info, - const ReserveQuotaCallback& callback, - quota::QuotaStatusCode status, int64 usage, int64 quota) { - DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); - if (status != quota::kQuotaStatusOk) { - callback.Run(base::PLATFORM_FILE_ERROR_FAILED); - return; - } - - if (quota < usage + info.delta) { - callback.Run(base::PLATFORM_FILE_ERROR_NO_SPACE); - return; - } - - ReserveQuotaInternal(info); - if (callback.Run(base::PLATFORM_FILE_OK)) - return; - // The requester could not accept the reserved quota. Revert it. - ReserveQuotaInternal( - QuotaReservationInfo(info.origin, info.type, -info.delta)); -} - -void QuotaBackendImpl::ReserveQuotaInternal(const QuotaReservationInfo& info) { - DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); - DCHECK(quota_manager_proxy_); - quota_manager_proxy_->NotifyStorageModified( - quota::QuotaClient::kFileSystem, info.origin, - FileSystemTypeToQuotaStorageType(info.type), info.delta); -} - -base::PlatformFileError QuotaBackendImpl::GetUsageCachePath( - const GURL& origin, - FileSystemType type, - base::FilePath* usage_file_path) { - DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); - DCHECK(usage_file_path); - base::PlatformFileError error = base::PLATFORM_FILE_OK; - *usage_file_path = - SandboxFileSystemBackendDelegate::GetUsageCachePathForOriginAndType( - obfuscated_file_util_, origin, type, &error); - return error; -} - -QuotaBackendImpl::QuotaReservationInfo::QuotaReservationInfo( - const GURL& origin, FileSystemType type, int64 delta) - : origin(origin), type(type), delta(delta) { -} - -QuotaBackendImpl::QuotaReservationInfo::~QuotaReservationInfo() { -} - -} // namespace fileapi diff --git a/webkit/browser/fileapi/quota/quota_backend_impl.h b/webkit/browser/fileapi/quota/quota_backend_impl.h deleted file mode 100644 index 10c38e7..0000000 --- a/webkit/browser/fileapi/quota/quota_backend_impl.h +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 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. - -#ifndef WEBKIT_BROWSER_FILEAPI_QUOTA_QUOTA_BACKEND_IMPL_H_ -#define WEBKIT_BROWSER_FILEAPI_QUOTA_QUOTA_BACKEND_IMPL_H_ - -#include "base/memory/ref_counted.h" -#include "base/memory/weak_ptr.h" -#include "webkit/browser/fileapi/quota/quota_reservation_manager.h" -#include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" -#include "webkit/browser/webkit_storage_browser_export.h" -#include "webkit/common/quota/quota_status_code.h" - -namespace base { -class SequencedTaskRunner; -} - -namespace quota { -class QuotaManagerProxy; -} - -namespace fileapi { - -class FileSystemUsageCache; -class ObfuscatedFileUtil; - -// An instance of this class is owned by QuotaReservationManager. -class WEBKIT_STORAGE_BROWSER_EXPORT QuotaBackendImpl - : public QuotaReservationManager::QuotaBackend { - public: - typedef QuotaReservationManager::ReserveQuotaCallback - ReserveQuotaCallback; - - QuotaBackendImpl(base::SequencedTaskRunner* file_task_runner, - ObfuscatedFileUtil* obfuscated_file_util, - FileSystemUsageCache* file_system_usage_cache, - quota::QuotaManagerProxy* quota_manager_proxy); - virtual ~QuotaBackendImpl(); - - // QuotaReservationManager::QuotaBackend overrides. - virtual void ReserveQuota( - const GURL& origin, - FileSystemType type, - int64 delta, - const ReserveQuotaCallback& callback) OVERRIDE; - virtual void ReleaseReservedQuota( - const GURL& origin, - FileSystemType type, - int64 size) OVERRIDE; - virtual void CommitQuotaUsage( - const GURL& origin, - FileSystemType type, - int64 delta) OVERRIDE; - virtual void IncrementDirtyCount( - const GURL& origin, - FileSystemType type) OVERRIDE; - virtual void DecrementDirtyCount( - const GURL& origin, - FileSystemType type) OVERRIDE; - - private: - friend class QuotaBackendImplTest; - - struct QuotaReservationInfo { - QuotaReservationInfo(const GURL& origin, FileSystemType type, int64 delta); - ~QuotaReservationInfo(); - - GURL origin; - FileSystemType type; - int64 delta; - }; - - void DidGetUsageAndQuotaForReserveQuota( - const QuotaReservationInfo& info, - const ReserveQuotaCallback& callback, - quota::QuotaStatusCode status, - int64 usage, - int64 quota); - - void ReserveQuotaInternal( - const QuotaReservationInfo& info); - base::PlatformFileError GetUsageCachePath( - const GURL& origin, - FileSystemType type, - base::FilePath* usage_file_path); - - scoped_refptr<base::SequencedTaskRunner> file_task_runner_; - - // Owned by SandboxFileSystemBackendDelegate. - ObfuscatedFileUtil* obfuscated_file_util_; - FileSystemUsageCache* file_system_usage_cache_; - - scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; - - base::WeakPtrFactory<QuotaBackendImpl> weak_ptr_factory_; - - DISALLOW_COPY_AND_ASSIGN(QuotaBackendImpl); -}; - -} // namespace fileapi - -#endif // WEBKIT_BROWSER_FILEAPI_QUOTA_QUOTA_BACKEND_IMPL_H_ diff --git a/webkit/browser/fileapi/quota/quota_backend_impl_unittest.cc b/webkit/browser/fileapi/quota/quota_backend_impl_unittest.cc deleted file mode 100644 index bd1483a..0000000 --- a/webkit/browser/fileapi/quota/quota_backend_impl_unittest.cc +++ /dev/null @@ -1,243 +0,0 @@ -// Copyright 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 "webkit/browser/fileapi/quota/quota_backend_impl.h" - -#include "base/files/scoped_temp_dir.h" -#include "base/message_loop/message_loop.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "webkit/browser/fileapi/file_system_usage_cache.h" -#include "webkit/browser/fileapi/obfuscated_file_util.h" -#include "webkit/browser/quota/quota_manager.h" - -namespace fileapi { - -namespace { - -const char kOrigin[] = "http://example.com"; - -bool DidReserveQuota(bool accepted, - base::PlatformFileError* error_out, - base::PlatformFileError error) { - DCHECK(error_out); - *error_out = error; - return accepted; -} - -class MockQuotaManagerProxy : public quota::QuotaManagerProxy { - public: - MockQuotaManagerProxy() - : QuotaManagerProxy(NULL, NULL), - storage_modified_count_(0), - usage_(0), quota_(0) {} - - // We don't mock them. - virtual void NotifyOriginInUse(const GURL& origin) OVERRIDE {} - virtual void NotifyOriginNoLongerInUse(const GURL& origin) OVERRIDE {} - virtual void SetUsageCacheEnabled(quota::QuotaClient::ID client_id, - const GURL& origin, - quota::StorageType type, - bool enabled) OVERRIDE {} - - virtual void NotifyStorageModified( - quota::QuotaClient::ID client_id, - const GURL& origin, - quota::StorageType type, - int64 delta) OVERRIDE { - ++storage_modified_count_; - usage_ += delta; - ASSERT_LT(usage_, quota_); - } - - virtual void GetUsageAndQuota( - base::SequencedTaskRunner* original_task_runner, - const GURL& origin, - quota::StorageType type, - const GetUsageAndQuotaCallback& callback) OVERRIDE { - callback.Run(quota::kQuotaStatusOk, usage_, quota_); - } - - int storage_modified_count() { return storage_modified_count_; } - int64 usage() { return usage_; } - void set_usage(int64 usage) { usage_ = usage; } - void set_quota(int64 quota) { quota_ = quota; } - - protected: - virtual ~MockQuotaManagerProxy() {} - - private: - int storage_modified_count_; - int64 usage_; - int64 quota_; - - DISALLOW_COPY_AND_ASSIGN(MockQuotaManagerProxy); -}; - -} // namespace - -class QuotaBackendImplTest : public testing::Test { - public: - QuotaBackendImplTest() - : file_system_usage_cache_(file_task_runner()), - quota_manager_proxy_(new MockQuotaManagerProxy) {} - - virtual void SetUp() OVERRIDE { - ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); - file_util_.reset(ObfuscatedFileUtil::CreateForTesting( - NULL, data_dir_.path(), file_task_runner())); - backend_.reset(new QuotaBackendImpl(file_task_runner(), - file_util_.get(), - &file_system_usage_cache_, - quota_manager_proxy_.get())); - } - - virtual void TearDown() OVERRIDE { - backend_.reset(); - quota_manager_proxy_ = NULL; - file_util_.reset(); - message_loop_.RunUntilIdle(); - } - - protected: - void InitializeForOriginAndType(const GURL& origin, FileSystemType type) { - file_util_->InitOriginDatabase(origin, true /* create */); - ASSERT_TRUE(file_util_->origin_database_ != NULL); - - std::string type_string = - SandboxFileSystemBackendDelegate::GetTypeString(type); - base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; - base::FilePath path = file_util_->GetDirectoryForOriginAndType( - origin, type_string, true /* create */, &error); - ASSERT_EQ(base::PLATFORM_FILE_OK, error); - file_system_usage_cache_.UpdateUsage(GetUsageCachePath(origin, type), 0); - } - - base::SequencedTaskRunner* file_task_runner() { - return base::MessageLoopProxy::current().get(); - } - - base::FilePath GetUsageCachePath(const GURL& origin, FileSystemType type) { - base::FilePath path; - DCHECK_EQ(base::PLATFORM_FILE_OK, - backend_->GetUsageCachePath(origin, type, &path)); - DCHECK(!path.empty()); - return path; - } - - base::MessageLoop message_loop_; - base::ScopedTempDir data_dir_; - scoped_ptr<ObfuscatedFileUtil> file_util_; - FileSystemUsageCache file_system_usage_cache_; - scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; - scoped_ptr<QuotaBackendImpl> backend_; - - private: - DISALLOW_COPY_AND_ASSIGN(QuotaBackendImplTest); -}; - -TEST_F(QuotaBackendImplTest, ReserveQuota_Basic) { - FileSystemType type = fileapi::kFileSystemTypeTemporary; - InitializeForOriginAndType(GURL(kOrigin), type); - quota_manager_proxy_->set_quota(10000); - - const int64 kDelta1 = 1000; - base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; - backend_->ReserveQuota(GURL(kOrigin), type, kDelta1, - base::Bind(&DidReserveQuota, true, &error)); - EXPECT_EQ(base::PLATFORM_FILE_OK, error); - EXPECT_EQ(kDelta1, quota_manager_proxy_->usage()); - - const int64 kDelta2 = -300; - error = base::PLATFORM_FILE_ERROR_FAILED; - backend_->ReserveQuota(GURL(kOrigin), type, kDelta2, - base::Bind(&DidReserveQuota, true, &error)); - EXPECT_EQ(base::PLATFORM_FILE_OK, error); - EXPECT_EQ(kDelta1 + kDelta2, quota_manager_proxy_->usage()); - - EXPECT_EQ(2, quota_manager_proxy_->storage_modified_count()); -} - -TEST_F(QuotaBackendImplTest, ReserveQuota_NoSpace) { - FileSystemType type = fileapi::kFileSystemTypeTemporary; - InitializeForOriginAndType(GURL(kOrigin), type); - quota_manager_proxy_->set_quota(100); - - const int64 kDelta = 1000; - base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; - backend_->ReserveQuota(GURL(kOrigin), type, kDelta, - base::Bind(&DidReserveQuota, true, &error)); - EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, error); - EXPECT_EQ(0, quota_manager_proxy_->usage()); - - EXPECT_EQ(0, quota_manager_proxy_->storage_modified_count()); -} - -TEST_F(QuotaBackendImplTest, ReserveQuota_Revert) { - FileSystemType type = fileapi::kFileSystemTypeTemporary; - InitializeForOriginAndType(GURL(kOrigin), type); - quota_manager_proxy_->set_quota(10000); - - const int64 kDelta = 1000; - base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; - backend_->ReserveQuota(GURL(kOrigin), type, kDelta, - base::Bind(&DidReserveQuota, false, &error)); - EXPECT_EQ(base::PLATFORM_FILE_OK, error); - EXPECT_EQ(0, quota_manager_proxy_->usage()); - - EXPECT_EQ(2, quota_manager_proxy_->storage_modified_count()); -} - -TEST_F(QuotaBackendImplTest, ReleaseReservedQuota) { - FileSystemType type = fileapi::kFileSystemTypeTemporary; - InitializeForOriginAndType(GURL(kOrigin), type); - const int64 kInitialUsage = 2000; - quota_manager_proxy_->set_usage(kInitialUsage); - quota_manager_proxy_->set_quota(10000); - - const int64 kSize = 1000; - backend_->ReleaseReservedQuota(GURL(kOrigin), type, kSize); - EXPECT_EQ(kInitialUsage - kSize, quota_manager_proxy_->usage()); - - EXPECT_EQ(1, quota_manager_proxy_->storage_modified_count()); -} - -TEST_F(QuotaBackendImplTest, CommitQuotaUsage) { - FileSystemType type = fileapi::kFileSystemTypeTemporary; - InitializeForOriginAndType(GURL(kOrigin), type); - quota_manager_proxy_->set_quota(10000); - base::FilePath path = GetUsageCachePath(GURL(kOrigin), type); - - const int64 kDelta1 = 1000; - backend_->CommitQuotaUsage(GURL(kOrigin), type, kDelta1); - EXPECT_EQ(kDelta1, quota_manager_proxy_->usage()); - int64 usage = 0; - EXPECT_TRUE(file_system_usage_cache_.GetUsage(path, &usage)); - EXPECT_EQ(kDelta1, usage); - - const int64 kDelta2 = -300; - backend_->CommitQuotaUsage(GURL(kOrigin), type, kDelta2); - EXPECT_EQ(kDelta1 + kDelta2, quota_manager_proxy_->usage()); - usage = 0; - EXPECT_TRUE(file_system_usage_cache_.GetUsage(path, &usage)); - EXPECT_EQ(kDelta1 + kDelta2, usage); - - EXPECT_EQ(2, quota_manager_proxy_->storage_modified_count()); -} - -TEST_F(QuotaBackendImplTest, DirtyCount) { - FileSystemType type = fileapi::kFileSystemTypeTemporary; - InitializeForOriginAndType(GURL(kOrigin), type); - base::FilePath path = GetUsageCachePath(GURL(kOrigin), type); - - backend_->IncrementDirtyCount(GURL(kOrigin), type); - uint32 dirty = 0; - ASSERT_TRUE(file_system_usage_cache_.GetDirty(path, &dirty)); - EXPECT_EQ(1u, dirty); - - backend_->DecrementDirtyCount(GURL(kOrigin), type); - ASSERT_TRUE(file_system_usage_cache_.GetDirty(path, &dirty)); - EXPECT_EQ(0u, dirty); -} - -} // namespace fileapi diff --git a/webkit/browser/fileapi/quota/quota_reservation_buffer.cc b/webkit/browser/fileapi/quota/quota_reservation_buffer.cc index 4a4e036..c83073e 100644 --- a/webkit/browser/fileapi/quota/quota_reservation_buffer.cc +++ b/webkit/browser/fileapi/quota/quota_reservation_buffer.cc @@ -26,7 +26,7 @@ QuotaReservationBuffer::QuotaReservationBuffer( type_(type), reserved_quota_(0) { DCHECK(sequence_checker_.CalledOnValidSequencedThread()); - reservation_manager_->IncrementDirtyCount(origin, type); + reservation_manager_->IncreaseDirtyCount(origin, type); } scoped_refptr<QuotaReservation> QuotaReservationBuffer::CreateReservation() { @@ -49,7 +49,10 @@ void QuotaReservationBuffer::CommitFileGrowth(int64 quota_consumption, DCHECK(sequence_checker_.CalledOnValidSequencedThread()); if (!reservation_manager_) return; - reservation_manager_->CommitQuotaUsage(origin_, type_, usage_delta); + + reservation_manager_->CommitQuotaUsage( + origin_, type_, usage_delta, + base::Bind(&IgnoreResult)); DCHECK_LE(quota_consumption, reserved_quota_); if (quota_consumption > 0) { @@ -81,20 +84,20 @@ QuotaReservationBuffer::~QuotaReservationBuffer() { if (reserved_quota_ && reservation_manager_) { reservation_manager_->ReserveQuota( origin_, type_, -reserved_quota_, - base::Bind(&QuotaReservationBuffer::DecrementDirtyCount, + base::Bind(&QuotaReservationBuffer::DecreaseDirtyCount, reservation_manager_, origin_, type_)); } reservation_manager_->ReleaseReservationBuffer(this); } // static -bool QuotaReservationBuffer::DecrementDirtyCount( +bool QuotaReservationBuffer::DecreaseDirtyCount( base::WeakPtr<QuotaReservationManager> reservation_manager, const GURL& origin, FileSystemType type, base::PlatformFileError error) { if (error == base::PLATFORM_FILE_OK && reservation_manager) { - reservation_manager->DecrementDirtyCount(origin, type); + reservation_manager->DecreaseDirtyCount(origin, type); return true; } return false; diff --git a/webkit/browser/fileapi/quota/quota_reservation_buffer.h b/webkit/browser/fileapi/quota/quota_reservation_buffer.h index 9a11fa5..1b27529 100644 --- a/webkit/browser/fileapi/quota/quota_reservation_buffer.h +++ b/webkit/browser/fileapi/quota/quota_reservation_buffer.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef WEBKIT_BROWSER_FILEAPI_QUOTA_QUOTA_RESERVATION_BUFFER_H_ -#define WEBKIT_BROWSER_FILEAPI_QUOTA_QUOTA_RESERVATION_BUFFER_H_ +#ifndef WEBKIT_BROWSER_FILEAPI_QUOTA_RESERVATION_BUFFER_H_ +#define WEBKIT_BROWSER_FILEAPI_QUOTA_RESERVATION_BUFFER_H_ #include <map> @@ -56,7 +56,7 @@ class QuotaReservationBuffer : public base::RefCounted<QuotaReservationBuffer> { friend class base::RefCounted<QuotaReservationBuffer>; virtual ~QuotaReservationBuffer(); - static bool DecrementDirtyCount( + static bool DecreaseDirtyCount( base::WeakPtr<QuotaReservationManager> reservation_manager, const GURL& origin, FileSystemType type, @@ -83,4 +83,4 @@ class QuotaReservationBuffer : public base::RefCounted<QuotaReservationBuffer> { } // namespace fileapi -#endif // WEBKIT_BROWSER_FILEAPI_QUOTA_QUOTA_RESERVATION_BUFFER_H_ +#endif // WEBKIT_BROWSER_FILEAPI_QUOTA_RESERVATION_BUFFER_H_ diff --git a/webkit/browser/fileapi/quota/quota_reservation_manager.cc b/webkit/browser/fileapi/quota/quota_reservation_manager.cc index 7968b1f..0a02940 100644 --- a/webkit/browser/fileapi/quota/quota_reservation_manager.cc +++ b/webkit/browser/fileapi/quota/quota_reservation_manager.cc @@ -9,9 +9,8 @@ namespace fileapi { -QuotaReservationManager::QuotaReservationManager( - scoped_ptr<QuotaBackend> backend) - : backend_(backend.Pass()), +QuotaReservationManager::QuotaReservationManager(QuotaBackend* backend) + : backend_(backend), weak_ptr_factory_(this) { DCHECK(sequence_checker_.CalledOnValidSequencedThread()); } @@ -38,18 +37,19 @@ void QuotaReservationManager::ReleaseReservedQuota( void QuotaReservationManager::CommitQuotaUsage( const GURL& origin, FileSystemType type, - int64 delta) { - backend_->CommitQuotaUsage(origin, type, delta); + int64 delta, + const StatusCallback& callback) { + backend_->CommitQuotaUsage(origin, type, delta, callback); } -void QuotaReservationManager::IncrementDirtyCount(const GURL& origin, +void QuotaReservationManager::IncreaseDirtyCount(const GURL& origin, FileSystemType type) { - backend_->IncrementDirtyCount(origin, type); + backend_->IncreaseDirtyCount(origin, type); } -void QuotaReservationManager::DecrementDirtyCount(const GURL& origin, +void QuotaReservationManager::DecreaseDirtyCount(const GURL& origin, FileSystemType type) { - backend_->DecrementDirtyCount(origin, type); + backend_->DecreaseDirtyCount(origin, type); } scoped_refptr<QuotaReservationBuffer> diff --git a/webkit/browser/fileapi/quota/quota_reservation_manager.h b/webkit/browser/fileapi/quota/quota_reservation_manager.h index 07beacc..2e3ae93 100644 --- a/webkit/browser/fileapi/quota/quota_reservation_manager.h +++ b/webkit/browser/fileapi/quota/quota_reservation_manager.h @@ -6,7 +6,6 @@ #define WEBKIT_BROWSER_FILEAPI_QUOTA_QUOTA_RESERVATION_MANAGER_H_ #include <map> -#include <utility> #include "base/basictypes.h" #include "base/callback_forward.h" @@ -26,17 +25,13 @@ class OpenFileHandleContext; class WEBKIT_STORAGE_BROWSER_EXPORT QuotaReservationManager { public: - // Callback for ReserveQuota. When this callback returns false, ReserveQuota - // operation should be reverted. + typedef base::Callback<void(base::PlatformFileError error)> StatusCallback; typedef base::Callback<bool(base::PlatformFileError error)> ReserveQuotaCallback; // An abstraction of backing quota system. - class WEBKIT_STORAGE_BROWSER_EXPORT QuotaBackend { + class QuotaBackend { public: - QuotaBackend() {} - virtual ~QuotaBackend() {} - // Reserves or reclaims |delta| of quota for |origin| and |type| pair. // Reserved quota should be counted as usage, but it should be on-memory // and be cleared by a browser restart. @@ -57,18 +52,23 @@ class WEBKIT_STORAGE_BROWSER_EXPORT QuotaReservationManager { // Invokes |callback| upon completion with an error code. virtual void CommitQuotaUsage(const GURL& origin, FileSystemType type, - int64 delta) = 0; + int64 delta, + const StatusCallback& callback) = 0; - virtual void IncrementDirtyCount(const GURL& origin, + virtual void IncreaseDirtyCount(const GURL& origin, FileSystemType type) = 0; - virtual void DecrementDirtyCount(const GURL& origin, + virtual void DecreaseDirtyCount(const GURL& origin, FileSystemType type) = 0; + protected: + QuotaBackend() {} + virtual ~QuotaBackend() {} + private: DISALLOW_COPY_AND_ASSIGN(QuotaBackend); }; - explicit QuotaReservationManager(scoped_ptr<QuotaBackend> backend); + explicit QuotaReservationManager(QuotaBackend* backend); ~QuotaReservationManager(); // The entry point of the quota reservation. Creates new reservation object @@ -83,7 +83,6 @@ class WEBKIT_STORAGE_BROWSER_EXPORT QuotaReservationManager { friend class QuotaReservation; friend class QuotaReservationBuffer; - friend class QuotaReservationManagerTest; void ReserveQuota(const GURL& origin, FileSystemType type, @@ -96,17 +95,20 @@ class WEBKIT_STORAGE_BROWSER_EXPORT QuotaReservationManager { void CommitQuotaUsage(const GURL& origin, FileSystemType type, - int64 delta); + int64 delta, + const StatusCallback& callback); - void IncrementDirtyCount(const GURL& origin, FileSystemType type); - void DecrementDirtyCount(const GURL& origin, FileSystemType type); + void IncreaseDirtyCount(const GURL& origin, FileSystemType type); + void DecreaseDirtyCount(const GURL& origin, FileSystemType type); scoped_refptr<QuotaReservationBuffer> GetReservationBuffer( const GURL& origin, FileSystemType type); void ReleaseReservationBuffer(QuotaReservationBuffer* reservation_pool); - scoped_ptr<QuotaBackend> backend_; + + // Not owned. |backend_| should outlive QuotaReservationManager + QuotaBackend* backend_; // Not owned. The destructor of ReservationBuffer should erase itself from // |reservation_buffers_| by calling ReleaseReservationBuffer. diff --git a/webkit/browser/fileapi/quota/quota_reservation_manager_unittest.cc b/webkit/browser/fileapi/quota/quota_reservation_manager_unittest.cc index d9a521d..86590c7a 100644 --- a/webkit/browser/fileapi/quota/quota_reservation_manager_unittest.cc +++ b/webkit/browser/fileapi/quota/quota_reservation_manager_unittest.cc @@ -23,6 +23,7 @@ const FileSystemType kType = kFileSystemTypeTemporary; const int64 kInitialFileSize = 30; typedef QuotaReservationManager::ReserveQuotaCallback ReserveQuotaCallback; +typedef QuotaReservationManager::StatusCallback StatusCallback; class FakeBackend : public QuotaReservationManager::QuotaBackend { public: @@ -54,16 +55,19 @@ class FakeBackend : public QuotaReservationManager::QuotaBackend { virtual void CommitQuotaUsage(const GURL& origin, FileSystemType type, - int64 delta) OVERRIDE { + int64 delta, + const StatusCallback& callback) OVERRIDE { EXPECT_EQ(GURL(kOrigin), origin); EXPECT_EQ(kType, type); on_disk_usage_ += delta; + base::MessageLoopProxy::current()->PostTask( + FROM_HERE, base::Bind(callback, base::PLATFORM_FILE_OK)); } - virtual void IncrementDirtyCount(const GURL& origin, - FileSystemType type) OVERRIDE {} - virtual void DecrementDirtyCount(const GURL& origin, - FileSystemType type) OVERRIDE {} + virtual void IncreaseDirtyCount(const GURL& origin, + FileSystemType type) OVERRIDE {} + virtual void DecreaseDirtyCount(const GURL& origin, + FileSystemType type) OVERRIDE {} int64 on_memory_usage() { return on_memory_usage_; } int64 on_disk_usage() { return on_disk_usage_; } @@ -102,12 +106,14 @@ class QuotaReservationManagerTest : public testing::Test { file_path_ = work_dir_.path().Append(FILE_PATH_LITERAL("hoge")); SetFileSize(kInitialFileSize); - scoped_ptr<QuotaReservationManager::QuotaBackend> backend(new FakeBackend); - reservation_manager_.reset(new QuotaReservationManager(backend.Pass())); + fake_backend_.reset(new FakeBackend); + reservation_manager_.reset(new QuotaReservationManager( + fake_backend_.get())); } virtual void TearDown() OVERRIDE { reservation_manager_.reset(); + fake_backend_.reset(); } int64 GetFileSize() { @@ -134,7 +140,7 @@ class QuotaReservationManagerTest : public testing::Test { } FakeBackend* fake_backend() { - return static_cast<FakeBackend*>(reservation_manager_->backend_.get()); + return fake_backend_.get(); } QuotaReservationManager* reservation_manager() { @@ -149,6 +155,7 @@ class QuotaReservationManagerTest : public testing::Test { base::MessageLoop message_loop_; base::ScopedTempDir work_dir_; base::FilePath file_path_; + scoped_ptr<FakeBackend> fake_backend_; scoped_ptr<QuotaReservationManager> reservation_manager_; DISALLOW_COPY_AND_ASSIGN(QuotaReservationManagerTest); diff --git a/webkit/browser/fileapi/sandbox_file_system_backend_delegate.h b/webkit/browser/fileapi/sandbox_file_system_backend_delegate.h index 962797c..c011a48 100644 --- a/webkit/browser/fileapi/sandbox_file_system_backend_delegate.h +++ b/webkit/browser/fileapi/sandbox_file_system_backend_delegate.h @@ -187,7 +187,6 @@ class WEBKIT_STORAGE_BROWSER_EXPORT SandboxFileSystemBackendDelegate private: friend class SandboxQuotaObserver; friend class SandboxFileSystemTestHelper; - friend class QuotaBackendImpl; FRIEND_TEST_ALL_PREFIXES(SandboxFileSystemBackendDelegateTest, IsAccessValid); // Performs API-specific validity checks on the given path |url|. diff --git a/webkit/storage_browser.gyp b/webkit/storage_browser.gyp index c474c56..9a71f1a 100644 --- a/webkit/storage_browser.gyp +++ b/webkit/storage_browser.gyp @@ -156,8 +156,6 @@ 'browser/fileapi/quota/open_file_handle.h', 'browser/fileapi/quota/open_file_handle_context.cc', 'browser/fileapi/quota/open_file_handle_context.h', - 'browser/fileapi/quota/quota_backend_impl.cc', - 'browser/fileapi/quota/quota_backend_impl.h', 'browser/fileapi/quota/quota_reservation.cc', 'browser/fileapi/quota/quota_reservation.h', 'browser/fileapi/quota/quota_reservation_buffer.cc', |