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

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

Issue 402049: Revert my last... (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"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // The IO thread can't go away while the WebKit thread is still running. 143 // The IO thread can't go away while the WebKit thread is still running.
144 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 144 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
145 ChromeThread::PostTask( 145 ChromeThread::PostTask(
146 ChromeThread::IO, FROM_HERE, 146 ChromeThread::IO, FROM_HERE,
147 NewRunnableMethod(this, &DOMStorageDispatcherHost::Send, message)); 147 NewRunnableMethod(this, &DOMStorageDispatcherHost::Send, message));
148 } 148 }
149 149
150 void DOMStorageDispatcherHost::OnNamespaceId(DOMStorageType storage_type, 150 void DOMStorageDispatcherHost::OnNamespaceId(DOMStorageType storage_type,
151 IPC::Message* reply_msg) { 151 IPC::Message* reply_msg) {
152 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { 152 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
153 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( 153 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
154 this, &DOMStorageDispatcherHost::OnNamespaceId, storage_type, 154 &DOMStorageDispatcherHost::OnNamespaceId,
155 reply_msg)); 155 storage_type, reply_msg));
156 return; 156 return;
157 } 157 }
158 158
159 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 159 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
160 StorageNamespace* new_namespace; 160 StorageNamespace* new_namespace;
161 if (storage_type == DOM_STORAGE_LOCAL) 161 if (storage_type == DOM_STORAGE_LOCAL)
162 new_namespace = Context()->LocalStorage(); 162 new_namespace = Context()->LocalStorage();
163 else 163 else
164 new_namespace = Context()->NewSessionStorage(); 164 new_namespace = Context()->NewSessionStorage();
165 ViewHostMsg_DOMStorageNamespaceId::WriteReplyParams(reply_msg, 165 ViewHostMsg_DOMStorageNamespaceId::WriteReplyParams(reply_msg,
166 new_namespace->id()); 166 new_namespace->id());
167 Send(reply_msg); 167 Send(reply_msg);
168 } 168 }
169 169
170 void DOMStorageDispatcherHost::OnCloneNamespaceId(int64 namespace_id, 170 void DOMStorageDispatcherHost::OnCloneNamespaceId(int64 namespace_id,
171 IPC::Message* reply_msg) { 171 IPC::Message* reply_msg) {
172 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { 172 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
173 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( 173 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
174 this, &DOMStorageDispatcherHost::OnCloneNamespaceId, namespace_id, 174 &DOMStorageDispatcherHost::OnCloneNamespaceId,
175 reply_msg)); 175 namespace_id, reply_msg));
176 return; 176 return;
177 } 177 }
178 178
179 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 179 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
180 StorageNamespace* existing_namespace = 180 StorageNamespace* existing_namespace =
181 Context()->GetStorageNamespace(namespace_id); 181 Context()->GetStorageNamespace(namespace_id);
182 if (!existing_namespace) { 182 if (!existing_namespace) {
183 BrowserRenderProcessHost::BadMessageTerminateProcess( 183 BrowserRenderProcessHost::BadMessageTerminateProcess(
184 ViewHostMsg_DOMStorageCloneNamespaceId::ID, process_handle_); 184 ViewHostMsg_DOMStorageCloneNamespaceId::ID, process_handle_);
185 delete reply_msg; 185 delete reply_msg;
186 return; 186 return;
187 } 187 }
188 StorageNamespace* new_namespace = existing_namespace->Copy(); 188 StorageNamespace* new_namespace = existing_namespace->Copy();
189 ViewHostMsg_DOMStorageCloneNamespaceId::WriteReplyParams(reply_msg, 189 ViewHostMsg_DOMStorageCloneNamespaceId::WriteReplyParams(reply_msg,
190 new_namespace->id()); 190 new_namespace->id());
191 Send(reply_msg); 191 Send(reply_msg);
192 } 192 }
193 193
194 void DOMStorageDispatcherHost::OnStorageAreaId(int64 namespace_id, 194 void DOMStorageDispatcherHost::OnStorageAreaId(int64 namespace_id,
195 const string16& origin, 195 const string16& origin,
196 IPC::Message* reply_msg) { 196 IPC::Message* reply_msg) {
197 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { 197 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
198 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( 198 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
199 this, &DOMStorageDispatcherHost::OnStorageAreaId, namespace_id, origin, 199 &DOMStorageDispatcherHost::OnStorageAreaId,
200 reply_msg)); 200 namespace_id, origin, reply_msg));
201 return; 201 return;
202 } 202 }
203 203
204 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 204 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
205 StorageNamespace* storage_namespace = 205 StorageNamespace* storage_namespace =
206 Context()->GetStorageNamespace(namespace_id); 206 Context()->GetStorageNamespace(namespace_id);
207 if (!storage_namespace) { 207 if (!storage_namespace) {
208 BrowserRenderProcessHost::BadMessageTerminateProcess( 208 BrowserRenderProcessHost::BadMessageTerminateProcess(
209 ViewHostMsg_DOMStorageStorageAreaId::ID, process_handle_); 209 ViewHostMsg_DOMStorageStorageAreaId::ID, process_handle_);
210 delete reply_msg; 210 delete reply_msg;
211 return; 211 return;
212 } 212 }
213 StorageArea* storage_area = storage_namespace->GetStorageArea(origin); 213 StorageArea* storage_area = storage_namespace->GetStorageArea(origin);
214 ViewHostMsg_DOMStorageCloneNamespaceId::WriteReplyParams(reply_msg, 214 ViewHostMsg_DOMStorageCloneNamespaceId::WriteReplyParams(reply_msg,
215 storage_area->id()); 215 storage_area->id());
216 Send(reply_msg); 216 Send(reply_msg);
217 } 217 }
218 218
219 void DOMStorageDispatcherHost::OnLength(int64 storage_area_id, 219 void DOMStorageDispatcherHost::OnLength(int64 storage_area_id,
220 IPC::Message* reply_msg) { 220 IPC::Message* reply_msg) {
221 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { 221 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
222 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( 222 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
223 this, &DOMStorageDispatcherHost::OnLength, storage_area_id, reply_msg)); 223 &DOMStorageDispatcherHost::OnLength, storage_area_id, reply_msg));
224 return; 224 return;
225 } 225 }
226 226
227 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 227 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
228 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); 228 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id);
229 if (!storage_area) { 229 if (!storage_area) {
230 BrowserRenderProcessHost::BadMessageTerminateProcess( 230 BrowserRenderProcessHost::BadMessageTerminateProcess(
231 ViewHostMsg_DOMStorageLength::ID, process_handle_); 231 ViewHostMsg_DOMStorageLength::ID, process_handle_);
232 delete reply_msg; 232 delete reply_msg;
233 return; 233 return;
234 } 234 }
235 unsigned length = storage_area->Length(); 235 unsigned length = storage_area->Length();
236 ViewHostMsg_DOMStorageLength::WriteReplyParams(reply_msg, length); 236 ViewHostMsg_DOMStorageLength::WriteReplyParams(reply_msg, length);
237 Send(reply_msg); 237 Send(reply_msg);
238 } 238 }
239 239
240 void DOMStorageDispatcherHost::OnKey(int64 storage_area_id, unsigned index, 240 void DOMStorageDispatcherHost::OnKey(int64 storage_area_id, unsigned index,
241 IPC::Message* reply_msg) { 241 IPC::Message* reply_msg) {
242 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { 242 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
243 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( 243 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
244 this, &DOMStorageDispatcherHost::OnKey, storage_area_id, index, 244 &DOMStorageDispatcherHost::OnKey, storage_area_id, index, reply_msg));
245 reply_msg));
246 return; 245 return;
247 } 246 }
248 247
249 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 248 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
250 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); 249 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id);
251 if (!storage_area) { 250 if (!storage_area) {
252 BrowserRenderProcessHost::BadMessageTerminateProcess( 251 BrowserRenderProcessHost::BadMessageTerminateProcess(
253 ViewHostMsg_DOMStorageKey::ID, process_handle_); 252 ViewHostMsg_DOMStorageKey::ID, process_handle_);
254 delete reply_msg; 253 delete reply_msg;
255 return; 254 return;
256 } 255 }
257 const NullableString16& key = storage_area->Key(index); 256 const NullableString16& key = storage_area->Key(index);
258 ViewHostMsg_DOMStorageKey::WriteReplyParams(reply_msg, key); 257 ViewHostMsg_DOMStorageKey::WriteReplyParams(reply_msg, key);
259 Send(reply_msg); 258 Send(reply_msg);
260 } 259 }
261 260
262 void DOMStorageDispatcherHost::OnGetItem(int64 storage_area_id, 261 void DOMStorageDispatcherHost::OnGetItem(int64 storage_area_id,
263 const string16& key, 262 const string16& key,
264 IPC::Message* reply_msg) { 263 IPC::Message* reply_msg) {
265 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { 264 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
266 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( 265 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
267 this, &DOMStorageDispatcherHost::OnGetItem, storage_area_id, key, 266 &DOMStorageDispatcherHost::OnGetItem,
268 reply_msg)); 267 storage_area_id, key, reply_msg));
269 return; 268 return;
270 } 269 }
271 270
272 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 271 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
273 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); 272 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id);
274 if (!storage_area) { 273 if (!storage_area) {
275 BrowserRenderProcessHost::BadMessageTerminateProcess( 274 BrowserRenderProcessHost::BadMessageTerminateProcess(
276 ViewHostMsg_DOMStorageGetItem::ID, process_handle_); 275 ViewHostMsg_DOMStorageGetItem::ID, process_handle_);
277 delete reply_msg; 276 delete reply_msg;
278 return; 277 return;
279 } 278 }
280 const NullableString16& value = storage_area->GetItem(key); 279 const NullableString16& value = storage_area->GetItem(key);
281 ViewHostMsg_DOMStorageGetItem::WriteReplyParams(reply_msg, value); 280 ViewHostMsg_DOMStorageGetItem::WriteReplyParams(reply_msg, value);
282 Send(reply_msg); 281 Send(reply_msg);
283 } 282 }
284 283
285 void DOMStorageDispatcherHost::OnSetItem( 284 void DOMStorageDispatcherHost::OnSetItem(
286 int64 storage_area_id, const string16& key, const string16& value, 285 int64 storage_area_id, const string16& key, const string16& value,
287 const GURL& url, IPC::Message* reply_msg) { 286 const GURL& url, IPC::Message* reply_msg) {
288 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { 287 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
289 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( 288 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
290 this, &DOMStorageDispatcherHost::OnSetItem, storage_area_id, key, value, 289 &DOMStorageDispatcherHost::OnSetItem, storage_area_id, key, value,
291 url, reply_msg)); 290 url, reply_msg));
292 return; 291 return;
293 } 292 }
294 293
295 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 294 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
296 bool quota_exception = false; 295 bool quota_exception = false;
297 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); 296 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id);
298 if (!storage_area) { 297 if (!storage_area) {
299 BrowserRenderProcessHost::BadMessageTerminateProcess( 298 BrowserRenderProcessHost::BadMessageTerminateProcess(
300 ViewHostMsg_DOMStorageSetItem::ID, process_handle_); 299 ViewHostMsg_DOMStorageSetItem::ID, process_handle_);
301 return; 300 return;
302 } 301 }
303 302
304 ScopedStorageEventContext scope(this, &url); 303 ScopedStorageEventContext scope(this, &url);
305 storage_area->SetItem(key, value, &quota_exception); 304 storage_area->SetItem(key, value, &quota_exception);
306 ViewHostMsg_DOMStorageSetItem::WriteReplyParams(reply_msg, quota_exception); 305 ViewHostMsg_DOMStorageSetItem::WriteReplyParams(reply_msg, quota_exception);
307 Send(reply_msg); 306 Send(reply_msg);
308 } 307 }
309 308
310 void DOMStorageDispatcherHost::OnRemoveItem( 309 void DOMStorageDispatcherHost::OnRemoveItem(
311 int64 storage_area_id, const string16& key, const GURL& url) { 310 int64 storage_area_id, const string16& key, const GURL& url) {
312 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { 311 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
313 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( 312 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
314 this, &DOMStorageDispatcherHost::OnRemoveItem, storage_area_id, key, 313 &DOMStorageDispatcherHost::OnRemoveItem, storage_area_id, key, url));
315 url));
316 return; 314 return;
317 } 315 }
318 316
319 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 317 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
320 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); 318 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id);
321 if (!storage_area) { 319 if (!storage_area) {
322 BrowserRenderProcessHost::BadMessageTerminateProcess( 320 BrowserRenderProcessHost::BadMessageTerminateProcess(
323 ViewHostMsg_DOMStorageRemoveItem::ID, process_handle_); 321 ViewHostMsg_DOMStorageRemoveItem::ID, process_handle_);
324 return; 322 return;
325 } 323 }
326 324
327 ScopedStorageEventContext scope(this, &url); 325 ScopedStorageEventContext scope(this, &url);
328 storage_area->RemoveItem(key); 326 storage_area->RemoveItem(key);
329 } 327 }
330 328
331 void DOMStorageDispatcherHost::OnClear(int64 storage_area_id, const GURL& url) { 329 void DOMStorageDispatcherHost::OnClear(int64 storage_area_id, const GURL& url) {
332 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { 330 if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
333 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod( 331 PostTaskToWebKitThread(FROM_HERE, NewRunnableMethod(this,
334 this, &DOMStorageDispatcherHost::OnClear, storage_area_id, url)); 332 &DOMStorageDispatcherHost::OnClear, storage_area_id, url));
335 return; 333 return;
336 } 334 }
337 335
338 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); 336 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
339 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id); 337 StorageArea* storage_area = Context()->GetStorageArea(storage_area_id);
340 if (!storage_area) { 338 if (!storage_area) {
341 BrowserRenderProcessHost::BadMessageTerminateProcess( 339 BrowserRenderProcessHost::BadMessageTerminateProcess(
342 ViewHostMsg_DOMStorageClear::ID, process_handle_); 340 ViewHostMsg_DOMStorageClear::ID, process_handle_);
343 return; 341 return;
344 } 342 }
345 343
346 ScopedStorageEventContext scope(this, &url); 344 ScopedStorageEventContext scope(this, &url);
347 storage_area->Clear(); 345 storage_area->Clear();
348 } 346 }
349 347
350 void DOMStorageDispatcherHost::OnStorageEvent( 348 void DOMStorageDispatcherHost::OnStorageEvent(
351 const ViewMsg_DOMStorageEvent_Params& params) { 349 const ViewMsg_DOMStorageEvent_Params& params) {
352 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); 350 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
353 const DOMStorageContext::DispatcherHostSet* set = 351 const DOMStorageContext::DispatcherHostSet* set =
354 Context()->GetDispatcherHostSet(); 352 Context()->GetDispatcherHostSet();
355 DOMStorageContext::DispatcherHostSet::const_iterator cur = set->begin(); 353 DOMStorageContext::DispatcherHostSet::const_iterator cur = set->begin();
356 while (cur != set->end()) { 354 while (cur != set->end()) {
357 (*cur)->Send(new ViewMsg_DOMStorageEvent(params)); 355 (*cur)->Send(new ViewMsg_DOMStorageEvent(params));
358 ++cur; 356 ++cur;
359 } 357 }
360 } 358 }
359
360 void DOMStorageDispatcherHost::PostTaskToWebKitThread(
361 const tracked_objects::Location& from_here, Task* task) {
362 webkit_thread_->EnsureInitialized();
363 ChromeThread::PostTask(ChromeThread::WEBKIT, FROM_HERE, task);
364 }
OLDNEW
« no previous file with comments | « chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h ('k') | chrome/browser/in_process_webkit/webkit_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698