| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHILD_PROCESS_LAUNCHER_H_ | |
| 6 #define CHROME_BROWSER_CHILD_PROCESS_LAUNCHER_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/process_util.h" | |
| 10 #include "base/ref_counted.h" | |
| 11 | |
| 12 class CommandLine; | |
| 13 | |
| 14 // Launches a process asynchronously and notifies the client of the process | |
| 15 // handle when it's available. It's used to avoid blocking the calling thread | |
| 16 // on the OS since often it can take > 100 ms to create the process. | |
| 17 class ChildProcessLauncher { | |
| 18 public: | |
| 19 class Client { | |
| 20 public: | |
| 21 // Will be called on the thread that the ChildProcessLauncher was | |
| 22 // constructed on. | |
| 23 virtual void OnProcessLaunched() = 0; | |
| 24 }; | |
| 25 | |
| 26 // Launches the process asynchronously, calling the client when the result is | |
| 27 // ready. Deleting this object before the process is created is safe, since | |
| 28 // the callback won't be called. If the process is still running by the time | |
| 29 // this object destructs, it will be terminated. | |
| 30 // Takes ownership of cmd_line. | |
| 31 ChildProcessLauncher( | |
| 32 #if defined(OS_WIN) | |
| 33 const FilePath& exposed_dir, | |
| 34 #elif defined(OS_POSIX) | |
| 35 bool use_zygote, | |
| 36 const base::environment_vector& environ, | |
| 37 int ipcfd, | |
| 38 #endif | |
| 39 CommandLine* cmd_line, | |
| 40 Client* client); | |
| 41 ~ChildProcessLauncher(); | |
| 42 | |
| 43 // True if the process is being launched and so the handle isn't available. | |
| 44 bool IsStarting(); | |
| 45 | |
| 46 // Getter for the process handle. Only call after the process has started. | |
| 47 base::ProcessHandle GetHandle(); | |
| 48 | |
| 49 // Call this when the process exits to know if a process crashed or not. | |
| 50 bool DidProcessCrash(); | |
| 51 | |
| 52 // Changes whether the process runs in the background or not. Only call | |
| 53 // this after the process has started. | |
| 54 void SetProcessBackgrounded(bool background); | |
| 55 | |
| 56 private: | |
| 57 class Context; | |
| 58 | |
| 59 scoped_refptr<Context> context_; | |
| 60 | |
| 61 DISALLOW_COPY_AND_ASSIGN(ChildProcessLauncher); | |
| 62 }; | |
| 63 | |
| 64 #endif // CHROME_BROWSER_CHILD_PROCESS_LAUNCHER_H_ | |
| OLD | NEW |