Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 DCHECK(current_); | 29 DCHECK(current_); |
| 30 current_ = NULL; | 30 current_ = NULL; |
| 31 } | 31 } |
| 32 | 32 |
| 33 DOMStorageDispatcherHost::DOMStorageDispatcherHost( | 33 DOMStorageDispatcherHost::DOMStorageDispatcherHost( |
| 34 IPC::Message::Sender* message_sender, WebKitContext* webkit_context, | 34 IPC::Message::Sender* message_sender, WebKitContext* webkit_context, |
| 35 WebKitThread* webkit_thread) | 35 WebKitThread* webkit_thread) |
| 36 : webkit_context_(webkit_context), | 36 : webkit_context_(webkit_context), |
| 37 webkit_thread_(webkit_thread), | 37 webkit_thread_(webkit_thread), |
| 38 message_sender_(message_sender), | 38 message_sender_(message_sender), |
| 39 process_handle_(0), | 39 process_handle_(0) { |
| 40 ever_used_(false), | |
| 41 shutdown_(false) { | |
| 42 DCHECK(webkit_context_.get()); | 40 DCHECK(webkit_context_.get()); |
| 43 DCHECK(webkit_thread_); | 41 DCHECK(webkit_thread_); |
| 44 DCHECK(message_sender_); | 42 DCHECK(message_sender_); |
| 45 } | 43 } |
| 46 | 44 |
| 47 DOMStorageDispatcherHost::~DOMStorageDispatcherHost() { | 45 DOMStorageDispatcherHost::~DOMStorageDispatcherHost() { |
| 48 DCHECK(shutdown_); | |
| 49 } | 46 } |
| 50 | 47 |
| 51 void DOMStorageDispatcherHost::Init(base::ProcessHandle process_handle) { | 48 void DOMStorageDispatcherHost::Init(base::ProcessHandle process_handle) { |
| 52 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 49 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 53 DCHECK(message_sender_); // Make sure Shutdown() has not yet been called. | 50 DCHECK(message_sender_); // Make sure Shutdown() has not yet been called. |
| 54 DCHECK(!process_handle_); // Make sure Init() has not yet been called. | 51 DCHECK(!process_handle_); // Make sure Init() has not yet been called. |
| 55 DCHECK(process_handle); | 52 DCHECK(process_handle); |
| 56 Context()->RegisterDispatcherHost(this); | 53 Context()->RegisterDispatcherHost(this); |
| 57 process_handle_ = process_handle; | 54 process_handle_ = process_handle; |
| 58 } | 55 } |
| 59 | 56 |
| 60 void DOMStorageDispatcherHost::Shutdown() { | 57 void DOMStorageDispatcherHost::Shutdown() { |
| 61 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 58 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 62 if (process_handle_) // Init() was called | 59 if (process_handle_) // Init() was called |
| 63 Context()->UnregisterDispatcherHost(this); | 60 Context()->UnregisterDispatcherHost(this); |
| 64 message_sender_ = NULL; | 61 message_sender_ = NULL; |
| 65 if (!ever_used_) { | |
| 66 // No need to (possibly) spin up the WebKit thread for a no-op. | |
| 67 shutdown_ = true; | |
| 68 return; | |
| 69 } | |
| 70 | 62 |
| 71 MessageLoop* webkit_loop = webkit_thread_->GetMessageLoop(); | 63 // The task will only execute if the WebKit thread is already running. |
| 72 webkit_loop->PostTask(FROM_HERE, NewRunnableMethod(this, | 64 ChromeThread::PostTask( |
| 73 &DOMStorageDispatcherHost::Shutdown)); | 65 ChromeThread::WEBKIT, FROM_HERE, |
| 66 NewRunnableMethod(this, &DOMStorageDispatcherHost::Shutdown)); | |
| 74 return; | 67 return; |
| 75 } | 68 } |
| 76 | 69 |
| 77 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 70 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 78 DCHECK(ever_used_); | |
| 79 DCHECK(!message_sender_); | 71 DCHECK(!message_sender_); |
| 80 DCHECK(!shutdown_); | |
| 81 shutdown_ = true; | |
| 82 | 72 |
| 83 // TODO(jorlow): Do stuff that needs to be run on the WebKit thread. Locks | 73 // TODO(jorlow): Do stuff that needs to be run on the WebKit thread. Locks |
| 84 // and others will likely need this, so let's not delete this | 74 // and others will likely need this, so let's not delete this |
| 85 // code even though it doesn't do anyting yet. | 75 // code even though it doesn't do anyting yet. |
| 86 } | 76 } |
| 87 | 77 |
| 88 /* static */ | 78 /* static */ |
| 89 void DOMStorageDispatcherHost::DispatchStorageEvent(const string16& key, | 79 void DOMStorageDispatcherHost::DispatchStorageEvent(const string16& key, |
| 90 const NullableString16& old_value, const NullableString16& new_value, | 80 const NullableString16& old_value, const NullableString16& new_value, |
| 91 const string16& origin, bool is_local_storage) { | 81 const string16& origin, bool is_local_storage) { |
| 92 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 82 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 93 DCHECK(current_); | 83 DCHECK(current_); |
| 94 current_->webkit_thread_->PostIOThreadTask(FROM_HERE, NewRunnableMethod( | 84 ChromeThread::PostTask( |
| 95 current_, &DOMStorageDispatcherHost::OnStorageEvent, key, old_value, | 85 ChromeThread::IO, FROM_HERE, |
| 96 new_value, origin, is_local_storage)); | 86 NewRunnableMethod( |
| 87 current_, &DOMStorageDispatcherHost::OnStorageEvent, key, old_value, | |
| 88 new_value, origin, is_local_storage)); | |
| 97 } | 89 } |
| 98 | 90 |
| 99 bool DOMStorageDispatcherHost::OnMessageReceived(const IPC::Message& message, | 91 bool DOMStorageDispatcherHost::OnMessageReceived(const IPC::Message& message, |
| 100 bool *msg_is_ok) { | 92 bool *msg_is_ok) { |
| 101 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 93 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 102 DCHECK(!shutdown_); | |
| 103 DCHECK(process_handle_); | 94 DCHECK(process_handle_); |
| 104 | 95 |
| 105 bool handled = true; | 96 bool handled = true; |
| 106 IPC_BEGIN_MESSAGE_MAP_EX(DOMStorageDispatcherHost, message, *msg_is_ok) | 97 IPC_BEGIN_MESSAGE_MAP_EX(DOMStorageDispatcherHost, message, *msg_is_ok) |
| 107 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageNamespaceId, | 98 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageNamespaceId, |
| 108 OnNamespaceId) | 99 OnNamespaceId) |
| 109 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageCloneNamespaceId, | 100 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageCloneNamespaceId, |
| 110 OnCloneNamespaceId) | 101 OnCloneNamespaceId) |
| 111 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageStorageAreaId, | 102 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageStorageAreaId, |
| 112 OnStorageAreaId) | 103 OnStorageAreaId) |
| 113 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageLength, OnLength) | 104 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageLength, OnLength) |
| 114 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageKey, OnKey) | 105 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageKey, OnKey) |
| 115 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageGetItem, OnGetItem) | 106 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageGetItem, OnGetItem) |
| 116 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageSetItem, OnSetItem) | 107 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_DOMStorageSetItem, OnSetItem) |
| 117 IPC_MESSAGE_HANDLER(ViewHostMsg_DOMStorageRemoveItem, OnRemoveItem) | 108 IPC_MESSAGE_HANDLER(ViewHostMsg_DOMStorageRemoveItem, OnRemoveItem) |
| 118 IPC_MESSAGE_HANDLER(ViewHostMsg_DOMStorageClear, OnClear) | 109 IPC_MESSAGE_HANDLER(ViewHostMsg_DOMStorageClear, OnClear) |
| 119 IPC_MESSAGE_UNHANDLED(handled = false) | 110 IPC_MESSAGE_UNHANDLED(handled = false) |
| 120 IPC_END_MESSAGE_MAP() | 111 IPC_END_MESSAGE_MAP() |
| 121 if (handled) | |
| 122 ever_used_ = true; | |
| 123 return handled; | 112 return handled; |
| 124 } | 113 } |
| 125 | 114 |
| 126 void DOMStorageDispatcherHost::Send(IPC::Message* message) { | 115 void DOMStorageDispatcherHost::Send(IPC::Message* message) { |
| 127 DCHECK(!shutdown_); | |
| 128 if (!message_sender_) { | 116 if (!message_sender_) { |
| 129 delete message; | 117 delete message; |
| 130 return; | 118 return; |
| 131 } | 119 } |
| 132 | 120 |
| 133 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 121 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 134 message_sender_->Send(message); | 122 message_sender_->Send(message); |
| 135 return; | 123 return; |
| 136 } | 124 } |
| 137 | 125 |
| 138 // The IO thread can't go away while the WebKit thread is still running. | 126 // The IO thread can't go away while the WebKit thread is still running. |
| 139 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 127 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 140 webkit_thread_->PostIOThreadTask(FROM_HERE, NewRunnableMethod(this, | 128 ChromeThread::PostTask( |
| 141 &DOMStorageDispatcherHost::Send, message)); | 129 ChromeThread::IO, FROM_HERE, |
| 130 NewRunnableMethod(this, &DOMStorageDispatcherHost::Send, message)); | |
| 142 } | 131 } |
| 143 | 132 |
| 144 void DOMStorageDispatcherHost::OnNamespaceId(DOMStorageType storage_type, | 133 void DOMStorageDispatcherHost::OnNamespaceId(DOMStorageType storage_type, |
| 145 IPC::Message* reply_msg) { | 134 IPC::Message* reply_msg) { |
| 146 DCHECK(!shutdown_); | |
| 147 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 135 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 148 MessageLoop* webkit_loop = webkit_thread_->GetMessageLoop(); | 136 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, |
| 149 webkit_loop->PostTask(FROM_HERE, NewRunnableMethod(this, | |
| 150 &DOMStorageDispatcherHost::OnNamespaceId, | 137 &DOMStorageDispatcherHost::OnNamespaceId, |
| 151 storage_type, reply_msg)); | 138 storage_type, reply_msg)); |
| 152 return; | 139 return; |
| 153 } | 140 } |
| 154 | 141 |
| 155 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 142 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 156 StorageNamespace* new_namespace; | 143 StorageNamespace* new_namespace; |
| 157 if (storage_type == DOM_STORAGE_LOCAL) | 144 if (storage_type == DOM_STORAGE_LOCAL) |
| 158 new_namespace = Context()->LocalStorage(); | 145 new_namespace = Context()->LocalStorage(); |
| 159 else | 146 else |
| 160 new_namespace = Context()->NewSessionStorage(); | 147 new_namespace = Context()->NewSessionStorage(); |
| 161 ViewHostMsg_DOMStorageNamespaceId::WriteReplyParams(reply_msg, | 148 ViewHostMsg_DOMStorageNamespaceId::WriteReplyParams(reply_msg, |
| 162 new_namespace->id()); | 149 new_namespace->id()); |
| 163 Send(reply_msg); | 150 Send(reply_msg); |
| 164 } | 151 } |
| 165 | 152 |
| 166 void DOMStorageDispatcherHost::OnCloneNamespaceId(int64 namespace_id, | 153 void DOMStorageDispatcherHost::OnCloneNamespaceId(int64 namespace_id, |
| 167 IPC::Message* reply_msg) { | 154 IPC::Message* reply_msg) { |
| 168 DCHECK(!shutdown_); | |
| 169 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 155 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 170 MessageLoop* webkit_loop = webkit_thread_->GetMessageLoop(); | 156 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, |
| 171 webkit_loop->PostTask(FROM_HERE, NewRunnableMethod(this, | |
| 172 &DOMStorageDispatcherHost::OnCloneNamespaceId, | 157 &DOMStorageDispatcherHost::OnCloneNamespaceId, |
| 173 namespace_id, reply_msg)); | 158 namespace_id, reply_msg)); |
| 174 return; | 159 return; |
| 175 } | 160 } |
| 176 | 161 |
| 177 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 162 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 178 StorageNamespace* existing_namespace = | 163 StorageNamespace* existing_namespace = |
| 179 Context()->GetStorageNamespace(namespace_id); | 164 Context()->GetStorageNamespace(namespace_id); |
| 180 if (!existing_namespace) { | 165 if (!existing_namespace) { |
| 181 BrowserRenderProcessHost::BadMessageTerminateProcess( | 166 BrowserRenderProcessHost::BadMessageTerminateProcess( |
| 182 ViewHostMsg_DOMStorageCloneNamespaceId::ID, process_handle_); | 167 ViewHostMsg_DOMStorageCloneNamespaceId::ID, process_handle_); |
| 183 delete reply_msg; | 168 delete reply_msg; |
| 184 return; | 169 return; |
| 185 } | 170 } |
| 186 StorageNamespace* new_namespace = existing_namespace->Copy(); | 171 StorageNamespace* new_namespace = existing_namespace->Copy(); |
| 187 ViewHostMsg_DOMStorageCloneNamespaceId::WriteReplyParams(reply_msg, | 172 ViewHostMsg_DOMStorageCloneNamespaceId::WriteReplyParams(reply_msg, |
| 188 new_namespace->id()); | 173 new_namespace->id()); |
| 189 Send(reply_msg); | 174 Send(reply_msg); |
| 190 } | 175 } |
| 191 | 176 |
| 192 void DOMStorageDispatcherHost::OnStorageAreaId(int64 namespace_id, | 177 void DOMStorageDispatcherHost::OnStorageAreaId(int64 namespace_id, |
| 193 const string16& origin, | 178 const string16& origin, |
| 194 IPC::Message* reply_msg) { | 179 IPC::Message* reply_msg) { |
| 195 DCHECK(!shutdown_); | |
| 196 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 180 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 197 MessageLoop* webkit_loop = webkit_thread_->GetMessageLoop(); | 181 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, |
| 198 webkit_loop->PostTask(FROM_HERE, NewRunnableMethod(this, | |
| 199 &DOMStorageDispatcherHost::OnStorageAreaId, | 182 &DOMStorageDispatcherHost::OnStorageAreaId, |
| 200 namespace_id, origin, reply_msg)); | 183 namespace_id, origin, reply_msg)); |
| 201 return; | 184 return; |
| 202 } | 185 } |
| 203 | 186 |
| 204 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 187 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 205 StorageNamespace* storage_namespace = | 188 StorageNamespace* storage_namespace = |
| 206 Context()->GetStorageNamespace(namespace_id); | 189 Context()->GetStorageNamespace(namespace_id); |
| 207 if (!storage_namespace) { | 190 if (!storage_namespace) { |
| 208 BrowserRenderProcessHost::BadMessageTerminateProcess( | 191 BrowserRenderProcessHost::BadMessageTerminateProcess( |
| 209 ViewHostMsg_DOMStorageStorageAreaId::ID, process_handle_); | 192 ViewHostMsg_DOMStorageStorageAreaId::ID, process_handle_); |
| 210 delete reply_msg; | 193 delete reply_msg; |
| 211 return; | 194 return; |
| 212 } | 195 } |
| 213 StorageArea* storage_area = storage_namespace->GetStorageArea(origin); | 196 StorageArea* storage_area = storage_namespace->GetStorageArea(origin); |
| 214 ViewHostMsg_DOMStorageCloneNamespaceId::WriteReplyParams(reply_msg, | 197 ViewHostMsg_DOMStorageCloneNamespaceId::WriteReplyParams(reply_msg, |
| 215 storage_area->id()); | 198 storage_area->id()); |
| 216 Send(reply_msg); | 199 Send(reply_msg); |
| 217 } | 200 } |
| 218 | 201 |
| 219 void DOMStorageDispatcherHost::OnLength(int64 storage_area_id, | 202 void DOMStorageDispatcherHost::OnLength(int64 storage_area_id, |
| 220 IPC::Message* reply_msg) { | 203 IPC::Message* reply_msg) { |
| 221 DCHECK(!shutdown_); | |
| 222 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 204 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 223 MessageLoop* webkit_loop = webkit_thread_->GetMessageLoop(); | 205 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, |
| 224 webkit_loop->PostTask(FROM_HERE, NewRunnableMethod(this, | |
| 225 &DOMStorageDispatcherHost::OnLength, storage_area_id, reply_msg)); | 206 &DOMStorageDispatcherHost::OnLength, storage_area_id, reply_msg)); |
| 226 return; | 207 return; |
| 227 } | 208 } |
| 228 | 209 |
| 229 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 210 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 230 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); | 211 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); |
| 231 if (!storage_area) { | 212 if (!storage_area) { |
| 232 BrowserRenderProcessHost::BadMessageTerminateProcess( | 213 BrowserRenderProcessHost::BadMessageTerminateProcess( |
| 233 ViewHostMsg_DOMStorageLength::ID, process_handle_); | 214 ViewHostMsg_DOMStorageLength::ID, process_handle_); |
| 234 delete reply_msg; | 215 delete reply_msg; |
| 235 return; | 216 return; |
| 236 } | 217 } |
| 237 unsigned length = storage_area->Length(); | 218 unsigned length = storage_area->Length(); |
| 238 ViewHostMsg_DOMStorageLength::WriteReplyParams(reply_msg, length); | 219 ViewHostMsg_DOMStorageLength::WriteReplyParams(reply_msg, length); |
| 239 Send(reply_msg); | 220 Send(reply_msg); |
| 240 } | 221 } |
| 241 | 222 |
| 242 void DOMStorageDispatcherHost::OnKey(int64 storage_area_id, unsigned index, | 223 void DOMStorageDispatcherHost::OnKey(int64 storage_area_id, unsigned index, |
| 243 IPC::Message* reply_msg) { | 224 IPC::Message* reply_msg) { |
| 244 DCHECK(!shutdown_); | |
| 245 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 225 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 246 MessageLoop* webkit_loop = webkit_thread_->GetMessageLoop(); | 226 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, |
| 247 webkit_loop->PostTask(FROM_HERE, NewRunnableMethod(this, | |
| 248 &DOMStorageDispatcherHost::OnKey, storage_area_id, index, reply_msg)); | 227 &DOMStorageDispatcherHost::OnKey, storage_area_id, index, reply_msg)); |
| 249 return; | 228 return; |
| 250 } | 229 } |
| 251 | 230 |
| 252 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 231 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 253 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); | 232 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); |
| 254 if (!storage_area) { | 233 if (!storage_area) { |
| 255 BrowserRenderProcessHost::BadMessageTerminateProcess( | 234 BrowserRenderProcessHost::BadMessageTerminateProcess( |
| 256 ViewHostMsg_DOMStorageKey::ID, process_handle_); | 235 ViewHostMsg_DOMStorageKey::ID, process_handle_); |
| 257 delete reply_msg; | 236 delete reply_msg; |
| 258 return; | 237 return; |
| 259 } | 238 } |
| 260 const NullableString16& key = storage_area->Key(index); | 239 const NullableString16& key = storage_area->Key(index); |
| 261 ViewHostMsg_DOMStorageKey::WriteReplyParams(reply_msg, key); | 240 ViewHostMsg_DOMStorageKey::WriteReplyParams(reply_msg, key); |
| 262 Send(reply_msg); | 241 Send(reply_msg); |
| 263 } | 242 } |
| 264 | 243 |
| 265 void DOMStorageDispatcherHost::OnGetItem(int64 storage_area_id, | 244 void DOMStorageDispatcherHost::OnGetItem(int64 storage_area_id, |
| 266 const string16& key, | 245 const string16& key, |
| 267 IPC::Message* reply_msg) { | 246 IPC::Message* reply_msg) { |
| 268 DCHECK(!shutdown_); | |
| 269 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 247 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 270 MessageLoop* webkit_loop = webkit_thread_->GetMessageLoop(); | 248 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, |
| 271 webkit_loop->PostTask(FROM_HERE, NewRunnableMethod(this, | |
| 272 &DOMStorageDispatcherHost::OnGetItem, | 249 &DOMStorageDispatcherHost::OnGetItem, |
| 273 storage_area_id, key, reply_msg)); | 250 storage_area_id, key, reply_msg)); |
| 274 return; | 251 return; |
| 275 } | 252 } |
| 276 | 253 |
| 277 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 254 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 278 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); | 255 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); |
| 279 if (!storage_area) { | 256 if (!storage_area) { |
| 280 BrowserRenderProcessHost::BadMessageTerminateProcess( | 257 BrowserRenderProcessHost::BadMessageTerminateProcess( |
| 281 ViewHostMsg_DOMStorageGetItem::ID, process_handle_); | 258 ViewHostMsg_DOMStorageGetItem::ID, process_handle_); |
| 282 delete reply_msg; | 259 delete reply_msg; |
| 283 return; | 260 return; |
| 284 } | 261 } |
| 285 const NullableString16& value = storage_area->GetItem(key); | 262 const NullableString16& value = storage_area->GetItem(key); |
| 286 ViewHostMsg_DOMStorageGetItem::WriteReplyParams(reply_msg, value); | 263 ViewHostMsg_DOMStorageGetItem::WriteReplyParams(reply_msg, value); |
| 287 Send(reply_msg); | 264 Send(reply_msg); |
| 288 } | 265 } |
| 289 | 266 |
| 290 void DOMStorageDispatcherHost::OnSetItem(int64 storage_area_id, | 267 void DOMStorageDispatcherHost::OnSetItem(int64 storage_area_id, |
| 291 const string16& key, const string16& value, IPC::Message* reply_msg) { | 268 const string16& key, const string16& value, IPC::Message* reply_msg) { |
| 292 DCHECK(!shutdown_); | |
| 293 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 269 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 294 MessageLoop* webkit_loop = webkit_thread_->GetMessageLoop(); | 270 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, |
| 295 webkit_loop->PostTask(FROM_HERE, NewRunnableMethod(this, | |
| 296 &DOMStorageDispatcherHost::OnSetItem, storage_area_id, key, value, | 271 &DOMStorageDispatcherHost::OnSetItem, storage_area_id, key, value, |
| 297 reply_msg)); | 272 reply_msg)); |
| 298 return; | 273 return; |
| 299 } | 274 } |
| 300 | 275 |
| 301 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 276 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 302 bool quota_exception = false; | 277 bool quota_exception = false; |
| 303 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); | 278 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); |
| 304 if (!storage_area) { | 279 if (!storage_area) { |
| 305 BrowserRenderProcessHost::BadMessageTerminateProcess( | 280 BrowserRenderProcessHost::BadMessageTerminateProcess( |
| 306 ViewHostMsg_DOMStorageSetItem::ID, process_handle_); | 281 ViewHostMsg_DOMStorageSetItem::ID, process_handle_); |
| 307 return; | 282 return; |
| 308 } | 283 } |
| 309 | 284 |
| 310 AutoSetCurrentDispatcherHost auto_set(this); | 285 AutoSetCurrentDispatcherHost auto_set(this); |
| 311 storage_area->SetItem(key, value, "a_exception); | 286 storage_area->SetItem(key, value, "a_exception); |
| 312 ViewHostMsg_DOMStorageSetItem::WriteReplyParams(reply_msg, quota_exception); | 287 ViewHostMsg_DOMStorageSetItem::WriteReplyParams(reply_msg, quota_exception); |
| 313 Send(reply_msg); | 288 Send(reply_msg); |
| 314 } | 289 } |
| 315 | 290 |
| 316 void DOMStorageDispatcherHost::OnRemoveItem(int64 storage_area_id, | 291 void DOMStorageDispatcherHost::OnRemoveItem(int64 storage_area_id, |
| 317 const string16& key) { | 292 const string16& key) { |
| 318 DCHECK(!shutdown_); | |
| 319 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 293 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 320 MessageLoop* webkit_loop = webkit_thread_->GetMessageLoop(); | 294 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, |
| 321 webkit_loop->PostTask(FROM_HERE, NewRunnableMethod(this, | |
| 322 &DOMStorageDispatcherHost::OnRemoveItem, storage_area_id, key)); | 295 &DOMStorageDispatcherHost::OnRemoveItem, storage_area_id, key)); |
| 323 return; | 296 return; |
| 324 } | 297 } |
| 325 | 298 |
| 326 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 299 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 327 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); | 300 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); |
| 328 if (!storage_area) { | 301 if (!storage_area) { |
| 329 BrowserRenderProcessHost::BadMessageTerminateProcess( | 302 BrowserRenderProcessHost::BadMessageTerminateProcess( |
| 330 ViewHostMsg_DOMStorageRemoveItem::ID, process_handle_); | 303 ViewHostMsg_DOMStorageRemoveItem::ID, process_handle_); |
| 331 return; | 304 return; |
| 332 } | 305 } |
| 333 | 306 |
| 334 AutoSetCurrentDispatcherHost auto_set(this); | 307 AutoSetCurrentDispatcherHost auto_set(this); |
| 335 storage_area->RemoveItem(key); | 308 storage_area->RemoveItem(key); |
| 336 } | 309 } |
| 337 | 310 |
| 338 void DOMStorageDispatcherHost::OnClear(int64 storage_area_id) { | 311 void DOMStorageDispatcherHost::OnClear(int64 storage_area_id) { |
| 339 DCHECK(!shutdown_); | |
| 340 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 312 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 341 MessageLoop* webkit_loop = webkit_thread_->GetMessageLoop(); | 313 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this, |
| 342 webkit_loop->PostTask(FROM_HERE, NewRunnableMethod(this, | |
| 343 &DOMStorageDispatcherHost::OnClear, storage_area_id)); | 314 &DOMStorageDispatcherHost::OnClear, storage_area_id)); |
| 344 return; | 315 return; |
| 345 } | 316 } |
| 346 | 317 |
| 347 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 318 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 348 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); | 319 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); |
| 349 if (!storage_area) { | 320 if (!storage_area) { |
| 350 BrowserRenderProcessHost::BadMessageTerminateProcess( | 321 BrowserRenderProcessHost::BadMessageTerminateProcess( |
| 351 ViewHostMsg_DOMStorageClear::ID, process_handle_); | 322 ViewHostMsg_DOMStorageClear::ID, process_handle_); |
| 352 return; | 323 return; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 365 : DOM_STORAGE_SESSION; | 336 : DOM_STORAGE_SESSION; |
| 366 const DOMStorageContext::DispatcherHostSet* set = | 337 const DOMStorageContext::DispatcherHostSet* set = |
| 367 Context()->GetDispatcherHostSet(); | 338 Context()->GetDispatcherHostSet(); |
| 368 DOMStorageContext::DispatcherHostSet::const_iterator cur = set->begin(); | 339 DOMStorageContext::DispatcherHostSet::const_iterator cur = set->begin(); |
| 369 while (cur != set->end()) { | 340 while (cur != set->end()) { |
| 370 (*cur)->Send(new ViewMsg_DOMStorageEvent(key, old_value, new_value, origin, | 341 (*cur)->Send(new ViewMsg_DOMStorageEvent(key, old_value, new_value, origin, |
| 371 dom_storage_type)); | 342 dom_storage_type)); |
| 372 ++cur; | 343 ++cur; |
| 373 } | 344 } |
| 374 } | 345 } |
| 346 | |
| 347 void DOMStorageDispatcherHost::PostTaskToWebKitThread( | |
| 348 const tracked_objects::Location& from_here, Task* task) { | |
| 349 webkit_thread_->EnsureInitialized(); | |
| 350 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, task); | |
|
jorlow
2009/10/27 21:37:25
use from_here, not FROM_HERE
| |
| 351 } | |
| OLD | NEW |