diff options
Diffstat (limited to 'content/common')
-rw-r--r-- | content/common/child_thread.cc | 4 | ||||
-rw-r--r-- | content/common/child_thread.h | 7 | ||||
-rw-r--r-- | content/common/content_message_generator.h | 1 | ||||
-rw-r--r-- | content/common/quota_dispatcher.cc | 90 | ||||
-rw-r--r-- | content/common/quota_dispatcher.h | 61 | ||||
-rw-r--r-- | content/common/quota_dispatcher_dummy.cc | 21 | ||||
-rw-r--r-- | content/common/quota_messages.h | 43 |
7 files changed, 227 insertions, 0 deletions
diff --git a/content/common/child_thread.cc b/content/common/child_thread.cc index 574b43b..92d2cca 100644 --- a/content/common/child_thread.cc +++ b/content/common/child_thread.cc @@ -13,6 +13,7 @@ #include "content/common/content_switches.h" #include "content/common/file_system/file_system_dispatcher.h" #include "content/common/notification_service.h" +#include "content/common/quota_dispatcher.h" #include "content/common/resource_dispatcher.h" #include "content/common/socket_stream_dispatcher.h" #include "ipc/ipc_logging.h" @@ -53,6 +54,7 @@ void ChildThread::Init() { resource_dispatcher_.reset(new ResourceDispatcher(this)); socket_stream_dispatcher_.reset(new SocketStreamDispatcher()); file_system_dispatcher_.reset(new FileSystemDispatcher()); + quota_dispatcher_.reset(new QuotaDispatcher()); sync_message_filter_ = new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); @@ -150,6 +152,8 @@ bool ChildThread::OnMessageReceived(const IPC::Message& msg) { return true; if (file_system_dispatcher_->OnMessageReceived(msg)) return true; + if (quota_dispatcher_->OnMessageReceived(msg)) + return true; bool handled = true; IPC_BEGIN_MESSAGE_MAP(ChildThread, msg) diff --git a/content/common/child_thread.h b/content/common/child_thread.h index 4b27ab7..f2ac864 100644 --- a/content/common/child_thread.h +++ b/content/common/child_thread.h @@ -14,6 +14,7 @@ class FileSystemDispatcher; class MessageLoop; class NotificationService; +class QuotaDispatcher; class ResourceDispatcher; class SocketStreamDispatcher; @@ -56,6 +57,10 @@ class ChildThread : public IPC::Channel::Listener, return file_system_dispatcher_.get(); } + QuotaDispatcher* quota_dispatcher() const { + return quota_dispatcher_.get(); + } + // Safe to call on any thread, as long as it's guaranteed that the thread's // lifetime is less than the main thread. IPC::SyncMessageFilter* sync_message_filter(); @@ -122,6 +127,8 @@ class ChildThread : public IPC::Channel::Listener, scoped_ptr<FileSystemDispatcher> file_system_dispatcher_; + scoped_ptr<QuotaDispatcher> quota_dispatcher_; + DISALLOW_COPY_AND_ASSIGN(ChildThread); }; diff --git a/content/common/content_message_generator.h b/content/common/content_message_generator.h index eab0100..10c9fd8 100644 --- a/content/common/content_message_generator.h +++ b/content/common/content_message_generator.h @@ -26,6 +26,7 @@ #include "content/common/p2p_messages.h" #include "content/common/pepper_file_messages.h" #include "content/common/plugin_messages.h" +#include "content/common/quota_messages.h" #include "content/common/resource_messages.h" #include "content/common/speech_input_messages.h" #include "content/common/socket_stream_messages.h" diff --git a/content/common/quota_dispatcher.cc b/content/common/quota_dispatcher.cc new file mode 100644 index 0000000..0ecf1c4 --- /dev/null +++ b/content/common/quota_dispatcher.cc @@ -0,0 +1,90 @@ +// 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/common/quota_dispatcher.h" + +#include "content/common/child_thread.h" +#include "content/common/quota_messages.h" +#include "googleurl/src/gurl.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaCallbacks.h" + +using WebKit::WebStorageQuotaCallbacks; +using WebKit::WebStorageQuotaError; +using WebKit::WebStorageQuotaType; + +QuotaDispatcher::QuotaDispatcher() { +} + +QuotaDispatcher::~QuotaDispatcher() { + IDMap<WebStorageQuotaCallbacks>::iterator iter(&pending_quota_callbacks_); + while (!iter.IsAtEnd()) { + iter.GetCurrentValue()->didFail(WebKit::WebStorageQuotaErrorAbort); + iter.Advance(); + } +} + +bool QuotaDispatcher::OnMessageReceived(const IPC::Message& msg) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(QuotaDispatcher, msg) + IPC_MESSAGE_HANDLER(QuotaMsg_DidGrantStorageQuota, + DidGrantStorageQuota) + IPC_MESSAGE_HANDLER(QuotaMsg_DidQueryStorageUsageAndQuota, + DidQueryStorageUsageAndQuota); + IPC_MESSAGE_HANDLER(QuotaMsg_DidFail, DidFail); + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void QuotaDispatcher::QueryStorageUsageAndQuota( + const GURL& origin_url, + WebStorageQuotaType type, + WebStorageQuotaCallbacks* callbacks) { + DCHECK(callbacks); + int request_id = pending_quota_callbacks_.Add(callbacks); + ChildThread::current()->Send(new QuotaHostMsg_QueryStorageUsageAndQuota( + request_id, origin_url, type)); +} + +void QuotaDispatcher::RequestStorageQuota( + const GURL& origin_url, + WebStorageQuotaType type, + unsigned long long requested_size, + WebStorageQuotaCallbacks* callbacks) { + DCHECK(callbacks); + int request_id = pending_quota_callbacks_.Add(callbacks); + ChildThread::current()->Send(new QuotaHostMsg_RequestStorageQuota( + request_id, origin_url, type, requested_size)); +} + +void QuotaDispatcher::DidGrantStorageQuota( + int request_id, + int64 granted_quota) { + WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup( + request_id); + DCHECK(callbacks); + callbacks->didGrantStorageQuota(granted_quota); + pending_quota_callbacks_.Remove(request_id); +} + +void QuotaDispatcher::DidQueryStorageUsageAndQuota( + int request_id, + int64 current_usage, + int64 current_quota) { + WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup( + request_id); + DCHECK(callbacks); + callbacks->didQueryStorageUsageAndQuota(current_usage, current_quota); + pending_quota_callbacks_.Remove(request_id); +} + +void QuotaDispatcher::DidFail( + int request_id, + WebStorageQuotaError error) { + WebStorageQuotaCallbacks* callbacks = pending_quota_callbacks_.Lookup( + request_id); + DCHECK(callbacks); + callbacks->didFail(error); + pending_quota_callbacks_.Remove(request_id); +} diff --git a/content/common/quota_dispatcher.h b/content/common/quota_dispatcher.h new file mode 100644 index 0000000..d283b28 --- /dev/null +++ b/content/common/quota_dispatcher.h @@ -0,0 +1,61 @@ +// 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_COMMON_QUOTA_DISPATCHER_H_ +#define CONTENT_COMMON_QUOTA_DISPATCHER_H_ + +#include <map> +#include <set> + +#include "base/basictypes.h" +#include "base/id_map.h" +#include "ipc/ipc_channel.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaError.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaType.h" + +class GURL; + +namespace IPC { +class Message; +} + +namespace WebKit { +class WebStorageQuotaCallbacks; +} + +// Dispatches and sends quota related messages sent to/from a child +// process from/to the main browser process. There is one instance +// per child process. Messages are dispatched on the main child thread. +class QuotaDispatcher : public IPC::Channel::Listener { + public: + QuotaDispatcher(); + ~QuotaDispatcher(); + + // IPC::Channel::Listener implementation. + virtual bool OnMessageReceived(const IPC::Message& msg); + + void QueryStorageUsageAndQuota(const GURL& gurl, + WebKit::WebStorageQuotaType type, + WebKit::WebStorageQuotaCallbacks* callbacks); + void RequestStorageQuota(const GURL& gurl, + WebKit::WebStorageQuotaType type, + unsigned long long requested_size, + WebKit::WebStorageQuotaCallbacks* callbacks); + + private: + // Message handlers. + void DidQueryStorageUsageAndQuota(int request_id, + int64 current_usage, + int64 current_quota); + void DidGrantStorageQuota(int request_id, + int64 granted_quota); + void DidFail(int request_id, + WebKit::WebStorageQuotaError error); + + IDMap<WebKit::WebStorageQuotaCallbacks> pending_quota_callbacks_; + + DISALLOW_COPY_AND_ASSIGN(QuotaDispatcher); +}; + +#endif // CONTENT_COMMON_QUOTA_DISPATCHER_H_ diff --git a/content/common/quota_dispatcher_dummy.cc b/content/common/quota_dispatcher_dummy.cc new file mode 100644 index 0000000..7eec28b --- /dev/null +++ b/content/common/quota_dispatcher_dummy.cc @@ -0,0 +1,21 @@ +// 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/common/quota_dispatcher.h" + +#include "base/compiler_specific.h" + +// QuotaDispatcher ------------------------------------------------------------- + +QuotaDispatcher::QuotaDispatcher() { +} + +QuotaDispatcher::~QuotaDispatcher() { +} + +// QuotaDispatcher implementation ---------------------------------------------- + +bool QuotaDispatcher::OnMessageReceived(const IPC::Message& message) { + return false; +} diff --git a/content/common/quota_messages.h b/content/common/quota_messages.h new file mode 100644 index 0000000..205c4a8 --- /dev/null +++ b/content/common/quota_messages.h @@ -0,0 +1,43 @@ +// 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. + +// Multiply-included message file, hence no include guard. + +#include "base/basictypes.h" +#include "ipc/ipc_message_macros.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaError.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageQuotaType.h" + +#define IPC_MESSAGE_START QuotaMsgStart + +IPC_ENUM_TRAITS(WebKit::WebStorageQuotaType) +IPC_ENUM_TRAITS(WebKit::WebStorageQuotaError) + +// Quota messages sent from the browser to the child process. + +IPC_MESSAGE_CONTROL2(QuotaMsg_DidGrantStorageQuota, + int /* request_id */, + int64 /* granted_quota */) + +IPC_MESSAGE_CONTROL3(QuotaMsg_DidQueryStorageUsageAndQuota, + int /* request_id */, + int64 /* current_usage */, + int64 /* current_quota */) + +IPC_MESSAGE_CONTROL2(QuotaMsg_DidFail, + int /* request_id */, + WebKit::WebStorageQuotaError /* error */) + +// Quota messages sent from the child process to the browser. + +IPC_MESSAGE_CONTROL3(QuotaHostMsg_QueryStorageUsageAndQuota, + int /* request_id */, + GURL /* origin_url */, + WebKit::WebStorageQuotaType /* type */) + +IPC_MESSAGE_CONTROL4(QuotaHostMsg_RequestStorageQuota, + int /* request_id */, + GURL /* origin_url */, + WebKit::WebStorageQuotaType /* type */, + int64 /* requested_size */) |