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 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/android/context_utils.h" | 13 #include "base/android/context_utils.h" |
14 #include "base/android/jni_android.h" | 14 #include "base/android/jni_android.h" |
15 #include "base/android/jni_array.h" | 15 #include "base/android/jni_array.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "content/browser/android/scoped_surface_request_manager.h" | 17 #include "content/browser/android/scoped_surface_request_manager.h" |
18 #include "content/browser/file_descriptor_info_impl.h" | |
19 #include "content/browser/frame_host/render_frame_host_impl.h" | 18 #include "content/browser/frame_host/render_frame_host_impl.h" |
20 #include "content/browser/media/android/browser_media_player_manager.h" | 19 #include "content/browser/media/android/browser_media_player_manager.h" |
21 #include "content/browser/media/android/media_web_contents_observer_android.h" | 20 #include "content/browser/media/android/media_web_contents_observer_android.h" |
22 #include "content/browser/web_contents/web_contents_impl.h" | 21 #include "content/browser/web_contents/web_contents_impl.h" |
23 #include "content/common/child_process_host_impl.h" | |
24 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/content_browser_client.h" | |
26 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
27 #include "content/public/common/content_client.h" | |
28 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
29 #include "jni/ChildProcessLauncher_jni.h" | 25 #include "jni/ChildProcessLauncher_jni.h" |
30 #include "media/base/android/media_player_android.h" | 26 #include "media/base/android/media_player_android.h" |
31 #include "ui/gl/android/surface_texture.h" | 27 #include "ui/gl/android/surface_texture.h" |
32 | 28 |
33 using base::android::AttachCurrentThread; | 29 using base::android::AttachCurrentThread; |
34 using base::android::JavaParamRef; | 30 using base::android::JavaParamRef; |
35 using base::android::JavaRef; | 31 using base::android::JavaRef; |
36 using base::android::ToJavaArrayOfStrings; | 32 using base::android::ToJavaArrayOfStrings; |
37 using base::android::ScopedJavaGlobalRef; | 33 using base::android::ScopedJavaGlobalRef; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 DVLOG(1) << "Cannot find media player for player_id " << player_id; | 81 DVLOG(1) << "Cannot find media player for player_id " << player_id; |
86 return; | 82 return; |
87 } | 83 } |
88 | 84 |
89 if (player != player_manager->GetFullscreenPlayer()) { | 85 if (player != player_manager->GetFullscreenPlayer()) { |
90 gl::ScopedJavaSurface scoped_surface(surface); | 86 gl::ScopedJavaSurface scoped_surface(surface); |
91 player->SetVideoSurface(std::move(scoped_surface)); | 87 player->SetVideoSurface(std::move(scoped_surface)); |
92 } | 88 } |
93 } | 89 } |
94 | 90 |
95 void LaunchDownloadProcess(base::CommandLine* cmd_line) { | |
96 std::unique_ptr<base::CommandLine> cmd_line_deleter(cmd_line); | |
97 | |
98 JNIEnv* env = AttachCurrentThread(); | |
99 DCHECK(env); | |
100 | |
101 // Create the Command line String[] | |
102 ScopedJavaLocalRef<jobjectArray> j_argv = | |
103 ToJavaArrayOfStrings(env, cmd_line->argv()); | |
104 | |
105 // TODO(qinmin): pass download parameters here. | |
106 Java_ChildProcessLauncher_startDownloadProcessIfNecessary( | |
107 env, base::android::GetApplicationContext(), j_argv); | |
108 } | |
109 | |
110 } // anonymous namespace | 91 } // anonymous namespace |
111 | 92 |
112 // Called from ChildProcessLauncher.java when the ChildProcess was | 93 // Called from ChildProcessLauncher.java when the ChildProcess was |
113 // started. | 94 // started. |
114 // |client_context| is the pointer to StartChildProcessCallback which was | 95 // |client_context| is the pointer to StartChildProcessCallback which was |
115 // passed in from StartChildProcess. | 96 // passed in from StartChildProcess. |
116 // |handle| is the processID of the child process as originated in Java, 0 if | 97 // |handle| is the processID of the child process as originated in Java, 0 if |
117 // the ChildProcess could not be created. | 98 // the ChildProcess could not be created. |
118 static void OnChildProcessStarted(JNIEnv*, | 99 static void OnChildProcessStarted(JNIEnv*, |
119 const JavaParamRef<jclass>&, | 100 const JavaParamRef<jclass>&, |
120 jlong client_context, | 101 jlong client_context, |
121 jint handle) { | 102 jint handle) { |
122 StartChildProcessCallback* callback = | 103 StartChildProcessCallback* callback = |
123 reinterpret_cast<StartChildProcessCallback*>(client_context); | 104 reinterpret_cast<StartChildProcessCallback*>(client_context); |
124 if (handle) | 105 if (handle) |
125 callback->Run(static_cast<base::ProcessHandle>(handle)); | 106 callback->Run(static_cast<base::ProcessHandle>(handle)); |
126 delete callback; | 107 delete callback; |
127 } | 108 } |
128 | 109 |
129 void StartDownloadProcessIfNecessary() { | |
130 base::FilePath exe_path = content::ChildProcessHost::GetChildPath( | |
131 content::ChildProcessHost::CHILD_NORMAL); | |
132 if (exe_path.empty()) { | |
133 NOTREACHED() << "Unable to get download process binary name."; | |
134 return; | |
135 } | |
136 base::CommandLine* cmd_line = new base::CommandLine(exe_path); | |
137 cmd_line->AppendSwitchASCII(switches::kProcessType, | |
138 switches::kDownloadProcess); | |
139 cmd_line->AppendSwitch(switches::kNoSandbox); | |
140 | |
141 const base::CommandLine browser_command_line = | |
142 *base::CommandLine::ForCurrentProcess(); | |
143 static const char* const kForwardSwitches[] = { | |
144 switches::kDisableLogging, | |
145 switches::kEnableLogging, | |
146 switches::kLoggingLevel, | |
147 }; | |
148 cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches, | |
149 arraysize(kForwardSwitches)); | |
150 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); | |
151 BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE, | |
152 base::Bind(&LaunchDownloadProcess, cmd_line)); | |
153 } | |
154 | |
155 void StartChildProcess( | 110 void StartChildProcess( |
156 const base::CommandLine::StringVector& argv, | 111 const base::CommandLine::StringVector& argv, |
157 int child_process_id, | 112 int child_process_id, |
158 std::unique_ptr<content::FileDescriptorInfo> files_to_register, | 113 std::unique_ptr<content::FileDescriptorInfo> files_to_register, |
159 const std::map<int, base::MemoryMappedFile::Region>& regions, | 114 const std::map<int, base::MemoryMappedFile::Region>& regions, |
160 const StartChildProcessCallback& callback) { | 115 const StartChildProcessCallback& callback) { |
161 JNIEnv* env = AttachCurrentThread(); | 116 JNIEnv* env = AttachCurrentThread(); |
162 DCHECK(env); | 117 DCHECK(env); |
163 | 118 |
164 // Create the Command line String[] | 119 // Create the Command line String[] |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 jboolean IsSingleProcess(JNIEnv* env, const JavaParamRef<jclass>& clazz) { | 261 jboolean IsSingleProcess(JNIEnv* env, const JavaParamRef<jclass>& clazz) { |
307 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 262 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
308 switches::kSingleProcess); | 263 switches::kSingleProcess); |
309 } | 264 } |
310 | 265 |
311 bool RegisterChildProcessLauncher(JNIEnv* env) { | 266 bool RegisterChildProcessLauncher(JNIEnv* env) { |
312 return RegisterNativesImpl(env); | 267 return RegisterNativesImpl(env); |
313 } | 268 } |
314 | 269 |
315 } // namespace content | 270 } // namespace content |
OLD | NEW |