| OLD | NEW |
| 1 // Copyright (c) 2009 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/browser_process.h" | |
| 10 #include "chrome/browser/utility_process_host.h" | 9 #include "chrome/browser/utility_process_host.h" |
| 11 #include "content/common/indexed_db_key.h" | 10 #include "content/common/indexed_db_key.h" |
| 12 #include "content/common/serialized_script_value.h" | 11 #include "content/common/serialized_script_value.h" |
| 13 | 12 |
| 14 // This class is used to obtain IndexedDBKeys from SerializedScriptValues | 13 // This class is used to obtain IndexedDBKeys from SerializedScriptValues |
| 15 // given an IDBKeyPath. It uses UtilityProcess to do this inside a sandbox | 14 // given an IDBKeyPath. It uses UtilityProcess to do this inside a sandbox |
| 16 // (a V8 lock is required there). At this level, all methods are synchronous | 15 // (a V8 lock is required there). At this level, all methods are synchronous |
| 17 // as required by the caller. The public API is used on WEBKIT thread, | 16 // as required by the caller. The public API is used on WEBKIT thread, |
| 18 // but internally it moves around to UI and IO as needed. | 17 // but internally it moves around to UI and IO as needed. |
| 19 class KeyUtilityClientImpl | 18 class KeyUtilityClientImpl |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 private: | 54 private: |
| 56 KeyUtilityClientImpl* parent_; | 55 KeyUtilityClientImpl* parent_; |
| 57 | 56 |
| 58 DISALLOW_COPY_AND_ASSIGN(Client); | 57 DISALLOW_COPY_AND_ASSIGN(Client); |
| 59 }; | 58 }; |
| 60 | 59 |
| 61 friend class base::RefCountedThreadSafe<KeyUtilityClientImpl>; | 60 friend class base::RefCountedThreadSafe<KeyUtilityClientImpl>; |
| 62 ~KeyUtilityClientImpl(); | 61 ~KeyUtilityClientImpl(); |
| 63 | 62 |
| 64 void GetRDHAndStartUtilityProcess(); | 63 void GetRDHAndStartUtilityProcess(); |
| 65 void StartUtilityProcessInternal(ResourceDispatcherHost* rdh); | 64 void StartUtilityProcessInternal(); |
| 66 void EndUtilityProcessInternal(); | 65 void EndUtilityProcessInternal(); |
| 67 void CallStartIDBKeyFromValueAndKeyPathFromIOThread( | 66 void CallStartIDBKeyFromValueAndKeyPathFromIOThread( |
| 68 const std::vector<SerializedScriptValue>& values, | 67 const std::vector<SerializedScriptValue>& values, |
| 69 const string16& key_path); | 68 const string16& key_path); |
| 70 void CallStartInjectIDBKeyFromIOThread( | 69 void CallStartInjectIDBKeyFromIOThread( |
| 71 const IndexedDBKey& key, | 70 const IndexedDBKey& key, |
| 72 const SerializedScriptValue& value, | 71 const SerializedScriptValue& value, |
| 73 const string16& key_path); | 72 const string16& key_path); |
| 74 | 73 |
| 75 void SetKeys(const std::vector<IndexedDBKey>& keys); | 74 void SetKeys(const std::vector<IndexedDBKey>& keys); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 // browser_process.h | 244 // browser_process.h |
| 246 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 245 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 247 BrowserThread::PostTask( | 246 BrowserThread::PostTask( |
| 248 BrowserThread::UI, FROM_HERE, | 247 BrowserThread::UI, FROM_HERE, |
| 249 NewRunnableMethod( | 248 NewRunnableMethod( |
| 250 this, | 249 this, |
| 251 &KeyUtilityClientImpl::GetRDHAndStartUtilityProcess)); | 250 &KeyUtilityClientImpl::GetRDHAndStartUtilityProcess)); |
| 252 return; | 251 return; |
| 253 } | 252 } |
| 254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 255 StartUtilityProcessInternal(g_browser_process->resource_dispatcher_host()); | 254 StartUtilityProcessInternal(); |
| 256 } | 255 } |
| 257 | 256 |
| 258 void KeyUtilityClientImpl::StartUtilityProcessInternal( | 257 void KeyUtilityClientImpl::StartUtilityProcessInternal() { |
| 259 ResourceDispatcherHost* rdh) { | |
| 260 DCHECK(rdh); | |
| 261 // The ResourceDispatcherHost can only be used on the IO thread. | 258 // The ResourceDispatcherHost can only be used on the IO thread. |
| 262 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 259 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 264 BrowserThread::PostTask( | 261 BrowserThread::PostTask( |
| 265 BrowserThread::IO, FROM_HERE, | 262 BrowserThread::IO, FROM_HERE, |
| 266 NewRunnableMethod( | 263 NewRunnableMethod( |
| 267 this, | 264 this, |
| 268 &KeyUtilityClientImpl::StartUtilityProcessInternal, | 265 &KeyUtilityClientImpl::StartUtilityProcessInternal)); |
| 269 rdh)); | |
| 270 return; | 266 return; |
| 271 } | 267 } |
| 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 273 DCHECK(state_ == STATE_UNINITIALIZED); | 269 DCHECK(state_ == STATE_UNINITIALIZED); |
| 274 | 270 |
| 275 client_ = new KeyUtilityClientImpl::Client(this); | 271 client_ = new KeyUtilityClientImpl::Client(this); |
| 276 utility_process_host_ = new UtilityProcessHost( | 272 utility_process_host_ = new UtilityProcessHost( |
| 277 rdh, client_.get(), BrowserThread::IO); | 273 client_.get(), BrowserThread::IO); |
| 278 utility_process_host_->StartBatchMode(); | 274 utility_process_host_->StartBatchMode(); |
| 279 state_ = STATE_INITIALIZED; | 275 state_ = STATE_INITIALIZED; |
| 280 waitable_event_.Signal(); | 276 waitable_event_.Signal(); |
| 281 } | 277 } |
| 282 | 278 |
| 283 void KeyUtilityClientImpl::EndUtilityProcessInternal() { | 279 void KeyUtilityClientImpl::EndUtilityProcessInternal() { |
| 284 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 280 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 285 BrowserThread::PostTask( | 281 BrowserThread::PostTask( |
| 286 BrowserThread::IO, FROM_HERE, | 282 BrowserThread::IO, FROM_HERE, |
| 287 NewRunnableMethod( | 283 NewRunnableMethod( |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 void KeyUtilityClientImpl::Client::OnInjectIDBKeyFinished( | 370 void KeyUtilityClientImpl::Client::OnInjectIDBKeyFinished( |
| 375 const SerializedScriptValue& value) { | 371 const SerializedScriptValue& value) { |
| 376 parent_->SetValueAfterInjection(value); | 372 parent_->SetValueAfterInjection(value); |
| 377 parent_->FinishInjectingKey(); | 373 parent_->FinishInjectingKey(); |
| 378 } | 374 } |
| 379 | 375 |
| 380 void KeyUtilityClientImpl::Client::OnIDBKeysFromValuesAndKeyPathFailed( | 376 void KeyUtilityClientImpl::Client::OnIDBKeysFromValuesAndKeyPathFailed( |
| 381 int id) { | 377 int id) { |
| 382 parent_->FinishCreatingKeys(); | 378 parent_->FinishCreatingKeys(); |
| 383 } | 379 } |
| OLD | NEW |