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

Side by Side Diff: chrome/browser/in_process_webkit/dom_storage_dispatcher_host.cc

Issue 223013: Another stab at the Chromium side of storage events. The WebKit side can be ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include "chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h" 5 #include "chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h"
6 6
7 #include "base/nullable_string16.h" 7 #include "base/nullable_string16.h"
8 #include "chrome/browser/chrome_thread.h" 8 #include "chrome/browser/chrome_thread.h"
9 #include "chrome/browser/in_process_webkit/dom_storage_context.h" 9 #include "chrome/browser/in_process_webkit/dom_storage_context.h"
10 #include "chrome/browser/in_process_webkit/storage_area.h" 10 #include "chrome/browser/in_process_webkit/storage_area.h"
11 #include "chrome/browser/in_process_webkit/storage_namespace.h" 11 #include "chrome/browser/in_process_webkit/storage_namespace.h"
12 #include "chrome/browser/in_process_webkit/webkit_thread.h" 12 #include "chrome/browser/in_process_webkit/webkit_thread.h"
13 #include "chrome/browser/renderer_host/browser_render_process_host.h" 13 #include "chrome/browser/renderer_host/browser_render_process_host.h"
14 #include "chrome/common/render_messages.h" 14 #include "chrome/common/render_messages.h"
15 15
16 DOMStorageDispatcherHost* DOMStorageDispatcherHost::current_ = NULL;
17
18 DOMStorageDispatcherHost::
19 AutoSetCurrentDispatcherHost::AutoSetCurrentDispatcherHost(
20 DOMStorageDispatcherHost* dispatcher_host) {
21 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
22 DCHECK(!current_);
23 current_ = dispatcher_host;
24 }
25
26 DOMStorageDispatcherHost::
27 AutoSetCurrentDispatcherHost::~AutoSetCurrentDispatcherHost() {
28 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
29 DCHECK(current_);
30 current_ = NULL;
31 }
32
16 DOMStorageDispatcherHost::DOMStorageDispatcherHost( 33 DOMStorageDispatcherHost::DOMStorageDispatcherHost(
17 IPC::Message::Sender* message_sender, WebKitContext* webkit_context, 34 IPC::Message::Sender* message_sender, WebKitContext* webkit_context,
18 WebKitThread* webkit_thread) 35 WebKitThread* webkit_thread)
19 : webkit_context_(webkit_context), 36 : webkit_context_(webkit_context),
20 webkit_thread_(webkit_thread), 37 webkit_thread_(webkit_thread),
21 message_sender_(message_sender), 38 message_sender_(message_sender),
22 process_handle_(0), 39 process_handle_(0),
23 ever_used_(false), 40 ever_used_(false),
24 shutdown_(false) { 41 shutdown_(false) {
25 DCHECK(webkit_context_.get()); 42 DCHECK(webkit_context_.get());
26 DCHECK(webkit_thread_); 43 DCHECK(webkit_thread_);
27 DCHECK(message_sender_); 44 DCHECK(message_sender_);
28 } 45 }
29 46
30 DOMStorageDispatcherHost::~DOMStorageDispatcherHost() { 47 DOMStorageDispatcherHost::~DOMStorageDispatcherHost() {
31 DCHECK(shutdown_); 48 DCHECK(shutdown_);
32 } 49 }
33 50
34 void DOMStorageDispatcherHost::Init(base::ProcessHandle process_handle) { 51 void DOMStorageDispatcherHost::Init(base::ProcessHandle process_handle) {
52 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
53 Context()->RegisterDispatcherHost(this);
54
35 DCHECK(!process_handle_); 55 DCHECK(!process_handle_);
36 process_handle_ = process_handle; 56 process_handle_ = process_handle;
37 DCHECK(process_handle_); 57 DCHECK(process_handle_);
38 } 58 }
39 59
40 void DOMStorageDispatcherHost::Shutdown() { 60 void DOMStorageDispatcherHost::Shutdown() {
41 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { 61 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
62 Context()->UnregisterDispatcherHost(this);
42 message_sender_ = NULL; 63 message_sender_ = NULL;
43 if (!ever_used_) { 64 if (!ever_used_) {
44 // No need to (possibly) spin up the WebKit thread for a no-op. 65 // No need to (possibly) spin up the WebKit thread for a no-op.
45 shutdown_ = true; 66 shutdown_ = true;
46 return; 67 return;
47 } 68 }
48 69
49 MessageLoop* webkit_loop = webkit_thread_->GetMessageLoop(); 70 MessageLoop* webkit_loop = webkit_thread_->GetMessageLoop();
50 webkit_loop->PostTask(FROM_HERE, NewRunnableMethod(this, 71 webkit_loop->PostTask(FROM_HERE, NewRunnableMethod(this,
51 &DOMStorageDispatcherHost::Shutdown)); 72 &DOMStorageDispatcherHost::Shutdown));
52 return; 73 return;
53 } 74 }
54 75
55 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 76 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
56 DCHECK(ever_used_); 77 DCHECK(ever_used_);
57 DCHECK(!message_sender_); 78 DCHECK(!message_sender_);
58 DCHECK(!shutdown_); 79 DCHECK(!shutdown_);
59 shutdown_ = true; 80 shutdown_ = true;
60 81
61 // TODO(jorlow): If we have any locks or are tracking resources that need to 82 // TODO(jorlow): Do stuff that needs to be run on the WebKit thread. Locks
62 // be released on the WebKit thread, do it here. 83 // and others will likely need this, so let's not delete this
84 // code even though it doesn't do anyting yet.
63 } 85 }
64 86
65 bool DOMStorageDispatcherHost::OnMessageReceived( 87 /* static */
66 const IPC::Message& message, bool *msg_is_ok) { 88 void DOMStorageDispatcherHost::DispatchStorageEvent(const string16& key,
89 const NullableString16& old_value, const NullableString16& new_value,
90 const string16& origin, bool is_local_storage) {
91 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
92 DCHECK(current_);
93 current_->webkit_thread_->PostIOThreadTask(FROM_HERE, NewRunnableMethod(
94 current_, &DOMStorageDispatcherHost::OnStorageEvent, key, old_value,
95 new_value, origin, is_local_storage));
96 }
97
98 bool DOMStorageDispatcherHost::OnMessageReceived(const IPC::Message& message,
99 bool *msg_is_ok) {
67 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); 100 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
68 DCHECK(!shutdown_); 101 DCHECK(!shutdown_);
69 DCHECK(process_handle_); 102 DCHECK(process_handle_);
70 103
71 bool handled = true; 104 bool handled = true;
72 IPC_BEGIN_MESSAGE_MAP_EX(DOMStorageDispatcherHost, message, *msg_is_ok) 105 IPC_BEGIN_MESSAGE_MAP_EX(DOMStorageDispatcherHost, message, *msg_is_ok)
73 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageNamespaceId, 106 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageNamespaceId,
74 OnNamespaceId) 107 OnNamespaceId)
75 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageCloneNamespaceId, 108 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageCloneNamespaceId,
76 OnCloneNamespaceId) 109 OnCloneNamespaceId)
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 } 298 }
266 299
267 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 300 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
268 bool quota_exception = false; 301 bool quota_exception = false;
269 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); 302 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id);
270 if (!storage_area) { 303 if (!storage_area) {
271 BrowserRenderProcessHost::BadMessageTerminateProcess( 304 BrowserRenderProcessHost::BadMessageTerminateProcess(
272 ViewHostMsg_DOMStorageSetItem::ID, process_handle_); 305 ViewHostMsg_DOMStorageSetItem::ID, process_handle_);
273 return; 306 return;
274 } 307 }
308
309 AutoSetCurrentDispatcherHost auto_set(this);
275 storage_area->SetItem(key, value, &quota_exception); 310 storage_area->SetItem(key, value, &quota_exception);
276 DCHECK(!quota_exception); // This is tracked by the renderer. 311 DCHECK(!quota_exception); // This is tracked by the renderer.
277 } 312 }
278 313
279 void DOMStorageDispatcherHost::OnRemoveItem(int64 storage_area_id, 314 void DOMStorageDispatcherHost::OnRemoveItem(int64 storage_area_id,
280 const string16& key) { 315 const string16& key) {
281 DCHECK(!shutdown_); 316 DCHECK(!shutdown_);
282 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { 317 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
283 MessageLoop* webkit_loop = webkit_thread_->GetMessageLoop(); 318 MessageLoop* webkit_loop = webkit_thread_->GetMessageLoop();
284 webkit_loop->PostTask(FROM_HERE, NewRunnableMethod(this, 319 webkit_loop->PostTask(FROM_HERE, NewRunnableMethod(this,
285 &DOMStorageDispatcherHost::OnRemoveItem, storage_area_id, key)); 320 &DOMStorageDispatcherHost::OnRemoveItem, storage_area_id, key));
286 return; 321 return;
287 } 322 }
288 323
289 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 324 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
290 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); 325 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id);
291 if (!storage_area) { 326 if (!storage_area) {
292 BrowserRenderProcessHost::BadMessageTerminateProcess( 327 BrowserRenderProcessHost::BadMessageTerminateProcess(
293 ViewHostMsg_DOMStorageRemoveItem::ID, process_handle_); 328 ViewHostMsg_DOMStorageRemoveItem::ID, process_handle_);
294 return; 329 return;
295 } 330 }
331
332 AutoSetCurrentDispatcherHost auto_set(this);
296 storage_area->RemoveItem(key); 333 storage_area->RemoveItem(key);
297 } 334 }
298 335
299 void DOMStorageDispatcherHost::OnClear(int64 storage_area_id) { 336 void DOMStorageDispatcherHost::OnClear(int64 storage_area_id) {
300 DCHECK(!shutdown_); 337 DCHECK(!shutdown_);
301 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { 338 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
302 MessageLoop* webkit_loop = webkit_thread_->GetMessageLoop(); 339 MessageLoop* webkit_loop = webkit_thread_->GetMessageLoop();
303 webkit_loop->PostTask(FROM_HERE, NewRunnableMethod(this, 340 webkit_loop->PostTask(FROM_HERE, NewRunnableMethod(this,
304 &DOMStorageDispatcherHost::OnClear, storage_area_id)); 341 &DOMStorageDispatcherHost::OnClear, storage_area_id));
305 return; 342 return;
306 } 343 }
307 344
308 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 345 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
309 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); 346 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id);
310 if (!storage_area) { 347 if (!storage_area) {
311 BrowserRenderProcessHost::BadMessageTerminateProcess( 348 BrowserRenderProcessHost::BadMessageTerminateProcess(
312 ViewHostMsg_DOMStorageClear::ID, process_handle_); 349 ViewHostMsg_DOMStorageClear::ID, process_handle_);
313 return; 350 return;
314 } 351 }
352
353 AutoSetCurrentDispatcherHost auto_set(this);
315 storage_area->Clear(); 354 storage_area->Clear();
316 } 355 }
356
357 void DOMStorageDispatcherHost::OnStorageEvent(const string16& key,
358 const NullableString16& old_value, const NullableString16& new_value,
359 const string16& origin, bool is_local_storage) {
360 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
361 DCHECK(is_local_storage); // Only LocalStorage is implemented right now.
362 DOMStorageType dom_storage_type = is_local_storage ? DOM_STORAGE_LOCAL
363 : DOM_STORAGE_SESSION;
364 const DOMStorageContext::DispatcherHostSet* set =
365 Context()->GetDispatcherHostSet();
366 DOMStorageContext::DispatcherHostSet::const_iterator cur = set->begin();
367 while (cur != set->end()) {
368 (*cur)->Send(new ViewMsg_DOMStorageEvent(key, old_value, new_value, origin,
369 dom_storage_type));
370 ++cur;
371 }
372 }
OLDNEW
« 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