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

Side by Side Diff: chrome/browser/process_singleton_browsertest.cc

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

Powered by Google App Engine
This is Rietveld 408576698