Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #ifndef IOS_CHROME_BROWSER_TABS_LEGACY_TAB_HELPER_H_ | 5 #ifndef IOS_CHROME_BROWSER_TABS_LEGACY_TAB_HELPER_H_ |
| 6 #define IOS_CHROME_BROWSER_TABS_LEGACY_TAB_HELPER_H_ | 6 #define IOS_CHROME_BROWSER_TABS_LEGACY_TAB_HELPER_H_ |
| 7 | 7 |
| 8 #import "base/ios/weak_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #import "ios/web/public/web_state/web_state_observer.h" | |
| 10 #import "ios/web/public/web_state/web_state_user_data.h" | 11 #import "ios/web/public/web_state/web_state_user_data.h" |
| 11 | 12 |
| 12 @class Tab; | 13 @class Tab; |
| 13 | 14 |
| 14 // LegacyTabHelper allows to access to the Tab owning a given WebState for | 15 // LegacyTabHelper associates a Tab instance to a WebState object. |
| 15 // interoperability of code using WebStates with legacy code using Tabs. | 16 class LegacyTabHelper : public web::WebStateObserver, |
| 16 class LegacyTabHelper : public web::WebStateUserData<LegacyTabHelper> { | 17 public web::WebStateUserData<LegacyTabHelper> { |
| 17 public: | 18 public: |
| 18 // Creates the LegacyTabHelper to record the association of |web_state| | 19 // Creates the LegacyTabHelper. This immediately creates the Tab object. |
| 19 // with |tab|. It is an error if |web_state| is already associated with | 20 static void CreateForWebState(web::WebState* web_state); |
| 20 // another Tab. | |
| 21 static void CreateForWebState(web::WebState* web_state, Tab* tab); | |
| 22 | 21 |
| 23 // Returns the Tab associated with |web_state| if it exists or nil. | 22 // Returns the Tab associated with |web_state| or nil. |
| 24 static Tab* GetTabForWebState(web::WebState* web_state); | 23 static Tab* GetTabForWebState(web::WebState* web_state); |
| 25 | 24 |
| 26 private: | 25 private: |
| 27 LegacyTabHelper(web::WebState* web_state, Tab* tab); | 26 explicit LegacyTabHelper(web::WebState* web_state); |
| 28 ~LegacyTabHelper() override; | 27 ~LegacyTabHelper() override; |
| 29 | 28 |
| 30 // The Tab instance associated with the WebState. The Tab currently owns | 29 // web::WebStateObserver implementation. |
| 31 // the WebState, so this should only be nil between the call to -[Tab close] | 30 void WebStateDestroyed() override; |
| 32 // and the object is deallocated. | 31 |
| 33 base::WeakNSObject<Tab> tab_; | 32 // The Tab instance associated with the WebState. |
|
rohitrao (ping after 24h)
2017/03/26 23:21:21
Should we document the lifetime of this Tab object
sdefresne
2017/03/28 15:15:05
Done in ios/chrome/browser/tabs/tab_lifecycle.md (
| |
| 33 base::scoped_nsobject<Tab> tab_; | |
| 34 | 34 |
| 35 DISALLOW_COPY_AND_ASSIGN(LegacyTabHelper); | 35 DISALLOW_COPY_AND_ASSIGN(LegacyTabHelper); |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 #endif // IOS_CHROME_BROWSER_TABS_LEGACY_TAB_HELPER_H_ | 38 #endif // IOS_CHROME_BROWSER_TABS_LEGACY_TAB_HELPER_H_ |
| OLD | NEW |