| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.content.browser; | |
| 6 | |
| 7 import android.content.Context; | |
| 8 | |
| 9 /** | |
| 10 * Manages oom bindings used to bound child services. "Oom binding" is a binding
that raises the | |
| 11 * process oom priority so that it shouldn't be killed by the OS out-of-memory k
iller under | |
| 12 * normal conditions (it can still be killed under drastic memory pressure). Chi
ldProcessConnections | |
| 13 * have two oom bindings: initial binding and strong binding. | |
| 14 * | |
| 15 * BindingManager receives calls that signal status of each service (setInForegr
ound(), | |
| 16 * determinedVisibility()) and the entire embedding application (onSentToBackgro
und(), | |
| 17 * onBroughtToForeground()) and manipulates child process bindings accordingly. | |
| 18 * | |
| 19 * In particular, BindingManager is responsible for: | |
| 20 * - adding and removing the strong binding as service visibility changes (setIn
Foreground()) | |
| 21 * - removing the initial binding of a service when we can start to rely on the
visibility signal / | |
| 22 * strong binding exclusively (after determinedVisibility()) | |
| 23 * - dropping the current oom bindings when a new connection is started on a low
-memory device | |
| 24 * - keeping a strong binding on the foreground service while the entire applica
tion is in | |
| 25 * background | |
| 26 * | |
| 27 * Thread-safety: most of the methods will be called only on the main thread, ex
ceptions are | |
| 28 * explicitly noted. | |
| 29 */ | |
| 30 public interface BindingManager { | |
| 31 /** | |
| 32 * Registers a freshly started child process. This can be called on any thre
ad. | |
| 33 * @param pid handle of the service process | |
| 34 */ | |
| 35 void addNewConnection(int pid, ManagedChildProcessConnection connection); | |
| 36 | |
| 37 /** | |
| 38 * Called when the service visibility changes or is determined for the first
time. On low-memory | |
| 39 * devices this will also drop the oom bindings of the last process that was
oom-bound if a new | |
| 40 * process is used in foreground. | |
| 41 * @param pid handle of the service process | |
| 42 * @param inForeground true iff the service is visibile to the user | |
| 43 */ | |
| 44 void setInForeground(int pid, boolean inForeground); | |
| 45 | |
| 46 /** | |
| 47 * Called when we can begin to rely on the visibility signal only and remove
the initial | |
| 48 * binding. It's safe to call it multiple times, only the first call matters
. | |
| 49 * @param pid handle of the service process | |
| 50 */ | |
| 51 void onDeterminedVisibility(int pid); | |
| 52 | |
| 53 /** | |
| 54 * Called when the embedding application is sent to background. We want to m
aintain a strong | |
| 55 * binding on the most recently used renderer while the embedder is in backg
round, to indicate | |
| 56 * the relative importance of the renderer to system oom killer. | |
| 57 * | |
| 58 * The embedder needs to ensure that: | |
| 59 * - every onBroughtToForeground() is followed by onSentToBackground() | |
| 60 * - pairs of consecutive onBroughtToForeground() / onSentToBackground() ca
lls do not overlap | |
| 61 */ | |
| 62 void onSentToBackground(); | |
| 63 | |
| 64 /** | |
| 65 * Called when the embedding application is brought to foreground. This will
drop the strong | |
| 66 * binding kept on the main renderer during the background period, so the em
bedder should make | |
| 67 * sure that this is called after the regular strong binding is attached for
the foreground | |
| 68 * session. | |
| 69 */ | |
| 70 void onBroughtToForeground(); | |
| 71 | |
| 72 /** | |
| 73 * Should be called when the connection to the child process goes away (eith
er after a clean | |
| 74 * exit or an unexpected crash). At this point we let go of the reference to
the | |
| 75 * ChildProcessConnection. This can be called on any thread. | |
| 76 */ | |
| 77 void removeConnection(int pid); | |
| 78 | |
| 79 /** | |
| 80 * Starts moderate binding management. | |
| 81 * Please see https://goo.gl/tl9MQm for details. | |
| 82 */ | |
| 83 void startModerateBindingManagement(Context context, int maxSize); | |
| 84 | |
| 85 /** | |
| 86 * Releases all moderate bindings. | |
| 87 */ | |
| 88 void releaseAllModerateBindings(); | |
| 89 } | |
| OLD | NEW |