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

Side by Side Diff: content/browser/in_process_webkit/indexed_db_key_utility_client.cc

Issue 6995095: Move UtilityProcessHost to content and move the message sending/dispatching to the clients. This... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/in_process_webkit/indexed_db_key_utility_client.h" 5 #include "content/browser/in_process_webkit/indexed_db_key_utility_client.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/synchronization/waitable_event.h" 8 #include "base/synchronization/waitable_event.h"
9 #include "chrome/browser/utility_process_host.h" 9 #include "content/browser/utility_process_host.h"
10 #include "content/common/indexed_db_key.h" 10 #include "content/common/indexed_db_key.h"
11 #include "content/common/indexed_db_messages.h"
12 #include "content/common/utility_messages.h"
11 #include "content/common/serialized_script_value.h" 13 #include "content/common/serialized_script_value.h"
12 14
13 // This class is used to obtain IndexedDBKeys from SerializedScriptValues 15 // This class is used to obtain IndexedDBKeys from SerializedScriptValues
14 // given an IDBKeyPath. It uses UtilityProcess to do this inside a sandbox 16 // given an IDBKeyPath. It uses UtilityProcess to do this inside a sandbox
15 // (a V8 lock is required there). At this level, all methods are synchronous 17 // (a V8 lock is required there). At this level, all methods are synchronous
16 // as required by the caller. The public API is used on WEBKIT thread, 18 // as required by the caller. The public API is used on WEBKIT thread,
17 // but internally it moves around to UI and IO as needed. 19 // but internally it moves around to UI and IO as needed.
18 class KeyUtilityClientImpl 20 class KeyUtilityClientImpl
19 : public base::RefCountedThreadSafe<KeyUtilityClientImpl> { 21 : public base::RefCountedThreadSafe<KeyUtilityClientImpl> {
20 public: 22 public:
(...skipping 18 matching lines...) Expand all
39 const SerializedScriptValue& value, 41 const SerializedScriptValue& value,
40 const string16& key_path); 42 const string16& key_path);
41 43
42 private: 44 private:
43 class Client : public UtilityProcessHost::Client { 45 class Client : public UtilityProcessHost::Client {
44 public: 46 public:
45 explicit Client(KeyUtilityClientImpl* parent); 47 explicit Client(KeyUtilityClientImpl* parent);
46 48
47 // UtilityProcessHost::Client 49 // UtilityProcessHost::Client
48 virtual void OnProcessCrashed(int exit_code); 50 virtual void OnProcessCrashed(int exit_code);
49 virtual void OnIDBKeysFromValuesAndKeyPathSucceeded( 51 virtual bool OnMessageReceived(const IPC::Message& message);
52
53 // IPC message handlers
54 void OnIDBKeysFromValuesAndKeyPathSucceeded(
50 int id, const std::vector<IndexedDBKey>& keys); 55 int id, const std::vector<IndexedDBKey>& keys);
51 virtual void OnIDBKeysFromValuesAndKeyPathFailed(int id); 56 void OnIDBKeysFromValuesAndKeyPathFailed(int id);
52 virtual void OnInjectIDBKeyFinished(const SerializedScriptValue& value); 57 void OnInjectIDBKeyFinished(const SerializedScriptValue& value);
53 58
54 private: 59 private:
55 KeyUtilityClientImpl* parent_; 60 KeyUtilityClientImpl* parent_;
56 61
57 DISALLOW_COPY_AND_ASSIGN(Client); 62 DISALLOW_COPY_AND_ASSIGN(Client);
58 }; 63 };
59 64
60 friend class base::RefCountedThreadSafe<KeyUtilityClientImpl>; 65 friend class base::RefCountedThreadSafe<KeyUtilityClientImpl>;
61 ~KeyUtilityClientImpl(); 66 ~KeyUtilityClientImpl();
62 67
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 BrowserThread::PostTask( 305 BrowserThread::PostTask(
301 BrowserThread::IO, FROM_HERE, 306 BrowserThread::IO, FROM_HERE,
302 NewRunnableMethod(this, 307 NewRunnableMethod(this,
303 &KeyUtilityClientImpl:: 308 &KeyUtilityClientImpl::
304 CallStartIDBKeyFromValueAndKeyPathFromIOThread, 309 CallStartIDBKeyFromValueAndKeyPathFromIOThread,
305 values, key_path)); 310 values, key_path));
306 return; 311 return;
307 } 312 }
308 313
309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 314 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
310 utility_process_host_->StartIDBKeysFromValuesAndKeyPath( 315 utility_process_host_->Send(new UtilityMsg_IDBKeysFromValuesAndKeyPath(
311 0, values, key_path); 316 0, values, key_path));
312 } 317 }
313 318
314 void KeyUtilityClientImpl::CallStartInjectIDBKeyFromIOThread( 319 void KeyUtilityClientImpl::CallStartInjectIDBKeyFromIOThread(
315 const IndexedDBKey& key, 320 const IndexedDBKey& key,
316 const SerializedScriptValue& value, 321 const SerializedScriptValue& value,
317 const string16& key_path) { 322 const string16& key_path) {
318 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 323 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
319 BrowserThread::PostTask( 324 BrowserThread::PostTask(
320 BrowserThread::IO, FROM_HERE, 325 BrowserThread::IO, FROM_HERE,
321 NewRunnableMethod(this, 326 NewRunnableMethod(this,
322 &KeyUtilityClientImpl:: 327 &KeyUtilityClientImpl::
323 CallStartInjectIDBKeyFromIOThread, 328 CallStartInjectIDBKeyFromIOThread,
324 key, value, key_path)); 329 key, value, key_path));
325 return; 330 return;
326 } 331 }
327 332
328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
329 utility_process_host_->StartInjectIDBKey(key, value, key_path); 334 utility_process_host_->Send(new UtilityMsg_InjectIDBKey(
335 key, value, key_path));
330 } 336 }
331 337
332 void KeyUtilityClientImpl::SetKeys(const std::vector<IndexedDBKey>& keys) { 338 void KeyUtilityClientImpl::SetKeys(const std::vector<IndexedDBKey>& keys) {
333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
334 keys_ = keys; 340 keys_ = keys;
335 } 341 }
336 342
337 void KeyUtilityClientImpl::FinishCreatingKeys() { 343 void KeyUtilityClientImpl::FinishCreatingKeys() {
338 DCHECK(state_ == STATE_CREATING_KEYS); 344 DCHECK(state_ == STATE_CREATING_KEYS);
339 state_ = STATE_INITIALIZED; 345 state_ = STATE_INITIALIZED;
(...skipping 14 matching lines...) Expand all
354 360
355 KeyUtilityClientImpl::Client::Client(KeyUtilityClientImpl* parent) 361 KeyUtilityClientImpl::Client::Client(KeyUtilityClientImpl* parent)
356 : parent_(parent) { 362 : parent_(parent) {
357 } 363 }
358 364
359 void KeyUtilityClientImpl::Client::OnProcessCrashed(int exit_code) { 365 void KeyUtilityClientImpl::Client::OnProcessCrashed(int exit_code) {
360 if (parent_->state_ == STATE_CREATING_KEYS) 366 if (parent_->state_ == STATE_CREATING_KEYS)
361 parent_->FinishCreatingKeys(); 367 parent_->FinishCreatingKeys();
362 } 368 }
363 369
370 bool KeyUtilityClientImpl::Client::OnMessageReceived(
371 const IPC::Message& message) {
372 bool handled = true;
373 IPC_BEGIN_MESSAGE_MAP(KeyUtilityClientImpl::Client, message)
374 IPC_MESSAGE_HANDLER(UtilityHostMsg_IDBKeysFromValuesAndKeyPath_Succeeded,
375 OnIDBKeysFromValuesAndKeyPathSucceeded)
376 IPC_MESSAGE_HANDLER(UtilityHostMsg_IDBKeysFromValuesAndKeyPath_Failed,
377 OnIDBKeysFromValuesAndKeyPathFailed)
378 IPC_MESSAGE_HANDLER(UtilityHostMsg_InjectIDBKey_Finished,
379 OnInjectIDBKeyFinished)
380 IPC_MESSAGE_UNHANDLED(handled = false)
381 IPC_END_MESSAGE_MAP_EX()
382 return handled;
383 }
384
364 void KeyUtilityClientImpl::Client::OnIDBKeysFromValuesAndKeyPathSucceeded( 385 void KeyUtilityClientImpl::Client::OnIDBKeysFromValuesAndKeyPathSucceeded(
365 int id, const std::vector<IndexedDBKey>& keys) { 386 int id, const std::vector<IndexedDBKey>& keys) {
366 parent_->SetKeys(keys); 387 parent_->SetKeys(keys);
367 parent_->FinishCreatingKeys(); 388 parent_->FinishCreatingKeys();
368 } 389 }
369 390
370 void KeyUtilityClientImpl::Client::OnInjectIDBKeyFinished( 391 void KeyUtilityClientImpl::Client::OnInjectIDBKeyFinished(
371 const SerializedScriptValue& value) { 392 const SerializedScriptValue& value) {
372 parent_->SetValueAfterInjection(value); 393 parent_->SetValueAfterInjection(value);
373 parent_->FinishInjectingKey(); 394 parent_->FinishInjectingKey();
374 } 395 }
375 396
376 void KeyUtilityClientImpl::Client::OnIDBKeysFromValuesAndKeyPathFailed( 397 void KeyUtilityClientImpl::Client::OnIDBKeysFromValuesAndKeyPathFailed(
377 int id) { 398 int id) {
378 parent_->FinishCreatingKeys(); 399 parent_->FinishCreatingKeys();
379 } 400 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698