diff options
author | nhiroki@chromium.org <nhiroki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-17 16:59:45 +0000 |
---|---|---|
committer | nhiroki@chromium.org <nhiroki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-17 16:59:45 +0000 |
commit | 844a7f8f28c3806bf6c9aa5bc774ef8d5503d4f1 (patch) | |
tree | 6243cdcbd546456d9e5d9318a9983c022094a7f1 | |
parent | 29bb23a3e05e2456b514b8c38c8efd89b4351234 (diff) | |
download | chromium_src-844a7f8f28c3806bf6c9aa5bc774ef8d5503d4f1.zip chromium_src-844a7f8f28c3806bf6c9aa5bc774ef8d5503d4f1.tar.gz chromium_src-844a7f8f28c3806bf6c9aa5bc774ef8d5503d4f1.tar.bz2 |
Quota: Factor out (Mock)QuotaManagerProxy into its own file for readability
BUG=n/a
TEST=compile (mechanical changes only)
TBR=michaeln@chromium.orgjochen@chromium.org
Review URL: https://codereview.chromium.org/136573007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245533 0039d316-1c4b-4281-b951-d872f2087c98
37 files changed, 419 insertions, 326 deletions
diff --git a/chrome/browser/browsing_data/browsing_data_quota_helper_unittest.cc b/chrome/browser/browsing_data/browsing_data_quota_helper_unittest.cc index 5d06580..8b652f2 100644 --- a/chrome/browser/browsing_data/browsing_data_quota_helper_unittest.cc +++ b/chrome/browser/browsing_data/browsing_data_quota_helper_unittest.cc @@ -14,6 +14,7 @@ #include "content/public/test/test_browser_thread_bundle.h" #include "webkit/browser/quota/mock_storage_client.h" #include "webkit/browser/quota/quota_manager.h" +#include "webkit/browser/quota/quota_manager_proxy.h" using content::BrowserThread; diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 9b55fe8..394b32c 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -280,6 +280,8 @@ '../ui/gfx/image/image_unittest_util.h', '../webkit/browser/quota/mock_quota_manager.cc', '../webkit/browser/quota/mock_quota_manager.h', + '../webkit/browser/quota/mock_quota_manager_proxy.cc', + '../webkit/browser/quota/mock_quota_manager_proxy.h', '../webkit/browser/quota/mock_special_storage_policy.cc', '../webkit/browser/quota/mock_special_storage_policy.h', ], diff --git a/content/browser/fileapi/copy_or_move_operation_delegate_unittest.cc b/content/browser/fileapi/copy_or_move_operation_delegate_unittest.cc index 0bed27f..a1501964 100644 --- a/content/browser/fileapi/copy_or_move_operation_delegate_unittest.cc +++ b/content/browser/fileapi/copy_or_move_operation_delegate_unittest.cc @@ -26,6 +26,7 @@ #include "webkit/browser/fileapi/file_system_url.h" #include "webkit/browser/fileapi/test_file_set.h" #include "webkit/browser/quota/mock_quota_manager.h" +#include "webkit/browser/quota/mock_quota_manager_proxy.h" #include "webkit/browser/quota/quota_manager.h" #include "webkit/common/fileapi/file_system_util.h" diff --git a/content/browser/fileapi/file_system_operation_impl_unittest.cc b/content/browser/fileapi/file_system_operation_impl_unittest.cc index b7e92ffb..e084947 100644 --- a/content/browser/fileapi/file_system_operation_impl_unittest.cc +++ b/content/browser/fileapi/file_system_operation_impl_unittest.cc @@ -23,7 +23,9 @@ #include "webkit/browser/fileapi/mock_file_change_observer.h" #include "webkit/browser/fileapi/sandbox_file_system_backend.h" #include "webkit/browser/quota/mock_quota_manager.h" +#include "webkit/browser/quota/mock_quota_manager_proxy.h" #include "webkit/browser/quota/quota_manager.h" +#include "webkit/browser/quota/quota_manager_proxy.h" #include "webkit/common/blob/shareable_file_reference.h" #include "webkit/common/fileapi/file_system_util.h" diff --git a/content/browser/indexed_db/indexed_db_context_impl.cc b/content/browser/indexed_db/indexed_db_context_impl.cc index df99bf4..af84c29 100644 --- a/content/browser/indexed_db/indexed_db_context_impl.cc +++ b/content/browser/indexed_db/indexed_db_context_impl.cc @@ -30,7 +30,7 @@ #include "content/public/common/content_switches.h" #include "ui/base/text/bytes_formatting.h" #include "webkit/browser/database/database_util.h" -#include "webkit/browser/quota/quota_manager.h" +#include "webkit/browser/quota/quota_manager_proxy.h" #include "webkit/browser/quota/special_storage_policy.h" #include "webkit/common/database/database_identifier.h" diff --git a/content/browser/renderer_host/database_message_filter.cc b/content/browser/renderer_host/database_message_filter.cc index 4cb73a4..261019d 100644 --- a/content/browser/renderer_host/database_message_filter.cc +++ b/content/browser/renderer_host/database_message_filter.cc @@ -18,6 +18,7 @@ #include "webkit/browser/database/database_util.h" #include "webkit/browser/database/vfs_backend.h" #include "webkit/browser/quota/quota_manager.h" +#include "webkit/browser/quota/quota_manager_proxy.h" #include "webkit/common/database/database_identifier.h" #if defined(OS_POSIX) @@ -25,7 +26,6 @@ #endif using quota::QuotaManager; -using quota::QuotaManagerProxy; using quota::QuotaStatusCode; using webkit_database::DatabaseTracker; using webkit_database::DatabaseUtil; diff --git a/content/browser/renderer_host/pepper/pepper_file_system_browser_host.cc b/content/browser/renderer_host/pepper/pepper_file_system_browser_host.cc index c7f742f..3e63a23 100644 --- a/content/browser/renderer_host/pepper/pepper_file_system_browser_host.cc +++ b/content/browser/renderer_host/pepper/pepper_file_system_browser_host.cc @@ -23,7 +23,7 @@ #include "ppapi/shared_impl/file_type_conversion.h" #include "webkit/browser/fileapi/file_system_operation_runner.h" #include "webkit/browser/fileapi/isolated_context.h" -#include "webkit/browser/quota/quota_manager.h" +#include "webkit/browser/quota/quota_manager_proxy.h" #include "webkit/common/fileapi/file_system_util.h" #include "webkit/common/quota/quota_types.h" diff --git a/content/browser/service_worker/service_worker_context_wrapper.cc b/content/browser/service_worker/service_worker_context_wrapper.cc index 49a6842..e423d70 100644 --- a/content/browser/service_worker/service_worker_context_wrapper.cc +++ b/content/browser/service_worker/service_worker_context_wrapper.cc @@ -7,7 +7,7 @@ #include "base/files/file_path.h" #include "content/browser/service_worker/service_worker_context_core.h" #include "content/public/browser/browser_thread.h" -#include "webkit/browser/quota/quota_manager.h" +#include "webkit/browser/quota/quota_manager_proxy.h" namespace content { diff --git a/content/browser/service_worker/service_worker_storage.cc b/content/browser/service_worker/service_worker_storage.cc index 1f95cf7..26e1f50 100644 --- a/content/browser/service_worker/service_worker_storage.cc +++ b/content/browser/service_worker/service_worker_storage.cc @@ -9,7 +9,7 @@ #include "base/strings/string_util.h" #include "content/browser/service_worker/service_worker_registration.h" #include "content/public/browser/browser_thread.h" -#include "webkit/browser/quota/quota_manager.h" +#include "webkit/browser/quota/quota_manager_proxy.h" namespace { // This is temporary until we figure out how registration ids will be diff --git a/content/content_tests.gypi b/content/content_tests.gypi index ce170ee..0967d0f 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -624,6 +624,8 @@ '../webkit/common/user_agent/user_agent_unittest.cc', '../webkit/browser/quota/mock_quota_manager.cc', '../webkit/browser/quota/mock_quota_manager.h', + '../webkit/browser/quota/mock_quota_manager_proxy.cc', + '../webkit/browser/quota/mock_quota_manager_proxy.h', '../webkit/browser/quota/mock_quota_manager_unittest.cc', '../webkit/browser/quota/mock_special_storage_policy.cc', '../webkit/browser/quota/mock_special_storage_policy.h', diff --git a/content/public/test/sandbox_file_system_test_helper.cc b/content/public/test/sandbox_file_system_test_helper.cc index 1e294b7..621ee221 100644 --- a/content/public/test/sandbox_file_system_test_helper.cc +++ b/content/public/test/sandbox_file_system_test_helper.cc @@ -17,6 +17,7 @@ #include "webkit/browser/fileapi/file_system_usage_cache.h" #include "webkit/browser/fileapi/sandbox_file_system_backend.h" #include "webkit/browser/quota/mock_special_storage_policy.h" +#include "webkit/browser/quota/quota_manager_proxy.h" #include "webkit/common/fileapi/file_system_util.h" using fileapi::FileSystemContext; diff --git a/webkit/browser/appcache/appcache_host.cc b/webkit/browser/appcache/appcache_host.cc index 0f6523b..a8a86f8 100644 --- a/webkit/browser/appcache/appcache_host.cc +++ b/webkit/browser/appcache/appcache_host.cc @@ -12,7 +12,7 @@ #include "webkit/browser/appcache/appcache_backend_impl.h" #include "webkit/browser/appcache/appcache_policy.h" #include "webkit/browser/appcache/appcache_request_handler.h" -#include "webkit/browser/quota/quota_manager.h" +#include "webkit/browser/quota/quota_manager_proxy.h" namespace appcache { diff --git a/webkit/browser/appcache/appcache_service.cc b/webkit/browser/appcache/appcache_service.cc index c11631c..e951ad0 100644 --- a/webkit/browser/appcache/appcache_service.cc +++ b/webkit/browser/appcache/appcache_service.cc @@ -22,7 +22,6 @@ #include "webkit/browser/appcache/appcache_quota_client.h" #include "webkit/browser/appcache/appcache_response.h" #include "webkit/browser/appcache/appcache_storage_impl.h" -#include "webkit/browser/quota/quota_manager.h" #include "webkit/browser/quota/special_storage_policy.h" namespace appcache { diff --git a/webkit/browser/appcache/appcache_service.h b/webkit/browser/appcache/appcache_service.h index 43e38b4..51647d1 100644 --- a/webkit/browser/appcache/appcache_service.h +++ b/webkit/browser/appcache/appcache_service.h @@ -15,6 +15,7 @@ #include "net/base/completion_callback.h" #include "net/base/net_errors.h" #include "webkit/browser/appcache/appcache_storage.h" +#include "webkit/browser/quota/quota_manager_proxy.h" #include "webkit/browser/webkit_storage_browser_export.h" #include "webkit/common/appcache/appcache_interfaces.h" @@ -28,7 +29,6 @@ class MessageLoopProxy; } namespace quota { -class QuotaManagerProxy; class SpecialStoragePolicy; } diff --git a/webkit/browser/appcache/appcache_storage.cc b/webkit/browser/appcache/appcache_storage.cc index 2482cfa..3f6e09c 100644 --- a/webkit/browser/appcache/appcache_storage.cc +++ b/webkit/browser/appcache/appcache_storage.cc @@ -10,7 +10,7 @@ #include "webkit/browser/appcache/appcache_response.h" #include "webkit/browser/appcache/appcache_service.h" #include "webkit/browser/quota/quota_client.h" -#include "webkit/browser/quota/quota_manager.h" +#include "webkit/browser/quota/quota_manager_proxy.h" namespace appcache { diff --git a/webkit/browser/appcache/appcache_storage_impl.cc b/webkit/browser/appcache/appcache_storage_impl.cc index f762a16..e0d0263 100644 --- a/webkit/browser/appcache/appcache_storage_impl.cc +++ b/webkit/browser/appcache/appcache_storage_impl.cc @@ -30,6 +30,7 @@ #include "webkit/browser/appcache/appcache_service.h" #include "webkit/browser/quota/quota_client.h" #include "webkit/browser/quota/quota_manager.h" +#include "webkit/browser/quota/quota_manager_proxy.h" #include "webkit/browser/quota/special_storage_policy.h" namespace appcache { diff --git a/webkit/browser/appcache/appcache_storage_unittest.cc b/webkit/browser/appcache/appcache_storage_unittest.cc index 32bca0c..8145f13 100644 --- a/webkit/browser/appcache/appcache_storage_unittest.cc +++ b/webkit/browser/appcache/appcache_storage_unittest.cc @@ -9,7 +9,7 @@ #include "webkit/browser/appcache/appcache_response.h" #include "webkit/browser/appcache/appcache_storage.h" #include "webkit/browser/appcache/mock_appcache_service.h" -#include "webkit/browser/quota/mock_quota_manager.h" +#include "webkit/browser/quota/mock_quota_manager_proxy.h" namespace appcache { diff --git a/webkit/browser/database/database_tracker.cc b/webkit/browser/database/database_tracker.cc index a9b70d6..085e81d 100644 --- a/webkit/browser/database/database_tracker.cc +++ b/webkit/browser/database/database_tracker.cc @@ -23,7 +23,7 @@ #include "webkit/browser/database/database_quota_client.h" #include "webkit/browser/database/database_util.h" #include "webkit/browser/database/databases_table.h" -#include "webkit/browser/quota/quota_manager.h" +#include "webkit/browser/quota/quota_manager_proxy.h" #include "webkit/browser/quota/special_storage_policy.h" #include "webkit/common/database/database_identifier.h" diff --git a/webkit/browser/database/database_tracker_unittest.cc b/webkit/browser/database/database_tracker_unittest.cc index d7efeb5..9d4d0ac 100644 --- a/webkit/browser/database/database_tracker_unittest.cc +++ b/webkit/browser/database/database_tracker_unittest.cc @@ -17,7 +17,7 @@ #include "third_party/sqlite/sqlite3.h" #include "webkit/browser/database/database_tracker.h" #include "webkit/browser/quota/mock_special_storage_policy.h" -#include "webkit/browser/quota/quota_manager.h" +#include "webkit/browser/quota/quota_manager_proxy.h" #include "webkit/common/database/database_identifier.h" using base::ASCIIToUTF16; diff --git a/webkit/browser/fileapi/file_system_context.cc b/webkit/browser/fileapi/file_system_context.cc index cd704e8..d1054fb 100644 --- a/webkit/browser/fileapi/file_system_context.cc +++ b/webkit/browser/fileapi/file_system_context.cc @@ -25,7 +25,7 @@ #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/quota_manager_proxy.h" #include "webkit/browser/quota/special_storage_policy.h" #include "webkit/common/fileapi/file_system_info.h" #include "webkit/common/fileapi/file_system_util.h" diff --git a/webkit/browser/fileapi/file_system_operation_impl.cc b/webkit/browser/fileapi/file_system_operation_impl.cc index 180e120..af6e1ca 100644 --- a/webkit/browser/fileapi/file_system_operation_impl.cc +++ b/webkit/browser/fileapi/file_system_operation_impl.cc @@ -21,7 +21,7 @@ #include "webkit/browser/fileapi/file_writer_delegate.h" #include "webkit/browser/fileapi/remove_operation_delegate.h" #include "webkit/browser/fileapi/sandbox_file_system_backend.h" -#include "webkit/browser/quota/quota_manager.h" +#include "webkit/browser/quota/quota_manager_proxy.h" #include "webkit/common/blob/shareable_file_reference.h" #include "webkit/common/fileapi/file_system_types.h" #include "webkit/common/fileapi/file_system_util.h" diff --git a/webkit/browser/fileapi/quota/quota_backend_impl.cc b/webkit/browser/fileapi/quota/quota_backend_impl.cc index 41cc952..05e199b 100644 --- a/webkit/browser/fileapi/quota/quota_backend_impl.cc +++ b/webkit/browser/fileapi/quota/quota_backend_impl.cc @@ -12,7 +12,7 @@ #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/browser/quota/quota_manager_proxy.h" #include "webkit/common/fileapi/file_system_util.h" namespace fileapi { diff --git a/webkit/browser/fileapi/quota/quota_backend_impl_unittest.cc b/webkit/browser/fileapi/quota/quota_backend_impl_unittest.cc index 75e8db8..edc554c 100644 --- a/webkit/browser/fileapi/quota/quota_backend_impl_unittest.cc +++ b/webkit/browser/fileapi/quota/quota_backend_impl_unittest.cc @@ -11,7 +11,7 @@ #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" +#include "webkit/browser/quota/quota_manager_proxy.h" namespace fileapi { diff --git a/webkit/browser/fileapi/sandbox_file_stream_writer.cc b/webkit/browser/fileapi/sandbox_file_stream_writer.cc index 24fe1c9..404bdba 100644 --- a/webkit/browser/fileapi/sandbox_file_stream_writer.cc +++ b/webkit/browser/fileapi/sandbox_file_stream_writer.cc @@ -14,7 +14,7 @@ #include "webkit/browser/fileapi/file_stream_writer.h" #include "webkit/browser/fileapi/file_system_context.h" #include "webkit/browser/fileapi/file_system_operation_runner.h" -#include "webkit/browser/quota/quota_manager.h" +#include "webkit/browser/quota/quota_manager_proxy.h" #include "webkit/common/fileapi/file_system_util.h" namespace fileapi { diff --git a/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc b/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc index c2b88d5..ce18afe1 100644 --- a/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc +++ b/webkit/browser/fileapi/sandbox_file_system_backend_delegate.cc @@ -25,7 +25,7 @@ #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" -#include "webkit/browser/quota/quota_manager.h" +#include "webkit/browser/quota/quota_manager_proxy.h" #include "webkit/common/fileapi/file_system_util.h" namespace fileapi { diff --git a/webkit/browser/fileapi/sandbox_quota_observer.cc b/webkit/browser/fileapi/sandbox_quota_observer.cc index fe5ee37..e81e440 100644 --- a/webkit/browser/fileapi/sandbox_quota_observer.cc +++ b/webkit/browser/fileapi/sandbox_quota_observer.cc @@ -10,7 +10,7 @@ #include "webkit/browser/fileapi/sandbox_file_system_backend_delegate.h" #include "webkit/browser/fileapi/timed_task_helper.h" #include "webkit/browser/quota/quota_client.h" -#include "webkit/browser/quota/quota_manager.h" +#include "webkit/browser/quota/quota_manager_proxy.h" #include "webkit/common/fileapi/file_system_util.h" namespace fileapi { diff --git a/webkit/browser/quota/mock_quota_manager.cc b/webkit/browser/quota/mock_quota_manager.cc index 69e3b0e..8f7798f 100644 --- a/webkit/browser/quota/mock_quota_manager.cc +++ b/webkit/browser/quota/mock_quota_manager.cc @@ -4,10 +4,6 @@ #include "webkit/browser/quota/mock_quota_manager.h" -#include <set> -#include <string> -#include <vector> - #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" @@ -32,8 +28,6 @@ MockQuotaManager::OriginInfo::~OriginInfo() {} MockQuotaManager::StorageInfo::StorageInfo() : usage(0), quota(kint64max) {} MockQuotaManager::StorageInfo::~StorageInfo() {} -// MockQuotaManager ---------------------------------------------------------- - MockQuotaManager::MockQuotaManager( bool is_incognito, const base::FilePath& profile_path, @@ -148,52 +142,4 @@ void MockQuotaManager::DidDeleteOriginData( callback.Run(status); } -// MockQuotaManagerProxy ----------------------------------------------------- - -MockQuotaManagerProxy::MockQuotaManagerProxy( - MockQuotaManager* quota_manager, - base::SingleThreadTaskRunner* task_runner) - : QuotaManagerProxy(quota_manager, task_runner), - storage_accessed_count_(0), - storage_modified_count_(0), - last_notified_type_(kStorageTypeUnknown), - last_notified_delta_(0), - registered_client_(NULL) {} - -void MockQuotaManagerProxy::RegisterClient(QuotaClient* client) { - DCHECK(!registered_client_); - registered_client_ = client; -} - -void MockQuotaManagerProxy::SimulateQuotaManagerDestroyed() { - if (registered_client_) { - // We cannot call this in the destructor as the client (indirectly) - // holds a refptr of the proxy. - registered_client_->OnQuotaManagerDestroyed(); - registered_client_ = NULL; - } -} - -void MockQuotaManagerProxy::NotifyStorageAccessed( - QuotaClient::ID client_id, const GURL& origin, StorageType type) { - ++storage_accessed_count_; - last_notified_origin_ = origin; - last_notified_type_ = type; -} - -void MockQuotaManagerProxy::NotifyStorageModified( - QuotaClient::ID client_id, const GURL& origin, - StorageType type, int64 delta) { - ++storage_modified_count_; - last_notified_origin_ = origin; - last_notified_type_ = type; - last_notified_delta_ = delta; - if (mock_manager()) - mock_manager()->UpdateUsage(origin, type, delta); -} - -MockQuotaManagerProxy::~MockQuotaManagerProxy() { - DCHECK(!registered_client_); -} - } // namespace quota diff --git a/webkit/browser/quota/mock_quota_manager.h b/webkit/browser/quota/mock_quota_manager.h index 0c93c11..1750e94 100644 --- a/webkit/browser/quota/mock_quota_manager.h +++ b/webkit/browser/quota/mock_quota_manager.h @@ -5,7 +5,9 @@ #ifndef WEBKIT_BROWSER_QUOTA_MOCK_QUOTA_MANAGER_H_ #define WEBKIT_BROWSER_QUOTA_MOCK_QUOTA_MANAGER_H_ -#include <string> +#include <map> +#include <set> +#include <utility> #include <vector> #include "base/memory/scoped_ptr.h" @@ -137,70 +139,6 @@ class MockQuotaManager : public QuotaManager { DISALLOW_COPY_AND_ASSIGN(MockQuotaManager); }; -// MockQuotaManagerProxy. -class MockQuotaManagerProxy : public QuotaManagerProxy { - public: - // It is ok to give NULL to |quota_manager|. - MockQuotaManagerProxy(MockQuotaManager* quota_manager, - base::SingleThreadTaskRunner* task_runner); - - virtual void RegisterClient(QuotaClient* client) OVERRIDE; - - void SimulateQuotaManagerDestroyed(); - - // We don't mock them. - virtual void NotifyOriginInUse(const GURL& origin) OVERRIDE {} - virtual void NotifyOriginNoLongerInUse(const GURL& origin) OVERRIDE {} - virtual void SetUsageCacheEnabled(QuotaClient::ID client_id, - const GURL& origin, - StorageType type, - bool enabled) OVERRIDE {} - virtual void GetUsageAndQuota( - base::SequencedTaskRunner* original_task_runner, - const GURL& origin, - StorageType type, - const QuotaManager::GetUsageAndQuotaCallback& callback) OVERRIDE {} - - // Validates the |client_id| and updates the internal access count - // which can be accessed via notify_storage_accessed_count(). - // The also records the |origin| and |type| in last_notified_origin_ and - // last_notified_type_. - virtual void NotifyStorageAccessed(QuotaClient::ID client_id, - const GURL& origin, - StorageType type) OVERRIDE; - - // Records the |origin|, |type| and |delta| as last_notified_origin_, - // last_notified_type_ and last_notified_delta_ respecitvely. - // If non-null MockQuotaManager is given to the constructor this also - // updates the manager's internal usage information. - virtual void NotifyStorageModified(QuotaClient::ID client_id, - const GURL& origin, - StorageType type, - int64 delta) OVERRIDE; - - int notify_storage_accessed_count() const { return storage_accessed_count_; } - int notify_storage_modified_count() const { return storage_modified_count_; } - GURL last_notified_origin() const { return last_notified_origin_; } - StorageType last_notified_type() const { return last_notified_type_; } - int64 last_notified_delta() const { return last_notified_delta_; } - - protected: - virtual ~MockQuotaManagerProxy(); - - private: - MockQuotaManager* mock_manager() const { - return static_cast<MockQuotaManager*>(quota_manager()); - } - - int storage_accessed_count_; - int storage_modified_count_; - GURL last_notified_origin_; - StorageType last_notified_type_; - int64 last_notified_delta_; - - QuotaClient* registered_client_; -}; - } // namespace quota #endif // WEBKIT_BROWSER_QUOTA_MOCK_QUOTA_MANAGER_H_ diff --git a/webkit/browser/quota/mock_quota_manager_proxy.cc b/webkit/browser/quota/mock_quota_manager_proxy.cc new file mode 100644 index 0000000..1317919 --- /dev/null +++ b/webkit/browser/quota/mock_quota_manager_proxy.cc @@ -0,0 +1,59 @@ +// Copyright 2014 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/quota/mock_quota_manager_proxy.h" + +#include "base/message_loop/message_loop.h" +#include "base/single_thread_task_runner.h" +#include "url/gurl.h" + +namespace quota { + +MockQuotaManagerProxy::MockQuotaManagerProxy( + MockQuotaManager* quota_manager, + base::SingleThreadTaskRunner* task_runner) + : QuotaManagerProxy(quota_manager, task_runner), + storage_accessed_count_(0), + storage_modified_count_(0), + last_notified_type_(kStorageTypeUnknown), + last_notified_delta_(0), + registered_client_(NULL) {} + +void MockQuotaManagerProxy::RegisterClient(QuotaClient* client) { + DCHECK(!registered_client_); + registered_client_ = client; +} + +void MockQuotaManagerProxy::SimulateQuotaManagerDestroyed() { + if (registered_client_) { + // We cannot call this in the destructor as the client (indirectly) + // holds a refptr of the proxy. + registered_client_->OnQuotaManagerDestroyed(); + registered_client_ = NULL; + } +} + +void MockQuotaManagerProxy::NotifyStorageAccessed( + QuotaClient::ID client_id, const GURL& origin, StorageType type) { + ++storage_accessed_count_; + last_notified_origin_ = origin; + last_notified_type_ = type; +} + +void MockQuotaManagerProxy::NotifyStorageModified( + QuotaClient::ID client_id, const GURL& origin, + StorageType type, int64 delta) { + ++storage_modified_count_; + last_notified_origin_ = origin; + last_notified_type_ = type; + last_notified_delta_ = delta; + if (mock_manager()) + mock_manager()->UpdateUsage(origin, type, delta); +} + +MockQuotaManagerProxy::~MockQuotaManagerProxy() { + DCHECK(!registered_client_); +} + +} // namespace quota diff --git a/webkit/browser/quota/mock_quota_manager_proxy.h b/webkit/browser/quota/mock_quota_manager_proxy.h new file mode 100644 index 0000000..dfae52e --- /dev/null +++ b/webkit/browser/quota/mock_quota_manager_proxy.h @@ -0,0 +1,85 @@ +// Copyright 2014 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_QUOTA_MOCK_QUOTA_MANAGER_PROXY_H_ +#define WEBKIT_BROWSER_QUOTA_MOCK_QUOTA_MANAGER_PROXY_H_ + +#include "url/gurl.h" +#include "webkit/browser/quota/mock_quota_manager.h" +#include "webkit/browser/quota/quota_client.h" +#include "webkit/browser/quota/quota_manager_proxy.h" +#include "webkit/common/quota/quota_types.h" + +namespace quota { + +class MockQuotaManager; + +class MockQuotaManagerProxy : public QuotaManagerProxy { + public: + // It is ok to give NULL to |quota_manager|. + MockQuotaManagerProxy(MockQuotaManager* quota_manager, + base::SingleThreadTaskRunner* task_runner); + + virtual void RegisterClient(QuotaClient* client) OVERRIDE; + + void SimulateQuotaManagerDestroyed(); + + // We don't mock them. + virtual void NotifyOriginInUse(const GURL& origin) OVERRIDE {} + virtual void NotifyOriginNoLongerInUse(const GURL& origin) OVERRIDE {} + virtual void SetUsageCacheEnabled(QuotaClient::ID client_id, + const GURL& origin, + StorageType type, + bool enabled) OVERRIDE {} + virtual void GetUsageAndQuota( + base::SequencedTaskRunner* original_task_runner, + const GURL& origin, + StorageType type, + const QuotaManager::GetUsageAndQuotaCallback& callback) OVERRIDE {} + + // Validates the |client_id| and updates the internal access count + // which can be accessed via notify_storage_accessed_count(). + // The also records the |origin| and |type| in last_notified_origin_ and + // last_notified_type_. + virtual void NotifyStorageAccessed(QuotaClient::ID client_id, + const GURL& origin, + StorageType type) OVERRIDE; + + // Records the |origin|, |type| and |delta| as last_notified_origin_, + // last_notified_type_ and last_notified_delta_ respecitvely. + // If non-null MockQuotaManager is given to the constructor this also + // updates the manager's internal usage information. + virtual void NotifyStorageModified(QuotaClient::ID client_id, + const GURL& origin, + StorageType type, + int64 delta) OVERRIDE; + + int notify_storage_accessed_count() const { return storage_accessed_count_; } + int notify_storage_modified_count() const { return storage_modified_count_; } + GURL last_notified_origin() const { return last_notified_origin_; } + StorageType last_notified_type() const { return last_notified_type_; } + int64 last_notified_delta() const { return last_notified_delta_; } + + protected: + virtual ~MockQuotaManagerProxy(); + + private: + MockQuotaManager* mock_manager() const { + return static_cast<MockQuotaManager*>(quota_manager()); + } + + int storage_accessed_count_; + int storage_modified_count_; + GURL last_notified_origin_; + StorageType last_notified_type_; + int64 last_notified_delta_; + + QuotaClient* registered_client_; + + DISALLOW_COPY_AND_ASSIGN(MockQuotaManagerProxy); +}; + +} // namespace quota + +#endif // WEBKIT_BROWSER_QUOTA_MOCK_QUOTA_MANAGER_PROXY_H_ diff --git a/webkit/browser/quota/mock_storage_client.cc b/webkit/browser/quota/mock_storage_client.cc index 61fd667..eb344bc 100644 --- a/webkit/browser/quota/mock_storage_client.cc +++ b/webkit/browser/quota/mock_storage_client.cc @@ -11,7 +11,7 @@ #include "base/message_loop/message_loop_proxy.h" #include "base/stl_util.h" #include "net/base/net_util.h" -#include "webkit/browser/quota/quota_manager.h" +#include "webkit/browser/quota/quota_manager_proxy.h" namespace quota { diff --git a/webkit/browser/quota/quota_manager.cc b/webkit/browser/quota/quota_manager.cc index 0663935..bc94ff7 100644 --- a/webkit/browser/quota/quota_manager.cc +++ b/webkit/browser/quota/quota_manager.cc @@ -24,6 +24,7 @@ #include "base/time/time.h" #include "net/base/net_util.h" #include "webkit/browser/quota/quota_database.h" +#include "webkit/browser/quota/quota_manager_proxy.h" #include "webkit/browser/quota/quota_temporary_storage_evictor.h" #include "webkit/browser/quota/usage_tracker.h" #include "webkit/common/quota/quota_types.h" @@ -43,21 +44,6 @@ const int kMinutesInMilliSeconds = 60 * 1000; const int64 kReportHistogramInterval = 60 * 60 * 1000; // 1 hour const double kTemporaryQuotaRatioToAvail = 1.0 / 3.0; // 33% -void DidGetUsageAndQuota( - base::SequencedTaskRunner* original_task_runner, - const QuotaManagerProxy::GetUsageAndQuotaCallback& callback, - QuotaStatusCode status, int64 usage, int64 quota) { - if (!original_task_runner->RunsTasksOnCurrentThread()) { - original_task_runner->PostTask( - FROM_HERE, - base::Bind(&DidGetUsageAndQuota, - make_scoped_refptr(original_task_runner), - callback, status, usage, quota)); - return; - } - callback.Run(status, usage, quota); -} - } // namespace // Arbitrary for now, but must be reasonably small so that @@ -1605,130 +1591,4 @@ void QuotaManager::PostTaskAndReplyWithResultForDBThread( reply); } -// QuotaManagerProxy ---------------------------------------------------------- - -void QuotaManagerProxy::RegisterClient(QuotaClient* client) { - if (!io_thread_->BelongsToCurrentThread() && - io_thread_->PostTask( - FROM_HERE, - base::Bind(&QuotaManagerProxy::RegisterClient, this, client))) { - return; - } - - if (manager_) - manager_->RegisterClient(client); - else - client->OnQuotaManagerDestroyed(); -} - -void QuotaManagerProxy::NotifyStorageAccessed( - QuotaClient::ID client_id, - const GURL& origin, - StorageType type) { - if (!io_thread_->BelongsToCurrentThread()) { - io_thread_->PostTask( - FROM_HERE, - base::Bind(&QuotaManagerProxy::NotifyStorageAccessed, this, client_id, - origin, type)); - return; - } - - if (manager_) - manager_->NotifyStorageAccessed(client_id, origin, type); -} - -void QuotaManagerProxy::NotifyStorageModified( - QuotaClient::ID client_id, - const GURL& origin, - StorageType type, - int64 delta) { - if (!io_thread_->BelongsToCurrentThread()) { - io_thread_->PostTask( - FROM_HERE, - base::Bind(&QuotaManagerProxy::NotifyStorageModified, this, client_id, - origin, type, delta)); - return; - } - - if (manager_) - manager_->NotifyStorageModified(client_id, origin, type, delta); -} - -void QuotaManagerProxy::NotifyOriginInUse( - const GURL& origin) { - if (!io_thread_->BelongsToCurrentThread()) { - io_thread_->PostTask( - FROM_HERE, - base::Bind(&QuotaManagerProxy::NotifyOriginInUse, this, origin)); - return; - } - - if (manager_) - manager_->NotifyOriginInUse(origin); -} - -void QuotaManagerProxy::NotifyOriginNoLongerInUse( - const GURL& origin) { - if (!io_thread_->BelongsToCurrentThread()) { - io_thread_->PostTask( - FROM_HERE, - base::Bind(&QuotaManagerProxy::NotifyOriginNoLongerInUse, this, - origin)); - return; - } - if (manager_) - manager_->NotifyOriginNoLongerInUse(origin); -} - -void QuotaManagerProxy::SetUsageCacheEnabled(QuotaClient::ID client_id, - const GURL& origin, - StorageType type, - bool enabled) { - if (!io_thread_->BelongsToCurrentThread()) { - io_thread_->PostTask( - FROM_HERE, - base::Bind(&QuotaManagerProxy::SetUsageCacheEnabled, this, - client_id, origin, type, enabled)); - return; - } - if (manager_) - manager_->SetUsageCacheEnabled(client_id, origin, type, enabled); -} - -void QuotaManagerProxy::GetUsageAndQuota( - base::SequencedTaskRunner* original_task_runner, - const GURL& origin, - StorageType type, - const GetUsageAndQuotaCallback& callback) { - if (!io_thread_->BelongsToCurrentThread()) { - io_thread_->PostTask( - FROM_HERE, - base::Bind(&QuotaManagerProxy::GetUsageAndQuota, this, - make_scoped_refptr(original_task_runner), - origin, type, callback)); - return; - } - if (!manager_) { - DidGetUsageAndQuota(original_task_runner, callback, kQuotaErrorAbort, 0, 0); - return; - } - manager_->GetUsageAndQuota( - origin, type, - base::Bind(&DidGetUsageAndQuota, - make_scoped_refptr(original_task_runner), callback)); -} - -QuotaManager* QuotaManagerProxy::quota_manager() const { - DCHECK(!io_thread_.get() || io_thread_->BelongsToCurrentThread()); - return manager_; -} - -QuotaManagerProxy::QuotaManagerProxy( - QuotaManager* manager, base::SingleThreadTaskRunner* io_thread) - : manager_(manager), io_thread_(io_thread) { -} - -QuotaManagerProxy::~QuotaManagerProxy() { -} - } // namespace quota diff --git a/webkit/browser/quota/quota_manager.h b/webkit/browser/quota/quota_manager.h index 5481b20..064d548 100644 --- a/webkit/browser/quota/quota_manager.h +++ b/webkit/browser/quota/quota_manager.h @@ -434,52 +434,6 @@ struct QuotaManagerDeleter { } }; -// The proxy may be called and finally released on any thread. -class WEBKIT_STORAGE_BROWSER_EXPORT QuotaManagerProxy - : public base::RefCountedThreadSafe<QuotaManagerProxy> { - public: - typedef QuotaManager::GetUsageAndQuotaCallback - GetUsageAndQuotaCallback; - - virtual void RegisterClient(QuotaClient* client); - virtual void NotifyStorageAccessed(QuotaClient::ID client_id, - const GURL& origin, - StorageType type); - virtual void NotifyStorageModified(QuotaClient::ID client_id, - const GURL& origin, - StorageType type, - int64 delta); - virtual void NotifyOriginInUse(const GURL& origin); - virtual void NotifyOriginNoLongerInUse(const GURL& origin); - - virtual void SetUsageCacheEnabled(QuotaClient::ID client_id, - const GURL& origin, - StorageType type, - bool enabled); - virtual void GetUsageAndQuota( - base::SequencedTaskRunner* original_task_runner, - const GURL& origin, - StorageType type, - const GetUsageAndQuotaCallback& callback); - - // This method may only be called on the IO thread. - // It may return NULL if the manager has already been deleted. - QuotaManager* quota_manager() const; - - protected: - friend class QuotaManager; - friend class base::RefCountedThreadSafe<QuotaManagerProxy>; - - QuotaManagerProxy(QuotaManager* manager, - base::SingleThreadTaskRunner* io_thread); - virtual ~QuotaManagerProxy(); - - QuotaManager* manager_; // only accessed on the io thread - scoped_refptr<base::SingleThreadTaskRunner> io_thread_; - - DISALLOW_COPY_AND_ASSIGN(QuotaManagerProxy); -}; - } // namespace quota #endif // WEBKIT_BROWSER_QUOTA_QUOTA_MANAGER_H_ diff --git a/webkit/browser/quota/quota_manager_proxy.cc b/webkit/browser/quota/quota_manager_proxy.cc new file mode 100644 index 0000000..20b42c3 --- /dev/null +++ b/webkit/browser/quota/quota_manager_proxy.cc @@ -0,0 +1,160 @@ +// Copyright 2014 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/quota/quota_manager_proxy.h" + +#include "base/bind.h" +#include "base/bind_helpers.h" +#include "base/callback.h" +#include "base/sequenced_task_runner.h" +#include "base/single_thread_task_runner.h" +#include "base/strings/string_number_conversions.h" +#include "base/task_runner_util.h" + +namespace quota { + +namespace { + +void DidGetUsageAndQuota( + base::SequencedTaskRunner* original_task_runner, + const QuotaManagerProxy::GetUsageAndQuotaCallback& callback, + QuotaStatusCode status, int64 usage, int64 quota) { + if (!original_task_runner->RunsTasksOnCurrentThread()) { + original_task_runner->PostTask( + FROM_HERE, + base::Bind(&DidGetUsageAndQuota, + make_scoped_refptr(original_task_runner), + callback, status, usage, quota)); + return; + } + callback.Run(status, usage, quota); +} + +} // namespace + +void QuotaManagerProxy::RegisterClient(QuotaClient* client) { + if (!io_thread_->BelongsToCurrentThread() && + io_thread_->PostTask( + FROM_HERE, + base::Bind(&QuotaManagerProxy::RegisterClient, this, client))) { + return; + } + + if (manager_) + manager_->RegisterClient(client); + else + client->OnQuotaManagerDestroyed(); +} + +void QuotaManagerProxy::NotifyStorageAccessed( + QuotaClient::ID client_id, + const GURL& origin, + StorageType type) { + if (!io_thread_->BelongsToCurrentThread()) { + io_thread_->PostTask( + FROM_HERE, + base::Bind(&QuotaManagerProxy::NotifyStorageAccessed, this, client_id, + origin, type)); + return; + } + + if (manager_) + manager_->NotifyStorageAccessed(client_id, origin, type); +} + +void QuotaManagerProxy::NotifyStorageModified( + QuotaClient::ID client_id, + const GURL& origin, + StorageType type, + int64 delta) { + if (!io_thread_->BelongsToCurrentThread()) { + io_thread_->PostTask( + FROM_HERE, + base::Bind(&QuotaManagerProxy::NotifyStorageModified, this, client_id, + origin, type, delta)); + return; + } + + if (manager_) + manager_->NotifyStorageModified(client_id, origin, type, delta); +} + +void QuotaManagerProxy::NotifyOriginInUse( + const GURL& origin) { + if (!io_thread_->BelongsToCurrentThread()) { + io_thread_->PostTask( + FROM_HERE, + base::Bind(&QuotaManagerProxy::NotifyOriginInUse, this, origin)); + return; + } + + if (manager_) + manager_->NotifyOriginInUse(origin); +} + +void QuotaManagerProxy::NotifyOriginNoLongerInUse( + const GURL& origin) { + if (!io_thread_->BelongsToCurrentThread()) { + io_thread_->PostTask( + FROM_HERE, + base::Bind(&QuotaManagerProxy::NotifyOriginNoLongerInUse, this, + origin)); + return; + } + if (manager_) + manager_->NotifyOriginNoLongerInUse(origin); +} + +void QuotaManagerProxy::SetUsageCacheEnabled(QuotaClient::ID client_id, + const GURL& origin, + StorageType type, + bool enabled) { + if (!io_thread_->BelongsToCurrentThread()) { + io_thread_->PostTask( + FROM_HERE, + base::Bind(&QuotaManagerProxy::SetUsageCacheEnabled, this, + client_id, origin, type, enabled)); + return; + } + if (manager_) + manager_->SetUsageCacheEnabled(client_id, origin, type, enabled); +} + +void QuotaManagerProxy::GetUsageAndQuota( + base::SequencedTaskRunner* original_task_runner, + const GURL& origin, + StorageType type, + const GetUsageAndQuotaCallback& callback) { + if (!io_thread_->BelongsToCurrentThread()) { + io_thread_->PostTask( + FROM_HERE, + base::Bind(&QuotaManagerProxy::GetUsageAndQuota, this, + make_scoped_refptr(original_task_runner), + origin, type, callback)); + return; + } + if (!manager_) { + DidGetUsageAndQuota(original_task_runner, callback, kQuotaErrorAbort, 0, 0); + return; + } + manager_->GetUsageAndQuota( + origin, type, + base::Bind(&DidGetUsageAndQuota, + make_scoped_refptr(original_task_runner), callback)); +} + +QuotaManager* QuotaManagerProxy::quota_manager() const { + DCHECK(!io_thread_.get() || io_thread_->BelongsToCurrentThread()); + return manager_; +} + +QuotaManagerProxy::QuotaManagerProxy( + QuotaManager* manager, base::SingleThreadTaskRunner* io_thread) + : manager_(manager), io_thread_(io_thread) { +} + +QuotaManagerProxy::~QuotaManagerProxy() { +} + +} // namespace quota diff --git a/webkit/browser/quota/quota_manager_proxy.h b/webkit/browser/quota/quota_manager_proxy.h new file mode 100644 index 0000000..21c97c6 --- /dev/null +++ b/webkit/browser/quota/quota_manager_proxy.h @@ -0,0 +1,78 @@ +// Copyright 2014 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_QUOTA_QUOTA_MANAGER_PROXY_H_ +#define WEBKIT_BROWSER_QUOTA_QUOTA_MANAGER_PROXY_H_ + +#include "base/basictypes.h" +#include "base/callback.h" +#include "base/files/file_path.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" +#include "base/sequenced_task_runner_helpers.h" +#include "webkit/browser/quota/quota_callbacks.h" +#include "webkit/browser/quota/quota_client.h" +#include "webkit/browser/quota/quota_database.h" +#include "webkit/browser/quota/quota_manager.h" +#include "webkit/browser/quota/quota_task.h" +#include "webkit/browser/quota/special_storage_policy.h" +#include "webkit/browser/webkit_storage_browser_export.h" + +namespace base { +class SequencedTaskRunner; +class SingleThreadTaskRunner; +} + +namespace quota { + +// The proxy may be called and finally released on any thread. +class WEBKIT_STORAGE_BROWSER_EXPORT QuotaManagerProxy + : public base::RefCountedThreadSafe<QuotaManagerProxy> { + public: + typedef QuotaManager::GetUsageAndQuotaCallback + GetUsageAndQuotaCallback; + + virtual void RegisterClient(QuotaClient* client); + virtual void NotifyStorageAccessed(QuotaClient::ID client_id, + const GURL& origin, + StorageType type); + virtual void NotifyStorageModified(QuotaClient::ID client_id, + const GURL& origin, + StorageType type, + int64 delta); + virtual void NotifyOriginInUse(const GURL& origin); + virtual void NotifyOriginNoLongerInUse(const GURL& origin); + + virtual void SetUsageCacheEnabled(QuotaClient::ID client_id, + const GURL& origin, + StorageType type, + bool enabled); + virtual void GetUsageAndQuota( + base::SequencedTaskRunner* original_task_runner, + const GURL& origin, + StorageType type, + const GetUsageAndQuotaCallback& callback); + + // This method may only be called on the IO thread. + // It may return NULL if the manager has already been deleted. + QuotaManager* quota_manager() const; + + protected: + friend class QuotaManager; + friend class base::RefCountedThreadSafe<QuotaManagerProxy>; + + QuotaManagerProxy(QuotaManager* manager, + base::SingleThreadTaskRunner* io_thread); + virtual ~QuotaManagerProxy(); + + QuotaManager* manager_; // only accessed on the io thread + scoped_refptr<base::SingleThreadTaskRunner> io_thread_; + + DISALLOW_COPY_AND_ASSIGN(QuotaManagerProxy); +}; + +} // namespace quota + +#endif // WEBKIT_BROWSER_QUOTA_QUOTA_MANAGER_PROXY_H_ diff --git a/webkit/browser/quota/quota_manager_unittest.cc b/webkit/browser/quota/quota_manager_unittest.cc index b5a8bdc..9210537 100644 --- a/webkit/browser/quota/quota_manager_unittest.cc +++ b/webkit/browser/quota/quota_manager_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <algorithm> #include <set> #include <sstream> #include <vector> @@ -22,6 +23,7 @@ #include "webkit/browser/quota/mock_storage_client.h" #include "webkit/browser/quota/quota_database.h" #include "webkit/browser/quota/quota_manager.h" +#include "webkit/browser/quota/quota_manager_proxy.h" using base::MessageLoopProxy; diff --git a/webkit/storage_browser.gyp b/webkit/storage_browser.gyp index c474c56..e299dc9 100644 --- a/webkit/storage_browser.gyp +++ b/webkit/storage_browser.gyp @@ -199,6 +199,8 @@ 'browser/quota/quota_database.h', 'browser/quota/quota_manager.cc', 'browser/quota/quota_manager.h', + 'browser/quota/quota_manager_proxy.cc', + 'browser/quota/quota_manager_proxy.h', 'browser/quota/quota_task.cc', 'browser/quota/quota_task.h', 'browser/quota/quota_temporary_storage_evictor.cc', |