OLD | NEW |
1 // Copyright (c) 2011 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 // 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 continue; | 85 continue; |
86 | 86 |
87 command_line.AppendSwitchNative(switch_name, i->second); | 87 command_line.AppendSwitchNative(switch_name, i->second); |
88 } | 88 } |
89 | 89 |
90 // Try to get all threads to launch the app at the same time. | 90 // Try to get all threads to launch the app at the same time. |
91 // So let the test know we are ready. | 91 // So let the test know we are ready. |
92 ready_event_.Signal(); | 92 ready_event_.Signal(); |
93 // And then wait for the test to tell us to GO! | 93 // And then wait for the test to tell us to GO! |
94 ASSERT_NE(static_cast<base::WaitableEvent*>(NULL), start_event); | 94 ASSERT_NE(static_cast<base::WaitableEvent*>(NULL), start_event); |
95 ASSERT_TRUE(start_event->Wait()); | 95 start_event->Wait(); |
96 | 96 |
97 // Here we don't wait for the app to be terminated because one of the | 97 // Here we don't wait for the app to be terminated because one of the |
98 // process will stay alive while the others will be restarted. If we would | 98 // process will stay alive while the others will be restarted. If we would |
99 // wait here, we would never get a handle to the main process... | 99 // wait here, we would never get a handle to the main process... |
100 base::LaunchProcess(command_line, base::LaunchOptions(), &process_handle_); | 100 base::LaunchProcess(command_line, base::LaunchOptions(), &process_handle_); |
101 ASSERT_NE(base::kNullProcessHandle, process_handle_); | 101 ASSERT_NE(base::kNullProcessHandle, process_handle_); |
102 | 102 |
103 // We can wait on the handle here, we should get stuck on one and only | 103 // We can wait on the handle here, we should get stuck on one and only |
104 // one process. The test below will take care of killing that process | 104 // one process. The test below will take care of killing that process |
105 // to unstuck us once it confirms there is only one. | 105 // to unstuck us once it confirms there is only one. |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 FROM_HERE, NewRunnableMethod(chrome_starters_[i].get(), | 259 FROM_HERE, NewRunnableMethod(chrome_starters_[i].get(), |
260 &ChromeStarter::StartChrome, | 260 &ChromeStarter::StartChrome, |
261 &threads_waker_, | 261 &threads_waker_, |
262 first_run)); | 262 first_run)); |
263 } | 263 } |
264 | 264 |
265 // Wait for all the starters to be ready. | 265 // Wait for all the starters to be ready. |
266 // We could replace this loop if we ever implement a WaitAll(). | 266 // We could replace this loop if we ever implement a WaitAll(). |
267 for (size_t i = 0; i < kNbThreads; ++i) { | 267 for (size_t i = 0; i < kNbThreads; ++i) { |
268 SCOPED_TRACE(testing::Message() << "Waiting on thread: " << i << "."); | 268 SCOPED_TRACE(testing::Message() << "Waiting on thread: " << i << "."); |
269 ASSERT_TRUE(chrome_starters_[i]->ready_event_.Wait()); | 269 chrome_starters_[i]->ready_event_.Wait(); |
270 } | 270 } |
271 // GO! | 271 // GO! |
272 threads_waker_.Signal(); | 272 threads_waker_.Signal(); |
273 | 273 |
274 // As we wait for all threads to signal that they are done, we remove their | 274 // As we wait for all threads to signal that they are done, we remove their |
275 // index from this vector so that we get left with only the index of | 275 // index from this vector so that we get left with only the index of |
276 // the thread that started the main process. | 276 // the thread that started the main process. |
277 std::vector<size_t> pending_starters(kNbThreads); | 277 std::vector<size_t> pending_starters(kNbThreads); |
278 for (size_t i = 0; i < kNbThreads; ++i) | 278 for (size_t i = 0; i < kNbThreads; ++i) |
279 pending_starters[i] = i; | 279 pending_starters[i] = i; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 pending_starters.empty(); | 317 pending_starters.empty(); |
318 if (chrome_starters_[last_index]->process_handle_ != | 318 if (chrome_starters_[last_index]->process_handle_ != |
319 base::kNullProcessHandle) { | 319 base::kNullProcessHandle) { |
320 KillProcessTree(chrome_starters_[last_index]->process_handle_); | 320 KillProcessTree(chrome_starters_[last_index]->process_handle_); |
321 chrome_starters_[last_index]->done_event_.Wait(); | 321 chrome_starters_[last_index]->done_event_.Wait(); |
322 } | 322 } |
323 } | 323 } |
324 } | 324 } |
325 | 325 |
326 } // namespace | 326 } // namespace |
OLD | NEW |