Peter E Conn | 5b603ca | 2023-05-18 14:44:27 | [diff] [blame^] | 1 | # Lifetime annotations |
| 2 | |
| 3 | [TOC] |
| 4 | |
| 5 | ## Overview |
| 6 | |
| 7 | As part of the WebView Multi-profile project, classes and state in |
| 8 | `//android_webview/`` will be annotated to make their lifetimes explicit. |
| 9 | There are broadly 4 different lifetimes that a class can have: |
| 10 | |
| 11 | - Singleton - there is one instance of this class per WebView process. As |
| 12 | WebView is run in the embedding app's process, this means there is one |
| 13 | instance per embedding app. |
| 14 | - Scoped to Profile - this class is specific to a Profile. It is likely to do |
| 15 | with the user's browsing state, such as cookies or permissions. |
| 16 | - Scoped to WebView - this class is specific to a WebView (the Android View), |
| 17 | for example the AwZoomControls. |
| 18 | - Temporary - this class has a shorter lifetime than a WebView, likely just |
| 19 | existing within a call stack, for example return types. |
| 20 | |
| 21 | There is a many to one relationship between WebViews and Profiles. A single |
| 22 | Profile can support multiple WebViews, each WebView will only have a single |
| 23 | (constant) Profile. |
| 24 | |
| 25 | These annotations are purely for documentation, there is no static analysis to |
| 26 | check them. |
| 27 | |
| 28 | ## Annotations |
| 29 | |
| 30 | In Java, use the following annotations: |
| 31 | |
| 32 | - `@Lifetime.Singleton` |
| 33 | - `@Lifetime.Profile` |
| 34 | - `@Lifetime.WebView` |
| 35 | - `@Lifetime.Temporary` |
| 36 | |
| 37 | In C++, use the following comment format as the last line of the classes |
| 38 | documentation: |
| 39 | |
| 40 | ``` |
| 41 | * Lifetime: Singleton |
| 42 | * Lifetime: Profile |
| 43 | * Lifetime: WebView |
| 44 | * Lifetime: Temporary |
| 45 | ``` |