diff options
author | nhiroki@chromium.org <nhiroki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-12 18:09:07 +0000 |
---|---|---|
committer | nhiroki@chromium.org <nhiroki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-12 18:09:07 +0000 |
commit | 6372a7046bf3e4f44bf2d9c863db3f1d6535d6b6 (patch) | |
tree | 7d238bea3a46019645fab0ccbc62bb96af7fe23a | |
parent | 541123e2fa2540f4447a4c32076c71edc3a3ff93 (diff) | |
download | chromium_src-6372a7046bf3e4f44bf2d9c863db3f1d6535d6b6.zip chromium_src-6372a7046bf3e4f44bf2d9c863db3f1d6535d6b6.tar.gz chromium_src-6372a7046bf3e4f44bf2d9c863db3f1d6535d6b6.tar.bz2 |
Quota: Wire up between QuotaReservationManager and FileSystemContext
This change includes:
- Wiring up between QuotaReservationManager and FileSystemContext
- Adding a new interface into FileSystemQuotaUtil
- Exposing FileSystemContext::CreateQuotaReservationOnFileTaskRunner
as an entry point of the quota reservation.
BUG=303443
TEST=n/a
Review URL: https://codereview.chromium.org/66173003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@234559 0039d316-1c4b-4281-b951-d872f2087c98
10 files changed, 86 insertions, 3 deletions
diff --git a/content/public/test/test_file_system_backend.cc b/content/public/test/test_file_system_backend.cc index 6a38fc6..bdc63b2 100644 --- a/content/public/test/test_file_system_backend.cc +++ b/content/public/test/test_file_system_backend.cc @@ -18,6 +18,7 @@ #include "webkit/browser/fileapi/file_system_quota_util.h" #include "webkit/browser/fileapi/local_file_util.h" #include "webkit/browser/fileapi/native_file_util.h" +#include "webkit/browser/fileapi/quota/quota_reservation.h" #include "webkit/browser/fileapi/sandbox_file_stream_writer.h" #include "webkit/browser/quota/quota_manager.h" #include "webkit/common/fileapi/file_system_util.h" @@ -52,7 +53,7 @@ class TestFileSystemBackend::QuotaUtil : public FileSystemQuotaUtil, public FileUpdateObserver { public: - QuotaUtil(base::SequencedTaskRunner* task_runner) + explicit QuotaUtil(base::SequencedTaskRunner* task_runner) : usage_(0), task_runner_(task_runner) { update_observers_ = update_observers_.AddObserver(this, task_runner_.get()); @@ -69,6 +70,14 @@ class TestFileSystemBackend::QuotaUtil return base::PLATFORM_FILE_OK; } + virtual scoped_refptr<QuotaReservation> + CreateQuotaReservationOnFileTaskRunner( + const GURL& origin_url, + FileSystemType type) OVERRIDE { + NOTREACHED(); + return scoped_refptr<QuotaReservation>(); + } + virtual void GetOriginsForTypeOnFileThread( FileSystemType type, std::set<GURL>* origins) OVERRIDE { diff --git a/webkit/browser/fileapi/file_system_context.cc b/webkit/browser/fileapi/file_system_context.cc index 14072ecb..fd6ae4d 100644 --- a/webkit/browser/fileapi/file_system_context.cc +++ b/webkit/browser/fileapi/file_system_context.cc @@ -23,6 +23,7 @@ #include "webkit/browser/fileapi/isolated_context.h" #include "webkit/browser/fileapi/isolated_file_system_backend.h" #include "webkit/browser/fileapi/mount_points.h" +#include "webkit/browser/fileapi/quota/quota_reservation.h" #include "webkit/browser/fileapi/sandbox_file_system_backend.h" #include "webkit/browser/quota/quota_manager.h" #include "webkit/browser/quota/special_storage_policy.h" @@ -191,6 +192,18 @@ bool FileSystemContext::DeleteDataForOriginOnFileThread( return success; } +scoped_refptr<QuotaReservation> +FileSystemContext::CreateQuotaReservationOnFileTaskRunner( + const GURL& origin_url, + FileSystemType type) { + DCHECK(default_file_task_runner()->RunsTasksOnCurrentThread()); + FileSystemBackend* backend = GetFileSystemBackend(type); + if (!backend || !backend->GetQuotaUtil()) + return scoped_refptr<QuotaReservation>(); + return backend->GetQuotaUtil()->CreateQuotaReservationOnFileTaskRunner( + origin_url, type); +} + void FileSystemContext::Shutdown() { if (!io_task_runner_->RunsTasksOnCurrentThread()) { io_task_runner_->PostTask( diff --git a/webkit/browser/fileapi/file_system_context.h b/webkit/browser/fileapi/file_system_context.h index 7d781ed..745bdae 100644 --- a/webkit/browser/fileapi/file_system_context.h +++ b/webkit/browser/fileapi/file_system_context.h @@ -59,6 +59,7 @@ class FileSystemQuotaUtil; class FileSystemURL; class IsolatedFileSystemBackend; class MountPoints; +class QuotaReservation; class SandboxFileSystemBackend; struct DefaultContextDeleter; @@ -104,8 +105,18 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemContext const base::FilePath& partition_path, const FileSystemOptions& options); + // TODO(nhiroki): Rename *OnFileThread methods since these are no longer on + // FILE thread. bool DeleteDataForOriginOnFileThread(const GURL& origin_url); + // Creates a new QuotaReservation for the given |origin_url| and |type|. + // Returns NULL if |type| does not support quota or reservation fails. + // This should be run on |default_file_task_runner_| and the returned value + // should be destroyed on the runner. + scoped_refptr<QuotaReservation> CreateQuotaReservationOnFileTaskRunner( + const GURL& origin_url, + FileSystemType type); + quota::QuotaManagerProxy* quota_manager_proxy() const { return quota_manager_proxy_.get(); } diff --git a/webkit/browser/fileapi/file_system_quota_util.h b/webkit/browser/fileapi/file_system_quota_util.h index 5f3c7dd..e393086 100644 --- a/webkit/browser/fileapi/file_system_quota_util.h +++ b/webkit/browser/fileapi/file_system_quota_util.h @@ -26,6 +26,7 @@ class QuotaManagerProxy; namespace fileapi { class FileSystemContext; +class QuotaReservation; // An abstract interface that provides common quota-related utility functions // for file_system_quota_client. @@ -56,6 +57,12 @@ class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemQuotaUtil { const GURL& origin_url, fileapi::FileSystemType type) = 0; + // Creates new reservation object for the origin and the type. + virtual scoped_refptr<QuotaReservation> + CreateQuotaReservationOnFileTaskRunner( + const GURL& origin_url, + FileSystemType type) = 0; + virtual void AddFileUpdateObserver( FileSystemType type, FileUpdateObserver* observer, diff --git a/webkit/browser/fileapi/plugin_private_file_system_backend.cc b/webkit/browser/fileapi/plugin_private_file_system_backend.cc index 244aac4..e701ce9 100644 --- a/webkit/browser/fileapi/plugin_private_file_system_backend.cc +++ b/webkit/browser/fileapi/plugin_private_file_system_backend.cc @@ -19,13 +19,14 @@ #include "webkit/browser/fileapi/file_system_options.h" #include "webkit/browser/fileapi/isolated_context.h" #include "webkit/browser/fileapi/obfuscated_file_util.h" +#include "webkit/browser/fileapi/quota/quota_reservation.h" #include "webkit/common/fileapi/file_system_util.h" namespace fileapi { class PluginPrivateFileSystemBackend::FileSystemIDToPluginMap { public: - FileSystemIDToPluginMap(base::SequencedTaskRunner* task_runner) + explicit FileSystemIDToPluginMap(base::SequencedTaskRunner* task_runner) : task_runner_(task_runner) {} ~FileSystemIDToPluginMap() {} @@ -260,6 +261,15 @@ int64 PluginPrivateFileSystemBackend::GetOriginUsageOnFileThread( return 0; } +scoped_refptr<QuotaReservation> +PluginPrivateFileSystemBackend::CreateQuotaReservationOnFileTaskRunner( + const GURL& origin_url, + FileSystemType type) { + // We don't track usage on this filesystem. + NOTREACHED(); + return scoped_refptr<QuotaReservation>(); +} + void PluginPrivateFileSystemBackend::AddFileUpdateObserver( FileSystemType type, FileUpdateObserver* observer, diff --git a/webkit/browser/fileapi/plugin_private_file_system_backend.h b/webkit/browser/fileapi/plugin_private_file_system_backend.h index a12e4c3..69d61c2 100644 --- a/webkit/browser/fileapi/plugin_private_file_system_backend.h +++ b/webkit/browser/fileapi/plugin_private_file_system_backend.h @@ -100,6 +100,10 @@ class WEBKIT_STORAGE_BROWSER_EXPORT PluginPrivateFileSystemBackend FileSystemContext* context, const GURL& origin_url, FileSystemType type) OVERRIDE; + virtual scoped_refptr<QuotaReservation> + CreateQuotaReservationOnFileTaskRunner( + const GURL& origin_url, + FileSystemType type) OVERRIDE; virtual void AddFileUpdateObserver( FileSystemType type, FileUpdateObserver* observer, diff --git a/webkit/browser/fileapi/quota/quota_backend_impl_unittest.cc b/webkit/browser/fileapi/quota/quota_backend_impl_unittest.cc index 0dca1c2..75e8db8 100644 --- a/webkit/browser/fileapi/quota/quota_backend_impl_unittest.cc +++ b/webkit/browser/fileapi/quota/quota_backend_impl_unittest.cc @@ -4,6 +4,8 @@ #include "webkit/browser/fileapi/quota/quota_backend_impl.h" +#include <string> + #include "base/files/scoped_temp_dir.h" #include "base/message_loop/message_loop.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/webkit/browser/fileapi/quota/quota_reservation_manager.cc b/webkit/browser/fileapi/quota/quota_reservation_manager.cc index 7968b1f..93e6d33 100644 --- a/webkit/browser/fileapi/quota/quota_reservation_manager.cc +++ b/webkit/browser/fileapi/quota/quota_reservation_manager.cc @@ -13,7 +13,7 @@ QuotaReservationManager::QuotaReservationManager( scoped_ptr<QuotaBackend> backend) : backend_(backend.Pass()), weak_ptr_factory_(this) { - DCHECK(sequence_checker_.CalledOnValidSequencedThread()); + sequence_checker_.DetachFromSequence(); } QuotaReservationManager::~QuotaReservationManager() { diff --git a/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc b/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc index 593e1a0..bb4d48e 100644 --- a/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc +++ b/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc @@ -4,6 +4,8 @@ #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" +#include <vector> + #include "base/command_line.h" #include "base/file_util.h" #include "base/metrics/histogram.h" @@ -17,6 +19,9 @@ #include "webkit/browser/fileapi/file_system_url.h" #include "webkit/browser/fileapi/file_system_usage_cache.h" #include "webkit/browser/fileapi/obfuscated_file_util.h" +#include "webkit/browser/fileapi/quota/quota_backend_impl.h" +#include "webkit/browser/fileapi/quota/quota_reservation.h" +#include "webkit/browser/fileapi/quota/quota_reservation_manager.h" #include "webkit/browser/fileapi/sandbox_file_stream_writer.h" #include "webkit/browser/fileapi/sandbox_file_system_backend.h" #include "webkit/browser/fileapi/sandbox_quota_observer.h" @@ -185,6 +190,12 @@ SandboxFileSystemBackendDelegate::SandboxFileSystemBackendDelegate( file_task_runner, obfuscated_file_util(), usage_cache())), + quota_reservation_manager_(new QuotaReservationManager( + scoped_ptr<QuotaReservationManager::QuotaBackend>( + new QuotaBackendImpl(file_task_runner_, + obfuscated_file_util(), + usage_cache(), + quota_manager_proxy)))), special_storage_policy_(special_storage_policy), file_system_options_(file_system_options), is_filesystem_opened_(false), @@ -208,6 +219,7 @@ SandboxFileSystemBackendDelegate::~SandboxFileSystemBackendDelegate() { io_thread_checker_.DetachFromThread(); if (!file_task_runner_->RunsTasksOnCurrentThread()) { + DeleteSoon(file_task_runner_.get(), quota_reservation_manager_.release()); DeleteSoon(file_task_runner_.get(), sandbox_file_util_.release()); DeleteSoon(file_task_runner_.get(), quota_observer_.release()); DeleteSoon(file_task_runner_.get(), file_system_usage_cache_.release()); @@ -406,6 +418,15 @@ int64 SandboxFileSystemBackendDelegate::GetOriginUsageOnFileThread( return usage; } +scoped_refptr<QuotaReservation> +SandboxFileSystemBackendDelegate::CreateQuotaReservationOnFileTaskRunner( + const GURL& origin, + FileSystemType type) { + DCHECK(file_task_runner_->RunsTasksOnCurrentThread()); + DCHECK(quota_reservation_manager_); + return quota_reservation_manager_->CreateReservation(origin, type); +} + void SandboxFileSystemBackendDelegate::AddFileUpdateObserver( FileSystemType type, FileUpdateObserver* observer, diff --git a/webkit/browser/fileapi/sandbox_file_system_backend_delegate.h b/webkit/browser/fileapi/sandbox_file_system_backend_delegate.h index 962797c..dd5e11f 100644 --- a/webkit/browser/fileapi/sandbox_file_system_backend_delegate.h +++ b/webkit/browser/fileapi/sandbox_file_system_backend_delegate.h @@ -44,6 +44,7 @@ class FileSystemOperationContext; class FileSystemURL; class FileSystemUsageCache; class ObfuscatedFileUtil; +class QuotaReservationManager; class SandboxFileSystemBackend; class SandboxFileSystemTestHelper; class SandboxQuotaObserver; @@ -137,6 +138,10 @@ class WEBKIT_STORAGE_BROWSER_EXPORT SandboxFileSystemBackendDelegate FileSystemContext* context, const GURL& origin_url, FileSystemType type) OVERRIDE; + virtual scoped_refptr<QuotaReservation> + CreateQuotaReservationOnFileTaskRunner( + const GURL& origin_url, + FileSystemType type) OVERRIDE; virtual void AddFileUpdateObserver( FileSystemType type, FileUpdateObserver* observer, @@ -221,6 +226,7 @@ class WEBKIT_STORAGE_BROWSER_EXPORT SandboxFileSystemBackendDelegate scoped_ptr<AsyncFileUtil> sandbox_file_util_; scoped_ptr<FileSystemUsageCache> file_system_usage_cache_; scoped_ptr<SandboxQuotaObserver> quota_observer_; + scoped_ptr<QuotaReservationManager> quota_reservation_manager_; scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; |