summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/profiles/profile.cc11
-rw-r--r--chrome/browser/profiles/profile_impl.cc11
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/test/testing_profile.cc2
-rw-r--r--content/browser/in_process_webkit/indexed_db_context.cc11
-rw-r--r--content/browser/in_process_webkit/indexed_db_context.h17
-rw-r--r--content/browser/in_process_webkit/indexed_db_quota_client.cc219
-rw-r--r--content/browser/in_process_webkit/indexed_db_quota_client.h80
-rw-r--r--content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc104
-rw-r--r--content/browser/in_process_webkit/webkit_context.cc12
-rw-r--r--content/browser/in_process_webkit/webkit_context.h11
-rw-r--r--content/browser/in_process_webkit/webkit_context_unittest.cc6
-rw-r--r--content/content_browser.gypi2
13 files changed, 461 insertions, 26 deletions
diff --git a/chrome/browser/profiles/profile.cc b/chrome/browser/profiles/profile.cc
index 4f882cb..fbb0f4b 100644
--- a/chrome/browser/profiles/profile.cc
+++ b/chrome/browser/profiles/profile.cc
@@ -565,11 +565,7 @@ class OffTheRecordProfileImpl : public Profile,
}
virtual WebKitContext* GetWebKitContext() {
- if (!webkit_context_.get()) {
- webkit_context_ = new WebKitContext(
- IsOffTheRecord(), GetPath(), GetExtensionSpecialStoragePolicy(),
- false);
- }
+ CreateQuotaManagerAndClients();
return webkit_context_.get();
}
@@ -694,6 +690,7 @@ class OffTheRecordProfileImpl : public Profile,
if (quota_manager_.get()) {
DCHECK(file_system_context_.get());
DCHECK(db_tracker_.get());
+ DCHECK(webkit_context_.get());
return;
}
@@ -717,6 +714,10 @@ class OffTheRecordProfileImpl : public Profile,
GetPath(), IsOffTheRecord(), GetExtensionSpecialStoragePolicy(),
quota_manager_->proxy(),
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
+ webkit_context_ = new WebKitContext(
+ IsOffTheRecord(), GetPath(), GetExtensionSpecialStoragePolicy(),
+ false, quota_manager_->proxy(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT));
appcache_service_ = new ChromeAppCacheService(quota_manager_->proxy());
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 3ed5116..4780570 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -1306,6 +1306,7 @@ void ProfileImpl::CreateQuotaManagerAndClients() {
if (quota_manager_.get()) {
DCHECK(file_system_context_.get());
DCHECK(db_tracker_.get());
+ DCHECK(webkit_context_.get());
return;
}
@@ -1329,6 +1330,10 @@ void ProfileImpl::CreateQuotaManagerAndClients() {
GetPath(), IsOffTheRecord(), GetExtensionSpecialStoragePolicy(),
quota_manager_->proxy(),
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
+ webkit_context_ = new WebKitContext(
+ IsOffTheRecord(), GetPath(), GetExtensionSpecialStoragePolicy(),
+ clear_local_state_on_exit_, quota_manager_->proxy(),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT));
appcache_service_ = new ChromeAppCacheService(quota_manager_->proxy());
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
@@ -1343,11 +1348,7 @@ void ProfileImpl::CreateQuotaManagerAndClients() {
}
WebKitContext* ProfileImpl::GetWebKitContext() {
- if (!webkit_context_.get()) {
- webkit_context_ = new WebKitContext(
- IsOffTheRecord(), GetPath(), GetExtensionSpecialStoragePolicy(),
- clear_local_state_on_exit_);
- }
+ CreateQuotaManagerAndClients();
return webkit_context_.get();
}
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 9faad86..dd9e8b5 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1923,6 +1923,7 @@
'../content/browser/geolocation/win7_location_api_unittest_win.cc',
'../content/browser/geolocation/win7_location_provider_unittest_win.cc',
'../content/browser/gpu/gpu_blacklist_unittest.cc',
+ '../content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc',
'../content/browser/in_process_webkit/webkit_context_unittest.cc',
'../content/browser/in_process_webkit/webkit_thread_unittest.cc',
'../content/browser/media_stream/video_capture_manager_unittest.cc',
diff --git a/chrome/test/testing_profile.cc b/chrome/test/testing_profile.cc
index 3604f9d..12e6c1e 100644
--- a/chrome/test/testing_profile.cc
+++ b/chrome/test/testing_profile.cc
@@ -680,7 +680,7 @@ WebKitContext* TestingProfile::GetWebKitContext() {
webkit_context_ = new WebKitContext(
IsOffTheRecord(), GetPath(),
GetExtensionSpecialStoragePolicy(),
- false);
+ false, NULL, NULL);
}
return webkit_context_;
}
diff --git a/content/browser/in_process_webkit/indexed_db_context.cc b/content/browser/in_process_webkit/indexed_db_context.cc
index f9722ec..23c5214 100644
--- a/content/browser/in_process_webkit/indexed_db_context.cc
+++ b/content/browser/in_process_webkit/indexed_db_context.cc
@@ -6,9 +6,11 @@
#include "base/file_util.h"
#include "base/logging.h"
+#include "base/message_loop_proxy.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "content/browser/browser_thread.h"
+#include "content/browser/in_process_webkit/indexed_db_quota_client.h"
#include "content/browser/in_process_webkit/webkit_context.h"
#include "googleurl/src/gurl.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h"
@@ -17,6 +19,7 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
#include "webkit/glue/webkit_glue.h"
+#include "webkit/quota/quota_manager.h"
#include "webkit/quota/special_storage_policy.h"
using WebKit::WebIDBDatabase;
@@ -54,10 +57,16 @@ const FilePath::CharType IndexedDBContext::kIndexedDBExtension[] =
IndexedDBContext::IndexedDBContext(
WebKitContext* webkit_context,
- quota::SpecialStoragePolicy* special_storage_policy)
+ quota::SpecialStoragePolicy* special_storage_policy,
+ quota::QuotaManagerProxy* quota_manager_proxy,
+ base::MessageLoopProxy* webkit_thread_loop)
: clear_local_state_on_exit_(false),
special_storage_policy_(special_storage_policy) {
data_path_ = webkit_context->data_path().Append(kIndexedDBDirectory);
+ if (quota_manager_proxy) {
+// quota_manager_proxy->RegisterClient(
+// new IndexedDBQuotaClient(webkit_thread_loop, this));
+ }
}
IndexedDBContext::~IndexedDBContext() {
diff --git a/content/browser/in_process_webkit/indexed_db_context.h b/content/browser/in_process_webkit/indexed_db_context.h
index 2bd32e5..be23e0d 100644
--- a/content/browser/in_process_webkit/indexed_db_context.h
+++ b/content/browser/in_process_webkit/indexed_db_context.h
@@ -10,6 +10,7 @@
#include "base/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "content/browser/browser_thread.h"
class GURL;
class FilePath;
@@ -19,14 +20,24 @@ namespace WebKit {
class WebIDBFactory;
}
+namespace base {
+class MessageLoopProxy;
+}
+
namespace quota {
+class QuotaManagerProxy;
class SpecialStoragePolicy;
}
-class IndexedDBContext {
+class IndexedDBContext :
+ public base::RefCountedThreadSafe<IndexedDBContext,
+ BrowserThread::DeleteOnWebKitThread> {
public:
IndexedDBContext(WebKitContext* webkit_context,
- quota::SpecialStoragePolicy* special_storage_policy);
+ quota::SpecialStoragePolicy* special_storage_policy,
+ quota::QuotaManagerProxy* quota_manager_proxy,
+ base::MessageLoopProxy* webkit_thread_loop);
+
~IndexedDBContext();
WebKit::WebIDBFactory* GetIDBFactory();
@@ -69,6 +80,8 @@ class IndexedDBContext {
scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_;
+ scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_;
+
DISALLOW_COPY_AND_ASSIGN(IndexedDBContext);
};
diff --git a/content/browser/in_process_webkit/indexed_db_quota_client.cc b/content/browser/in_process_webkit/indexed_db_quota_client.cc
new file mode 100644
index 0000000..2334bac
--- /dev/null
+++ b/content/browser/in_process_webkit/indexed_db_quota_client.cc
@@ -0,0 +1,219 @@
+// 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 "content/browser/in_process_webkit/indexed_db_quota_client.h"
+
+#include <vector>
+
+#include "base/file_util.h"
+#include "base/message_loop_proxy.h"
+#include "content/browser/in_process_webkit/indexed_db_context.h"
+#include "net/base/net_util.h"
+#include "webkit/database/database_util.h"
+
+using quota::QuotaClient;
+
+
+// Helper tasks ---------------------------------------------------------------
+
+class IndexedDBQuotaClient::HelperTask : public quota::QuotaThreadTask {
+ protected:
+ HelperTask(
+ IndexedDBQuotaClient* client,
+ base::MessageLoopProxy* webkit_thread_message_loop)
+ : QuotaThreadTask(client, webkit_thread_message_loop),
+ client_(client), indexed_db_context_(client->indexed_db_context_) {
+ }
+
+ IndexedDBQuotaClient* client_;
+ scoped_refptr<IndexedDBContext> indexed_db_context_;
+};
+
+class IndexedDBQuotaClient::GetOriginUsageTask : public HelperTask {
+ public:
+ GetOriginUsageTask(
+ IndexedDBQuotaClient* client,
+ base::MessageLoopProxy* webkit_thread_message_loop,
+ const GURL& origin_url)
+ : HelperTask(client, webkit_thread_message_loop),
+ origin_url_(origin_url), usage_(0) {
+ }
+
+ private:
+ virtual void RunOnTargetThread() OVERRIDE {
+ string16 origin_id =
+ webkit_database::DatabaseUtil::GetOriginIdentifier(origin_url_);
+ FilePath file_path = indexed_db_context_->GetIndexedDBFilePath(origin_id);
+ usage_ = 0;
+ if (!file_util::GetFileSize(file_path, &usage_)) {
+ LOG(ERROR) << "Failed to get file size for " << file_path.value();
+ }
+ }
+ virtual void Completed() OVERRIDE {
+ client_->DidGetOriginUsage(origin_url_, usage_);
+ }
+ GURL origin_url_;
+ int64 usage_;
+};
+
+class IndexedDBQuotaClient::GetOriginsTaskBase : public HelperTask {
+ protected:
+ GetOriginsTaskBase(
+ IndexedDBQuotaClient* client,
+ base::MessageLoopProxy* webkit_thread_message_loop)
+ : HelperTask(client, webkit_thread_message_loop) {
+ }
+
+ virtual bool ShouldAddOrigin(const GURL& origin) = 0;
+
+ virtual void RunOnTargetThread() OVERRIDE {
+ // TODO(dgrogan): Implement.
+ }
+
+ std::set<GURL> origins_;
+};
+
+class IndexedDBQuotaClient::GetAllOriginsTask : public GetOriginsTaskBase {
+ public:
+ GetAllOriginsTask(
+ IndexedDBQuotaClient* client,
+ base::MessageLoopProxy* webkit_thread_message_loop)
+ : GetOriginsTaskBase(client, webkit_thread_message_loop) {
+ }
+
+ protected:
+ virtual bool ShouldAddOrigin(const GURL& origin) OVERRIDE {
+ return true;
+ }
+ virtual void Completed() OVERRIDE {
+ client_->DidGetAllOrigins(origins_);
+ }
+};
+
+class IndexedDBQuotaClient::GetOriginsForHostTask : public GetOriginsTaskBase {
+ public:
+ GetOriginsForHostTask(
+ IndexedDBQuotaClient* client,
+ base::MessageLoopProxy* webkit_thread_message_loop,
+ const std::string& host)
+ : GetOriginsTaskBase(client, webkit_thread_message_loop),
+ host_(host) {
+ }
+
+ private:
+ virtual bool ShouldAddOrigin(const GURL& origin) OVERRIDE {
+ return host_ == net::GetHostOrSpecFromURL(origin);
+ }
+ virtual void Completed() OVERRIDE {
+ client_->DidGetOriginsForHost(host_, origins_);
+ }
+ std::string host_;
+};
+
+// IndexedDBQuotaClient --------------------------------------------------------
+
+IndexedDBQuotaClient::IndexedDBQuotaClient(
+ base::MessageLoopProxy* webkit_thread_message_loop,
+ IndexedDBContext* indexed_db_context)
+ : webkit_thread_message_loop_(webkit_thread_message_loop),
+ indexed_db_context_(indexed_db_context) {
+}
+
+IndexedDBQuotaClient::~IndexedDBQuotaClient() {
+}
+
+QuotaClient::ID IndexedDBQuotaClient::id() const {
+ return kIndexedDatabase;
+}
+
+void IndexedDBQuotaClient::OnQuotaManagerDestroyed() {
+ delete this;
+}
+
+void IndexedDBQuotaClient::GetOriginUsage(
+ const GURL& origin_url,
+ quota::StorageType type,
+ GetUsageCallback* callback_ptr) {
+ DCHECK(callback_ptr);
+ DCHECK(indexed_db_context_.get());
+ scoped_ptr<GetUsageCallback> callback(callback_ptr);
+
+ // IndexedDB is in the temp namespace for now.
+ if (type != quota::kStorageTypeTemporary) {
+ callback->Run(0);
+ return;
+ }
+
+ if (usage_for_origin_callbacks_.Add(origin_url, callback.release())) {
+ scoped_refptr<GetOriginUsageTask> task(
+ new GetOriginUsageTask(this, webkit_thread_message_loop_, origin_url));
+ task->Start();
+ }
+}
+
+void IndexedDBQuotaClient::GetOriginsForType(
+ quota::StorageType type,
+ GetOriginsCallback* callback_ptr) {
+ DCHECK(callback_ptr);
+ DCHECK(indexed_db_context_.get());
+ scoped_ptr<GetOriginsCallback> callback(callback_ptr);
+
+ // All databases are in the temp namespace for now.
+ if (type != quota::kStorageTypeTemporary) {
+ callback->Run(std::set<GURL>());
+ return;
+ }
+
+ if (origins_for_type_callbacks_.Add(callback.release())) {
+ scoped_refptr<GetAllOriginsTask> task(
+ new GetAllOriginsTask(this, webkit_thread_message_loop_));
+ task->Start();
+ }
+}
+
+void IndexedDBQuotaClient::GetOriginsForHost(
+ quota::StorageType type,
+ const std::string& host,
+ GetOriginsCallback* callback_ptr) {
+ DCHECK(callback_ptr);
+ DCHECK(indexed_db_context_.get());
+ scoped_ptr<GetOriginsCallback> callback(callback_ptr);
+
+ // All databases are in the temp namespace for now.
+ if (type != quota::kStorageTypeTemporary) {
+ callback->Run(std::set<GURL>());
+ return;
+ }
+
+ if (origins_for_host_callbacks_.Add(host, callback.release())) {
+ scoped_refptr<GetOriginsForHostTask> task(
+ new GetOriginsForHostTask(this, webkit_thread_message_loop_, host));
+ task->Start();
+ }
+}
+
+void IndexedDBQuotaClient::DeleteOriginData(const GURL& origin,
+ quota::StorageType type,
+ DeletionCallback* callback) {
+ // TODO(tzik): implement me
+ callback->Run(quota::kQuotaErrorNotSupported);
+ delete callback;
+}
+
+void IndexedDBQuotaClient::DidGetOriginUsage(
+ const GURL& origin_url, int64 usage) {
+ DCHECK(usage_for_origin_callbacks_.HasCallbacks(origin_url));
+ usage_for_origin_callbacks_.Run(origin_url, usage);
+}
+
+void IndexedDBQuotaClient::DidGetAllOrigins(const std::set<GURL>& origins) {
+ DCHECK(origins_for_type_callbacks_.HasCallbacks());
+ origins_for_type_callbacks_.Run(origins);
+}
+
+void IndexedDBQuotaClient::DidGetOriginsForHost(
+ const std::string& host, const std::set<GURL>& origins) {
+ DCHECK(origins_for_host_callbacks_.HasCallbacks(host));
+ origins_for_host_callbacks_.Run(host, origins);
+}
diff --git a/content/browser/in_process_webkit/indexed_db_quota_client.h b/content/browser/in_process_webkit/indexed_db_quota_client.h
new file mode 100644
index 0000000..59b3b23
--- /dev/null
+++ b/content/browser/in_process_webkit/indexed_db_quota_client.h
@@ -0,0 +1,80 @@
+// 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.
+
+#ifndef CONTENT_BROWER_IN_PROCESS_WEBKIT_QUOTA_CLIENT_H_
+#define CONTENT_BROWER_IN_PROCESS_WEBKIT_QUOTA_CLIENT_H_
+
+#include <set>
+#include <string>
+
+#include "base/memory/ref_counted.h"
+#include "base/message_loop_proxy.h"
+#include "webkit/quota/quota_client.h"
+#include "webkit/quota/quota_task.h"
+#include "webkit/quota/quota_types.h"
+
+class IndexedDBContext;
+
+// A QuotaClient implementation to integrate IndexedDB
+// with the quota management system. This interface is used
+// on the IO thread by the quota manager.
+class IndexedDBQuotaClient : public quota::QuotaClient,
+ public quota::QuotaTaskObserver {
+ public:
+ IndexedDBQuotaClient(
+ base::MessageLoopProxy* tracker_thread,
+ IndexedDBContext* indexed_db_context);
+ virtual ~IndexedDBQuotaClient();
+
+ // QuotaClient method overrides
+ virtual ID id() const OVERRIDE;
+ virtual void OnQuotaManagerDestroyed() OVERRIDE;
+ virtual void GetOriginUsage(const GURL& origin_url,
+ quota::StorageType type,
+ GetUsageCallback* callback) OVERRIDE;
+ virtual void GetOriginsForType(quota::StorageType type,
+ GetOriginsCallback* callback) OVERRIDE;
+ virtual void GetOriginsForHost(quota::StorageType type,
+ const std::string& host,
+ GetOriginsCallback* callback) OVERRIDE;
+ virtual void DeleteOriginData(const GURL& origin,
+ quota::StorageType type,
+ DeletionCallback* callback) OVERRIDE;
+ private:
+ class HelperTask;
+ class GetOriginUsageTask;
+ class GetOriginsTaskBase;
+ class GetAllOriginsTask;
+ class GetOriginsForHostTask;
+
+ typedef quota::CallbackQueueMap1
+ <GetUsageCallback*,
+ GURL, // origin
+ int64
+ > UsageForOriginCallbackMap;
+ typedef quota::CallbackQueue1
+ <GetOriginsCallback*,
+ const std::set<GURL>&
+ > OriginsForTypeCallbackQueue;
+ typedef quota::CallbackQueueMap1
+ <GetOriginsCallback*,
+ std::string, // host
+ const std::set<GURL>&
+ > OriginsForHostCallbackMap;
+
+ void DidGetOriginUsage(const GURL& origin_url, int64 usage);
+ void DidGetAllOrigins(const std::set<GURL>& origins);
+ void DidGetOriginsForHost(
+ const std::string& host, const std::set<GURL>& origins);
+
+ scoped_refptr<base::MessageLoopProxy> webkit_thread_message_loop_;
+ scoped_refptr<IndexedDBContext> indexed_db_context_;
+ UsageForOriginCallbackMap usage_for_origin_callbacks_;
+ OriginsForTypeCallbackQueue origins_for_type_callbacks_;
+ OriginsForHostCallbackMap origins_for_host_callbacks_;
+
+ DISALLOW_COPY_AND_ASSIGN(IndexedDBQuotaClient);
+};
+
+#endif // CONTENT_BROWER_IN_PROCESS_WEBKIT_QUOTA_CLIENT_H_
diff --git a/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc b/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc
new file mode 100644
index 0000000..d9f39cc
--- /dev/null
+++ b/content/browser/in_process_webkit/indexed_db_quota_client_unittest.cc
@@ -0,0 +1,104 @@
+// 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 <map>
+
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/memory/scoped_callback_factory.h"
+#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
+#include "chrome/test/testing_profile.h"
+#include "content/browser/in_process_webkit/indexed_db_context.h"
+#include "content/browser/in_process_webkit/indexed_db_quota_client.h"
+#include "content/browser/in_process_webkit/webkit_context.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/database/database_util.h"
+
+// Declared to shorten the line lengths.
+static const quota::StorageType kTemp = quota::kStorageTypeTemporary;
+static const quota::StorageType kPerm = quota::kStorageTypePersistent;
+
+using namespace webkit_database;
+
+// Base class for our test fixtures.
+class IndexedDBQuotaClientTest : public testing::Test {
+ public:
+ const GURL kOriginA;
+ const GURL kOriginB;
+
+ IndexedDBQuotaClientTest()
+ : kOriginA("http://host"),
+ kOriginB("http://host:8000"),
+ usage_(0),
+ callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
+ message_loop_(MessageLoop::TYPE_IO) {
+ TestingProfile profile;
+ idb_context_ = new IndexedDBContext(profile.GetWebKitContext(), NULL,
+ NULL, NULL);
+ }
+
+ int64 GetOriginUsage(
+ quota::QuotaClient* client,
+ const GURL& origin,
+ quota::StorageType type) {
+ usage_ = -1;
+ client->GetOriginUsage(origin, type,
+ callback_factory_.NewCallback(
+ &IndexedDBQuotaClientTest::OnGetOriginUsageComplete));
+ MessageLoop::current()->RunAllPending();
+ EXPECT_GT(usage_, -1);
+ return usage_;
+ }
+
+ IndexedDBContext* idb_context() { return idb_context_.get(); }
+
+ void SetFileSizeTo(const FilePath& path, int size) {
+ std::string junk(size, 'a');
+ ASSERT_EQ(size, file_util::WriteFile(path, junk.c_str(), size));
+ }
+
+
+ private:
+ void OnGetOriginUsageComplete(int64 usage) {
+ usage_ = usage;
+ }
+
+ int64 usage_;
+ scoped_refptr<IndexedDBContext> idb_context_;
+ base::ScopedCallbackFactory<IndexedDBQuotaClientTest> callback_factory_;
+ MessageLoop message_loop_;
+};
+
+
+TEST_F(IndexedDBQuotaClientTest, GetOriginUsage) {
+ IndexedDBQuotaClient client(
+ base::MessageLoopProxy::CreateForCurrentThread(),
+ idb_context());
+
+ ScopedTempDir temp_dir;
+ ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
+ FilePath indexeddb_dir = temp_dir.path().Append(
+ IndexedDBContext::kIndexedDBDirectory);
+ ASSERT_TRUE(file_util::CreateDirectory(indexeddb_dir));
+
+ idb_context()->set_data_path(indexeddb_dir);
+ FilePath file_path_origin_a = idb_context()->GetIndexedDBFilePath(
+ DatabaseUtil::GetOriginIdentifier(kOriginA));
+ FilePath file_path_origin_b = idb_context()->GetIndexedDBFilePath(
+ DatabaseUtil::GetOriginIdentifier(kOriginB));
+
+ SetFileSizeTo(file_path_origin_a, 6);
+ SetFileSizeTo(file_path_origin_b, 3);
+ EXPECT_EQ(6, GetOriginUsage(&client, kOriginA, kTemp));
+ EXPECT_EQ(0, GetOriginUsage(&client, kOriginA, kPerm));
+ EXPECT_EQ(3, GetOriginUsage(&client, kOriginB, kTemp));
+ EXPECT_EQ(0, GetOriginUsage(&client, kOriginB, kPerm));
+
+ SetFileSizeTo(file_path_origin_a, 1000);
+ EXPECT_EQ(1000, GetOriginUsage(&client, kOriginA, kTemp));
+ EXPECT_EQ(0, GetOriginUsage(&client, kOriginA, kPerm));
+ EXPECT_EQ(3, GetOriginUsage(&client, kOriginB, kTemp));
+ EXPECT_EQ(0, GetOriginUsage(&client, kOriginB, kPerm));
+}
diff --git a/content/browser/in_process_webkit/webkit_context.cc b/content/browser/in_process_webkit/webkit_context.cc
index 1983263..6359916 100644
--- a/content/browser/in_process_webkit/webkit_context.cc
+++ b/content/browser/in_process_webkit/webkit_context.cc
@@ -10,7 +10,9 @@
WebKitContext::WebKitContext(
bool is_incognito, const FilePath& data_path,
quota::SpecialStoragePolicy* special_storage_policy,
- bool clear_local_state_on_exit)
+ bool clear_local_state_on_exit,
+ quota::QuotaManagerProxy* quota_manager_proxy,
+ base::MessageLoopProxy* webkit_thread_loop)
: data_path_(is_incognito ? FilePath() : data_path),
is_incognito_(is_incognito),
clear_local_state_on_exit_(clear_local_state_on_exit),
@@ -19,7 +21,8 @@ WebKitContext::WebKitContext(
this, special_storage_policy))),
ALLOW_THIS_IN_INITIALIZER_LIST(
indexed_db_context_(new IndexedDBContext(
- this, special_storage_policy))) {
+ this, special_storage_policy, quota_manager_proxy,
+ webkit_thread_loop))) {
}
WebKitContext::~WebKitContext() {
@@ -38,11 +41,6 @@ WebKitContext::~WebKitContext() {
indexed_db_context_->set_clear_local_state_on_exit(
clear_local_state_on_exit_);
- IndexedDBContext* indexed_db_context = indexed_db_context_.release();
- if (!BrowserThread::DeleteSoon(
- BrowserThread::WEBKIT, FROM_HERE, indexed_db_context)) {
- delete indexed_db_context;
- }
}
void WebKitContext::PurgeMemory() {
diff --git a/content/browser/in_process_webkit/webkit_context.h b/content/browser/in_process_webkit/webkit_context.h
index 3c324a6..fa2d32d 100644
--- a/content/browser/in_process_webkit/webkit_context.h
+++ b/content/browser/in_process_webkit/webkit_context.h
@@ -15,7 +15,12 @@
#include "content/browser/in_process_webkit/dom_storage_context.h"
#include "content/browser/in_process_webkit/indexed_db_context.h"
+namespace base {
+class MessageLoopProxy;
+}
+
namespace quota {
+class QuotaManagerProxy;
class SpecialStoragePolicy;
}
@@ -30,7 +35,9 @@ class WebKitContext : public base::RefCountedThreadSafe<WebKitContext> {
public:
WebKitContext(bool is_incognito, const FilePath& data_path,
quota::SpecialStoragePolicy* special_storage_policy,
- bool clear_local_state_on_exit);
+ bool clear_local_state_on_exit,
+ quota::QuotaManagerProxy* quota_manager_proxy,
+ base::MessageLoopProxy* webkit_thread_loop);
const FilePath& data_path() const { return data_path_; }
bool is_incognito() const { return is_incognito_; }
@@ -78,7 +85,7 @@ class WebKitContext : public base::RefCountedThreadSafe<WebKitContext> {
bool clear_local_state_on_exit_;
scoped_ptr<DOMStorageContext> dom_storage_context_;
- scoped_ptr<IndexedDBContext> indexed_db_context_;
+ scoped_refptr<IndexedDBContext> indexed_db_context_;
DISALLOW_IMPLICIT_CONSTRUCTORS(WebKitContext);
};
diff --git a/content/browser/in_process_webkit/webkit_context_unittest.cc b/content/browser/in_process_webkit/webkit_context_unittest.cc
index 5232757..e27bece 100644
--- a/content/browser/in_process_webkit/webkit_context_unittest.cc
+++ b/content/browser/in_process_webkit/webkit_context_unittest.cc
@@ -33,14 +33,14 @@ TEST(WebKitContextTest, Basic) {
scoped_refptr<WebKitContext> context1(new WebKitContext(
profile.IsOffTheRecord(), profile.GetPath(),
profile.GetSpecialStoragePolicy(),
- false));
+ false, NULL, NULL));
EXPECT_TRUE(profile.GetPath() == context1->data_path());
EXPECT_TRUE(profile.IsOffTheRecord() == context1->is_incognito());
scoped_refptr<WebKitContext> context2(new WebKitContext(
profile.IsOffTheRecord(), profile.GetPath(),
profile.GetSpecialStoragePolicy(),
- false));
+ false, NULL, NULL));
EXPECT_TRUE(context1->data_path() == context2->data_path());
EXPECT_TRUE(context1->is_incognito() == context2->is_incognito());
}
@@ -56,7 +56,7 @@ TEST(WebKitContextTest, PurgeMemory) {
scoped_refptr<WebKitContext> context(new WebKitContext(
profile.IsOffTheRecord(), profile.GetPath(),
profile.GetSpecialStoragePolicy(),
- false));
+ false, NULL, NULL));
MockDOMStorageContext* mock_context = new MockDOMStorageContext(
context.get(), profile.GetSpecialStoragePolicy());
context->set_dom_storage_context(mock_context); // Takes ownership.
diff --git a/content/content_browser.gypi b/content/content_browser.gypi
index bc04327..6ceea3c 100644
--- a/content/content_browser.gypi
+++ b/content/content_browser.gypi
@@ -157,6 +157,8 @@
'browser/in_process_webkit/indexed_db_dispatcher_host.h',
'browser/in_process_webkit/indexed_db_key_utility_client.cc',
'browser/in_process_webkit/indexed_db_key_utility_client.h',
+ 'browser/in_process_webkit/indexed_db_quota_client.cc',
+ 'browser/in_process_webkit/indexed_db_quota_client.h',
'browser/in_process_webkit/indexed_db_transaction_callbacks.cc',
'browser/in_process_webkit/indexed_db_transaction_callbacks.h',
'browser/in_process_webkit/session_storage_namespace.cc',