blob: c272e6af6da137e0e60a2632f8a68b6dfa220554 [file] [log] [blame] [view]
Peter E Conn5b603ca2023-05-18 14:44:271# Lifetime annotations
2
Peter E Conn5b603ca2023-05-18 14:44:273## Overview
4
5As part of the WebView Multi-profile project, classes and state in
6`//android_webview/`` will be annotated to make their lifetimes explicit.
Wayne Jackson Jrb5ad37102023-06-03 14:57:037There are broadly 5 different lifetimes that a class can have:
Peter E Conn5b603ca2023-05-18 14:44:278
Nate Fischere7f39eba2024-01-03 11:06:109- Singleton - there is one instance of this class per WebView browser process.
10 As WebView is run in the embedding app's process, this means there is one
Peter E Conn5b603ca2023-05-18 14:44:2711 instance per embedding app.
12- Scoped to Profile - this class is specific to a Profile. It is likely to do
13 with the user's browsing state, such as cookies or permissions.
14- Scoped to WebView - this class is specific to a WebView (the Android View),
15 for example the AwZoomControls.
Nate Fischere7f39eba2024-01-03 11:06:1016- Temporary - this class has a shorter lifetime than a WebView. Examples include
17 objects that live within a single call stack, objects associated with
18 a single HTTP request or page navigation, etc.
19- Renderer - this class has a lifetime tied to specific to a Renderer.
Peter E Conn5b603ca2023-05-18 14:44:2720
21There is a many to one relationship between WebViews and Profiles. A single
22Profile can support multiple WebViews, each WebView will only have a single
23(constant) Profile.
24
25These annotations are purely for documentation, there is no static analysis to
26check them.
27
28## Annotations
29
30In Java, use the following annotations:
31
32- `@Lifetime.Singleton`
33- `@Lifetime.Profile`
34- `@Lifetime.WebView`
35- `@Lifetime.Temporary`
Wayne Jackson Jrb5ad37102023-06-03 14:57:0336- `@Lifetime.Renderer`
Peter E Conn5b603ca2023-05-18 14:44:2737
Nate Fischere7f39eba2024-01-03 11:06:1038In C++, use the following comment format as the last line of the class
Peter E Conn5b603ca2023-05-18 14:44:2739documentation:
40
41```
Nate Fischere7f39eba2024-01-03 11:06:1042// Lifetime: Singleton
43// Lifetime: Profile
44// Lifetime: WebView
45// Lifetime: Temporary
46// Lifetime: Renderer
Peter E Conn5b603ca2023-05-18 14:44:2747```