| 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/app/android/child_process_service.h" | 5 #include "content/app/android/child_process_service.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" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 // TODO(sievers): Use two different implementations of this depending on if | 32 // TODO(sievers): Use two different implementations of this depending on if |
| 33 // we're in a renderer or gpu process. | 33 // we're in a renderer or gpu process. |
| 34 class SurfaceTextureManagerImpl : public SurfaceTextureManager, | 34 class SurfaceTextureManagerImpl : public SurfaceTextureManager, |
| 35 public SurfaceTexturePeer, | 35 public SurfaceTexturePeer, |
| 36 public GpuSurfaceLookup { | 36 public GpuSurfaceLookup { |
| 37 public: | 37 public: |
| 38 // |service| is the instance of | 38 // |service| is the instance of |
| 39 // org.chromium.content.app.ChildProcessService. | 39 // org.chromium.content.app.ChildProcessService. |
| 40 explicit SurfaceTextureManagerImpl( | 40 explicit SurfaceTextureManagerImpl( |
| 41 const base::android::ScopedJavaLocalRef<jobject>& service) | 41 const base::android::JavaRef<jobject>& service) |
| 42 : service_(service) { | 42 : service_(service) { |
| 43 SurfaceTexturePeer::InitInstance(this); | 43 SurfaceTexturePeer::InitInstance(this); |
| 44 GpuSurfaceLookup::InitInstance(this); | 44 GpuSurfaceLookup::InitInstance(this); |
| 45 } | 45 } |
| 46 ~SurfaceTextureManagerImpl() override { | 46 ~SurfaceTextureManagerImpl() override { |
| 47 SurfaceTexturePeer::InitInstance(NULL); | 47 SurfaceTexturePeer::InitInstance(NULL); |
| 48 GpuSurfaceLookup::InitInstance(NULL); | 48 GpuSurfaceLookup::InitInstance(NULL); |
| 49 } | 49 } |
| 50 | 50 |
| 51 // Overridden from SurfaceTextureManager: | 51 // Overridden from SurfaceTextureManager: |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 private: | 125 private: |
| 126 // The instance of org.chromium.content.app.ChildProcessService. | 126 // The instance of org.chromium.content.app.ChildProcessService. |
| 127 base::android::ScopedJavaGlobalRef<jobject> service_; | 127 base::android::ScopedJavaGlobalRef<jobject> service_; |
| 128 | 128 |
| 129 DISALLOW_COPY_AND_ASSIGN(SurfaceTextureManagerImpl); | 129 DISALLOW_COPY_AND_ASSIGN(SurfaceTextureManagerImpl); |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 // Chrome actually uses the renderer code path for all of its child | 132 // Chrome actually uses the renderer code path for all of its child |
| 133 // processes such as renderers, plugins, etc. | 133 // processes such as renderers, plugins, etc. |
| 134 void InternalInitChildProcess(JNIEnv* env, | 134 void InternalInitChildProcess(JNIEnv* env, |
| 135 jclass clazz, | 135 const JavaParamRef<jobject>& service, |
| 136 jobject service_in, | |
| 137 jint cpu_count, | 136 jint cpu_count, |
| 138 jlong cpu_features) { | 137 jlong cpu_features) { |
| 139 base::android::ScopedJavaLocalRef<jobject> service( | |
| 140 env, env->NewLocalRef(service_in)); | |
| 141 | |
| 142 // Set the CPU properties. | 138 // Set the CPU properties. |
| 143 android_setCpu(cpu_count, cpu_features); | 139 android_setCpu(cpu_count, cpu_features); |
| 144 SurfaceTextureManager::SetInstance(new SurfaceTextureManagerImpl(service)); | 140 SurfaceTextureManager::SetInstance(new SurfaceTextureManagerImpl(service)); |
| 145 | 141 |
| 146 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); | 142 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); |
| 147 } | 143 } |
| 148 | 144 |
| 149 } // namespace <anonymous> | 145 } // namespace <anonymous> |
| 150 | 146 |
| 151 void RegisterGlobalFileDescriptor(JNIEnv* env, | 147 void RegisterGlobalFileDescriptor(JNIEnv* env, |
| 152 const JavaParamRef<jclass>& clazz, | 148 const JavaParamRef<jclass>& clazz, |
| 153 jint id, | 149 jint id, |
| 154 jint fd, | 150 jint fd, |
| 155 jlong offset, | 151 jlong offset, |
| 156 jlong size) { | 152 jlong size) { |
| 157 base::MemoryMappedFile::Region region = {offset, size}; | 153 base::MemoryMappedFile::Region region = {offset, size}; |
| 158 base::GlobalDescriptors::GetInstance()->Set(id, fd, region); | 154 base::GlobalDescriptors::GetInstance()->Set(id, fd, region); |
| 159 } | 155 } |
| 160 | 156 |
| 161 void InitChildProcess(JNIEnv* env, | 157 void InitChildProcess(JNIEnv* env, |
| 162 const JavaParamRef<jclass>& clazz, | 158 const JavaParamRef<jclass>& clazz, |
| 163 const JavaParamRef<jobject>& service, | 159 const JavaParamRef<jobject>& service, |
| 164 jint cpu_count, | 160 jint cpu_count, |
| 165 jlong cpu_features) { | 161 jlong cpu_features) { |
| 166 InternalInitChildProcess(env, clazz, service, cpu_count, cpu_features); | 162 InternalInitChildProcess(env, service, cpu_count, cpu_features); |
| 167 } | 163 } |
| 168 | 164 |
| 169 void ExitChildProcess(JNIEnv* env, const JavaParamRef<jclass>& clazz) { | 165 void ExitChildProcess(JNIEnv* env, const JavaParamRef<jclass>& clazz) { |
| 170 VLOG(0) << "ChildProcessService: Exiting child process."; | 166 VLOG(0) << "ChildProcessService: Exiting child process."; |
| 171 base::android::LibraryLoaderExitHook(); | 167 base::android::LibraryLoaderExitHook(); |
| 172 _exit(0); | 168 _exit(0); |
| 173 } | 169 } |
| 174 | 170 |
| 175 bool RegisterChildProcessService(JNIEnv* env) { | 171 bool RegisterChildProcessService(JNIEnv* env) { |
| 176 return RegisterNativesImpl(env); | 172 return RegisterNativesImpl(env); |
| 177 } | 173 } |
| 178 | 174 |
| 179 void ShutdownMainThread(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 175 void ShutdownMainThread(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 180 ChildThreadImpl::ShutdownThread(); | 176 ChildThreadImpl::ShutdownThread(); |
| 181 } | 177 } |
| 182 | 178 |
| 183 } // namespace content | 179 } // namespace content |
| OLD | NEW |