OLD | NEW |
---|---|
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 #include "content/browser/android/child_process_launcher_android.h" | 5 #include "content/browser/android/child_process_launcher_android.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/android/context_utils.h" | 11 #include "base/android/context_utils.h" |
12 #include "base/android/jni_android.h" | 12 #include "base/android/jni_android.h" |
13 #include "base/android/jni_array.h" | 13 #include "base/android/jni_array.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "content/browser/file_descriptor_info_impl.h" | |
16 #include "content/browser/frame_host/render_frame_host_impl.h" | 17 #include "content/browser/frame_host/render_frame_host_impl.h" |
17 #include "content/browser/media/android/browser_media_player_manager.h" | 18 #include "content/browser/media/android/browser_media_player_manager.h" |
18 #include "content/browser/media/android/media_web_contents_observer_android.h" | 19 #include "content/browser/media/android/media_web_contents_observer_android.h" |
19 #include "content/browser/web_contents/web_contents_impl.h" | 20 #include "content/browser/web_contents/web_contents_impl.h" |
21 #include "content/common/child_process_host_impl.h" | |
20 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/content_browser_client.h" | |
21 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
25 #include "content/public/common/content_client.h" | |
22 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
23 #include "jni/ChildProcessLauncher_jni.h" | 27 #include "jni/ChildProcessLauncher_jni.h" |
24 #include "media/base/android/media_player_android.h" | 28 #include "media/base/android/media_player_android.h" |
25 #include "ui/gl/android/surface_texture.h" | 29 #include "ui/gl/android/surface_texture.h" |
26 | 30 |
27 using base::android::AttachCurrentThread; | 31 using base::android::AttachCurrentThread; |
28 using base::android::ToJavaArrayOfStrings; | 32 using base::android::ToJavaArrayOfStrings; |
29 using base::android::ScopedJavaGlobalRef; | 33 using base::android::ScopedJavaGlobalRef; |
30 using base::android::ScopedJavaLocalRef; | 34 using base::android::ScopedJavaLocalRef; |
31 using content::StartChildProcessCallback; | 35 using content::StartChildProcessCallback; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 | 85 |
82 if (player != player_manager->GetFullscreenPlayer()) { | 86 if (player != player_manager->GetFullscreenPlayer()) { |
83 gfx::ScopedJavaSurface scoped_surface(surface); | 87 gfx::ScopedJavaSurface scoped_surface(surface); |
84 player->SetVideoSurface(std::move(scoped_surface)); | 88 player->SetVideoSurface(std::move(scoped_surface)); |
85 } | 89 } |
86 #else | 90 #else |
87 NOTREACHED(); | 91 NOTREACHED(); |
88 #endif | 92 #endif |
89 } | 93 } |
90 | 94 |
95 void EmptyCallback(base::ProcessHandle) {} | |
96 | |
97 void LaunchDownloadProcess(base::CommandLine* cmd_line, int child_process_id) { | |
98 scoped_ptr<base::CommandLine> cmd_line_deleter(cmd_line); | |
99 StartChildProcess(cmd_line->argv(), child_process_id, | |
no sievers
2016/02/02 01:37:38
How about a different Java entry point, if all the
qinmin
2016/02/02 20:51:41
Done. Call startDownloadProcess() in the java clas
| |
100 FileDescriptorInfoImpl::Create(), | |
101 std::map<int, base::MemoryMappedFile::Region>(), | |
102 base::Bind(&EmptyCallback)); | |
103 } | |
104 | |
91 } // anonymous namespace | 105 } // anonymous namespace |
92 | 106 |
93 // Called from ChildProcessLauncher.java when the ChildProcess was | 107 // Called from ChildProcessLauncher.java when the ChildProcess was |
94 // started. | 108 // started. |
95 // |client_context| is the pointer to StartChildProcessCallback which was | 109 // |client_context| is the pointer to StartChildProcessCallback which was |
96 // passed in from StartChildProcess. | 110 // passed in from StartChildProcess. |
97 // |handle| is the processID of the child process as originated in Java, 0 if | 111 // |handle| is the processID of the child process as originated in Java, 0 if |
98 // the ChildProcess could not be created. | 112 // the ChildProcess could not be created. |
99 static void OnChildProcessStarted(JNIEnv*, | 113 static void OnChildProcessStarted(JNIEnv*, |
100 const JavaParamRef<jclass>&, | 114 const JavaParamRef<jclass>&, |
101 jlong client_context, | 115 jlong client_context, |
102 jint handle) { | 116 jint handle) { |
103 StartChildProcessCallback* callback = | 117 StartChildProcessCallback* callback = |
104 reinterpret_cast<StartChildProcessCallback*>(client_context); | 118 reinterpret_cast<StartChildProcessCallback*>(client_context); |
105 if (handle) | 119 if (handle) |
106 callback->Run(static_cast<base::ProcessHandle>(handle)); | 120 callback->Run(static_cast<base::ProcessHandle>(handle)); |
107 delete callback; | 121 delete callback; |
108 } | 122 } |
109 | 123 |
124 void StartDownloadProcess() { | |
125 base::FilePath exe_path = content::ChildProcessHost::GetChildPath( | |
126 content::ChildProcessHost::CHILD_NORMAL); | |
127 if (exe_path.empty()) { | |
128 NOTREACHED() << "Unable to get download process binary name."; | |
129 return; | |
130 } | |
131 base::CommandLine* cmd_line = new base::CommandLine(exe_path); | |
132 cmd_line->AppendSwitchASCII(switches::kProcessType, | |
133 switches::kDownloadProcess); | |
134 cmd_line->AppendSwitch(switches::kNoSandbox); | |
135 int child_process_id = ChildProcessHostImpl::GenerateChildProcessUniqueId(); | |
136 GetContentClient()->browser()->AppendExtraCommandLineSwitches( | |
137 cmd_line, child_process_id); | |
138 | |
139 const base::CommandLine browser_command_line = | |
140 *base::CommandLine::ForCurrentProcess(); | |
141 static const char* kForwardSwitches[] = { | |
142 switches::kDisableLogging, | |
143 switches::kEnableLogging, | |
144 switches::kLoggingLevel, | |
145 }; | |
146 cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches, | |
147 arraysize(kForwardSwitches)); | |
148 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); | |
149 BrowserThread::PostTask( | |
150 BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | |
151 base::Bind(&LaunchDownloadProcess, cmd_line, child_process_id)); | |
152 } | |
153 | |
110 void StartChildProcess( | 154 void StartChildProcess( |
111 const base::CommandLine::StringVector& argv, | 155 const base::CommandLine::StringVector& argv, |
112 int child_process_id, | 156 int child_process_id, |
113 scoped_ptr<content::FileDescriptorInfo> files_to_register, | 157 scoped_ptr<content::FileDescriptorInfo> files_to_register, |
114 const std::map<int, base::MemoryMappedFile::Region>& regions, | 158 const std::map<int, base::MemoryMappedFile::Region>& regions, |
115 const StartChildProcessCallback& callback) { | 159 const StartChildProcessCallback& callback) { |
116 JNIEnv* env = AttachCurrentThread(); | 160 JNIEnv* env = AttachCurrentThread(); |
117 DCHECK(env); | 161 DCHECK(env); |
118 | 162 |
119 // Create the Command line String[] | 163 // Create the Command line String[] |
120 ScopedJavaLocalRef<jobjectArray> j_argv = ToJavaArrayOfStrings(env, argv); | 164 ScopedJavaLocalRef<jobjectArray> j_argv = ToJavaArrayOfStrings(env, argv); |
121 | 165 |
122 size_t file_count = files_to_register->GetMappingSize(); | 166 size_t file_count = files_to_register->GetMappingSize(); |
123 DCHECK(file_count > 0); | |
124 | 167 |
125 ScopedJavaLocalRef<jclass> j_file_info_class = base::android::GetClass( | 168 ScopedJavaLocalRef<jclass> j_file_info_class = base::android::GetClass( |
126 env, "org/chromium/content/browser/FileDescriptorInfo"); | 169 env, "org/chromium/content/browser/FileDescriptorInfo"); |
127 ScopedJavaLocalRef<jobjectArray> j_file_infos( | 170 ScopedJavaLocalRef<jobjectArray> j_file_infos( |
128 env, env->NewObjectArray(file_count, j_file_info_class.obj(), NULL)); | 171 env, env->NewObjectArray(file_count, j_file_info_class.obj(), NULL)); |
129 base::android::CheckException(env); | 172 base::android::CheckException(env); |
130 | 173 |
131 for (size_t i = 0; i < file_count; ++i) { | 174 for (size_t i = 0; i < file_count; ++i) { |
132 int fd = files_to_register->GetFDAt(i); | 175 int fd = files_to_register->GetFDAt(i); |
133 PCHECK(0 <= fd); | 176 PCHECK(0 <= fd); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 jboolean IsSingleProcess(JNIEnv* env, const JavaParamRef<jclass>& clazz) { | 279 jboolean IsSingleProcess(JNIEnv* env, const JavaParamRef<jclass>& clazz) { |
237 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 280 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
238 switches::kSingleProcess); | 281 switches::kSingleProcess); |
239 } | 282 } |
240 | 283 |
241 bool RegisterChildProcessLauncher(JNIEnv* env) { | 284 bool RegisterChildProcessLauncher(JNIEnv* env) { |
242 return RegisterNativesImpl(env); | 285 return RegisterNativesImpl(env); |
243 } | 286 } |
244 | 287 |
245 } // namespace content | 288 } // namespace content |
OLD | NEW |