| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // Our test fixture that initializes and holds onto a few global vars. | 131 // Our test fixture that initializes and holds onto a few global vars. |
| 132 class ProcessSingletonTest : public InProcessBrowserTest { | 132 class ProcessSingletonTest : public InProcessBrowserTest { |
| 133 public: | 133 public: |
| 134 ProcessSingletonTest() | 134 ProcessSingletonTest() |
| 135 // We use a manual reset so that all threads wake up at once when signaled | 135 // We use a manual reset so that all threads wake up at once when signaled |
| 136 // and thus we must manually reset it for each attempt. | 136 // and thus we must manually reset it for each attempt. |
| 137 : threads_waker_(true /* manual */, false /* signaled */) { | 137 : threads_waker_(true /* manual */, false /* signaled */) { |
| 138 EXPECT_TRUE(temp_profile_dir_.CreateUniqueTempDir()); | 138 EXPECT_TRUE(temp_profile_dir_.CreateUniqueTempDir()); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void SetUp() { | 141 virtual void SetUp() { |
| 142 // Start the threads and create the starters. | 142 // Start the threads and create the starters. |
| 143 for (size_t i = 0; i < kNbThreads; ++i) { | 143 for (size_t i = 0; i < kNbThreads; ++i) { |
| 144 chrome_starter_threads_[i].reset(new base::Thread("ChromeStarter")); | 144 chrome_starter_threads_[i].reset(new base::Thread("ChromeStarter")); |
| 145 ASSERT_TRUE(chrome_starter_threads_[i]->Start()); | 145 ASSERT_TRUE(chrome_starter_threads_[i]->Start()); |
| 146 chrome_starters_[i] = new ChromeStarter( | 146 chrome_starters_[i] = new ChromeStarter( |
| 147 TestTimeouts::action_max_timeout(), temp_profile_dir_.path()); | 147 TestTimeouts::action_max_timeout(), temp_profile_dir_.path()); |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 | 150 |
| 151 void TearDown() { | 151 virtual void TearDown() { |
| 152 // Stop the threads. | 152 // Stop the threads. |
| 153 for (size_t i = 0; i < kNbThreads; ++i) | 153 for (size_t i = 0; i < kNbThreads; ++i) |
| 154 chrome_starter_threads_[i]->Stop(); | 154 chrome_starter_threads_[i]->Stop(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 // This method is used to make sure we kill the main browser process after | 157 // This method is used to make sure we kill the main browser process after |
| 158 // all of its child processes have successfully attached to it. This was added | 158 // all of its child processes have successfully attached to it. This was added |
| 159 // when we realized that if we just kill the parent process right away, we | 159 // when we realized that if we just kill the parent process right away, we |
| 160 // sometimes end up with dangling child processes. If we Sleep for a certain | 160 // sometimes end up with dangling child processes. If we Sleep for a certain |
| 161 // amount of time, we are OK... So we introduced this method to avoid a | 161 // amount of time, we are OK... So we introduced this method to avoid a |
| 162 // flaky wait. Instead, we kill all descendants of the main process after we | 162 // flaky wait. Instead, we kill all descendants of the main process after we |
| 163 // killed it, relying on the fact that we can still get the parent id of a | 163 // killed it, relying on the fact that we can still get the parent id of a |
| 164 // child process, even when the parent dies. | 164 // child process, even when the parent dies. |
| 165 void KillProcessTree(base::ProcessHandle process_handle) { | 165 void KillProcessTree(base::ProcessHandle process_handle) { |
| 166 class ProcessTreeFilter : public base::ProcessFilter { | 166 class ProcessTreeFilter : public base::ProcessFilter { |
| 167 public: | 167 public: |
| 168 explicit ProcessTreeFilter(base::ProcessId parent_pid) { | 168 explicit ProcessTreeFilter(base::ProcessId parent_pid) { |
| 169 ancestor_pids_.insert(parent_pid); | 169 ancestor_pids_.insert(parent_pid); |
| 170 } | 170 } |
| 171 virtual bool Includes(const base::ProcessEntry & entry) const { | 171 virtual bool Includes(const base::ProcessEntry & entry) const OVERRIDE { |
| 172 if (ancestor_pids_.find(entry.parent_pid()) != ancestor_pids_.end()) { | 172 if (ancestor_pids_.find(entry.parent_pid()) != ancestor_pids_.end()) { |
| 173 ancestor_pids_.insert(entry.pid()); | 173 ancestor_pids_.insert(entry.pid()); |
| 174 return true; | 174 return true; |
| 175 } else { | 175 } else { |
| 176 return false; | 176 return false; |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 private: | 179 private: |
| 180 mutable std::set<base::ProcessId> ancestor_pids_; | 180 mutable std::set<base::ProcessId> ancestor_pids_; |
| 181 } process_tree_filter(base::GetProcId(process_handle)); | 181 } process_tree_filter(base::GetProcId(process_handle)); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 ASSERT_EQ(static_cast<size_t>(1), pending_starters.size()); | 316 ASSERT_EQ(static_cast<size_t>(1), pending_starters.size()); |
| 317 size_t last_index = pending_starters.front(); | 317 size_t last_index = pending_starters.front(); |
| 318 pending_starters.clear(); | 318 pending_starters.clear(); |
| 319 if (chrome_starters_[last_index]->process_handle_ != | 319 if (chrome_starters_[last_index]->process_handle_ != |
| 320 base::kNullProcessHandle) { | 320 base::kNullProcessHandle) { |
| 321 KillProcessTree(chrome_starters_[last_index]->process_handle_); | 321 KillProcessTree(chrome_starters_[last_index]->process_handle_); |
| 322 chrome_starters_[last_index]->done_event_.Wait(); | 322 chrome_starters_[last_index]->done_event_.Wait(); |
| 323 } | 323 } |
| 324 } | 324 } |
| 325 } | 325 } |
| OLD | NEW |