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

Side by Side Diff: content/browser/child_process_launcher.cc

Issue 6992006: Terminate plugin processes on a delayed task to allow the plugins to shutdown gracefully, i.e. NP... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/child_process_launcher.h ('k') | content/browser/plugin_process_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "content/browser/child_process_launcher.h" 5 #include "content/browser/child_process_launcher.h"
6 6
7 #include <utility> // For std::pair. 7 #include <utility> // For std::pair.
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 26 matching lines...) Expand all
37 37
38 // Having the functionality of ChildProcessLauncher be in an internal 38 // Having the functionality of ChildProcessLauncher be in an internal
39 // ref counted object allows us to automatically terminate the process when the 39 // ref counted object allows us to automatically terminate the process when the
40 // parent class destructs, while still holding on to state that we need. 40 // parent class destructs, while still holding on to state that we need.
41 class ChildProcessLauncher::Context 41 class ChildProcessLauncher::Context
42 : public base::RefCountedThreadSafe<ChildProcessLauncher::Context> { 42 : public base::RefCountedThreadSafe<ChildProcessLauncher::Context> {
43 public: 43 public:
44 Context() 44 Context()
45 : client_(NULL), 45 : client_(NULL),
46 client_thread_id_(BrowserThread::UI), 46 client_thread_id_(BrowserThread::UI),
47 starting_(true) 47 starting_(true),
48 terminate_child_on_shutdown_(true)
48 #if defined(OS_LINUX) 49 #if defined(OS_LINUX)
49 , zygote_(false) 50 , zygote_(false)
50 #endif 51 #endif
51 { 52 {
52 } 53 }
53 54
54 void Launch( 55 void Launch(
55 #if defined(OS_WIN) 56 #if defined(OS_WIN)
56 const FilePath& exposed_dir, 57 const FilePath& exposed_dir,
57 #elif defined(OS_POSIX) 58 #elif defined(OS_POSIX)
(...skipping 22 matching lines...) Expand all
80 cmd_line)); 81 cmd_line));
81 } 82 }
82 83
83 void ResetClient() { 84 void ResetClient() {
84 // No need for locking as this function gets called on the same thread that 85 // No need for locking as this function gets called on the same thread that
85 // client_ would be used. 86 // client_ would be used.
86 CHECK(BrowserThread::CurrentlyOn(client_thread_id_)); 87 CHECK(BrowserThread::CurrentlyOn(client_thread_id_));
87 client_ = NULL; 88 client_ = NULL;
88 } 89 }
89 90
91 void set_terminate_child_on_shutdown(bool terminate_on_shutdown) {
92 terminate_child_on_shutdown_ = terminate_on_shutdown;
93 }
94
90 private: 95 private:
91 friend class base::RefCountedThreadSafe<ChildProcessLauncher::Context>; 96 friend class base::RefCountedThreadSafe<ChildProcessLauncher::Context>;
92 friend class ChildProcessLauncher; 97 friend class ChildProcessLauncher;
93 98
94 ~Context() { 99 ~Context() {
95 Terminate(); 100 Terminate();
96 } 101 }
97 102
98 void LaunchInternal( 103 void LaunchInternal(
99 #if defined(OS_WIN) 104 #if defined(OS_WIN)
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 client_->OnProcessLaunched(); 208 client_->OnProcessLaunched();
204 } else { 209 } else {
205 Terminate(); 210 Terminate();
206 } 211 }
207 } 212 }
208 213
209 void Terminate() { 214 void Terminate() {
210 if (!process_.handle()) 215 if (!process_.handle())
211 return; 216 return;
212 217
218 if (!terminate_child_on_shutdown_)
219 return;
220
213 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! So 221 // On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep! So
214 // don't this on the UI/IO threads. 222 // don't this on the UI/IO threads.
215 BrowserThread::PostTask( 223 BrowserThread::PostTask(
216 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, 224 BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
217 NewRunnableFunction( 225 NewRunnableFunction(
218 &ChildProcessLauncher::Context::TerminateInternal, 226 &ChildProcessLauncher::Context::TerminateInternal,
219 #if defined(OS_LINUX) 227 #if defined(OS_LINUX)
220 zygote_, 228 zygote_,
221 #endif 229 #endif
222 process_.handle())); 230 process_.handle()));
(...skipping 27 matching lines...) Expand all
250 ProcessWatcher::EnsureProcessTerminated(handle); 258 ProcessWatcher::EnsureProcessTerminated(handle);
251 } 259 }
252 #endif // OS_POSIX 260 #endif // OS_POSIX
253 process.Close(); 261 process.Close();
254 } 262 }
255 263
256 Client* client_; 264 Client* client_;
257 BrowserThread::ID client_thread_id_; 265 BrowserThread::ID client_thread_id_;
258 base::Process process_; 266 base::Process process_;
259 bool starting_; 267 bool starting_;
268 // Controls whether the child process should be terminated on browser
269 // shutdown. Default behavior is to terminate the child.
270 bool terminate_child_on_shutdown_;
260 271
261 #if defined(OS_LINUX) 272 #if defined(OS_LINUX)
262 bool zygote_; 273 bool zygote_;
263 #endif 274 #endif
264 }; 275 };
265 276
266 277
267 ChildProcessLauncher::ChildProcessLauncher( 278 ChildProcessLauncher::ChildProcessLauncher(
268 #if defined(OS_WIN) 279 #if defined(OS_WIN)
269 const FilePath& exposed_dir, 280 const FilePath& exposed_dir,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 } 337 }
327 338
328 void ChildProcessLauncher::SetProcessBackgrounded(bool background) { 339 void ChildProcessLauncher::SetProcessBackgrounded(bool background) {
329 BrowserThread::PostTask( 340 BrowserThread::PostTask(
330 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, 341 BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
331 NewRunnableMethod( 342 NewRunnableMethod(
332 context_.get(), 343 context_.get(),
333 &ChildProcessLauncher::Context::SetProcessBackgrounded, 344 &ChildProcessLauncher::Context::SetProcessBackgrounded,
334 background)); 345 background));
335 } 346 }
347
348 void ChildProcessLauncher::SetTerminateChildOnShutdown(
349 bool terminate_on_shutdown) {
350 if (context_)
351 context_->set_terminate_child_on_shutdown(terminate_on_shutdown);
352 }
353
OLDNEW
« no previous file with comments | « content/browser/child_process_launcher.h ('k') | content/browser/plugin_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698