Chromium Code Reviews| 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_jni.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/android/unguessable_token_android.h" | 16 #include "base/android/unguessable_token_android.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "content/browser/android/scoped_surface_request_manager.h" | 18 #include "content/browser/android/scoped_surface_request_manager.h" |
| 19 #include "content/browser/frame_host/render_frame_host_impl.h" | 19 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 20 #include "content/browser/media/android/browser_media_player_manager.h" | 20 #include "content/browser/media/android/browser_media_player_manager.h" |
| 21 #include "content/browser/media/android/media_web_contents_observer_android.h" | 21 #include "content/browser/media/android/media_web_contents_observer_android.h" |
| 22 #include "content/browser/web_contents/web_contents_impl.h" | 22 #include "content/browser/web_contents/web_contents_impl.h" |
| 23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/render_process_host.h" | |
| 25 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
| 26 #include "gpu/ipc/common/gpu_surface_tracker.h" | 25 #include "gpu/ipc/common/gpu_surface_tracker.h" |
| 27 #include "jni/ChildProcessLauncher_jni.h" | 26 #include "jni/ChildProcessLauncher_jni.h" |
| 28 #include "media/base/android/media_player_android.h" | 27 #include "media/base/android/media_player_android.h" |
| 29 #include "ui/gl/android/surface_texture.h" | 28 #include "ui/gl/android/surface_texture.h" |
| 30 | 29 |
| 31 using base::android::AttachCurrentThread; | 30 using base::android::AttachCurrentThread; |
| 32 using base::android::JavaParamRef; | 31 using base::android::JavaParamRef; |
| 33 using base::android::JavaRef; | 32 using base::android::JavaRef; |
| 34 using base::android::ToJavaArrayOfStrings; | 33 using base::android::ToJavaArrayOfStrings; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 // |client_context| is the pointer to StartChildProcessCallback which was | 96 // |client_context| is the pointer to StartChildProcessCallback which was |
| 98 // passed in from StartChildProcess. | 97 // passed in from StartChildProcess. |
| 99 // |handle| is the processID of the child process as originated in Java, 0 if | 98 // |handle| is the processID of the child process as originated in Java, 0 if |
| 100 // the ChildProcess could not be created. | 99 // the ChildProcess could not be created. |
| 101 static void OnChildProcessStarted(JNIEnv*, | 100 static void OnChildProcessStarted(JNIEnv*, |
| 102 const JavaParamRef<jclass>&, | 101 const JavaParamRef<jclass>&, |
| 103 jlong client_context, | 102 jlong client_context, |
| 104 jint handle) { | 103 jint handle) { |
| 105 StartChildProcessCallback* callback = | 104 StartChildProcessCallback* callback = |
| 106 reinterpret_cast<StartChildProcessCallback*>(client_context); | 105 reinterpret_cast<StartChildProcessCallback*>(client_context); |
| 107 if (handle) | 106 int launch_result = (handle == base::kNullProcessHandle) |
| 108 callback->Run(static_cast<base::ProcessHandle>(handle)); | 107 ? LAUNCH_RESULT_FAILURE |
| 108 : LAUNCH_RESULT_SUCCESS; | |
| 109 callback->Run(static_cast<base::ProcessHandle>(handle), launch_result); | |
| 109 delete callback; | 110 delete callback; |
| 110 } | 111 } |
| 111 | 112 |
| 112 void StartChildProcess( | 113 void StartChildProcess( |
| 113 const base::CommandLine::StringVector& argv, | 114 const base::CommandLine::StringVector& argv, |
| 114 int child_process_id, | 115 int child_process_id, |
| 115 std::unique_ptr<content::FileDescriptorInfo> files_to_register, | 116 content::FileDescriptorInfo* files_to_register, |
| 116 const StartChildProcessCallback& callback) { | 117 const StartChildProcessCallback& callback) { |
| 117 JNIEnv* env = AttachCurrentThread(); | 118 JNIEnv* env = AttachCurrentThread(); |
| 118 DCHECK(env); | 119 DCHECK(env); |
| 119 | 120 |
| 120 // Create the Command line String[] | 121 // Create the Command line String[] |
| 121 ScopedJavaLocalRef<jobjectArray> j_argv = ToJavaArrayOfStrings(env, argv); | 122 ScopedJavaLocalRef<jobjectArray> j_argv = ToJavaArrayOfStrings(env, argv); |
| 122 | 123 |
| 123 size_t file_count = files_to_register->GetMappingSize(); | 124 size_t file_count = files_to_register->GetMappingSize(); |
| 124 DCHECK(file_count > 0); | 125 DCHECK(file_count > 0); |
| 125 | 126 |
| 126 ScopedJavaLocalRef<jclass> j_file_info_class = base::android::GetClass( | 127 ScopedJavaLocalRef<jclass> j_file_info_class = base::android::GetClass( |
| 127 env, "org/chromium/content/common/FileDescriptorInfo"); | 128 env, "org/chromium/content/common/FileDescriptorInfo"); |
| 128 ScopedJavaLocalRef<jobjectArray> j_file_infos( | 129 ScopedJavaLocalRef<jobjectArray> j_file_infos( |
| 129 env, env->NewObjectArray(file_count, j_file_info_class.obj(), NULL)); | 130 env, env->NewObjectArray(file_count, j_file_info_class.obj(), NULL)); |
| 130 base::android::CheckException(env); | 131 base::android::CheckException(env); |
| 131 | 132 |
| 132 for (size_t i = 0; i < file_count; ++i) { | 133 for (size_t i = 0; i < file_count; ++i) { |
| 133 int fd = files_to_register->GetFDAt(i); | 134 int fd = files_to_register->GetFDAt(i); |
| 134 PCHECK(0 <= fd); | 135 PCHECK(0 <= fd); |
| 135 int id = files_to_register->GetIDAt(i); | 136 int id = files_to_register->GetIDAt(i); |
| 137 auto region = files_to_register->GetRegionAt(i); | |
|
boliu
2017/01/12 02:00:07
I'm no c++11 expert, but I think this should be "c
Jay Civelli
2017/01/12 23:05:40
Done.
| |
| 136 bool auto_close = files_to_register->OwnsFD(fd); | 138 bool auto_close = files_to_register->OwnsFD(fd); |
| 137 const base::MemoryMappedFile::Region& region = | |
| 138 files_to_register->GetRegionAt(i); | |
| 139 int64_t offset = region.offset; | |
| 140 int64_t size = region.size; | |
| 141 ScopedJavaLocalRef<jobject> j_file_info = | 139 ScopedJavaLocalRef<jobject> j_file_info = |
| 142 Java_ChildProcessLauncher_makeFdInfo(env, id, fd, auto_close, offset, | 140 Java_ChildProcessLauncher_makeFdInfo(env, id, fd, auto_close, |
| 143 size); | 141 region.offset, region.size); |
| 144 PCHECK(j_file_info.obj()); | 142 PCHECK(j_file_info.obj()); |
| 145 env->SetObjectArrayElement(j_file_infos.obj(), i, j_file_info.obj()); | 143 env->SetObjectArrayElement(j_file_infos.obj(), i, j_file_info.obj()); |
| 146 if (auto_close) { | 144 if (auto_close) { |
| 147 ignore_result(files_to_register->ReleaseFD(fd).release()); | 145 ignore_result(files_to_register->ReleaseFD(fd).release()); |
| 148 } | 146 } |
| 149 } | 147 } |
| 150 | 148 |
| 151 Java_ChildProcessLauncher_start( | 149 Java_ChildProcessLauncher_start( |
| 152 env, base::android::GetApplicationContext(), j_argv, child_process_id, | 150 env, base::android::GetApplicationContext(), j_argv, child_process_id, |
| 153 j_file_infos, | 151 j_file_infos, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 gl::ScopedJavaSurface surface_view = | 220 gl::ScopedJavaSurface surface_view = |
| 223 gpu::GpuSurfaceTracker::GetInstance()->AcquireJavaSurface(surface_id); | 221 gpu::GpuSurfaceTracker::GetInstance()->AcquireJavaSurface(surface_id); |
| 224 return base::android::ScopedJavaLocalRef<jobject>(surface_view.j_surface()); | 222 return base::android::ScopedJavaLocalRef<jobject>(surface_view.j_surface()); |
| 225 } | 223 } |
| 226 | 224 |
| 227 bool RegisterChildProcessLauncher(JNIEnv* env) { | 225 bool RegisterChildProcessLauncher(JNIEnv* env) { |
| 228 return RegisterNativesImpl(env); | 226 return RegisterNativesImpl(env); |
| 229 } | 227 } |
| 230 | 228 |
| 231 } // namespace content | 229 } // namespace content |
| OLD | NEW |