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

Side by Side Diff: content/app/android/child_process_service_impl.cc

Issue 2684433003: Files required by a service now listed in manifest. (Closed)
Patch Set: Addressed @boliu and @jam's comments. Created 3 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/app/android/child_process_service_impl.h" 5 #include "content/app/android/child_process_service_impl.h"
6 6
7 #include <android/native_window_jni.h> 7 #include <android/native_window_jni.h>
8 #include <cpu-features.h> 8 #include <cpu-features.h>
9 9
10 #include "base/android/jni_array.h" 10 #include "base/android/jni_array.h"
11 #include "base/android/jni_string.h"
11 #include "base/android/library_loader/library_loader_hooks.h" 12 #include "base/android/library_loader/library_loader_hooks.h"
12 #include "base/android/memory_pressure_listener_android.h" 13 #include "base/android/memory_pressure_listener_android.h"
13 #include "base/android/unguessable_token_android.h" 14 #include "base/android/unguessable_token_android.h"
15 #include "base/file_descriptor_store.h"
14 #include "base/lazy_instance.h" 16 #include "base/lazy_instance.h"
15 #include "base/logging.h" 17 #include "base/logging.h"
16 #include "base/macros.h" 18 #include "base/macros.h"
17 #include "base/posix/global_descriptors.h" 19 #include "base/posix/global_descriptors.h"
18 #include "base/unguessable_token.h" 20 #include "base/unguessable_token.h"
19 #include "content/child/child_thread_impl.h" 21 #include "content/child/child_thread_impl.h"
20 #include "content/public/common/content_descriptors.h" 22 #include "content/public/common/content_descriptors.h"
23 #include "content/public/common/content_switches.h"
21 #include "gpu/ipc/common/android/scoped_surface_request_conduit.h" 24 #include "gpu/ipc/common/android/scoped_surface_request_conduit.h"
22 #include "gpu/ipc/common/gpu_surface_lookup.h" 25 #include "gpu/ipc/common/gpu_surface_lookup.h"
23 #include "ipc/ipc_descriptors.h" 26 #include "ipc/ipc_descriptors.h"
24 #include "jni/ChildProcessServiceImpl_jni.h" 27 #include "jni/ChildProcessServiceImpl_jni.h"
28 #include "services/service_manager/public/cpp/shared_file_util.h"
25 #include "ui/gl/android/scoped_java_surface.h" 29 #include "ui/gl/android/scoped_java_surface.h"
26 #include "ui/gl/android/surface_texture.h" 30 #include "ui/gl/android/surface_texture.h"
27 31
28 using base::android::AttachCurrentThread; 32 using base::android::AttachCurrentThread;
29 using base::android::CheckException; 33 using base::android::CheckException;
30 using base::android::JavaIntArrayToIntVector; 34 using base::android::JavaIntArrayToIntVector;
31 using base::android::JavaParamRef; 35 using base::android::JavaParamRef;
32 36
33 namespace content { 37 namespace content {
34 38
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 gpu::GpuSurfaceLookup::InitInstance( 118 gpu::GpuSurfaceLookup::InitInstance(
115 g_child_process_surface_manager.Pointer()); 119 g_child_process_surface_manager.Pointer());
116 gpu::ScopedSurfaceRequestConduit::SetInstance( 120 gpu::ScopedSurfaceRequestConduit::SetInstance(
117 g_child_process_surface_manager.Pointer()); 121 g_child_process_surface_manager.Pointer());
118 122
119 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); 123 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env);
120 } 124 }
121 125
122 } // namespace <anonymous> 126 } // namespace <anonymous>
123 127
124 void RegisterGlobalFileDescriptor(JNIEnv* env, 128 jlong CreateFileDescriptorStoreRegistrationContext(
boliu 2017/02/10 21:33:03 delete this
Jay Civelli 2017/02/13 18:48:25 Oh, yeah.
125 const JavaParamRef<jclass>& clazz, 129 JNIEnv* env,
126 jint id, 130 const JavaParamRef<jclass>& clazz,
127 jint fd, 131 const JavaParamRef<jstring>& shared_param) {
128 jlong offset, 132 if (shared_param.is_null())
129 jlong size) { 133 return 0L;
130 base::MemoryMappedFile::Region region = {offset, size}; 134
131 base::GlobalDescriptors::GetInstance()->Set(id, fd, region); 135 std::string param = base::android::ConvertJavaStringToUTF8(env, shared_param);
136 auto values = base::MakeUnique<std::map<int, std::string>>();
137 if (!service_manager::ParseSharedFileSwitchValue(param, values.get()))
138 return 0L;
139 return reinterpret_cast<jlong>(values.release());
140 }
141
142 void ReleaseFileDescriptorStoreRegistrationContext(
boliu 2017/02/10 21:33:03 and this
Jay Civelli 2017/02/13 18:48:25 Oh yeah (continued).
143 JNIEnv* env,
144 const JavaParamRef<jclass>& clazz,
145 jlong context) {
146 delete reinterpret_cast<std::map<int, std::string>*>(context);
147 }
148
149 void RegisterFileDescriptors(JNIEnv* env,
150 const JavaParamRef<jclass>& clazz,
151 const JavaParamRef<jintArray>& j_ids,
152 const JavaParamRef<jintArray>& j_fds,
153 const JavaParamRef<jlongArray>& j_offsets,
154 const JavaParamRef<jlongArray>& j_sizes) {
155 std::vector<int> ids;
156 base::android::JavaIntArrayToIntVector(env, j_ids, &ids);
157 std::vector<int> fds;
158 base::android::JavaIntArrayToIntVector(env, j_fds, &fds);
159 std::vector<int64_t> offsets;
160 base::android::JavaLongArrayToInt64Vector(env, j_offsets, &offsets);
161 std::vector<int64_t> sizes;
162 base::android::JavaLongArrayToInt64Vector(env, j_sizes, &sizes);
163
164 DCHECK(ids.size() == fds.size() && fds.size() == offsets.size() &&
boliu 2017/02/10 21:33:03 nit: separate DCHECKs, and use DCHECK_EQ
Jay Civelli 2017/02/13 18:48:25 Sure.
165 offsets.size() == sizes.size());
166
167 std::map<int, std::string> ids_to_keys;
168 std::string file_switch_value =
169 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
170 switches::kSharedFiles);
171 if (!file_switch_value.empty()) {
172 service_manager::ParseSharedFileSwitchValue(file_switch_value,
173 &ids_to_keys);
174 }
175
176 for (size_t i = 0; i < ids.size(); i++) {
177 base::MemoryMappedFile::Region region = {offsets.at(i), sizes.at(i)};
178 int id = ids.at(i);
179 int fd = fds.at(i);
180 auto iter = ids_to_keys.find(id);
181 if (iter != ids_to_keys.end()) {
182 base::FileDescriptorStore::GetInstance().Set(iter->second,
183 base::ScopedFD(fd), region);
184 } else {
185 base::GlobalDescriptors::GetInstance()->Set(id, fd, region);
186 }
187 }
132 } 188 }
133 189
134 void InitChildProcessImpl(JNIEnv* env, 190 void InitChildProcessImpl(JNIEnv* env,
135 const JavaParamRef<jclass>& clazz, 191 const JavaParamRef<jclass>& clazz,
136 const JavaParamRef<jobject>& service_impl, 192 const JavaParamRef<jobject>& service_impl,
137 jint cpu_count, 193 jint cpu_count,
138 jlong cpu_features) { 194 jlong cpu_features) {
139 InternalInitChildProcessImpl(env, service_impl, cpu_count, cpu_features); 195 InternalInitChildProcessImpl(env, service_impl, cpu_count, cpu_features);
140 } 196 }
141 197
142 void ExitChildProcess(JNIEnv* env, const JavaParamRef<jclass>& clazz) { 198 void ExitChildProcess(JNIEnv* env, const JavaParamRef<jclass>& clazz) {
143 VLOG(0) << "ChildProcessServiceImpl: Exiting child process."; 199 VLOG(0) << "ChildProcessServiceImpl: Exiting child process.";
144 base::android::LibraryLoaderExitHook(); 200 base::android::LibraryLoaderExitHook();
145 _exit(0); 201 _exit(0);
146 } 202 }
147 203
148 bool RegisterChildProcessServiceImpl(JNIEnv* env) { 204 bool RegisterChildProcessServiceImpl(JNIEnv* env) {
149 return RegisterNativesImpl(env); 205 return RegisterNativesImpl(env);
150 } 206 }
151 207
152 void ShutdownMainThread(JNIEnv* env, const JavaParamRef<jobject>& obj) { 208 void ShutdownMainThread(JNIEnv* env, const JavaParamRef<jobject>& obj) {
153 ChildThreadImpl::ShutdownThread(); 209 ChildThreadImpl::ShutdownThread();
154 } 210 }
155 211
156 } // namespace content 212 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698