| OLD | NEW |
| 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 // 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 ran on the windows platform only but has been | 8 // It is currently compiled and ran on the windows platform only but has been |
| 9 // written in a platform independent way (using the process/threads/sync | 9 // written in a platform independent way (using the process/threads/sync |
| 10 // routines from base). So it does compile fine on Mac and Linux but fails to | 10 // routines from base). So it does compile fine on Mac and Linux but fails to |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // amount of time, we are OK... So we introduced this method to avoid a | 132 // amount of time, we are OK... So we introduced this method to avoid a |
| 133 // flaky wait. Instead, we kill all descendants of the main process after we | 133 // flaky wait. Instead, we kill all descendants of the main process after we |
| 134 // killed it, relying on the fact that we can still get the parent id of a | 134 // killed it, relying on the fact that we can still get the parent id of a |
| 135 // child process, even when the parent dies. | 135 // child process, even when the parent dies. |
| 136 void KillProcessTree(base::ProcessHandle process_handle) { | 136 void KillProcessTree(base::ProcessHandle process_handle) { |
| 137 class ProcessTreeFilter : public base::ProcessFilter { | 137 class ProcessTreeFilter : public base::ProcessFilter { |
| 138 public: | 138 public: |
| 139 explicit ProcessTreeFilter(base::ProcessId parent_pid) { | 139 explicit ProcessTreeFilter(base::ProcessId parent_pid) { |
| 140 ancestor_pids_.insert(parent_pid); | 140 ancestor_pids_.insert(parent_pid); |
| 141 } | 141 } |
| 142 virtual bool Includes(base::ProcessId pid, | 142 virtual bool Includes(const base::ProcessEntry & entry) const { |
| 143 base::ProcessId parent_pid) const { | 143 if (ancestor_pids_.find(entry.parent_pid()) != ancestor_pids_.end()) { |
| 144 if (ancestor_pids_.find(parent_pid) != ancestor_pids_.end()) { | 144 ancestor_pids_.insert(entry.pid()); |
| 145 ancestor_pids_.insert(pid); | |
| 146 return true; | 145 return true; |
| 147 } else { | 146 } else { |
| 148 return false; | 147 return false; |
| 149 } | 148 } |
| 150 } | 149 } |
| 151 private: | 150 private: |
| 152 mutable std::set<base::ProcessId> ancestor_pids_; | 151 mutable std::set<base::ProcessId> ancestor_pids_; |
| 153 } process_tree_filter(base::GetProcId(process_handle)); | 152 } process_tree_filter(base::GetProcId(process_handle)); |
| 154 | 153 |
| 155 // Start by explicitly killing the main process we know about... | 154 // Start by explicitly killing the main process we know about... |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 size_t last_index = pending_starters.front(); | 261 size_t last_index = pending_starters.front(); |
| 263 pending_starters.empty(); | 262 pending_starters.empty(); |
| 264 if (chrome_starters_[last_index]->process_handle_ != NULL) { | 263 if (chrome_starters_[last_index]->process_handle_ != NULL) { |
| 265 KillProcessTree(chrome_starters_[last_index]->process_handle_); | 264 KillProcessTree(chrome_starters_[last_index]->process_handle_); |
| 266 chrome_starters_[last_index]->done_event_.Wait(); | 265 chrome_starters_[last_index]->done_event_.Wait(); |
| 267 } | 266 } |
| 268 } | 267 } |
| 269 } | 268 } |
| 270 | 269 |
| 271 } // namespace | 270 } // namespace |
| OLD | NEW |