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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 DVLOG(1) << "Cannot find media player for player_id " << player_id; | 81 DVLOG(1) << "Cannot find media player for player_id " << player_id; |
78 return; | 82 return; |
79 } | 83 } |
80 | 84 |
81 if (player != player_manager->GetFullscreenPlayer()) { | 85 if (player != player_manager->GetFullscreenPlayer()) { |
82 gfx::ScopedJavaSurface scoped_surface(surface); | 86 gfx::ScopedJavaSurface scoped_surface(surface); |
83 player->SetVideoSurface(std::move(scoped_surface)); | 87 player->SetVideoSurface(std::move(scoped_surface)); |
84 } | 88 } |
85 } | 89 } |
86 | 90 |
| 91 void LaunchDownloadProcess(base::CommandLine* cmd_line) { |
| 92 scoped_ptr<base::CommandLine> cmd_line_deleter(cmd_line); |
| 93 |
| 94 JNIEnv* env = AttachCurrentThread(); |
| 95 DCHECK(env); |
| 96 |
| 97 // Create the Command line String[] |
| 98 ScopedJavaLocalRef<jobjectArray> j_argv = |
| 99 ToJavaArrayOfStrings(env, cmd_line->argv()); |
| 100 |
| 101 // TODO(qinmin): pass download parameters here. |
| 102 Java_ChildProcessLauncher_startDownloadProcessIfNecessary( |
| 103 env, base::android::GetApplicationContext(), j_argv.obj()); |
| 104 } |
| 105 |
87 } // anonymous namespace | 106 } // anonymous namespace |
88 | 107 |
89 // Called from ChildProcessLauncher.java when the ChildProcess was | 108 // Called from ChildProcessLauncher.java when the ChildProcess was |
90 // started. | 109 // started. |
91 // |client_context| is the pointer to StartChildProcessCallback which was | 110 // |client_context| is the pointer to StartChildProcessCallback which was |
92 // passed in from StartChildProcess. | 111 // passed in from StartChildProcess. |
93 // |handle| is the processID of the child process as originated in Java, 0 if | 112 // |handle| is the processID of the child process as originated in Java, 0 if |
94 // the ChildProcess could not be created. | 113 // the ChildProcess could not be created. |
95 static void OnChildProcessStarted(JNIEnv*, | 114 static void OnChildProcessStarted(JNIEnv*, |
96 const JavaParamRef<jclass>&, | 115 const JavaParamRef<jclass>&, |
97 jlong client_context, | 116 jlong client_context, |
98 jint handle) { | 117 jint handle) { |
99 StartChildProcessCallback* callback = | 118 StartChildProcessCallback* callback = |
100 reinterpret_cast<StartChildProcessCallback*>(client_context); | 119 reinterpret_cast<StartChildProcessCallback*>(client_context); |
101 if (handle) | 120 if (handle) |
102 callback->Run(static_cast<base::ProcessHandle>(handle)); | 121 callback->Run(static_cast<base::ProcessHandle>(handle)); |
103 delete callback; | 122 delete callback; |
104 } | 123 } |
105 | 124 |
| 125 void StartDownloadProcessIfNecessary() { |
| 126 base::FilePath exe_path = content::ChildProcessHost::GetChildPath( |
| 127 content::ChildProcessHost::CHILD_NORMAL); |
| 128 if (exe_path.empty()) { |
| 129 NOTREACHED() << "Unable to get download process binary name."; |
| 130 return; |
| 131 } |
| 132 base::CommandLine* cmd_line = new base::CommandLine(exe_path); |
| 133 cmd_line->AppendSwitchASCII(switches::kProcessType, |
| 134 switches::kDownloadProcess); |
| 135 cmd_line->AppendSwitch(switches::kNoSandbox); |
| 136 |
| 137 const base::CommandLine browser_command_line = |
| 138 *base::CommandLine::ForCurrentProcess(); |
| 139 static const char* kForwardSwitches[] = { |
| 140 switches::kDisableLogging, |
| 141 switches::kEnableLogging, |
| 142 switches::kLoggingLevel, |
| 143 }; |
| 144 cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches, |
| 145 arraysize(kForwardSwitches)); |
| 146 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess)); |
| 147 BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE, |
| 148 base::Bind(&LaunchDownloadProcess, cmd_line)); |
| 149 } |
| 150 |
106 void StartChildProcess( | 151 void StartChildProcess( |
107 const base::CommandLine::StringVector& argv, | 152 const base::CommandLine::StringVector& argv, |
108 int child_process_id, | 153 int child_process_id, |
109 scoped_ptr<content::FileDescriptorInfo> files_to_register, | 154 scoped_ptr<content::FileDescriptorInfo> files_to_register, |
110 const std::map<int, base::MemoryMappedFile::Region>& regions, | 155 const std::map<int, base::MemoryMappedFile::Region>& regions, |
111 const StartChildProcessCallback& callback) { | 156 const StartChildProcessCallback& callback) { |
112 JNIEnv* env = AttachCurrentThread(); | 157 JNIEnv* env = AttachCurrentThread(); |
113 DCHECK(env); | 158 DCHECK(env); |
114 | 159 |
115 // Create the Command line String[] | 160 // Create the Command line String[] |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 jboolean IsSingleProcess(JNIEnv* env, const JavaParamRef<jclass>& clazz) { | 277 jboolean IsSingleProcess(JNIEnv* env, const JavaParamRef<jclass>& clazz) { |
233 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 278 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
234 switches::kSingleProcess); | 279 switches::kSingleProcess); |
235 } | 280 } |
236 | 281 |
237 bool RegisterChildProcessLauncher(JNIEnv* env) { | 282 bool RegisterChildProcessLauncher(JNIEnv* env) { |
238 return RegisterNativesImpl(env); | 283 return RegisterNativesImpl(env); |
239 } | 284 } |
240 | 285 |
241 } // namespace content | 286 } // namespace content |
OLD | NEW |