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

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

Issue 6209005: Fix IndexedDB race condition during shutdown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: First stab at new approach Created 9 years, 11 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/browser/in_process_webkit/indexed_db_key_utility_client.h" 5 #include "chrome/browser/in_process_webkit/indexed_db_key_utility_client.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/common/indexed_db_key.h" 10 #include "chrome/common/indexed_db_key.h"
11 #include "chrome/common/serialized_script_value.h" 11 #include "chrome/common/serialized_script_value.h"
12 12
13 IndexedDBKeyUtilityClient* IndexedDBKeyUtilityClient::Get() {
14 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT));
15 AutoLock auto_lock(instantiation_lock_);
16
17 if (!instance_.get()) {
18 instance_ = new IndexedDBKeyUtilityClient();
19 instance_->StartUtilityProcess();
20 }
21
22 return instance_.get();
23 }
24
25 void IndexedDBKeyUtilityClient::Shutdown() {
26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
27 AutoLock autolock(instantiation_lock_);
28
29 if (!instance_.get())
30 return;
31
32 instance_->utility_process_host_->EndBatchMode();
33 instance_->utility_process_host_ = NULL;
34 instance_->client_ = NULL;
35 instance_->state_ = STATE_SHUTDOWN;
36 instance_ = NULL;
37 }
38
13 IndexedDBKeyUtilityClient::IndexedDBKeyUtilityClient() 39 IndexedDBKeyUtilityClient::IndexedDBKeyUtilityClient()
14 : waitable_event_(false, false), 40 : waitable_event_(false, false),
15 state_(STATE_UNINITIALIZED), 41 state_(STATE_UNINITIALIZED),
16 utility_process_host_(NULL) { 42 utility_process_host_(NULL) {
17 } 43 }
18 44
19 IndexedDBKeyUtilityClient::~IndexedDBKeyUtilityClient() { 45 IndexedDBKeyUtilityClient::~IndexedDBKeyUtilityClient() {
20 DCHECK(state_ == STATE_UNINITIALIZED || state_ == STATE_SHUTDOWN); 46 DCHECK(state_ == STATE_UNINITIALIZED || state_ == STATE_SHUTDOWN);
21 DCHECK(!utility_process_host_); 47 DCHECK(!utility_process_host_);
22 DCHECK(!client_.get()); 48 DCHECK(!client_.get());
23 } 49 }
24 50
25 void IndexedDBKeyUtilityClient::StartUtilityProcess() { 51 void IndexedDBKeyUtilityClient::StartUtilityProcess() {
26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT));
27 DCHECK(state_ == STATE_UNINITIALIZED); 53 DCHECK(state_ == STATE_UNINITIALIZED);
28 54
29 GetRDHAndStartUtilityProcess(); 55 GetRDHAndStartUtilityProcess();
30 bool ret = waitable_event_.Wait(); 56 bool ret = waitable_event_.Wait();
31 57
32 DCHECK(ret && state_ == STATE_INITIALIZED); 58 DCHECK(ret && state_ == STATE_INITIALIZED);
33 } 59 }
34 60
35 void IndexedDBKeyUtilityClient::EndUtilityProcess() {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT));
37 DCHECK(state_ == STATE_INITIALIZED);
38
39 EndUtilityProcessInternal();
40 bool ret = waitable_event_.Wait();
41
42 DCHECK(ret && state_ == STATE_SHUTDOWN);
43 }
44
45 void IndexedDBKeyUtilityClient::CreateIDBKeysFromSerializedValuesAndKeyPath( 61 void IndexedDBKeyUtilityClient::CreateIDBKeysFromSerializedValuesAndKeyPath(
46 const std::vector<SerializedScriptValue>& values, 62 const std::vector<SerializedScriptValue>& values,
47 const string16& key_path, 63 const string16& key_path,
48 std::vector<IndexedDBKey>* keys) { 64 std::vector<IndexedDBKey>* keys) {
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT));
66 if (state_ == STATE_SHUTDOWN) {
67 keys->clear();
68 return;
69 }
70
50 DCHECK(state_ == STATE_INITIALIZED); 71 DCHECK(state_ == STATE_INITIALIZED);
51 72
52 state_ = STATE_CREATING_KEYS; 73 state_ = STATE_CREATING_KEYS;
53 CallStartIDBKeyFromValueAndKeyPathFromIOThread(values, key_path); 74 CallStartIDBKeyFromValueAndKeyPathFromIOThread(values, key_path);
54 bool ret = waitable_event_.Wait(); 75 bool ret = waitable_event_.Wait();
55 DCHECK(ret && state_ == STATE_INITIALIZED); 76 DCHECK(ret && state_ == STATE_INITIALIZED);
56 77
57 *keys = keys_; 78 *keys = keys_;
58 } 79 }
59 80
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 void IndexedDBKeyUtilityClient::Client::OnIDBKeysFromValuesAndKeyPathSucceeded( 178 void IndexedDBKeyUtilityClient::Client::OnIDBKeysFromValuesAndKeyPathSucceeded(
158 int id, const std::vector<IndexedDBKey>& keys) { 179 int id, const std::vector<IndexedDBKey>& keys) {
159 parent_->SetKeys(keys); 180 parent_->SetKeys(keys);
160 parent_->FinishCreatingKeys(); 181 parent_->FinishCreatingKeys();
161 } 182 }
162 183
163 void IndexedDBKeyUtilityClient::Client::OnIDBKeysFromValuesAndKeyPathFailed( 184 void IndexedDBKeyUtilityClient::Client::OnIDBKeysFromValuesAndKeyPathFailed(
164 int id) { 185 int id) {
165 parent_->FinishCreatingKeys(); 186 parent_->FinishCreatingKeys();
166 } 187 }
188
189 scoped_refptr<IndexedDBKeyUtilityClient> IndexedDBKeyUtilityClient::instance_;
190 base::Lock IndexedDBKeyUtilityClient::instantiation_lock_;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698