Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1406)

Unified Diff: content/browser/dom_storage/dom_storage_message_filter_new.cc

Issue 9667013: DOMStorageMessageFilter implementation that utilizes the new dom_storage classes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/dom_storage/dom_storage_message_filter_new.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/dom_storage/dom_storage_message_filter_new.cc
===================================================================
--- content/browser/dom_storage/dom_storage_message_filter_new.cc (revision 0)
+++ content/browser/dom_storage/dom_storage_message_filter_new.cc (working copy)
@@ -2,88 +2,78 @@
// 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/dom_storage_message_filter.h"
+#include "content/browser/dom_storage/dom_storage_message_filter_new.h"
+#ifdef ENABLE_NEW_DOM_STORAGE_BACKEND
+
+#include "base/auto_reset.h"
#include "base/bind.h"
#include "base/nullable_string16.h"
-#include "content/browser/in_process_webkit/dom_storage_area.h"
-#include "content/browser/in_process_webkit/dom_storage_context_impl.h"
-#include "content/browser/in_process_webkit/dom_storage_namespace.h"
+#include "base/threading/sequenced_worker_pool.h"
+#include "base/utf_string_conversions.h"
+#include "content/browser/dom_storage/dom_storage_context_impl_new.h"
#include "content/common/dom_storage_messages.h"
-#include "content/public/browser/browser_thread.h"
#include "googleurl/src/gurl.h"
+#include "webkit/dom_storage/dom_storage_area.h"
+#include "webkit/dom_storage/dom_storage_host.h"
+#include "webkit/dom_storage/dom_storage_task_runner.h"
-using content::BrowserMessageFilter;
using content::BrowserThread;
using WebKit::WebStorageArea;
-DOMStorageMessageFilter* DOMStorageMessageFilter::storage_event_message_filter =
- NULL;
-const GURL* DOMStorageMessageFilter::storage_event_url_ = NULL;
+DOMStorageMessageFilter::DOMStorageMessageFilter(
+ int unused,
+ DOMStorageContextImpl* context)
+ : context_(context->context()),
+ is_dispatching_message_(false) {
+}
-DOMStorageMessageFilter::
-ScopedStorageEventContext::ScopedStorageEventContext(
- DOMStorageMessageFilter* dispatcher_message_filter, const GURL* url) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
- DCHECK(!storage_event_message_filter);
- DCHECK(!storage_event_url_);
- storage_event_message_filter = dispatcher_message_filter;
- storage_event_url_ = url;
- DCHECK(storage_event_message_filter);
- DCHECK(storage_event_url_);
+DOMStorageMessageFilter::~DOMStorageMessageFilter() {
+ DCHECK(!host_.get());
}
-DOMStorageMessageFilter::
-ScopedStorageEventContext::~ScopedStorageEventContext() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
- DCHECK(storage_event_message_filter);
- DCHECK(storage_event_url_);
- storage_event_message_filter = NULL;
- storage_event_url_ = NULL;
+void DOMStorageMessageFilter::InitializeInSequence() {
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
+ host_.reset(new dom_storage::DomStorageHost(context_));
+ context_->AddEventObserver(this);
}
-DOMStorageMessageFilter::DOMStorageMessageFilter(
- int process_id, DOMStorageContextImpl* dom_storage_context)
- : dom_storage_context_(dom_storage_context),
- process_id_(process_id) {
+void DOMStorageMessageFilter::UninitializeInSequence() {
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
+ context_->RemoveEventObserver(this);
+ host_.reset();
}
-DOMStorageMessageFilter::~DOMStorageMessageFilter() {
- if (peer_handle())
- Context()->UnregisterMessageFilter(this);
+void DOMStorageMessageFilter::OnFilterAdded(IPC::Channel* channel) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ BrowserMessageFilter::OnFilterAdded(channel);
+ context_->task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind(&DOMStorageMessageFilter::InitializeInSequence, this));
}
-void DOMStorageMessageFilter::OnChannelConnected(int32 peer_pid) {
- BrowserMessageFilter::OnChannelConnected(peer_pid);
- if (peer_handle())
- Context()->RegisterMessageFilter(this);
+void DOMStorageMessageFilter::OnFilterRemoved() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ BrowserMessageFilter::OnFilterRemoved();
+ context_->task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind(&DOMStorageMessageFilter::UninitializeInSequence, this));
}
-/* static */
-void DOMStorageMessageFilter::DispatchStorageEvent(const NullableString16& key,
- const NullableString16& old_value, const NullableString16& new_value,
- const string16& origin, const GURL& url, bool is_local_storage) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
- DCHECK(is_local_storage); // Only LocalStorage is implemented right now.
- DCHECK(storage_event_message_filter);
- DOMStorageMsg_Event_Params params;
- params.key = key;
- params.old_value = old_value;
- params.new_value = new_value;
- params.origin = origin;
- params.url = *storage_event_url_; // The url passed in is junk.
- params.storage_type = is_local_storage ? DOM_STORAGE_LOCAL
- : DOM_STORAGE_SESSION;
- // The storage_event_message_filter is the DOMStorageMessageFilter that is up
- // in the current call stack since it caused the storage event to fire.
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&DOMStorageMessageFilter::OnStorageEvent,
- storage_event_message_filter, params));
+base::TaskRunner* DOMStorageMessageFilter::OverrideTaskRunnerForMessage(
+ const IPC::Message& message) {
+ if (IPC_MESSAGE_CLASS(message) == DOMStorageMsgStart)
+ return context_->task_runner();
+ return NULL;
}
bool DOMStorageMessageFilter::OnMessageReceived(const IPC::Message& message,
bool* message_was_ok) {
+ if (IPC_MESSAGE_CLASS(message) != DOMStorageMsgStart)
+ return false;
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
+ DCHECK(host_.get());
+ AutoReset<bool> auto_reset(&is_dispatching_message_, true);
bool handled = true;
IPC_BEGIN_MESSAGE_MAP_EX(DOMStorageMessageFilter, message, *message_was_ok)
IPC_MESSAGE_HANDLER(DOMStorageHostMsg_OpenStorageArea, OnOpenStorageArea)
@@ -96,128 +86,120 @@
IPC_MESSAGE_HANDLER(DOMStorageHostMsg_Clear, OnClear)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
-
return handled;
}
-void DOMStorageMessageFilter::OnDestruct() const {
- BrowserThread::DeleteOnIOThread::Destruct(this);
-}
-
-void DOMStorageMessageFilter::OverrideThreadForMessage(
- const IPC::Message& message,
- BrowserThread::ID* thread) {
- if (IPC_MESSAGE_CLASS(message) == DOMStorageMsgStart)
- *thread = BrowserThread::WEBKIT_DEPRECATED;
-}
-
void DOMStorageMessageFilter::OnOpenStorageArea(int64 namespace_id,
const string16& origin,
- int64* storage_area_id) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
-
- DOMStorageNamespace* storage_namespace =
- Context()->GetStorageNamespace(namespace_id, true);
- if (!storage_namespace) {
- *storage_area_id = DOMStorageContextImpl::kInvalidStorageId;
- return;
- }
- DOMStorageArea* storage_area = storage_namespace->GetStorageArea(origin);
- *storage_area_id = storage_area->id();
+ int64* connection_id) {
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
+ *connection_id = host_->OpenStorageArea(namespace_id, GURL(origin));
}
-void DOMStorageMessageFilter::OnCloseStorageArea(int64 storage_area_id) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
- // TODO(michaeln): make use of this message in the new backend.
+void DOMStorageMessageFilter::OnCloseStorageArea(int64 connection_id) {
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
+ host_->CloseStorageArea(connection_id);
}
-void DOMStorageMessageFilter::OnLength(int64 storage_area_id,
+void DOMStorageMessageFilter::OnLength(int64 connection_id,
unsigned* length) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
- DOMStorageArea* storage_area = Context()->GetStorageArea(storage_area_id);
- if (!storage_area) {
- *length = 0;
- } else {
- *length = storage_area->Length();
- }
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
+ *length = host_->GetAreaLength(connection_id);
}
-void DOMStorageMessageFilter::OnKey(int64 storage_area_id, unsigned index,
+void DOMStorageMessageFilter::OnKey(int64 connection_id, unsigned index,
NullableString16* key) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
- DOMStorageArea* storage_area = Context()->GetStorageArea(storage_area_id);
- if (!storage_area) {
- *key = NullableString16(true);
- } else {
- *key = storage_area->Key(index);
- }
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
+ *key = host_->GetAreaKey(connection_id, index);
}
-void DOMStorageMessageFilter::OnGetItem(int64 storage_area_id,
+void DOMStorageMessageFilter::OnGetItem(int64 connection_id,
const string16& key,
NullableString16* value) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
- DOMStorageArea* storage_area = Context()->GetStorageArea(storage_area_id);
- if (!storage_area) {
- *value = NullableString16(true);
- } else {
- *value = storage_area->GetItem(key);
- }
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
+ *value = host_->GetAreaItem(connection_id, key);
}
void DOMStorageMessageFilter::OnSetItem(
- int64 storage_area_id, const string16& key,
- const string16& value, const GURL& url,
+ int64 connection_id, const string16& key,
+ const string16& value, const GURL& page_url,
WebKit::WebStorageArea::Result* result, NullableString16* old_value) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
- DOMStorageArea* storage_area = Context()->GetStorageArea(storage_area_id);
- if (!storage_area) {
- *old_value = NullableString16(true);
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
+ *old_value = NullableString16(true);
+ if (host_->SetAreaItem(connection_id, key, value, page_url, old_value))
*result = WebKit::WebStorageArea::ResultOK;
- return;
- }
-
- ScopedStorageEventContext scope(this, &url);
- *old_value = storage_area->SetItem(key, value, result);
+ else
+ *result = WebKit::WebStorageArea::ResultBlockedByQuota;
}
void DOMStorageMessageFilter::OnRemoveItem(
- int64 storage_area_id, const string16& key, const GURL& url,
+ int64 connection_id, const string16& key, const GURL& pageUrl,
NullableString16* old_value) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
- DOMStorageArea* storage_area = Context()->GetStorageArea(storage_area_id);
- if (!storage_area) {
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
+ string16 old_string_value;
+ if (host_->RemoveAreaItem(connection_id, key, pageUrl, &old_string_value))
+ *old_value = NullableString16(old_string_value, false);
+ else
*old_value = NullableString16(true);
- return;
- }
-
- ScopedStorageEventContext scope(this, &url);
- *old_value = storage_area->RemoveItem(key);
}
-void DOMStorageMessageFilter::OnClear(int64 storage_area_id, const GURL& url,
+void DOMStorageMessageFilter::OnClear(int64 connection_id, const GURL& page_url,
bool* something_cleared) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED));
- DOMStorageArea* storage_area = Context()->GetStorageArea(storage_area_id);
- if (!storage_area) {
- *something_cleared = false;
- return;
- }
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
+ *something_cleared = host_->ClearArea(connection_id, page_url);
+}
- ScopedStorageEventContext scope(this, &url);
- *something_cleared = storage_area->Clear();
+void DOMStorageMessageFilter::OnDomStorageItemSet(
+ const dom_storage::DomStorageArea* area,
+ const string16& key,
+ const string16& new_value,
+ const NullableString16& old_value,
+ const GURL& page_url) {
+ SendDomStorageEvent(area, page_url,
+ NullableString16(key, false),
+ NullableString16(new_value, false),
+ old_value);
}
-void DOMStorageMessageFilter::OnStorageEvent(
- const DOMStorageMsg_Event_Params& params) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- const DOMStorageContextImpl::MessageFilterSet* set =
- Context()->GetMessageFilterSet();
- DOMStorageContextImpl::MessageFilterSet::const_iterator cur = set->begin();
- while (cur != set->end()) {
- // The renderer that generates the event handles it itself.
- if (*cur != this)
- (*cur)->Send(new DOMStorageMsg_Event(params));
- ++cur;
- }
+void DOMStorageMessageFilter::OnDomStorageItemRemoved(
+ const dom_storage::DomStorageArea* area,
+ const string16& key,
+ const string16& old_value,
+ const GURL& page_url) {
+ SendDomStorageEvent(area, page_url,
+ NullableString16(key, false),
+ NullableString16(true),
+ NullableString16(old_value, false));
}
+
+void DOMStorageMessageFilter::OnDomStorageAreaCleared(
+ const dom_storage::DomStorageArea* area,
+ const GURL& page_url) {
+ SendDomStorageEvent(area, page_url,
+ NullableString16(true),
+ NullableString16(true),
+ NullableString16(true));
+}
+
+void DOMStorageMessageFilter::SendDomStorageEvent(
+ const dom_storage::DomStorageArea* area,
+ const GURL& page_url,
+ const NullableString16& key,
+ const NullableString16& new_value,
+ const NullableString16& old_value) {
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
+ // Only send if this renderer is not the source of the event.
+ if (is_dispatching_message_)
+ return;
+ DOMStorageMsg_Event_Params params;
+ // TODO(michaeln): change the origin type to be GURL in ipc params.
+ params.origin = UTF8ToUTF16(area->origin().spec());
+ params.url = page_url;
+ params.storage_type = DOM_STORAGE_LOCAL;
+ params.key = key;
+ params.new_value = new_value;
+ params.old_value = old_value;
+ Send(new DOMStorageMsg_Event(params));
+}
+
+#endif // ENABLE_NEW_DOM_STORAGE_BACKEND
« no previous file with comments | « content/browser/dom_storage/dom_storage_message_filter_new.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698