By moving the call to Load() up in SearchProvider::Start(), we are giving a chance...
[chromium-blink-merge.git] / content / browser / child_process_launcher.h
blob9ee3d41b45be663dd183fe6a58a450a66d699870
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_
6 #define CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/process_util.h"
11 #include "content/common/content_export.h"
13 class CommandLine;
15 namespace content {
17 // Launches a process asynchronously and notifies the client of the process
18 // handle when it's available. It's used to avoid blocking the calling thread
19 // on the OS since often it can take > 100 ms to create the process.
20 class CONTENT_EXPORT ChildProcessLauncher {
21 public:
22 class CONTENT_EXPORT Client {
23 public:
24 // Will be called on the thread that the ChildProcessLauncher was
25 // constructed on.
26 virtual void OnProcessLaunched() = 0;
28 protected:
29 virtual ~Client() {}
32 // Launches the process asynchronously, calling the client when the result is
33 // ready. Deleting this object before the process is created is safe, since
34 // the callback won't be called. If the process is still running by the time
35 // this object destructs, it will be terminated.
36 // Takes ownership of cmd_line.
37 ChildProcessLauncher(
38 #if defined(OS_WIN)
39 const FilePath& exposed_dir,
40 #elif defined(OS_POSIX)
41 bool use_zygote,
42 const base::EnvironmentVector& environ,
43 int ipcfd,
44 #endif
45 CommandLine* cmd_line,
46 int child_process_id,
47 Client* client);
48 ~ChildProcessLauncher();
50 // True if the process is being launched and so the handle isn't available.
51 bool IsStarting();
53 // Getter for the process handle. Only call after the process has started.
54 base::ProcessHandle GetHandle();
56 // Call this when the child process exits to know what happened to it.
57 // |known_dead| can be true if we already know the process is dead as it can
58 // help the implemention figure the proper TerminationStatus.
59 // |exit_code| is the exit code of the process if it exited (e.g. status from
60 // waitpid if on posix, from GetExitCodeProcess on Windows). |exit_code| may
61 // be NULL.
62 base::TerminationStatus GetChildTerminationStatus(bool known_dead,
63 int* exit_code);
65 // Changes whether the process runs in the background or not. Only call
66 // this after the process has started.
67 void SetProcessBackgrounded(bool background);
69 // Controls whether the child process should be terminated on browser
70 // shutdown.
71 void SetTerminateChildOnShutdown(bool terminate_on_shutdown);
73 private:
74 class Context;
76 scoped_refptr<Context> context_;
78 DISALLOW_COPY_AND_ASSIGN(ChildProcessLauncher);
81 } // namespace content
83 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_