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

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

Issue 348071: First half of http://codereview.chromium.org/274014/show... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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; 16 DOMStorageDispatcherHost* DOMStorageDispatcherHost::storage_event_host_ = NULL;
17 17
18 DOMStorageDispatcherHost:: 18 DOMStorageDispatcherHost::
19 AutoSetCurrentDispatcherHost::AutoSetCurrentDispatcherHost( 19 ScopedStorageEventContext::ScopedStorageEventContext(
20 DOMStorageDispatcherHost* dispatcher_host) { 20 DOMStorageDispatcherHost* dispatcher_host) {
21 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 21 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
22 DCHECK(!current_); 22 DCHECK(!storage_event_host_);
23 current_ = dispatcher_host; 23 storage_event_host_ = dispatcher_host;
24 DCHECK(storage_event_host_);
24 } 25 }
25 26
26 DOMStorageDispatcherHost:: 27 DOMStorageDispatcherHost::
27 AutoSetCurrentDispatcherHost::~AutoSetCurrentDispatcherHost() { 28 ScopedStorageEventContext::~ScopedStorageEventContext() {
28 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 29 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
29 DCHECK(current_); 30 DCHECK(storage_event_host_);
30 current_ = NULL; 31 storage_event_host_ = NULL;
31 } 32 }
32 33
33 DOMStorageDispatcherHost::DOMStorageDispatcherHost( 34 DOMStorageDispatcherHost::DOMStorageDispatcherHost(
34 IPC::Message::Sender* message_sender, WebKitContext* webkit_context, 35 IPC::Message::Sender* message_sender, WebKitContext* webkit_context,
35 WebKitThread* webkit_thread) 36 WebKitThread* webkit_thread)
36 : webkit_context_(webkit_context), 37 : webkit_context_(webkit_context),
37 webkit_thread_(webkit_thread), 38 webkit_thread_(webkit_thread),
38 message_sender_(message_sender), 39 message_sender_(message_sender),
39 process_handle_(0) { 40 process_handle_(0) {
40 DCHECK(webkit_context_.get()); 41 DCHECK(webkit_context_.get());
(...skipping 28 matching lines...) Expand all
69 70
70 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 71 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
71 DCHECK(!message_sender_); 72 DCHECK(!message_sender_);
72 73
73 // TODO(jorlow): Do stuff that needs to be run on the WebKit thread. Locks 74 // TODO(jorlow): Do stuff that needs to be run on the WebKit thread. Locks
74 // and others will likely need this, so let's not delete this 75 // and others will likely need this, so let's not delete this
75 // code even though it doesn't do anyting yet. 76 // code even though it doesn't do anyting yet.
76 } 77 }
77 78
78 /* static */ 79 /* static */
79 void DOMStorageDispatcherHost::DispatchStorageEvent(const string16& key, 80 void DOMStorageDispatcherHost::DispatchStorageEvent(const NullableString16& key,
80 const NullableString16& old_value, const NullableString16& new_value, 81 const NullableString16& old_value, const NullableString16& new_value,
81 const string16& origin, bool is_local_storage) { 82 const string16& origin, bool is_local_storage) {
82 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 83 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
83 DCHECK(current_); 84 DCHECK(is_local_storage); // Only LocalStorage is implemented right now.
84 ChromeThread::PostTask( 85 DCHECK(storage_event_host_);
85 ChromeThread::IO, FROM_HERE, 86 ViewMsg_DOMStorageEvent_Params params;
86 NewRunnableMethod( 87 params.key_ = key;
87 current_, &DOMStorageDispatcherHost::OnStorageEvent, key, old_value, 88 params.old_value_ = old_value;
88 new_value, origin, is_local_storage)); 89 params.new_value_ = new_value;
90 params.origin_ = origin;
91 params.storage_type_ = is_local_storage ? DOM_STORAGE_LOCAL
92 : DOM_STORAGE_SESSION;
93 // The storage_event_host_ is the DOMStorageDispatcherHost that is up in the
94 // current call stack since it caused the storage event to fire.
95 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE,
96 NewRunnableMethod(storage_event_host_,
97 &DOMStorageDispatcherHost::OnStorageEvent, params));
89 } 98 }
90 99
91 bool DOMStorageDispatcherHost::OnMessageReceived(const IPC::Message& message, 100 bool DOMStorageDispatcherHost::OnMessageReceived(const IPC::Message& message,
92 bool *msg_is_ok) { 101 bool *msg_is_ok) {
93 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); 102 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
94 DCHECK(process_handle_); 103 DCHECK(process_handle_);
95 104
96 bool handled = true; 105 bool handled = true;
97 IPC_BEGIN_MESSAGE_MAP_EX(DOMStorageDispatcherHost, message, *msg_is_ok) 106 IPC_BEGIN_MESSAGE_MAP_EX(DOMStorageDispatcherHost, message, *msg_is_ok)
98 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageNamespaceId, 107 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageNamespaceId,
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 284
276 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 285 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
277 bool quota_exception = false; 286 bool quota_exception = false;
278 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); 287 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id);
279 if (!storage_area) { 288 if (!storage_area) {
280 BrowserRenderProcessHost::BadMessageTerminateProcess( 289 BrowserRenderProcessHost::BadMessageTerminateProcess(
281 ViewHostMsg_DOMStorageSetItem::ID, process_handle_); 290 ViewHostMsg_DOMStorageSetItem::ID, process_handle_);
282 return; 291 return;
283 } 292 }
284 293
285 AutoSetCurrentDispatcherHost auto_set(this); 294 ScopedStorageEventContext scope(this);
286 storage_area->SetItem(key, value, &quota_exception); 295 storage_area->SetItem(key, value, &quota_exception);
287 ViewHostMsg_DOMStorageSetItem::WriteReplyParams(reply_msg, quota_exception); 296 ViewHostMsg_DOMStorageSetItem::WriteReplyParams(reply_msg, quota_exception);
288 Send(reply_msg); 297 Send(reply_msg);
289 } 298 }
290 299
291 void DOMStorageDispatcherHost::OnRemoveItem(int64 storage_area_id, 300 void DOMStorageDispatcherHost::OnRemoveItem(
292 const string16& key) { 301 int64 storage_area_id, const string16& key) {
293 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { 302 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
294 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, 303 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
295 &DOMStorageDispatcherHost::OnRemoveItem, storage_area_id, key)); 304 &DOMStorageDispatcherHost::OnRemoveItem, storage_area_id, key));
296 return; 305 return;
297 } 306 }
298 307
299 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 308 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
300 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); 309 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id);
301 if (!storage_area) { 310 if (!storage_area) {
302 BrowserRenderProcessHost::BadMessageTerminateProcess( 311 BrowserRenderProcessHost::BadMessageTerminateProcess(
303 ViewHostMsg_DOMStorageRemoveItem::ID, process_handle_); 312 ViewHostMsg_DOMStorageRemoveItem::ID, process_handle_);
304 return; 313 return;
305 } 314 }
306 315
307 AutoSetCurrentDispatcherHost auto_set(this); 316 ScopedStorageEventContext scope(this);
308 storage_area->RemoveItem(key); 317 storage_area->RemoveItem(key);
309 } 318 }
310 319
311 void DOMStorageDispatcherHost::OnClear(int64 storage_area_id) { 320 void DOMStorageDispatcherHost::OnClear(int64 storage_area_id) {
312 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { 321 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
313 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, 322 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
314 &DOMStorageDispatcherHost::OnClear, storage_area_id)); 323 &DOMStorageDispatcherHost::OnClear, storage_area_id));
315 return; 324 return;
316 } 325 }
317 326
318 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 327 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
319 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); 328 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id);
320 if (!storage_area) { 329 if (!storage_area) {
321 BrowserRenderProcessHost::BadMessageTerminateProcess( 330 BrowserRenderProcessHost::BadMessageTerminateProcess(
322 ViewHostMsg_DOMStorageClear::ID, process_handle_); 331 ViewHostMsg_DOMStorageClear::ID, process_handle_);
323 return; 332 return;
324 } 333 }
325 334
326 AutoSetCurrentDispatcherHost auto_set(this); 335 ScopedStorageEventContext scope(this);
327 storage_area->Clear(); 336 storage_area->Clear();
328 } 337 }
329 338
330 void DOMStorageDispatcherHost::OnStorageEvent(const string16& key, 339 void DOMStorageDispatcherHost::OnStorageEvent(
331 const NullableString16& old_value, const NullableString16& new_value, 340 const ViewMsg_DOMStorageEvent_Params& params) {
332 const string16& origin, bool is_local_storage) {
333 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); 341 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
334 DCHECK(is_local_storage); // Only LocalStorage is implemented right now.
335 DOMStorageType dom_storage_type = is_local_storage ? DOM_STORAGE_LOCAL
336 : DOM_STORAGE_SESSION;
337 const DOMStorageContext::DispatcherHostSet* set = 342 const DOMStorageContext::DispatcherHostSet* set =
338 Context()->GetDispatcherHostSet(); 343 Context()->GetDispatcherHostSet();
339 DOMStorageContext::DispatcherHostSet::const_iterator cur = set->begin(); 344 DOMStorageContext::DispatcherHostSet::const_iterator cur = set->begin();
340 while (cur != set->end()) { 345 while (cur != set->end()) {
341 (*cur)->Send(new ViewMsg_DOMStorageEvent(key, old_value, new_value, origin, 346 (*cur)->Send(new ViewMsg_DOMStorageEvent(params));
342 dom_storage_type));
343 ++cur; 347 ++cur;
344 } 348 }
345 } 349 }
346 350
347 void DOMStorageDispatcherHost::PostTaskToWebKitThread( 351 void DOMStorageDispatcherHost::PostTaskToWebKitThread(
348 const tracked_objects::Location& from_here, Task* task) { 352 const tracked_objects::Location& from_here, Task* task) {
349 webkit_thread_->EnsureInitialized(); 353 webkit_thread_->EnsureInitialized();
350 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, task); 354 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, task);
351 } 355 }
OLDNEW
« no previous file with comments | « chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h ('k') | chrome/browser/in_process_webkit/dom_storage_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698