Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(494)

Side by Side Diff: ios/chrome/browser/tabs/tab_lifecycle.md

Issue 2775623002: [ios] WebStateList owns all WebState it manages. (Closed)
Patch Set: Fix gn check Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/tabs/tab_helper_util.mm ('k') | ios/chrome/browser/tabs/tab_model.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # `Tab` lifecycle
2
3 `LegacyTabHelper` creates `Tab` and keep it retained. `AttachTabHelpers`
4 creates `LegacyTabHelper` first and then all the other tab helpers. The
5 `AttachTabHelpers` method can be invoked on a newly created `WebState`.
6
7 From that point, `LegacyTabHelper::GetTabFromWebState()` will return the
8 `Tab` associated with `WebState`. That method will return `nil` before
9 the call to `AttachTabHelpers`.
10
11 ````cpp
12 web::WebState::CreateParams params{...};
13 std::unique_ptr<web::WebState> web_state = web::WebState::Create(params);
14 AttachTabHelper(web_state.get());
15
16 Tab* tab = LegacyTabHelper::GetFromWebState(web_state.get());
17 DCHECK(tab != nil);
18 ````
19
20 When a `WebState` is added to a `TabModel`'s `WebStateList`,
21 `TabModelWebStateListDelegate` will invoke `AttachTabHelpers` if necessary.
22
23 ```cpp
24 TabModel* tab_model = ...;
25 std::unique_ptr<web::WebState> web_state = ...;
26 [tab_model webStateList]->InsertWebState(0, std::move(web_state));
27 Tab* tab = LegacyTabHelper::GetFromWebState(
28 [tab_model webStateList]->GetWebStateAt(0));
29 DCHECK(tab != nil);
30 ```
31
32 `Tab` register itself as a `WebStateObserver`. When `-webStateDestroyed:`
33 is invoked as part of `WebState` destruction, `Tab` destroys its state and
34 should no longer be used (as `-webState` will return `nullptr`).
35
36 `LegacyTabHelper` is a `WebStateUserData` thus it is destroyed after the
37 `WebState` destructor completes. `LegacyTabHelper` release its reference
38 to `Tab` when destroyed.
39
40 It is better to only use `WebState` and to access the `Tab` via
41 `LegacyTabHelper` as `Tab` will be removed in the new architecture.
OLDNEW
« no previous file with comments | « ios/chrome/browser/tabs/tab_helper_util.mm ('k') | ios/chrome/browser/tabs/tab_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698