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

Side by Side Diff: content/browser/android/child_process_launcher_android.cc

Issue 1622743005: Introduce background Download process to android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressing siever's comments Created 4 years, 10 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 #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
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_startDownloadProcess(
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 StartDownloadProcess() {
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 int child_process_id = ChildProcessHostImpl::GenerateChildProcessUniqueId();
no sievers 2016/02/03 22:46:51 This is not needed right? It's not a normal ChildP
qinmin 2016/02/03 23:37:36 removed. I was just not sure whether we need any f
137 GetContentClient()->browser()->AppendExtraCommandLineSwitches(
138 cmd_line, child_process_id);
139
140 const base::CommandLine browser_command_line =
141 *base::CommandLine::ForCurrentProcess();
142 static const char* kForwardSwitches[] = {
143 switches::kDisableLogging,
144 switches::kEnableLogging,
145 switches::kLoggingLevel,
146 };
147 cmd_line->CopySwitchesFrom(browser_command_line, kForwardSwitches,
148 arraysize(kForwardSwitches));
149 CHECK(!cmd_line->HasSwitch(switches::kSingleProcess));
150 BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
151 base::Bind(&LaunchDownloadProcess, cmd_line));
152 }
153
106 void StartChildProcess( 154 void StartChildProcess(
107 const base::CommandLine::StringVector& argv, 155 const base::CommandLine::StringVector& argv,
108 int child_process_id, 156 int child_process_id,
109 scoped_ptr<content::FileDescriptorInfo> files_to_register, 157 scoped_ptr<content::FileDescriptorInfo> files_to_register,
110 const std::map<int, base::MemoryMappedFile::Region>& regions, 158 const std::map<int, base::MemoryMappedFile::Region>& regions,
111 const StartChildProcessCallback& callback) { 159 const StartChildProcessCallback& callback) {
112 JNIEnv* env = AttachCurrentThread(); 160 JNIEnv* env = AttachCurrentThread();
113 DCHECK(env); 161 DCHECK(env);
114 162
115 // Create the Command line String[] 163 // Create the Command line String[]
116 ScopedJavaLocalRef<jobjectArray> j_argv = ToJavaArrayOfStrings(env, argv); 164 ScopedJavaLocalRef<jobjectArray> j_argv = ToJavaArrayOfStrings(env, argv);
117 165
118 size_t file_count = files_to_register->GetMappingSize(); 166 size_t file_count = files_to_register->GetMappingSize();
119 DCHECK(file_count > 0);
no sievers 2016/02/03 22:46:51 This DCHECK() can stay now, right?
qinmin 2016/02/03 23:37:36 Done.
120 167
121 ScopedJavaLocalRef<jclass> j_file_info_class = base::android::GetClass( 168 ScopedJavaLocalRef<jclass> j_file_info_class = base::android::GetClass(
122 env, "org/chromium/content/browser/FileDescriptorInfo"); 169 env, "org/chromium/content/browser/FileDescriptorInfo");
123 ScopedJavaLocalRef<jobjectArray> j_file_infos( 170 ScopedJavaLocalRef<jobjectArray> j_file_infos(
124 env, env->NewObjectArray(file_count, j_file_info_class.obj(), NULL)); 171 env, env->NewObjectArray(file_count, j_file_info_class.obj(), NULL));
125 base::android::CheckException(env); 172 base::android::CheckException(env);
126 173
127 for (size_t i = 0; i < file_count; ++i) { 174 for (size_t i = 0; i < file_count; ++i) {
128 int fd = files_to_register->GetFDAt(i); 175 int fd = files_to_register->GetFDAt(i);
129 PCHECK(0 <= fd); 176 PCHECK(0 <= fd);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 jboolean IsSingleProcess(JNIEnv* env, const JavaParamRef<jclass>& clazz) { 279 jboolean IsSingleProcess(JNIEnv* env, const JavaParamRef<jclass>& clazz) {
233 return base::CommandLine::ForCurrentProcess()->HasSwitch( 280 return base::CommandLine::ForCurrentProcess()->HasSwitch(
234 switches::kSingleProcess); 281 switches::kSingleProcess);
235 } 282 }
236 283
237 bool RegisterChildProcessLauncher(JNIEnv* env) { 284 bool RegisterChildProcessLauncher(JNIEnv* env) {
238 return RegisterNativesImpl(env); 285 return RegisterNativesImpl(env);
239 } 286 }
240 287
241 } // namespace content 288 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698