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

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

Issue 1923653002: Wire up process launch error codes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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
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 #ifndef CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_ 5 #ifndef CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_
6 #define CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_ 6 #define CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_
7 7
8 #include "base/files/scoped_file.h" 8 #include "base/files/scoped_file.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/process/kill.h" 11 #include "base/process/kill.h"
12 #include "base/process/launch.h" 12 #include "base/process/launch.h"
13 #include "base/process/process.h" 13 #include "base/process/process.h"
14 #include "base/threading/non_thread_safe.h" 14 #include "base/threading/non_thread_safe.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "content/public/common/sandboxed_process_launcher_delegate.h" 18 #include "content/public/common/sandboxed_process_launcher_delegate.h"
19 #include "mojo/edk/embedder/platform_channel_pair.h" 19 #include "mojo/edk/embedder/platform_channel_pair.h"
20 20
21 #if defined(OS_WIN)
22 #include "sandbox/win/src/sandbox_types.h"
23 #endif
24
21 namespace base { 25 namespace base {
22 class CommandLine; 26 class CommandLine;
23 } 27 }
24 28
25 namespace content { 29 namespace content {
26 30
31 enum LaunchResultCode {
32 // Launch start code, to not overlap with sandbox::ResultCode.
33 LAUNCH_RESULT_START = 1001,
34 // Launch success.
35 LAUNCH_RESULT_SUCCESS,
36 // Generic launch failure.
37 LAUNCH_RESULT_FAILURE,
38 // Placeholder for last item of the enum.
39 LAUNCH_RESULT_CODE_LAST_CODE
40 };
41
42 #if defined(OS_WIN)
43 static_assert(LAUNCH_RESULT_START > sandbox::SBOX_ERROR_LAST,
44 "LaunchResultCode must not overlap with sandbox::ResultCode");
45 #endif
46
27 // Launches a process asynchronously and notifies the client of the process 47 // Launches a process asynchronously and notifies the client of the process
28 // handle when it's available. It's used to avoid blocking the calling thread 48 // handle when it's available. It's used to avoid blocking the calling thread
29 // on the OS since often it can take > 100 ms to create the process. 49 // on the OS since often it can take > 100 ms to create the process.
30 class CONTENT_EXPORT ChildProcessLauncher : public base::NonThreadSafe { 50 class CONTENT_EXPORT ChildProcessLauncher : public base::NonThreadSafe {
31 public: 51 public:
32 class CONTENT_EXPORT Client { 52 class CONTENT_EXPORT Client {
33 public: 53 public:
34 // Will be called on the thread that the ChildProcessLauncher was 54 // Will be called on the thread that the ChildProcessLauncher was
35 // constructed on. 55 // constructed on.
36 virtual void OnProcessLaunched() = 0; 56 virtual void OnProcessLaunched() = 0;
37 57
38 virtual void OnProcessLaunchFailed() {}; 58 virtual void OnProcessLaunchFailed(int error_code) {};
39 59
40 protected: 60 protected:
41 virtual ~Client() {} 61 virtual ~Client() {}
42 }; 62 };
43 63
44 // Launches the process asynchronously, calling the client when the result is 64 // Launches the process asynchronously, calling the client when the result is
45 // ready. Deleting this object before the process is created is safe, since 65 // ready. Deleting this object before the process is created is safe, since
46 // the callback won't be called. If the process is still running by the time 66 // the callback won't be called. If the process is still running by the time
47 // this object destructs, it will be terminated. 67 // this object destructs, it will be terminated.
48 // Takes ownership of cmd_line. 68 // Takes ownership of cmd_line.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // to launch the child process on the launcher thread. 114 // to launch the child process on the launcher thread.
95 // It makes sure we always perform the necessary cleanup if the 115 // It makes sure we always perform the necessary cleanup if the
96 // client went away. 116 // client went away.
97 static void DidLaunch(base::WeakPtr<ChildProcessLauncher> instance, 117 static void DidLaunch(base::WeakPtr<ChildProcessLauncher> instance,
98 bool terminate_on_shutdown, 118 bool terminate_on_shutdown,
99 ZygoteHandle zygote, 119 ZygoteHandle zygote,
100 #if defined(OS_ANDROID) 120 #if defined(OS_ANDROID)
101 base::ScopedFD ipcfd, 121 base::ScopedFD ipcfd,
102 base::ScopedFD mojo_fd, 122 base::ScopedFD mojo_fd,
103 #endif 123 #endif
104 base::Process process); 124 base::Process process,
125 int error_code);
105 126
106 // Notifies the client about the result of the operation. 127 // Notifies the client about the result of the operation.
107 void Notify(ZygoteHandle zygote, 128 void Notify(ZygoteHandle zygote,
108 #if defined(OS_ANDROID) 129 #if defined(OS_ANDROID)
109 base::ScopedFD ipcfd, 130 base::ScopedFD ipcfd,
110 #endif 131 #endif
111 base::Process process); 132 base::Process process,
133 int error_code);
112 134
113 #if defined(MOJO_SHELL_CLIENT) 135 #if defined(MOJO_SHELL_CLIENT)
114 // When this process is run from an external Mojo shell, this function will 136 // When this process is run from an external Mojo shell, this function will
115 // create a channel and pass one end to the spawned process and register the 137 // create a channel and pass one end to the spawned process and register the
116 // other end with the external shell, allowing the spawned process to bind an 138 // other end with the external shell, allowing the spawned process to bind an
117 // Application request from the shell. 139 // Application request from the shell.
118 void CreateMojoShellChannel(base::CommandLine* command_line, 140 void CreateMojoShellChannel(base::CommandLine* command_line,
119 int child_process_id); 141 int child_process_id);
120 #endif 142 #endif
121 143
(...skipping 12 matching lines...) Expand all
134 mojo::edk::PlatformChannelPair mojo_platform_channel_; 156 mojo::edk::PlatformChannelPair mojo_platform_channel_;
135 157
136 base::WeakPtrFactory<ChildProcessLauncher> weak_factory_; 158 base::WeakPtrFactory<ChildProcessLauncher> weak_factory_;
137 159
138 DISALLOW_COPY_AND_ASSIGN(ChildProcessLauncher); 160 DISALLOW_COPY_AND_ASSIGN(ChildProcessLauncher);
139 }; 161 };
140 162
141 } // namespace content 163 } // namespace content
142 164
143 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_ 165 #endif // CONTENT_BROWSER_CHILD_PROCESS_LAUNCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698