| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "content/browser/utility_process_host.h" | 10 #include "content/browser/utility_process_host_impl.h" |
| 11 #include "content/common/indexed_db/indexed_db_key.h" | 11 #include "content/common/indexed_db/indexed_db_key.h" |
| 12 #include "content/common/indexed_db/indexed_db_messages.h" | 12 #include "content/common/indexed_db/indexed_db_messages.h" |
| 13 #include "content/common/utility_messages.h" | 13 #include "content/common/utility_messages.h" |
| 14 #include "content/public/browser/utility_process_host_client.h" |
| 14 #include "content/public/common/serialized_script_value.h" | 15 #include "content/public/common/serialized_script_value.h" |
| 15 | 16 |
| 16 using content::BrowserThread; | 17 using content::BrowserThread; |
| 18 using content::UtilityProcessHostClient; |
| 17 | 19 |
| 18 // This class is used to obtain IndexedDBKeys from SerializedScriptValues | 20 // This class is used to obtain IndexedDBKeys from SerializedScriptValues |
| 19 // given an IDBKeyPath. It uses UtilityProcess to do this inside a sandbox | 21 // given an IDBKeyPath. It uses UtilityProcess to do this inside a sandbox |
| 20 // (a V8 lock is required there). At this level, all methods are synchronous | 22 // (a V8 lock is required there). At this level, all methods are synchronous |
| 21 // as required by the caller. The public API is used on WEBKIT thread, | 23 // as required by the caller. The public API is used on WEBKIT thread, |
| 22 // but internally it moves around to UI and IO as needed. | 24 // but internally it moves around to UI and IO as needed. |
| 23 class KeyUtilityClientImpl | 25 class KeyUtilityClientImpl |
| 24 : public base::RefCountedThreadSafe<KeyUtilityClientImpl> { | 26 : public base::RefCountedThreadSafe<KeyUtilityClientImpl> { |
| 25 public: | 27 public: |
| 26 KeyUtilityClientImpl(); | 28 KeyUtilityClientImpl(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 38 std::vector<IndexedDBKey>* keys); | 40 std::vector<IndexedDBKey>* keys); |
| 39 | 41 |
| 40 // Synchronously inject |key| into |value| using the given |key_path|, | 42 // Synchronously inject |key| into |value| using the given |key_path|, |
| 41 // returning the new value. | 43 // returning the new value. |
| 42 content::SerializedScriptValue InjectIDBKeyIntoSerializedValue( | 44 content::SerializedScriptValue InjectIDBKeyIntoSerializedValue( |
| 43 const IndexedDBKey& key, | 45 const IndexedDBKey& key, |
| 44 const content::SerializedScriptValue& value, | 46 const content::SerializedScriptValue& value, |
| 45 const string16& key_path); | 47 const string16& key_path); |
| 46 | 48 |
| 47 private: | 49 private: |
| 48 class Client : public UtilityProcessHost::Client { | 50 class Client : public UtilityProcessHostClient { |
| 49 public: | 51 public: |
| 50 explicit Client(KeyUtilityClientImpl* parent); | 52 explicit Client(KeyUtilityClientImpl* parent); |
| 51 | 53 |
| 52 // UtilityProcessHost::Client | 54 // UtilityProcessHostClient |
| 53 virtual void OnProcessCrashed(int exit_code); | 55 virtual void OnProcessCrashed(int exit_code); |
| 54 virtual bool OnMessageReceived(const IPC::Message& message); | 56 virtual bool OnMessageReceived(const IPC::Message& message); |
| 55 | 57 |
| 56 // IPC message handlers | 58 // IPC message handlers |
| 57 void OnIDBKeysFromValuesAndKeyPathSucceeded( | 59 void OnIDBKeysFromValuesAndKeyPathSucceeded( |
| 58 int id, const std::vector<IndexedDBKey>& keys); | 60 int id, const std::vector<IndexedDBKey>& keys); |
| 59 void OnIDBKeysFromValuesAndKeyPathFailed(int id); | 61 void OnIDBKeysFromValuesAndKeyPathFailed(int id); |
| 60 void OnInjectIDBKeyFinished(const content::SerializedScriptValue& value); | 62 void OnInjectIDBKeyFinished(const content::SerializedScriptValue& value); |
| 61 | 63 |
| 62 private: | 64 private: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 93 STATE_INITIALIZED, | 95 STATE_INITIALIZED, |
| 94 STATE_CREATING_KEYS, | 96 STATE_CREATING_KEYS, |
| 95 STATE_INJECTING_KEY, | 97 STATE_INJECTING_KEY, |
| 96 STATE_SHUTDOWN, | 98 STATE_SHUTDOWN, |
| 97 }; | 99 }; |
| 98 State state_; | 100 State state_; |
| 99 std::vector<IndexedDBKey> keys_; | 101 std::vector<IndexedDBKey> keys_; |
| 100 content::SerializedScriptValue value_after_injection_; | 102 content::SerializedScriptValue value_after_injection_; |
| 101 | 103 |
| 102 // Used in the IO thread. | 104 // Used in the IO thread. |
| 103 base::WeakPtr<UtilityProcessHost> utility_process_host_; | 105 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; |
| 104 scoped_refptr<Client> client_; | 106 scoped_refptr<Client> client_; |
| 105 | 107 |
| 106 DISALLOW_COPY_AND_ASSIGN(KeyUtilityClientImpl); | 108 DISALLOW_COPY_AND_ASSIGN(KeyUtilityClientImpl); |
| 107 }; | 109 }; |
| 108 | 110 |
| 109 // IndexedDBKeyUtilityClient definitions. | 111 // IndexedDBKeyUtilityClient definitions. |
| 110 | 112 |
| 111 static base::LazyInstance<IndexedDBKeyUtilityClient> client_instance = | 113 static base::LazyInstance<IndexedDBKeyUtilityClient> client_instance = |
| 112 LAZY_INSTANCE_INITIALIZER; | 114 LAZY_INSTANCE_INITIALIZER; |
| 113 | 115 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 269 BrowserThread::PostTask( | 271 BrowserThread::PostTask( |
| 270 BrowserThread::IO, FROM_HERE, | 272 BrowserThread::IO, FROM_HERE, |
| 271 base::Bind(&KeyUtilityClientImpl::StartUtilityProcessInternal, this)); | 273 base::Bind(&KeyUtilityClientImpl::StartUtilityProcessInternal, this)); |
| 272 return; | 274 return; |
| 273 } | 275 } |
| 274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 275 DCHECK(state_ == STATE_UNINITIALIZED); | 277 DCHECK(state_ == STATE_UNINITIALIZED); |
| 276 | 278 |
| 277 client_ = new KeyUtilityClientImpl::Client(this); | 279 client_ = new KeyUtilityClientImpl::Client(this); |
| 278 utility_process_host_ = (new UtilityProcessHost( | 280 utility_process_host_ = (new UtilityProcessHostImpl( |
| 279 client_.get(), BrowserThread::IO))->AsWeakPtr(); | 281 client_.get(), BrowserThread::IO))->AsWeakPtr(); |
| 280 utility_process_host_->set_use_linux_zygote(true); | 282 utility_process_host_->EnableZygote(); |
| 281 utility_process_host_->StartBatchMode(); | 283 utility_process_host_->StartBatchMode(); |
| 282 state_ = STATE_INITIALIZED; | 284 state_ = STATE_INITIALIZED; |
| 283 waitable_event_.Signal(); | 285 waitable_event_.Signal(); |
| 284 } | 286 } |
| 285 | 287 |
| 286 void KeyUtilityClientImpl::EndUtilityProcessInternal() { | 288 void KeyUtilityClientImpl::EndUtilityProcessInternal() { |
| 287 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 289 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 288 BrowserThread::PostTask( | 290 BrowserThread::PostTask( |
| 289 BrowserThread::IO, FROM_HERE, | 291 BrowserThread::IO, FROM_HERE, |
| 290 base::Bind(&KeyUtilityClientImpl::EndUtilityProcessInternal, this)); | 292 base::Bind(&KeyUtilityClientImpl::EndUtilityProcessInternal, this)); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 void KeyUtilityClientImpl::Client::OnInjectIDBKeyFinished( | 396 void KeyUtilityClientImpl::Client::OnInjectIDBKeyFinished( |
| 395 const content::SerializedScriptValue& value) { | 397 const content::SerializedScriptValue& value) { |
| 396 parent_->SetValueAfterInjection(value); | 398 parent_->SetValueAfterInjection(value); |
| 397 parent_->FinishInjectingKey(); | 399 parent_->FinishInjectingKey(); |
| 398 } | 400 } |
| 399 | 401 |
| 400 void KeyUtilityClientImpl::Client::OnIDBKeysFromValuesAndKeyPathFailed( | 402 void KeyUtilityClientImpl::Client::OnIDBKeysFromValuesAndKeyPathFailed( |
| 401 int id) { | 403 int id) { |
| 402 parent_->FinishCreatingKeys(); | 404 parent_->FinishCreatingKeys(); |
| 403 } | 405 } |
| OLD | NEW |