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

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

Issue 2049843004: Upstream: Renderers are running in WebAPKs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a check. Created 4 years, 6 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.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/library_loader/library_loader_hooks.h" 11 #include "base/android/library_loader/library_loader_hooks.h"
12 #include "base/android/memory_pressure_listener_android.h" 12 #include "base/android/memory_pressure_listener_android.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/posix/global_descriptors.h" 15 #include "base/posix/global_descriptors.h"
16 #include "content/child/child_thread_impl.h" 16 #include "content/child/child_thread_impl.h"
17 #include "content/public/common/content_descriptors.h" 17 #include "content/public/common/content_descriptors.h"
18 #include "gpu/ipc/common/android/surface_texture_manager.h" 18 #include "gpu/ipc/common/android/surface_texture_manager.h"
19 #include "gpu/ipc/common/android/surface_texture_peer.h" 19 #include "gpu/ipc/common/android/surface_texture_peer.h"
20 #include "gpu/ipc/common/gpu_surface_lookup.h" 20 #include "gpu/ipc/common/gpu_surface_lookup.h"
21 #include "ipc/ipc_descriptors.h" 21 #include "ipc/ipc_descriptors.h"
22 #include "jni/ChildProcessService_jni.h" 22 #include "jni/ChildProcessServiceImpl_jni.h"
23 #include "ui/gl/android/scoped_java_surface.h" 23 #include "ui/gl/android/scoped_java_surface.h"
24 24
25 using base::android::AttachCurrentThread; 25 using base::android::AttachCurrentThread;
26 using base::android::CheckException; 26 using base::android::CheckException;
27 using base::android::JavaIntArrayToIntVector; 27 using base::android::JavaIntArrayToIntVector;
28 28
29 namespace content { 29 namespace content {
30 30
31 namespace { 31 namespace {
32 32
33 // TODO(sievers): Use two different implementations of this depending on if 33 // TODO(sievers): Use two different implementations of this depending on if
34 // we're in a renderer or gpu process. 34 // we're in a renderer or gpu process.
35 class SurfaceTextureManagerImpl : public gpu::SurfaceTextureManager, 35 class SurfaceTextureManagerImpl : public gpu::SurfaceTextureManager,
36 public gpu::SurfaceTexturePeer, 36 public gpu::SurfaceTexturePeer,
37 public gpu::GpuSurfaceLookup { 37 public gpu::GpuSurfaceLookup {
38 public: 38 public:
39 // |service| is the instance of 39 // |service impl| is the instance of
40 // org.chromium.content.app.ChildProcessService. 40 // org.chromium.content.app.ChildProcessServiceImpl.
41 explicit SurfaceTextureManagerImpl( 41 explicit SurfaceTextureManagerImpl(
42 const base::android::JavaRef<jobject>& service) 42 const base::android::JavaRef<jobject>& service_impl)
43 : service_(service) { 43 : service_impl_(service_impl) {
44 SurfaceTexturePeer::InitInstance(this); 44 SurfaceTexturePeer::InitInstance(this);
45 gpu::GpuSurfaceLookup::InitInstance(this); 45 gpu::GpuSurfaceLookup::InitInstance(this);
46 } 46 }
47 ~SurfaceTextureManagerImpl() override { 47 ~SurfaceTextureManagerImpl() override {
48 SurfaceTexturePeer::InitInstance(NULL); 48 SurfaceTexturePeer::InitInstance(NULL);
49 gpu::GpuSurfaceLookup::InitInstance(NULL); 49 gpu::GpuSurfaceLookup::InitInstance(NULL);
50 } 50 }
51 51
52 // Overridden from SurfaceTextureManager: 52 // Overridden from SurfaceTextureManager:
53 void RegisterSurfaceTexture(int surface_texture_id, 53 void RegisterSurfaceTexture(int surface_texture_id,
54 int client_id, 54 int client_id,
55 gl::SurfaceTexture* surface_texture) override { 55 gl::SurfaceTexture* surface_texture) override {
56 JNIEnv* env = base::android::AttachCurrentThread(); 56 JNIEnv* env = base::android::AttachCurrentThread();
57 Java_ChildProcessService_createSurfaceTextureSurface( 57 Java_ChildProcessServiceImpl_createSurfaceTextureSurface(
58 env, 58 env,
59 service_.obj(), 59 service_impl_.obj(),
60 surface_texture_id, 60 surface_texture_id,
61 client_id, 61 client_id,
62 surface_texture->j_surface_texture().obj()); 62 surface_texture->j_surface_texture().obj());
63 } 63 }
64 void UnregisterSurfaceTexture(int surface_texture_id, 64 void UnregisterSurfaceTexture(int surface_texture_id,
65 int client_id) override { 65 int client_id) override {
66 JNIEnv* env = base::android::AttachCurrentThread(); 66 JNIEnv* env = base::android::AttachCurrentThread();
67 Java_ChildProcessService_destroySurfaceTextureSurface( 67 Java_ChildProcessServiceImpl_destroySurfaceTextureSurface(
68 env, service_.obj(), surface_texture_id, client_id); 68 env, service_impl_.obj(), surface_texture_id, client_id);
69 } 69 }
70 gfx::AcceleratedWidget AcquireNativeWidgetForSurfaceTexture( 70 gfx::AcceleratedWidget AcquireNativeWidgetForSurfaceTexture(
71 int surface_texture_id) override { 71 int surface_texture_id) override {
72 JNIEnv* env = base::android::AttachCurrentThread(); 72 JNIEnv* env = base::android::AttachCurrentThread();
73 gl::ScopedJavaSurface surface( 73 gl::ScopedJavaSurface surface(
74 Java_ChildProcessService_getSurfaceTextureSurface(env, service_.obj(), 74 Java_ChildProcessServiceImpl_getSurfaceTextureSurface(
75 surface_texture_id)); 75 env, service_impl_.obj(), surface_texture_id));
76 76
77 if (surface.j_surface().is_null()) 77 if (surface.j_surface().is_null())
78 return NULL; 78 return NULL;
79 79
80 // Note: This ensures that any local references used by 80 // Note: This ensures that any local references used by
81 // ANativeWindow_fromSurface are released immediately. This is needed as a 81 // ANativeWindow_fromSurface are released immediately. This is needed as a
82 // workaround for https://code.google.com/p/android/issues/detail?id=68174 82 // workaround for https://code.google.com/p/android/issues/detail?id=68174
83 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); 83 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env);
84 ANativeWindow* native_window = 84 ANativeWindow* native_window =
85 ANativeWindow_fromSurface(env, surface.j_surface().obj()); 85 ANativeWindow_fromSurface(env, surface.j_surface().obj());
86 86
87 return native_window; 87 return native_window;
88 } 88 }
89 89
90 // Overridden from SurfaceTexturePeer: 90 // Overridden from SurfaceTexturePeer:
91 void EstablishSurfaceTexturePeer( 91 void EstablishSurfaceTexturePeer(
92 base::ProcessHandle pid, 92 base::ProcessHandle pid,
93 scoped_refptr<gl::SurfaceTexture> surface_texture, 93 scoped_refptr<gl::SurfaceTexture> surface_texture,
94 int primary_id, 94 int primary_id,
95 int secondary_id) override { 95 int secondary_id) override {
96 JNIEnv* env = base::android::AttachCurrentThread(); 96 JNIEnv* env = base::android::AttachCurrentThread();
97 content::Java_ChildProcessService_establishSurfaceTexturePeer( 97 content::Java_ChildProcessServiceImpl_establishSurfaceTexturePeer(
98 env, 98 env,
99 service_.obj(), 99 service_impl_.obj(),
100 pid, 100 pid,
101 surface_texture->j_surface_texture().obj(), 101 surface_texture->j_surface_texture().obj(),
102 primary_id, 102 primary_id,
103 secondary_id); 103 secondary_id);
104 } 104 }
105 105
106 // Overridden from GpuSurfaceLookup: 106 // Overridden from GpuSurfaceLookup:
107 gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) override { 107 gfx::AcceleratedWidget AcquireNativeWidget(int surface_id) override {
108 JNIEnv* env = base::android::AttachCurrentThread(); 108 JNIEnv* env = base::android::AttachCurrentThread();
109 gl::ScopedJavaSurface surface( 109 gl::ScopedJavaSurface surface(
110 content::Java_ChildProcessService_getViewSurface(env, service_.obj(), 110 content::Java_ChildProcessServiceImpl_getViewSurface(
111 surface_id)); 111 env, service_impl_.obj(), surface_id));
112 112
113 if (surface.j_surface().is_null()) 113 if (surface.j_surface().is_null())
114 return NULL; 114 return NULL;
115 115
116 // Note: This ensures that any local references used by 116 // Note: This ensures that any local references used by
117 // ANativeWindow_fromSurface are released immediately. This is needed as a 117 // ANativeWindow_fromSurface are released immediately. This is needed as a
118 // workaround for https://code.google.com/p/android/issues/detail?id=68174 118 // workaround for https://code.google.com/p/android/issues/detail?id=68174
119 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); 119 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env);
120 ANativeWindow* native_window = 120 ANativeWindow* native_window =
121 ANativeWindow_fromSurface(env, surface.j_surface().obj()); 121 ANativeWindow_fromSurface(env, surface.j_surface().obj());
122 122
123 return native_window; 123 return native_window;
124 } 124 }
125 125
126 // Overridden from GpuSurfaceLookup: 126 // Overridden from GpuSurfaceLookup:
127 gl::ScopedJavaSurface AcquireJavaSurface(int surface_id) override { 127 gl::ScopedJavaSurface AcquireJavaSurface(int surface_id) override {
128 JNIEnv* env = base::android::AttachCurrentThread(); 128 JNIEnv* env = base::android::AttachCurrentThread();
129 return gl::ScopedJavaSurface( 129 return gl::ScopedJavaSurface(
130 content::Java_ChildProcessService_getViewSurface(env, service_.obj(), 130 content::Java_ChildProcessServiceImpl_getViewSurface(
131 surface_id)); 131 env, service_impl_.obj(), surface_id));
132 } 132 }
133 133
134 private: 134 private:
135 // The instance of org.chromium.content.app.ChildProcessService. 135 // The instance of org.chromium.content.app.ChildProcessServiceImpl.
136 base::android::ScopedJavaGlobalRef<jobject> service_; 136 base::android::ScopedJavaGlobalRef<jobject> service_impl_;
137 137
138 DISALLOW_COPY_AND_ASSIGN(SurfaceTextureManagerImpl); 138 DISALLOW_COPY_AND_ASSIGN(SurfaceTextureManagerImpl);
139 }; 139 };
140 140
141 // Chrome actually uses the renderer code path for all of its child 141 // Chrome actually uses the renderer code path for all of its child
142 // processes such as renderers, plugins, etc. 142 // processes such as renderers, plugins, etc.
143 void InternalInitChildProcess(JNIEnv* env, 143 void InternalInitChildProcessImpl(JNIEnv* env,
144 const JavaParamRef<jobject>& service, 144 const JavaParamRef<jobject>& service_impl,
145 jint cpu_count, 145 jint cpu_count,
146 jlong cpu_features) { 146 jlong cpu_features) {
147 // Set the CPU properties. 147 // Set the CPU properties.
148 android_setCpu(cpu_count, cpu_features); 148 android_setCpu(cpu_count, cpu_features);
149 gpu::SurfaceTextureManager::SetInstance( 149 gpu::SurfaceTextureManager::SetInstance(
150 new SurfaceTextureManagerImpl(service)); 150 new SurfaceTextureManagerImpl(service_impl));
151 151
152 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env); 152 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(env);
153 } 153 }
154 154
155 } // namespace <anonymous> 155 } // namespace <anonymous>
156 156
157 void RegisterGlobalFileDescriptor(JNIEnv* env, 157 void RegisterGlobalFileDescriptor(JNIEnv* env,
158 const JavaParamRef<jclass>& clazz, 158 const JavaParamRef<jclass>& clazz,
159 jint id, 159 jint id,
160 jint fd, 160 jint fd,
161 jlong offset, 161 jlong offset,
162 jlong size) { 162 jlong size) {
163 base::MemoryMappedFile::Region region = {offset, size}; 163 base::MemoryMappedFile::Region region = {offset, size};
164 base::GlobalDescriptors::GetInstance()->Set(id, fd, region); 164 base::GlobalDescriptors::GetInstance()->Set(id, fd, region);
165 } 165 }
166 166
167 void InitChildProcess(JNIEnv* env, 167 void InitChildProcessImpl(JNIEnv* env,
168 const JavaParamRef<jclass>& clazz, 168 const JavaParamRef<jclass>& clazz,
169 const JavaParamRef<jobject>& service, 169 const JavaParamRef<jobject>& service_impl,
170 jint cpu_count, 170 jint cpu_count,
171 jlong cpu_features) { 171 jlong cpu_features) {
172 InternalInitChildProcess(env, service, cpu_count, cpu_features); 172 InternalInitChildProcessImpl(env, service_impl, cpu_count, cpu_features);
173 } 173 }
174 174
175 void ExitChildProcess(JNIEnv* env, const JavaParamRef<jclass>& clazz) { 175 void ExitChildProcess(JNIEnv* env, const JavaParamRef<jclass>& clazz) {
176 VLOG(0) << "ChildProcessService: Exiting child process."; 176 VLOG(0) << "ChildProcessServiceImpl: Exiting child process.";
177 base::android::LibraryLoaderExitHook(); 177 base::android::LibraryLoaderExitHook();
178 _exit(0); 178 _exit(0);
179 } 179 }
180 180
181 bool RegisterChildProcessService(JNIEnv* env) { 181 bool RegisterChildProcessServiceImpl(JNIEnv* env) {
182 return RegisterNativesImpl(env); 182 return RegisterNativesImpl(env);
183 } 183 }
184 184
185 void ShutdownMainThread(JNIEnv* env, const JavaParamRef<jobject>& obj) { 185 void ShutdownMainThread(JNIEnv* env, const JavaParamRef<jobject>& obj) {
186 ChildThreadImpl::ShutdownThread(); 186 ChildThreadImpl::ShutdownThread();
187 } 187 }
188 188
189 } // namespace content 189 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698