| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.content.browser; | |
| 6 | |
| 7 import android.os.IBinder; | |
| 8 | |
| 9 import org.chromium.base.process_launcher.ChildProcessCreationParams; | |
| 10 import org.chromium.base.process_launcher.FileDescriptorInfo; | |
| 11 import org.chromium.base.process_launcher.IChildProcessService; | |
| 12 | |
| 13 import javax.annotation.Nullable; | |
| 14 | |
| 15 /** | |
| 16 * Manages a connection between the browser activity and a child service. ChildP
rocessConnection is | |
| 17 * responsible for estabilishing the connection (start()), closing it (stop()) a
nd manipulating the | |
| 18 * bindings held onto the service (addStrongBinding(), removeStrongBinding(), | |
| 19 * removeInitialBinding()). | |
| 20 */ | |
| 21 public interface ChildProcessConnection { | |
| 22 /** | |
| 23 * Used to notify the consumer about disconnection of the service. This call
back is provided | |
| 24 * earlier than ConnectionCallbacks below, as a child process might die befo
re the connection is | |
| 25 * fully set up. | |
| 26 */ | |
| 27 interface DeathCallback { | |
| 28 // Called on Launcher thread. | |
| 29 void onChildProcessDied(ChildProcessConnection connection); | |
| 30 } | |
| 31 | |
| 32 /** | |
| 33 * Used to notify the consumer about the process start. These callbacks will
be invoked before | |
| 34 * the ConnectionCallbacks. | |
| 35 */ | |
| 36 interface StartCallback { | |
| 37 /** | |
| 38 * Called when the child process has successfully started and is ready f
or connection | |
| 39 * setup. | |
| 40 */ | |
| 41 void onChildStarted(); | |
| 42 | |
| 43 /** | |
| 44 * Called when the child process failed to start. This can happen if the
process is already | |
| 45 * in use by another client. | |
| 46 */ | |
| 47 void onChildStartFailed(); | |
| 48 } | |
| 49 | |
| 50 /** | |
| 51 * Used to notify the consumer about the connection being established. | |
| 52 */ | |
| 53 interface ConnectionCallback { | |
| 54 /** | |
| 55 * Called when the connection to the service is established. | |
| 56 * @param pid the pid of the child process | |
| 57 */ | |
| 58 void onConnected(int pid); | |
| 59 } | |
| 60 | |
| 61 int getServiceNumber(); | |
| 62 | |
| 63 boolean isInSandbox(); | |
| 64 | |
| 65 String getPackageName(); | |
| 66 | |
| 67 ChildProcessCreationParams getCreationParams(); | |
| 68 | |
| 69 IChildProcessService getService(); | |
| 70 | |
| 71 /** | |
| 72 * @return the connection pid, or 0 if not yet connected | |
| 73 */ | |
| 74 int getPid(); | |
| 75 | |
| 76 /** | |
| 77 * Starts a connection to an IChildProcessService. This must be followed by
a call to | |
| 78 * setupConnection() to setup the connection parameters. start() and setupCo
nnection() are | |
| 79 * separate to allow to pass whatever parameters are available in start(), a
nd complete the | |
| 80 * remainder later while reducing the connection setup latency. | |
| 81 * @param startCallback (optional) callback when the child process starts or
fails to start. | |
| 82 */ | |
| 83 void start(StartCallback startCallback); | |
| 84 | |
| 85 /** | |
| 86 * Setups the connection after it was started with start(). | |
| 87 * @param commandLine (optional) will be ignored if the command line was alr
eady sent in start() | |
| 88 * @param filesToBeMapped a list of file descriptors that should be register
ed | |
| 89 * @param callback optional client specified callbacks that the child can us
e to communicate | |
| 90 * with the parent process | |
| 91 * @param connectionCallback will be called exactly once after the connectio
n is set up or the | |
| 92 * setup fails | |
| 93 */ | |
| 94 void setupConnection(String[] commandLine, FileDescriptorInfo[] filesToBeMap
ped, | |
| 95 @Nullable IBinder callback, ConnectionCallback connectionCallback); | |
| 96 | |
| 97 /** | |
| 98 * Terminates the connection to IChildProcessService, closing all bindings.
It is safe to call | |
| 99 * this multiple times. | |
| 100 */ | |
| 101 void stop(); | |
| 102 | |
| 103 /** @return true iff the initial oom binding is currently bound. */ | |
| 104 boolean isInitialBindingBound(); | |
| 105 | |
| 106 /** @return true iff the strong oom binding is currently bound. */ | |
| 107 boolean isStrongBindingBound(); | |
| 108 | |
| 109 /** | |
| 110 * Called to remove the strong binding established when the connection was s
tarted. It is safe | |
| 111 * to call this multiple times. | |
| 112 */ | |
| 113 void removeInitialBinding(); | |
| 114 | |
| 115 /** | |
| 116 * For live connections, this returns true iff either the initial or the str
ong binding is | |
| 117 * bound, i.e. the connection has at least one oom binding. For connections
that disconnected | |
| 118 * (did not exit properly), this returns true iff the connection had at leas
t one oom binding | |
| 119 * when it disconnected. | |
| 120 */ | |
| 121 boolean isOomProtectedOrWasWhenDied(); | |
| 122 | |
| 123 /** | |
| 124 * Unbinds the bindings that protect the process from oom killing. It is saf
e to call this | |
| 125 * multiple times, before as well as after stop(). | |
| 126 */ | |
| 127 void dropOomBindings(); | |
| 128 | |
| 129 /** | |
| 130 * Attaches a strong binding that will make the service as important as the
main process. Each | |
| 131 * call should be succeeded by removeStrongBinding(), but multiple strong bi
ndings can be | |
| 132 * requested and released independently. | |
| 133 */ | |
| 134 void addStrongBinding(); | |
| 135 | |
| 136 /** | |
| 137 * Called when the service is no longer in active use of the consumer. | |
| 138 */ | |
| 139 void removeStrongBinding(); | |
| 140 | |
| 141 /** | |
| 142 * Attaches a moderate binding that will give the service the priority of a
visible process, but | |
| 143 * keep the priority below a strongly bound process. | |
| 144 */ | |
| 145 void addModerateBinding(); | |
| 146 | |
| 147 /** | |
| 148 * Called when the service is no longer in moderate use of the consumer. | |
| 149 */ | |
| 150 void removeModerateBinding(); | |
| 151 | |
| 152 /** @return true iff the moderate oom binding is currently bound. */ | |
| 153 boolean isModerateBindingBound(); | |
| 154 } | |
| OLD | NEW |