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

Unified Diff: chrome/browser/in_process_webkit/dom_storage_dispatcher_host.cc

Issue 258010: Reverting 27759. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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
Index: chrome/browser/in_process_webkit/dom_storage_dispatcher_host.cc
===================================================================
--- chrome/browser/in_process_webkit/dom_storage_dispatcher_host.cc (revision 27849)
+++ chrome/browser/in_process_webkit/dom_storage_dispatcher_host.cc (working copy)
@@ -13,6 +13,23 @@
#include "chrome/browser/renderer_host/browser_render_process_host.h"
#include "chrome/common/render_messages.h"
+DOMStorageDispatcherHost* DOMStorageDispatcherHost::current_ = NULL;
+
+DOMStorageDispatcherHost::
+AutoSetCurrentDispatcherHost::AutoSetCurrentDispatcherHost(
+ DOMStorageDispatcherHost* dispatcher_host) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
+ DCHECK(!current_);
+ current_ = dispatcher_host;
+}
+
+DOMStorageDispatcherHost::
+AutoSetCurrentDispatcherHost::~AutoSetCurrentDispatcherHost() {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
+ DCHECK(current_);
+ current_ = NULL;
+}
+
DOMStorageDispatcherHost::DOMStorageDispatcherHost(
IPC::Message::Sender* message_sender, WebKitContext* webkit_context,
WebKitThread* webkit_thread)
@@ -32,13 +49,18 @@
}
void DOMStorageDispatcherHost::Init(base::ProcessHandle process_handle) {
- DCHECK(!process_handle_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ DCHECK(message_sender_); // Make sure Shutdown() has not yet been called.
+ DCHECK(!process_handle_); // Make sure Init() has not yet been called.
+ DCHECK(process_handle);
+ Context()->RegisterDispatcherHost(this);
process_handle_ = process_handle;
- DCHECK(process_handle_);
}
void DOMStorageDispatcherHost::Shutdown() {
if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
+ if (process_handle_) // Init() was called
+ Context()->UnregisterDispatcherHost(this);
message_sender_ = NULL;
if (!ever_used_) {
// No need to (possibly) spin up the WebKit thread for a no-op.
@@ -58,12 +80,24 @@
DCHECK(!shutdown_);
shutdown_ = true;
- // TODO(jorlow): If we have any locks or are tracking resources that need to
- // be released on the WebKit thread, do it here.
+ // TODO(jorlow): Do stuff that needs to be run on the WebKit thread. Locks
+ // and others will likely need this, so let's not delete this
+ // code even though it doesn't do anyting yet.
}
-bool DOMStorageDispatcherHost::OnMessageReceived(
- const IPC::Message& message, bool *msg_is_ok) {
+/* static */
+void DOMStorageDispatcherHost::DispatchStorageEvent(const string16& key,
+ const NullableString16& old_value, const NullableString16& new_value,
+ const string16& origin, bool is_local_storage) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
+ DCHECK(current_);
+ current_->webkit_thread_->PostIOThreadTask(FROM_HERE, NewRunnableMethod(
+ current_, &DOMStorageDispatcherHost::OnStorageEvent, key, old_value,
+ new_value, origin, is_local_storage));
+}
+
+bool DOMStorageDispatcherHost::OnMessageReceived(const IPC::Message& message,
+ bool *msg_is_ok) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
DCHECK(!shutdown_);
DCHECK(process_handle_);
@@ -272,6 +306,8 @@
ViewHostMsg_DOMStorageSetItem::ID, process_handle_);
return;
}
+
+ AutoSetCurrentDispatcherHost auto_set(this);
storage_area->SetItem(key, value, &quota_exception);
DCHECK(!quota_exception); // This is tracked by the renderer.
}
@@ -293,6 +329,8 @@
ViewHostMsg_DOMStorageRemoveItem::ID, process_handle_);
return;
}
+
+ AutoSetCurrentDispatcherHost auto_set(this);
storage_area->RemoveItem(key);
}
@@ -312,5 +350,24 @@
ViewHostMsg_DOMStorageClear::ID, process_handle_);
return;
}
+
+ AutoSetCurrentDispatcherHost auto_set(this);
storage_area->Clear();
}
+
+void DOMStorageDispatcherHost::OnStorageEvent(const string16& key,
+ const NullableString16& old_value, const NullableString16& new_value,
+ const string16& origin, bool is_local_storage) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ DCHECK(is_local_storage); // Only LocalStorage is implemented right now.
+ DOMStorageType dom_storage_type = is_local_storage ? DOM_STORAGE_LOCAL
+ : DOM_STORAGE_SESSION;
+ const DOMStorageContext::DispatcherHostSet* set =
+ Context()->GetDispatcherHostSet();
+ DOMStorageContext::DispatcherHostSet::const_iterator cur = set->begin();
+ while (cur != set->end()) {
+ (*cur)->Send(new ViewMsg_DOMStorageEvent(key, old_value, new_value, origin,
+ dom_storage_type));
+ ++cur;
+ }
+}
« no previous file with comments | « chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h ('k') | chrome/browser/in_process_webkit/storage_namespace.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698