blob: df930fb755d37ef788bae196e2d4755e564aac37 [file] [log] [blame] [view]
Peter E Conn5b603ca2023-05-18 14:44:271# Lifetime annotations
2
3[TOC]
4
5## Overview
6
7As part of the WebView Multi-profile project, classes and state in
8`//android_webview/`` will be annotated to make their lifetimes explicit.
9There 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
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`
36
37In C++, use the following comment format as the last line of the classes
38documentation:
39
40```
41 * Lifetime: Singleton
42 * Lifetime: Profile
43 * Lifetime: WebView
44 * Lifetime: Temporary
45```