• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Chromium Authors
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.base;
6 
7 /**
8  * Marker interface to be implemented by classes which makes them attachable to a host class that
9  * holds {@link UnownedUserDataHost} entries.
10  * <p>
11  * Marking something as a UnownedUserData has no other implications than that the class can be
12  * referenced from a {@link UnownedUserDataHost} as a {@link java.lang.ref.WeakReference}.
13  * <p>
14  * Implementors can also optionally implement the method
15  * {@link #onDetachedFromHost(UnownedUserDataHost)}
16  * to be informed whenever they have been detached from the host. This can happen when the
17  * particular {@link UnownedUserDataHost} they are attached to is destroyed.
18  *
19  * @see UnownedUserDataHost for more details on ownership and typical usage.
20  * @see UnownedUserDataKey for information about the type of key that is required.
21  */
22 public interface UnownedUserData {
23     /**
24      * Invoked whenever the particular UnownedUserData has been removed from a particular host. If
25      * the UnownedUserData has been garbage collected before the UserDataHost is informed of its
26      * removal, this method will of course not be invoked.
27      * <p>
28      * This method is invoked asynchronously, but from the correct thread.
29      *
30      * @param host from which host the UnownedUserData was detached.
31      */
onDetachedFromHost(UnownedUserDataHost host)32     default void onDetachedFromHost(UnownedUserDataHost host) {}
33 
34     /**
35      * WARNING: This may be invoked in a re-entrant way, but will be invoked on the correct thread.
36      *
37      * @return true if the UnownedUserData wants to be informed asynchronously about detachments.
38      */
informOnDetachmentFromHost()39     default boolean informOnDetachmentFromHost() {
40         return true;
41     }
42 }
43