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

Side by Side Diff: ios/chrome/browser/tabs/legacy_tab_helper.mm

Issue 2775623002: [ios] WebStateList owns all WebState it manages. (Closed)
Patch Set: Fix ios_chrome_unittests. Created 3 years, 9 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/tabs/legacy_tab_helper.h" 5 #import "ios/chrome/browser/tabs/legacy_tab_helper.h"
6 6
7 #import "ios/chrome/browser/tabs/tab.h" 7 #import "ios/chrome/browser/tabs/tab.h"
8 #import "ios/chrome/browser/tabs/tab_private.h"
8 9
9 #if !defined(__has_feature) || !__has_feature(objc_arc) 10 #if !defined(__has_feature) || !__has_feature(objc_arc)
10 #error "This file requires ARC support." 11 #error "This file requires ARC support."
11 #endif 12 #endif
12 13
13 DEFINE_WEB_STATE_USER_DATA_KEY(LegacyTabHelper); 14 DEFINE_WEB_STATE_USER_DATA_KEY(LegacyTabHelper);
14 15
15 // static 16 // static
16 void LegacyTabHelper::CreateForWebState(web::WebState* web_state, Tab* tab) { 17 void LegacyTabHelper::CreateForWebState(web::WebState* web_state) {
17 DCHECK(web_state); 18 DCHECK(web_state);
18 DCHECK(!FromWebState(web_state)); 19 DCHECK(!FromWebState(web_state));
19 web_state->SetUserData(UserDataKey(), new LegacyTabHelper(web_state, tab)); 20 web_state->SetUserData(UserDataKey(),
21 std::unique_ptr<base::SupportsUserData::Data>(
22 new LegacyTabHelper(web_state)));
20 } 23 }
21 24
22 // static 25 // static
23 Tab* LegacyTabHelper::GetTabForWebState(web::WebState* web_state) { 26 Tab* LegacyTabHelper::GetTabForWebState(web::WebState* web_state) {
24 DCHECK(web_state); 27 DCHECK(web_state);
25 LegacyTabHelper* tab_helper = LegacyTabHelper::FromWebState(web_state); 28 LegacyTabHelper* tab_helper = LegacyTabHelper::FromWebState(web_state);
26 return tab_helper ? tab_helper->tab_.get() : nil; 29 return tab_helper ? tab_helper->tab_.get() : nil;
27 } 30 }
28 31
29 LegacyTabHelper::~LegacyTabHelper() = default; 32 LegacyTabHelper::~LegacyTabHelper() = default;
30 33
31 LegacyTabHelper::LegacyTabHelper(web::WebState* web_state, Tab* tab) 34 LegacyTabHelper::LegacyTabHelper(web::WebState* web_state)
32 : tab_(tab) { 35 : WebStateObserver(web_state),
33 DCHECK_EQ(web_state, tab.webState); 36 tab_([[Tab alloc] initWithWebState:web_state]) {}
37
38 void LegacyTabHelper::WebStateDestroyed() {
39 [tab_ onWebStateDestroyed];
rohitrao (ping after 24h) 2017/03/26 23:21:21 Is this better than making Tab itself a WebStateOb
sdefresne 2017/03/28 15:15:05 Tab is already a CRWWebstateObserver. I agree that
34 } 40 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698