OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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; |
(...skipping 23 matching lines...) Expand all Loading... |
34 private final Context mContext; | 34 private final Context mContext; |
35 private final int mServiceNumber; | 35 private final int mServiceNumber; |
36 private final boolean mInSandbox; | 36 private final boolean mInSandbox; |
37 private final ChildProcessConnection.DeathCallback mDeathCallback; | 37 private final ChildProcessConnection.DeathCallback mDeathCallback; |
38 private final ComponentName mServiceName; | 38 private final ComponentName mServiceName; |
39 | 39 |
40 // Synchronization: While most internal flow occurs on the UI thread, the pu
blic API | 40 // Synchronization: While most internal flow occurs on the UI thread, the pu
blic API |
41 // (specifically start and stop) may be called from any thread, hence all en
try point methods | 41 // (specifically start and stop) may be called from any thread, hence all en
try point methods |
42 // into the class are synchronized on the lock to protect access to these me
mbers. | 42 // into the class are synchronized on the lock to protect access to these me
mbers. |
43 private final Object mLock = new Object(); | 43 private final Object mLock = new Object(); |
44 private IChildProcessService mService = null; | 44 private IChildProcessService mService; |
45 // Set to true when the service connected successfully. | 45 // Set to true when the service connected successfully. |
46 private boolean mServiceConnectComplete = false; | 46 private boolean mServiceConnectComplete; |
47 // Set to true when the service disconnects, as opposed to being properly cl
osed. This happens | 47 // Set to true when the service disconnects, as opposed to being properly cl
osed. This happens |
48 // when the process crashes or gets killed by the system out-of-memory kille
r. | 48 // when the process crashes or gets killed by the system out-of-memory kille
r. |
49 private boolean mServiceDisconnected = false; | 49 private boolean mServiceDisconnected; |
50 // When the service disconnects (i.e. mServiceDisconnected is set to true),
the status of the | 50 // When the service disconnects (i.e. mServiceDisconnected is set to true),
the status of the |
51 // oom bindings is stashed here for future inspection. | 51 // oom bindings is stashed here for future inspection. |
52 private boolean mWasOomProtected = false; | 52 private boolean mWasOomProtected; |
53 private int mPid = 0; // Process ID of the corresponding child process. | 53 private int mPid; // Process ID of the corresponding child process. |
54 // Initial binding protects the newly spawned process from being killed befo
re it is put to use, | 54 // Initial binding protects the newly spawned process from being killed befo
re it is put to use, |
55 // it is maintained between calls to start() and removeInitialBinding(). | 55 // it is maintained between calls to start() and removeInitialBinding(). |
56 private ChildServiceConnection mInitialBinding = null; | 56 private ChildServiceConnection mInitialBinding; |
57 // Strong binding will make the service priority equal to the priority of th
e activity. We want | 57 // Strong binding will make the service priority equal to the priority of th
e activity. We want |
58 // the OS to be able to kill background renderers as it kills other backgrou
nd apps, so strong | 58 // the OS to be able to kill background renderers as it kills other backgrou
nd apps, so strong |
59 // bindings are maintained only for services that are active at the moment (
between | 59 // bindings are maintained only for services that are active at the moment (
between |
60 // addStrongBinding() and removeStrongBinding()). | 60 // addStrongBinding() and removeStrongBinding()). |
61 private ChildServiceConnection mStrongBinding = null; | 61 private ChildServiceConnection mStrongBinding; |
62 // Low priority binding maintained in the entire lifetime of the connection,
i.e. between calls | 62 // Low priority binding maintained in the entire lifetime of the connection,
i.e. between calls |
63 // to start() and stop(). | 63 // to start() and stop(). |
64 private ChildServiceConnection mWaivedBinding = null; | 64 private ChildServiceConnection mWaivedBinding; |
65 // Incremented on addStrongBinding(), decremented on removeStrongBinding(). | 65 // Incremented on addStrongBinding(), decremented on removeStrongBinding(). |
66 private int mStrongBindingCount = 0; | 66 private int mStrongBindingCount; |
67 // Moderate binding will make the service priority equal to the priority of
a visible process | 67 // Moderate binding will make the service priority equal to the priority of
a visible process |
68 // while the app is in the foreground. It will stay bound only while the app
is in the | 68 // while the app is in the foreground. It will stay bound only while the app
is in the |
69 // foreground to protect a background process from the system out-of-memory
killer. | 69 // foreground to protect a background process from the system out-of-memory
killer. |
70 private ChildServiceConnection mModerateBinding = null; | 70 private ChildServiceConnection mModerateBinding; |
71 | 71 |
72 // Linker-related parameters. | 72 // Linker-related parameters. |
73 private ChromiumLinkerParams mLinkerParams = null; | 73 private ChromiumLinkerParams mLinkerParams; |
74 | 74 |
75 private final boolean mAlwaysInForeground; | 75 private final boolean mAlwaysInForeground; |
76 private final ChildProcessCreationParams mCreationParams; | 76 private final ChildProcessCreationParams mCreationParams; |
77 | 77 |
78 // Caches whether non-sandboxed and sandboxed services require an extra | 78 // Caches whether non-sandboxed and sandboxed services require an extra |
79 // binding flag provided via ChildProcessCreationParams. | 79 // binding flag provided via ChildProcessCreationParams. |
80 // TODO(mnaganov): Get rid of it after the release of the next Android SDK. | 80 // TODO(mnaganov): Get rid of it after the release of the next Android SDK. |
81 private static Boolean sNeedsExtrabindFlags[] = new Boolean[2]; | 81 private static Boolean sNeedsExtrabindFlags[] = new Boolean[2]; |
82 | 82 |
83 private static final String TAG = "ChildProcessConnect"; | 83 private static final String TAG = "ChildProcessConnect"; |
(...skipping 17 matching lines...) Expand all Loading... |
101 // the variable is cleared. Therefore this is only valid while the connectio
n is being set up. | 101 // the variable is cleared. Therefore this is only valid while the connectio
n is being set up. |
102 private ConnectionParams mConnectionParams; | 102 private ConnectionParams mConnectionParams; |
103 | 103 |
104 // Callback provided in setupConnection() that will communicate the result t
o the caller. This | 104 // Callback provided in setupConnection() that will communicate the result t
o the caller. This |
105 // has to be called exactly once after setupConnection(), even if setup fail
s, so that the | 105 // has to be called exactly once after setupConnection(), even if setup fail
s, so that the |
106 // caller can free up resources associated with the setup attempt. This is s
et to null after the | 106 // caller can free up resources associated with the setup attempt. This is s
et to null after the |
107 // call. | 107 // call. |
108 private ChildProcessConnection.ConnectionCallback mConnectionCallback; | 108 private ChildProcessConnection.ConnectionCallback mConnectionCallback; |
109 | 109 |
110 private class ChildServiceConnection implements ServiceConnection { | 110 private class ChildServiceConnection implements ServiceConnection { |
111 private boolean mBound = false; | 111 private boolean mBound; |
112 | 112 |
113 private final int mBindFlags; | 113 private final int mBindFlags; |
114 | 114 |
115 private Intent createServiceBindIntent() { | 115 private Intent createServiceBindIntent() { |
116 Intent intent = new Intent(); | 116 Intent intent = new Intent(); |
117 if (mCreationParams != null) { | 117 if (mCreationParams != null) { |
118 mCreationParams.addIntentExtras(intent); | 118 mCreationParams.addIntentExtras(intent); |
119 } | 119 } |
120 intent.setComponent(mServiceName); | 120 intent.setComponent(mServiceName); |
121 return intent; | 121 return intent; |
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 return true; | 515 return true; |
516 } | 516 } |
517 return false; | 517 return false; |
518 } | 518 } |
519 | 519 |
520 @VisibleForTesting | 520 @VisibleForTesting |
521 public boolean isConnected() { | 521 public boolean isConnected() { |
522 return mService != null; | 522 return mService != null; |
523 } | 523 } |
524 } | 524 } |
OLD | NEW |