summaryrefslogtreecommitdiffstats
path: root/content/browser
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-27 13:20:14 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-27 13:20:14 +0000
commit595765cf3c42fda899d308e6f875dd5627837989 (patch)
treeca06cb28f9a65f472011b0dc5f94d9b0ee9f653c /content/browser
parent216f6923c677b509de56a4735f91eafdd21d6fc2 (diff)
downloadchromium_src-595765cf3c42fda899d308e6f875dd5627837989.zip
chromium_src-595765cf3c42fda899d308e6f875dd5627837989.tar.gz
chromium_src-595765cf3c42fda899d308e6f875dd5627837989.tar.bz2
Add 1st cut of QuotaManager code
No persistent storage support yet. Some notes: - There are a lot of TODOs especially for persistent type storage handling. - QuotaTask base class is for now only subclassed by QuotaInitializeTask, but it is planned to add more subclasses. BUG=61676,79639 TEST=QuotaManagerTest.* Review URL: http://codereview.chromium.org/6826052 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83145 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser')
-rw-r--r--content/browser/renderer_host/browser_render_process_host.cc2
-rw-r--r--content/browser/renderer_host/quota_dispatcher_host.cc101
-rw-r--r--content/browser/renderer_host/quota_dispatcher_host.h15
3 files changed, 109 insertions, 9 deletions
diff --git a/content/browser/renderer_host/browser_render_process_host.cc b/content/browser/renderer_host/browser_render_process_host.cc
index 06081a4..cf43b2f 100644
--- a/content/browser/renderer_host/browser_render_process_host.cc
+++ b/content/browser/renderer_host/browser_render_process_host.cc
@@ -419,7 +419,7 @@ void BrowserRenderProcessHost::CreateMessageFilters() {
channel_->AddFilter(new TraceMessageFilter());
channel_->AddFilter(new ResolveProxyMsgHelper(NULL));
- channel_->AddFilter(new QuotaDispatcherHost());
+ channel_->AddFilter(new QuotaDispatcherHost(profile()->GetQuotaManager()));
}
int BrowserRenderProcessHost::GetNextRoutingID() {
diff --git a/content/browser/renderer_host/quota_dispatcher_host.cc b/content/browser/renderer_host/quota_dispatcher_host.cc
index aef300c..9d1449a 100644
--- a/content/browser/renderer_host/quota_dispatcher_host.cc
+++ b/content/browser/renderer_host/quota_dispatcher_host.cc
@@ -4,8 +4,84 @@
#include "content/browser/renderer_host/quota_dispatcher_host.h"
+#include "base/memory/scoped_callback_factory.h"
#include "content/common/quota_messages.h"
#include "googleurl/src/gurl.h"
+#include "webkit/quota/quota_manager.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaError.h"
+
+using quota::QuotaManager;
+using quota::QuotaStatusCode;
+using quota::StorageType;
+using WebKit::WebStorageQuotaError;
+
+// Created one per request to carry the request's request_id around.
+// Dispatches requests from renderer/worker to the QuotaManager and
+// sends back the response to the renderer/worker.
+class QuotaDispatcherHost::RequestDispatcher {
+ public:
+ RequestDispatcher(QuotaDispatcherHost* dispatcher_host,
+ quota::QuotaManager* quota_manager,
+ int request_id)
+ : dispatcher_host_(dispatcher_host),
+ quota_manager_(quota_manager),
+ request_id_(request_id),
+ callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ DCHECK(quota_manager_);
+ dispatcher_host_->outstanding_requests_.AddWithID(this, request_id_);
+ }
+
+ ~RequestDispatcher() {
+ }
+
+ void QueryStorageUsageAndQuota(const GURL& origin, StorageType type) {
+ quota_manager_->GetUsageAndQuota(origin, type,
+ callback_factory_.NewCallback(
+ &RequestDispatcher::DidQueryStorageUsageAndQuota));
+ }
+
+ void RequestStorageQuota(const GURL& origin, StorageType type,
+ int64 requested_size) {
+ quota_manager_->RequestQuota(origin, type, requested_size,
+ callback_factory_.NewCallback(
+ &RequestDispatcher::DidRequestStorageQuota));
+ }
+
+ private:
+ void DidQueryStorageUsageAndQuota(
+ QuotaStatusCode status, int64 usage, int64 quota) {
+ DCHECK(dispatcher_host_);
+ if (status != quota::kQuotaStatusOk) {
+ dispatcher_host_->Send(new QuotaMsg_DidFail(
+ request_id_, static_cast<WebStorageQuotaError>(status)));
+ } else {
+ dispatcher_host_->Send(new QuotaMsg_DidQueryStorageUsageAndQuota(
+ request_id_, usage, quota));
+ }
+ dispatcher_host_->outstanding_requests_.Remove(request_id_);
+ }
+
+ void DidRequestStorageQuota(QuotaStatusCode status, int64 granted_quota) {
+ DCHECK(dispatcher_host_);
+ if (status != quota::kQuotaStatusOk) {
+ dispatcher_host_->Send(new QuotaMsg_DidFail(
+ request_id_, static_cast<WebStorageQuotaError>(status)));
+ } else {
+ dispatcher_host_->Send(new QuotaMsg_DidGrantStorageQuota(
+ request_id_, granted_quota));
+ }
+ dispatcher_host_->outstanding_requests_.Remove(request_id_);
+ }
+
+ QuotaDispatcherHost* dispatcher_host_;
+ quota::QuotaManager* quota_manager_;
+ int request_id_;
+ base::ScopedCallbackFactory<RequestDispatcher> callback_factory_;
+};
+
+QuotaDispatcherHost::QuotaDispatcherHost(QuotaManager* quota_manager)
+ : quota_manager_(quota_manager) {
+}
QuotaDispatcherHost::~QuotaDispatcherHost() {
}
@@ -28,10 +104,9 @@ void QuotaDispatcherHost::OnQueryStorageUsageAndQuota(
int request_id,
const GURL& origin,
WebKit::WebStorageQuotaType type) {
- // TODO(kinuko): not implemented yet.
- Send(new QuotaMsg_DidFail(
- request_id,
- WebKit::WebStorageQuotaErrorNotSupported));
+ RequestDispatcher* dispatcher = new RequestDispatcher(
+ this, quota_manager_, request_id);
+ dispatcher->QueryStorageUsageAndQuota(origin, static_cast<StorageType>(type));
}
void QuotaDispatcherHost::OnRequestStorageQuota(
@@ -39,8 +114,18 @@ void QuotaDispatcherHost::OnRequestStorageQuota(
const GURL& origin,
WebKit::WebStorageQuotaType type,
int64 requested_size) {
- // TODO(kinuko): not implemented yet.
- Send(new QuotaMsg_DidFail(
- request_id,
- WebKit::WebStorageQuotaErrorNotSupported));
+ RequestDispatcher* dispatcher = new RequestDispatcher(
+ this, quota_manager_, request_id);
+ dispatcher->RequestStorageQuota(origin, static_cast<StorageType>(type),
+ requested_size);
}
+
+COMPILE_ASSERT(int(WebKit::WebStorageQuotaTypeTemporary) == \
+ int(quota::kStorageTypeTemporary), mismatching_enums);
+COMPILE_ASSERT(int(WebKit::WebStorageQuotaTypePersistent) == \
+ int(quota::kStorageTypePersistent), mismatching_enums);
+
+COMPILE_ASSERT(int(WebKit::WebStorageQuotaErrorNotSupported) == \
+ int(quota::kQuotaErrorNotSupported), mismatching_enums);
+COMPILE_ASSERT(int(WebKit::WebStorageQuotaErrorAbort) == \
+ int(quota::kQuotaErrorAbort), mismatching_enums);
diff --git a/content/browser/renderer_host/quota_dispatcher_host.h b/content/browser/renderer_host/quota_dispatcher_host.h
index 60227b4..5a9fd4a 100644
--- a/content/browser/renderer_host/quota_dispatcher_host.h
+++ b/content/browser/renderer_host/quota_dispatcher_host.h
@@ -6,13 +6,23 @@
#define CONTENT_BROWSER_RENDERER_HOST_QUOTA_DISPATCHER_HOST_H_
#include "base/basictypes.h"
+#include "base/id_map.h"
#include "content/browser/browser_message_filter.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaType.h"
class GURL;
+namespace IPC {
+class Message;
+}
+
+namespace quota {
+class QuotaManager;
+}
+
class QuotaDispatcherHost : public BrowserMessageFilter {
public:
+ QuotaDispatcherHost(quota::QuotaManager* quota_manager);
~QuotaDispatcherHost();
virtual bool OnMessageReceived(const IPC::Message& message,
bool* message_was_ok);
@@ -27,6 +37,11 @@ class QuotaDispatcherHost : public BrowserMessageFilter {
const GURL& origin_url,
WebKit::WebStorageQuotaType type,
int64 requested_size);
+
+ quota::QuotaManager* quota_manager_;
+
+ class RequestDispatcher;
+ IDMap<RequestDispatcher, IDMapOwnPointer> outstanding_requests_;
};
#endif // CONTENT_BROWSER_RENDERER_HOST_QUOTA_DISPATCHER_HOST_H_