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

Side by Side Diff: content/browser/indexed_db/idbbindingutilities_browsertest.cc

Issue 9235052: Fix race condition in utility process clients (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync to ToT Created 8 years, 10 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) 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/test/base/in_process_browser_test.h" 7 #include "chrome/test/base/in_process_browser_test.h"
8 #include "chrome/test/base/ui_test_utils.h" 8 #include "chrome/test/base/ui_test_utils.h"
9 #include "content/browser/renderer_host/resource_dispatcher_host.h" 9 #include "content/browser/renderer_host/resource_dispatcher_host.h"
10 #include "content/browser/utility_process_host.h" 10 #include "content/browser/utility_process_host.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 ASSERT_EQ(WebKit::WebIDBKey::NullType, values[0].type()); 101 ASSERT_EQ(WebKit::WebIDBKey::NullType, values[0].type());
102 ASSERT_EQ(WebKit::WebIDBKey::NullType, values[1].type()); 102 ASSERT_EQ(WebKit::WebIDBKey::NullType, values[1].type());
103 ASSERT_EQ(WebKit::WebIDBKey::NullType, values[2].type()); 103 ASSERT_EQ(WebKit::WebIDBKey::NullType, values[2].type());
104 ASSERT_EQ(WebKit::WebIDBKey::NullType, values[3].type()); 104 ASSERT_EQ(WebKit::WebIDBKey::NullType, values[3].type());
105 } 105 }
106 106
107 class IDBKeyPathHelper : public UtilityProcessHost::Client { 107 class IDBKeyPathHelper : public UtilityProcessHost::Client {
108 public: 108 public:
109 IDBKeyPathHelper() 109 IDBKeyPathHelper()
110 : expected_id_(0), 110 : expected_id_(0),
111 utility_process_host_(NULL),
112 value_for_key_path_failed_(false) { 111 value_for_key_path_failed_(false) {
113 } 112 }
114 113
115 void CreateUtilityProcess() { 114 void CreateUtilityProcess() {
116 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 115 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
117 BrowserThread::PostTask( 116 BrowserThread::PostTask(
118 BrowserThread::IO, FROM_HERE, 117 BrowserThread::IO, FROM_HERE,
119 base::Bind(&IDBKeyPathHelper::CreateUtilityProcess, this)); 118 base::Bind(&IDBKeyPathHelper::CreateUtilityProcess, this));
120 return; 119 return;
121 } 120 }
122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
123 utility_process_host_ = 122 utility_process_host_ =
124 new UtilityProcessHost(this, BrowserThread::IO); 123 (new UtilityProcessHost(this, BrowserThread::IO))->AsWeakPtr();
125 utility_process_host_->set_use_linux_zygote(true); 124 utility_process_host_->set_use_linux_zygote(true);
126 utility_process_host_->StartBatchMode(); 125 utility_process_host_->StartBatchMode();
127 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 126 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
128 MessageLoop::QuitClosure()); 127 MessageLoop::QuitClosure());
129 } 128 }
130 129
131 void DestroyUtilityProcess() { 130 void DestroyUtilityProcess() {
132 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 131 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
133 BrowserThread::PostTask( 132 BrowserThread::PostTask(
134 BrowserThread::IO, FROM_HERE, 133 BrowserThread::IO, FROM_HERE,
135 base::Bind(&IDBKeyPathHelper::DestroyUtilityProcess, this)); 134 base::Bind(&IDBKeyPathHelper::DestroyUtilityProcess, this));
136 return; 135 return;
137 } 136 }
138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
139 utility_process_host_->EndBatchMode(); 138 utility_process_host_->EndBatchMode();
140 utility_process_host_ = NULL; 139 utility_process_host_.reset();
141 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 140 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
142 MessageLoop::QuitClosure()); 141 MessageLoop::QuitClosure());
143 } 142 }
144 143
145 void SetExpectedKeys(int expected_id, 144 void SetExpectedKeys(int expected_id,
146 const std::vector<IndexedDBKey>& expected_keys, 145 const std::vector<IndexedDBKey>& expected_keys,
147 bool failed) { 146 bool failed) {
148 expected_id_ = expected_id; 147 expected_id_ = expected_id;
149 expected_keys_ = expected_keys; 148 expected_keys_ = expected_keys;
150 value_for_key_path_failed_ = failed; 149 value_for_key_path_failed_ = failed;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 void OnInjectIDBKeyFinished(const content::SerializedScriptValue& new_value) { 231 void OnInjectIDBKeyFinished(const content::SerializedScriptValue& new_value) {
233 EXPECT_EQ(expected_value_.data(), new_value.data()); 232 EXPECT_EQ(expected_value_.data(), new_value.data());
234 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 233 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
235 MessageLoop::QuitClosure()); 234 MessageLoop::QuitClosure());
236 } 235 }
237 236
238 237
239 private: 238 private:
240 int expected_id_; 239 int expected_id_;
241 std::vector<IndexedDBKey> expected_keys_; 240 std::vector<IndexedDBKey> expected_keys_;
242 UtilityProcessHost* utility_process_host_; 241 base::WeakPtr<UtilityProcessHost> utility_process_host_;
243 bool value_for_key_path_failed_; 242 bool value_for_key_path_failed_;
244 content::SerializedScriptValue expected_value_; 243 content::SerializedScriptValue expected_value_;
245 }; 244 };
246 245
247 // This test fixture runs in the UI thread. However, most of the work done by 246 // This test fixture runs in the UI thread. However, most of the work done by
248 // UtilityProcessHost (and wrapped by IDBKeyPathHelper above) happens on the IO 247 // UtilityProcessHost (and wrapped by IDBKeyPathHelper above) happens on the IO
249 // thread. This fixture delegates to IDBKeyPathHelper and blocks via 248 // thread. This fixture delegates to IDBKeyPathHelper and blocks via
250 // "ui_test_utils::RunMessageLoop()", until IDBKeyPathHelper posts a quit 249 // "ui_test_utils::RunMessageLoop()", until IDBKeyPathHelper posts a quit
251 // message the MessageLoop. 250 // message the MessageLoop.
252 class ScopedIDBKeyPathHelper { 251 class ScopedIDBKeyPathHelper {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 0x6f6f, 0x013f, 0x0353, 0x6f7a, 0x3f6f, 426 0x6f6f, 0x013f, 0x0353, 0x6f7a, 0x3f6f,
428 0x5301, 0x6203, 0x7261, 0x013f, 0x3f6f, 427 0x5301, 0x6203, 0x7261, 0x013f, 0x3f6f,
429 0x5302, 0x6203, 0x7a61, 0x023f, 0x0853, 428 0x5302, 0x6203, 0x7a61, 0x023f, 0x0853,
430 0x796d, 0x654e, 0x4b77, 0x7965, 0x017b, 429 0x796d, 0x654e, 0x4b77, 0x7965, 0x017b,
431 0x027b}; 430 0x027b};
432 content::SerializedScriptValue expected_value2( 431 content::SerializedScriptValue expected_value2(
433 false, false, string16(expected_data2, arraysize(expected_data2))); 432 false, false, string16(expected_data2, arraysize(expected_data2)));
434 scoped_helper.SetExpectedValue(expected_value2); 433 scoped_helper.SetExpectedValue(expected_value2);
435 scoped_helper.CheckInjectValue(key, value, UTF8ToUTF16("bar.baz")); 434 scoped_helper.CheckInjectValue(key, value, UTF8ToUTF16("bar.baz"));
436 } 435 }
OLDNEW
« no previous file with comments | « content/browser/in_process_webkit/indexed_db_key_utility_client.cc ('k') | content/browser/plugin_loader_posix.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698