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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/tabs/tab_lifecycle.md
diff --git a/ios/chrome/browser/tabs/tab_lifecycle.md b/ios/chrome/browser/tabs/tab_lifecycle.md
new file mode 100644
index 0000000000000000000000000000000000000000..fa4e850b03a2f5e5335b729c71ac354180735a91
--- /dev/null
+++ b/ios/chrome/browser/tabs/tab_lifecycle.md
@@ -0,0 +1,41 @@
+# `Tab` lifecycle
+
+`LegacyTabHelper` creates `Tab` and keep it retained. `AttachTabHelpers`
+creates `LegacyTabHelper` first and then all the other tab helpers. The
+`AttachTabHelpers` method can be invoked on a newly created `WebState`.
+
+From that point, `LegacyTabHelper::GetTabFromWebState()` will return the
+`Tab` associated with `WebState`. That method will return `nil` before
+the call to `AttachTabHelpers`.
+
+````cpp
+web::WebState::CreateParams params{...};
+std::unique_ptr<web::WebState> web_state = web::WebState::Create(params);
+AttachTabHelper(web_state.get());
+
+Tab* tab = LegacyTabHelper::GetFromWebState(web_state.get());
+DCHECK(tab != nil);
+````
+
+When a `WebState` is added to a `TabModel`'s `WebStateList`,
+`TabModelWebStateListDelegate` will invoke `AttachTabHelpers` if necessary.
+
+```cpp
+TabModel* tab_model = ...;
+std::unique_ptr<web::WebState> web_state = ...;
+[tab_model webStateList]->InsertWebState(0, std::move(web_state));
+Tab* tab = LegacyTabHelper::GetFromWebState(
+ [tab_model webStateList]->GetWebStateAt(0));
+DCHECK(tab != nil);
+```
+
+`Tab` register itself as a `WebStateObserver`. When `-webStateDestroyed:`
+is invoked as part of `WebState` destruction, `Tab` destroys its state and
+should no longer be used (as `-webState` will return `nullptr`).
+
+`LegacyTabHelper` is a `WebStateUserData` thus it is destroyed after the
+`WebState` destructor completes. `LegacyTabHelper` release its reference
+to `Tab` when destroyed.
+
+It is better to only use `WebState` and to access the `Tab` via
+`LegacyTabHelper` as `Tab` will be removed in the new architecture.
« 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