Index: webkit/quota/mock_quota_manager.cc |
diff --git a/webkit/quota/mock_quota_manager.cc b/webkit/quota/mock_quota_manager.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..81d9eb610f33697b3fd06d73eba1f4654c74450c |
--- /dev/null |
+++ b/webkit/quota/mock_quota_manager.cc |
@@ -0,0 +1,135 @@ |
+// 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/quota/mock_quota_manager.h" |
+ |
+#include <set> |
+#include <string> |
+#include <vector> |
+ |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "googleurl/src/gurl.h" |
+#include "webkit/quota/quota_client.h" |
+#include "webkit/quota/quota_manager.h" |
+#include "webkit/quota/quota_task.h" |
+#include "webkit/quota/quota_types.h" |
+ |
+// Done so that we can use PostTask on MockQuotaManager and not have |
+// MockQuotaManager implement RefCounted. |
jochen (gone - plz use gerrit)
2011/07/26 08:55:33
but isn't the base class, quota manager already re
Mike West
2011/07/26 12:08:32
You're right. I don't know why I thought I needed
|
+DISABLE_RUNNABLE_METHOD_REFCOUNT(quota::MockQuotaManager); |
+ |
+namespace quota { |
+ |
+class MockQuotaManager::GetModifiedSinceTask : public QuotaThreadTask { |
+ public: |
+ GetModifiedSinceTask(MockQuotaManager* manager, |
+ const std::set<GURL>& origins, GetOriginsCallback* callback) |
jochen (gone - plz use gerrit)
2011/07/26 08:55:33
all arguments on their own line, and aligned
Mike West
2011/07/26 12:08:32
Done.
|
+ : QuotaThreadTask(manager, manager->io_thread_), |
+ origins_(origins), |
+ callback_(callback) {} |
+ |
+ protected: |
+ virtual void RunOnTargetThread() OVERRIDE {} |
+ |
+ virtual void Completed() OVERRIDE { |
+ callback_->Run(origins_); |
+ } |
+ |
+ virtual void Aborted() OVERRIDE { |
+ callback_->Run(std::set<GURL>()); |
+ } |
+ |
+ private: |
+ std::set<GURL> origins_; |
+ scoped_ptr<GetOriginsCallback> callback_; |
+}; |
jochen (gone - plz use gerrit)
2011/07/26 08:55:33
disallow copy/assign
Mike West
2011/07/26 12:08:32
Done.
|
+ |
+class MockQuotaManager::DeleteOriginDataTask : public QuotaThreadTask { |
+ public: |
+ DeleteOriginDataTask(MockQuotaManager* manager, |
+ StatusCallback* callback) |
+ : QuotaThreadTask(manager, manager->io_thread_), |
+ callback_(callback) {} |
+ |
+ protected: |
+ virtual void RunOnTargetThread() OVERRIDE {} |
+ |
+ virtual void Completed() OVERRIDE { |
+ callback_->Run(quota::kQuotaStatusOk); |
+ } |
+ |
+ virtual void Aborted() OVERRIDE { |
+ callback_->Run(quota::kQuotaErrorAbort); |
+ } |
+ |
+ private: |
+ scoped_ptr<StatusCallback> callback_; |
+}; |
+ |
+MockQuotaManager::OriginInfo::OriginInfo( |
+ const GURL& origin, |
+ StorageType type, |
+ base::Time modified) |
+ : origin(origin), |
+ type(type), |
+ modified(modified) { |
+} |
+ |
+MockQuotaManager::OriginInfo::~OriginInfo() {} |
+ |
+MockQuotaManager::MockQuotaManager(bool is_incognito, |
+ const FilePath& profile_path, base::MessageLoopProxy* io_thread, |
+ base::MessageLoopProxy* db_thread, |
+ SpecialStoragePolicy* special_storage_policy) |
+ : QuotaManager(is_incognito, profile_path, io_thread, db_thread, |
+ special_storage_policy) { |
+} |
+ |
+MockQuotaManager::~MockQuotaManager() {} |
+ |
+bool MockQuotaManager::AddOrigin(const GURL& origin, StorageType type, |
+ base::Time modified) { |
+ origins_.push_back(OriginInfo(origin, type, modified)); |
+ return true; |
+} |
+ |
+bool MockQuotaManager::OriginHasData(const GURL& origin, |
+ StorageType type) { |
+ for (std::vector<OriginInfo>::iterator current = origins_.begin(); |
+ current != origins_.end(); |
+ ++current) { |
+ if (current->origin == origin && current->type == type) |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+void MockQuotaManager::GetOriginsModifiedSince(StorageType type, |
+ base::Time modified_since, GetOriginsCallback* callback) { |
+ std::set<GURL> origins_to_return; |
+ for (std::vector<OriginInfo>::iterator current = origins_.begin(); |
+ current != origins_.end(); |
+ ++current) { |
+ if (current->type == type && current->modified >= modified_since) |
+ origins_to_return.insert(current->origin); |
+ } |
+ make_scoped_refptr(new GetModifiedSinceTask(this, origins_to_return, |
+ callback))->Start(); |
+} |
+ |
+void MockQuotaManager::DeleteOriginData(const GURL& origin, StorageType type, |
+ StatusCallback* callback) { |
+ for (std::vector<OriginInfo>::iterator current = origins_.begin(); |
+ current != origins_.end(); |
+ ++current) { |
+ if (current->origin == origin && current->type == type) { |
+ origins_.erase(current); |
+ break; |
+ } |
+ } |
+ make_scoped_refptr(new DeleteOriginDataTask(this, callback))->Start(); |
+} |
+ |
+} // namespace quota |