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 // This test validates that the ProcessSingleton class properly makes sure | 5 // This test validates that the ProcessSingleton class properly makes sure |
6 // that there is only one main browser process. | 6 // that there is only one main browser process. |
7 // | 7 // |
8 // It is currently compiled and run on Windows and Posix(non-Mac) platforms. | 8 // It is currently compiled and run on Windows and Posix(non-Mac) platforms. |
9 // Mac uses system services and ProcessSingletonMac is a noop. (Maybe it still | 9 // Mac uses system services and ProcessSingletonMac is a noop. (Maybe it still |
10 // makes sense to test that the system services are giving the behavior we | 10 // makes sense to test that the system services are giving the behavior we |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 // This is for the code that is to be ran in multiple threads at once, | 41 // This is for the code that is to be ran in multiple threads at once, |
42 // to stress a race condition on first process start. | 42 // to stress a race condition on first process start. |
43 // We use the thread safe ref counted base class so that we can use the | 43 // We use the thread safe ref counted base class so that we can use the |
44 // base::Bind to run the StartChrome methods in many threads. | 44 // base::Bind to run the StartChrome methods in many threads. |
45 class ChromeStarter : public base::RefCountedThreadSafe<ChromeStarter> { | 45 class ChromeStarter : public base::RefCountedThreadSafe<ChromeStarter> { |
46 public: | 46 public: |
47 ChromeStarter(base::TimeDelta timeout, const base::FilePath& user_data_dir) | 47 ChromeStarter(base::TimeDelta timeout, const base::FilePath& user_data_dir) |
48 : ready_event_(false /* manual */, false /* signaled */), | 48 : ready_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
49 done_event_(false /* manual */, false /* signaled */), | 49 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 50 done_event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 51 base::WaitableEvent::InitialState::NOT_SIGNALED), |
50 process_terminated_(false), | 52 process_terminated_(false), |
51 timeout_(timeout), | 53 timeout_(timeout), |
52 user_data_dir_(user_data_dir) { | 54 user_data_dir_(user_data_dir) {} |
53 } | |
54 | 55 |
55 // We must reset some data members since we reuse the same ChromeStarter | 56 // We must reset some data members since we reuse the same ChromeStarter |
56 // object and start/stop it a few times. We must start fresh! :-) | 57 // object and start/stop it a few times. We must start fresh! :-) |
57 void Reset() { | 58 void Reset() { |
58 ready_event_.Reset(); | 59 ready_event_.Reset(); |
59 done_event_.Reset(); | 60 done_event_.Reset(); |
60 if (process_.IsValid()) | 61 if (process_.IsValid()) |
61 process_.Close(); | 62 process_.Close(); |
62 process_terminated_ = false; | 63 process_terminated_ = false; |
63 } | 64 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 }; | 133 }; |
133 | 134 |
134 } // namespace | 135 } // namespace |
135 | 136 |
136 // Our test fixture that initializes and holds onto a few global vars. | 137 // Our test fixture that initializes and holds onto a few global vars. |
137 class ProcessSingletonTest : public InProcessBrowserTest { | 138 class ProcessSingletonTest : public InProcessBrowserTest { |
138 public: | 139 public: |
139 ProcessSingletonTest() | 140 ProcessSingletonTest() |
140 // We use a manual reset so that all threads wake up at once when signaled | 141 // We use a manual reset so that all threads wake up at once when signaled |
141 // and thus we must manually reset it for each attempt. | 142 // and thus we must manually reset it for each attempt. |
142 : threads_waker_(true /* manual */, false /* signaled */) { | 143 : threads_waker_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 144 base::WaitableEvent::InitialState::NOT_SIGNALED) { |
143 EXPECT_TRUE(temp_profile_dir_.CreateUniqueTempDir()); | 145 EXPECT_TRUE(temp_profile_dir_.CreateUniqueTempDir()); |
144 } | 146 } |
145 | 147 |
146 void SetUp() override { | 148 void SetUp() override { |
147 InProcessBrowserTest::SetUp(); | 149 InProcessBrowserTest::SetUp(); |
148 // Start the threads and create the starters. | 150 // Start the threads and create the starters. |
149 for (size_t i = 0; i < kNbThreads; ++i) { | 151 for (size_t i = 0; i < kNbThreads; ++i) { |
150 chrome_starter_threads_[i].reset(new base::Thread("ChromeStarter")); | 152 chrome_starter_threads_[i].reset(new base::Thread("ChromeStarter")); |
151 ASSERT_TRUE(chrome_starter_threads_[i]->Start()); | 153 ASSERT_TRUE(chrome_starter_threads_[i]->Start()); |
152 chrome_starters_[i] = new ChromeStarter( | 154 chrome_starters_[i] = new ChromeStarter( |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 // "There can be only one!" :-) | 317 // "There can be only one!" :-) |
316 ASSERT_EQ(static_cast<size_t>(1), pending_starters.size()); | 318 ASSERT_EQ(static_cast<size_t>(1), pending_starters.size()); |
317 size_t last_index = pending_starters.front(); | 319 size_t last_index = pending_starters.front(); |
318 pending_starters.clear(); | 320 pending_starters.clear(); |
319 if (chrome_starters_[last_index]->process_.IsValid()) { | 321 if (chrome_starters_[last_index]->process_.IsValid()) { |
320 KillProcessTree(chrome_starters_[last_index]->process_); | 322 KillProcessTree(chrome_starters_[last_index]->process_); |
321 chrome_starters_[last_index]->done_event_.Wait(); | 323 chrome_starters_[last_index]->done_event_.Wait(); |
322 } | 324 } |
323 } | 325 } |
324 } | 326 } |
OLD | NEW |