OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.content.ComponentName; | 7 import android.content.ComponentName; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.content.ServiceConnection; | 10 import android.content.ServiceConnection; |
11 import android.os.AsyncTask; | 11 import android.os.AsyncTask; |
12 import android.os.Bundle; | 12 import android.os.Bundle; |
13 import android.os.Handler; | 13 import android.os.Handler; |
14 import android.os.IBinder; | 14 import android.os.IBinder; |
15 import android.os.Looper; | 15 import android.os.Looper; |
16 import android.os.ParcelFileDescriptor; | 16 import android.os.ParcelFileDescriptor; |
| 17 import android.os.RemoteException; |
17 import android.util.Log; | 18 import android.util.Log; |
18 | 19 |
19 import java.io.IOException; | 20 import java.io.IOException; |
20 import java.util.concurrent.atomic.AtomicBoolean; | 21 import java.util.concurrent.atomic.AtomicBoolean; |
21 | 22 |
22 import org.chromium.base.CalledByNative; | 23 import org.chromium.base.CalledByNative; |
23 import org.chromium.base.CpuFeatures; | 24 import org.chromium.base.CpuFeatures; |
| 25 import org.chromium.base.Linker; |
24 import org.chromium.base.SysUtils; | 26 import org.chromium.base.SysUtils; |
25 import org.chromium.base.ThreadUtils; | 27 import org.chromium.base.ThreadUtils; |
26 import org.chromium.content.app.ChildProcessService; | 28 import org.chromium.content.app.ChildProcessService; |
| 29 import org.chromium.content.app.LibraryLoader; |
27 import org.chromium.content.common.CommandLine; | 30 import org.chromium.content.common.CommandLine; |
28 import org.chromium.content.common.IChildProcessCallback; | 31 import org.chromium.content.common.IChildProcessCallback; |
29 import org.chromium.content.common.IChildProcessService; | 32 import org.chromium.content.common.IChildProcessService; |
30 import org.chromium.content.common.TraceEvent; | 33 import org.chromium.content.common.TraceEvent; |
31 | 34 |
32 /** | 35 /** |
33 * Manages a connection between the browser activity and a child service. The cl
ass is responsible | 36 * Manages a connection between the browser activity and a child service. The cl
ass is responsible |
34 * for estabilishing the connection (start()), closing it (stop()) and increasin
g the priority of | 37 * for estabilishing the connection (start()), closing it (stop()) and increasin
g the priority of |
35 * the service when it is in active use (between calls to attachAsActive() and d
etachAsActive()). | 38 * the service when it is in active use (between calls to attachAsActive() and d
etachAsActive()). |
36 */ | 39 */ |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 public static final String EXTRA_FILES_ID_SUFFIX = "_id"; | 83 public static final String EXTRA_FILES_ID_SUFFIX = "_id"; |
81 public static final String EXTRA_FILES_FD_SUFFIX = "_fd"; | 84 public static final String EXTRA_FILES_FD_SUFFIX = "_fd"; |
82 | 85 |
83 // Used to pass the CPU core count to child processes. | 86 // Used to pass the CPU core count to child processes. |
84 public static final String EXTRA_CPU_COUNT = | 87 public static final String EXTRA_CPU_COUNT = |
85 "com.google.android.apps.chrome.extra.cpu_count"; | 88 "com.google.android.apps.chrome.extra.cpu_count"; |
86 // Used to pass the CPU features mask to child processes. | 89 // Used to pass the CPU features mask to child processes. |
87 public static final String EXTRA_CPU_FEATURES = | 90 public static final String EXTRA_CPU_FEATURES = |
88 "com.google.android.apps.chrome.extra.cpu_features"; | 91 "com.google.android.apps.chrome.extra.cpu_features"; |
89 | 92 |
| 93 public static final String EXTRA_LINKER_BASE_LOAD_ADDRESS = |
| 94 "com.google.android.apps.chrome.extra.linker_base_load_address"; |
| 95 |
90 private final Context mContext; | 96 private final Context mContext; |
91 private final int mServiceNumber; | 97 private final int mServiceNumber; |
92 private final boolean mInSandbox; | 98 private final boolean mInSandbox; |
93 private final ChildProcessConnection.DeathCallback mDeathCallback; | 99 private final ChildProcessConnection.DeathCallback mDeathCallback; |
94 private final Class<? extends ChildProcessService> mServiceClass; | 100 private final Class<? extends ChildProcessService> mServiceClass; |
95 | 101 |
96 // Synchronization: While most internal flow occurs on the UI thread, the pu
blic API | 102 // Synchronization: While most internal flow occurs on the UI thread, the pu
blic API |
97 // (specifically start and stop) may be called from any thread, hence all en
try point methods | 103 // (specifically start and stop) may be called from any thread, hence all en
try point methods |
98 // into the class are synchronized on the lock to protect access to these me
mbers. But see also | 104 // into the class are synchronized on the lock to protect access to these me
mbers. But see also |
99 // the TODO where AsyncBoundServiceConnection is created. | 105 // the TODO where AsyncBoundServiceConnection is created. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 mBindFlags = bindFlags; | 159 mBindFlags = bindFlags; |
154 mProtectsFromOom = protectsFromOom; | 160 mProtectsFromOom = protectsFromOom; |
155 } | 161 } |
156 | 162 |
157 boolean bind(String[] commandLine) { | 163 boolean bind(String[] commandLine) { |
158 if (!mBound) { | 164 if (!mBound) { |
159 final Intent intent = createServiceBindIntent(); | 165 final Intent intent = createServiceBindIntent(); |
160 if (commandLine != null) { | 166 if (commandLine != null) { |
161 intent.putExtra(EXTRA_COMMAND_LINE, commandLine); | 167 intent.putExtra(EXTRA_COMMAND_LINE, commandLine); |
162 } | 168 } |
| 169 if (LibraryLoader.useCrazyLinker()) { |
| 170 intent.putExtra(EXTRA_LINKER_BASE_LOAD_ADDRESS, Linker.getBa
seLoadAddress()); |
| 171 } |
163 mBound = mContext.bindService(intent, this, mBindFlags); | 172 mBound = mContext.bindService(intent, this, mBindFlags); |
164 if (mBound && mProtectsFromOom && mConnectionCallbacks != null)
{ | 173 if (mBound && mProtectsFromOom && mConnectionCallbacks != null)
{ |
165 mConnectionCallbacks.onOomBindingAdded(getPid()); | 174 mConnectionCallbacks.onOomBindingAdded(getPid()); |
166 } | 175 } |
167 } | 176 } |
168 return mBound; | 177 return mBound; |
169 } | 178 } |
170 | 179 |
171 void unbind() { | 180 void unbind() { |
172 if (mBound) { | 181 if (mBound) { |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 415 |
407 if (mConnectionCallbacks != null) { | 416 if (mConnectionCallbacks != null) { |
408 // Number of out-of-memory bindings bound before the connection was
set up. | 417 // Number of out-of-memory bindings bound before the connection was
set up. |
409 int oomBindingCount = | 418 int oomBindingCount = |
410 (mInitialBinding.isBound() ? 1 : 0) + (mStrongBinding.isBoun
d() ? 1 : 0); | 419 (mInitialBinding.isBound() ? 1 : 0) + (mStrongBinding.isBoun
d() ? 1 : 0); |
411 mConnectionCallbacks.onConnected(getPid(), oomBindingCount); | 420 mConnectionCallbacks.onConnected(getPid(), oomBindingCount); |
412 } | 421 } |
413 TraceEvent.end(); | 422 TraceEvent.end(); |
414 } | 423 } |
415 | 424 |
| 425 public void applyRelro(Bundle relroBundle) { |
| 426 if (mService != null && relroBundle != null) |
| 427 try { |
| 428 mService.applyRelro(relroBundle); |
| 429 } catch (RemoteException e) { |
| 430 // Nothing to do if the child process died. |
| 431 } |
| 432 } |
| 433 |
416 private static final long REMOVE_INITIAL_BINDING_DELAY_MILLIS = 1 * 1000; /
/ One second. | 434 private static final long REMOVE_INITIAL_BINDING_DELAY_MILLIS = 1 * 1000; /
/ One second. |
417 | 435 |
418 /** | 436 /** |
419 * Called to remove the strong binding estabilished when the connection was
started. It is safe | 437 * Called to remove the strong binding estabilished when the connection was
started. It is safe |
420 * to call this multiple times. The binding is removed after a fixed delay p
eriod so that the | 438 * to call this multiple times. The binding is removed after a fixed delay p
eriod so that the |
421 * renderer will not be killed immediately after the call. | 439 * renderer will not be killed immediately after the call. |
422 */ | 440 */ |
423 void removeInitialBinding() { | 441 void removeInitialBinding() { |
424 synchronized(mLock) { | 442 synchronized(mLock) { |
425 if (!mInitialBinding.isBound()) { | 443 if (!mInitialBinding.isBound()) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 | 504 |
487 /** | 505 /** |
488 * @return The connection PID, or 0 if not yet connected. | 506 * @return The connection PID, or 0 if not yet connected. |
489 */ | 507 */ |
490 int getPid() { | 508 int getPid() { |
491 synchronized(mLock) { | 509 synchronized(mLock) { |
492 return mPID; | 510 return mPID; |
493 } | 511 } |
494 } | 512 } |
495 } | 513 } |
OLD | NEW |