|
|
Description[ios] Use WebStateList to back the tab grid.
BUG=686770
Review-Url: https://codereview.chromium.org/2741883002
Cr-Commit-Position: refs/heads/master@{#456805}
Committed: https://chromium.googlesource.com/chromium/src/+/5ddc2d6d65793379648307792c763f92cfe92574
Patch Set 1 #
Total comments: 5
Patch Set 2 : Local pointer to web state list #
Total comments: 12
Patch Set 3 : Favor int over NSInteger in interfaces. #Patch Set 4 : Make readonly reference property. #
Total comments: 16
Patch Set 5 : Address comments #Patch Set 6 : Add constant for invalid index #
Messages
Total messages: 40 (22 generated)
Description was changed from ========== [tab_grid] Hack-in WebStateList BUG= ========== to ========== [tab_grid] Hack-in WebStateList Simple replacement of WebState vector to WebStateList. BUG=686770 ==========
Patchset #1 (id:1) has been deleted
edchin@chromium.org changed reviewers: + lpromero@chromium.org, rohitrao@chromium.org, sczs@chromium.org, sdefresne@chromium.org
https://codereview.chromium.org/2741883002/diff/20001/ios/clean/chrome/browse... File ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm (right): https://codereview.chromium.org/2741883002/diff/20001/ios/clean/chrome/browse... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:56: browser->web_state_list().InsertWebState(0, webState.release(), nullptr); The change in ownership of the webState seems strange here. Should the function argument be a unique_ptr rather than a raw object pointer?
https://codereview.chromium.org/2741883002/diff/20001/ios/clean/chrome/browse... File ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm (left): https://codereview.chromium.org/2741883002/diff/20001/ios/clean/chrome/browse... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:37: std::vector<std::unique_ptr<web::WebState>> _webStates; WDYT about keeping a pointer to the web_state_list? That could make the code look cleaner https://codereview.chromium.org/2741883002/diff/20001/ios/clean/chrome/browse... File ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm (right): https://codereview.chromium.org/2741883002/diff/20001/ios/clean/chrome/browse... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:1: // Copyright 2016 The Chromium Authors. All rights reserved. The CL description says this is a Hack-in, but there's no HACK: comments, could you add some so we know what will change or what will be removed?
Description was changed from ========== [tab_grid] Hack-in WebStateList Simple replacement of WebState vector to WebStateList. BUG=686770 ========== to ========== [tab_grid] Replace vector with WebStateList. BUG=686770 ==========
Patchset #2 (id:40001) has been deleted
https://codereview.chromium.org/2741883002/diff/20001/ios/clean/chrome/browse... File ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm (left): https://codereview.chromium.org/2741883002/diff/20001/ios/clean/chrome/browse... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:37: std::vector<std::unique_ptr<web::WebState>> _webStates; On 2017/03/10 18:00:09, sczs wrote: > WDYT about keeping a pointer to the web_state_list? That could make the code > look cleaner Good idea. PTAL. https://codereview.chromium.org/2741883002/diff/20001/ios/clean/chrome/browse... File ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm (right): https://codereview.chromium.org/2741883002/diff/20001/ios/clean/chrome/browse... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:1: // Copyright 2016 The Chromium Authors. All rights reserved. On 2017/03/10 18:00:09, sczs wrote: > The CL description says this is a Hack-in, but there's no HACK: comments, > could you add some so we know what will change or what will be removed? You're right. This isn't a hack. The title has been updated to read "Replace vector with WebStateList".
Thanks lgtm
Friendly reminder to take a look at this CL. Thanks.
https://codereview.chromium.org/2741883002/diff/60001/ios/clean/chrome/browse... File ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm (right): https://codereview.chromium.org/2741883002/diff/60001/ios/clean/chrome/browse... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:87: int i = static_cast<int>(index); Please DCHECK that index fits in an int: #include <stdint.h> - (NSString*)titleAtIndex:(NSInteger)index { DCHECK_LE(index, INT_MAX); int i = static_cast<int>(index); ... https://codereview.chromium.org/2741883002/diff/60001/ios/clean/chrome/browse... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:88: DCHECK(i < self.webStateList->count()); This is not necessary, WebStateList::GetWebStateAt(i) already DCHECK that the index is in bound. https://codereview.chromium.org/2741883002/diff/60001/ios/clean/chrome/browse... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:106: DCHECK(index < self.webStateList->count()); Ditto. https://codereview.chromium.org/2741883002/diff/60001/ios/clean/chrome/browse... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:117: ignore_result(self.webStateList->DetachWebStateAt(index)); This is incorrect and leak memory. You need to delete the returned object. This simplest way to do that is to create a std::unique_ptr<> from the value returned by DetachWebStateAt: std::unique_ptr<web::WebState> closedWebState( self.webStateList->DetachWebStateAt(index));
These subject lines will be seen by all chromium developers, so I think that "tab_grid" is too specific -- most people won't know what that means. If we're going to put something in brackets, I'd suggest either "ios" or nothing. Something like [ios] Use WebStateList to back the tab grid. https://codereview.chromium.org/2741883002/diff/60001/ios/clean/chrome/browse... File ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm (right): https://codereview.chromium.org/2741883002/diff/60001/ios/clean/chrome/browse... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:40: @property(nonatomic, assign) WebStateList* webStateList; Can this be a readonly property with a custom implementation that does: return browser->web_state_list()? Can this property be a WebStateList& instead of a WebStateList*? Does the style guide disallow non-const references? https://codereview.chromium.org/2741883002/diff/60001/ios/clean/chrome/browse... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:82: - (NSUInteger)numberOfTabsInTabGrid { Should we rewrite these data source methods to use "int" instead of "NSUInteger"?
On 2017/03/13 11:44:15, rohitrao wrote: > These subject lines will be seen by all chromium developers, so I think that > "tab_grid" is too specific -- most people won't know what that means. If we're > going to put something in brackets, I'd suggest either "ios" or nothing. > Something like > > [ios] Use WebStateList to back the tab grid. > > https://codereview.chromium.org/2741883002/diff/60001/ios/clean/chrome/browse... > File ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm (right): > > https://codereview.chromium.org/2741883002/diff/60001/ios/clean/chrome/browse... > ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:40: > @property(nonatomic, assign) WebStateList* webStateList; > Can this be a readonly property with a custom implementation that does: > return browser->web_state_list()? > > Can this property be a WebStateList& instead of a WebStateList*? Does the style > guide disallow non-const references? > > https://codereview.chromium.org/2741883002/diff/60001/ios/clean/chrome/browse... > ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:82: - > (NSUInteger)numberOfTabsInTabGrid { > Should we rewrite these data source methods to use "int" instead of > "NSUInteger"? I think we should convert the code to use "int" for indexes. Both C++ and Objective-C style recommends avoiding using unsigned numbers (unless when representing bitmask, see [1] for C++, the Objective-C is comment is only in the internal version of the style guide, but says "Avoid unsigned integers except when matching types used by system interfaces"). In addition, the Objective-C style guide recommends against NSInteger/NSUinteger due to the different size in 32/64-bit. So I think we should use int for the indexes in the new code. [1]: https://google.github.io/styleguide/cppguide.html#Integer_Types
Description was changed from ========== [tab_grid] Replace vector with WebStateList. BUG=686770 ========== to ========== [ios] Use WebStateList to back the tab grid. BUG=686770 ==========
Patchset #5 (id:120001) has been deleted
Patchset #4 (id:100001) has been deleted
This new patch prefers int over NSInteger/NSUInteger in public interfaces. Also, webStateList is now a readonly reference property with no ivar backing. The getter returns the webStateLIst from the browser. https://codereview.chromium.org/2741883002/diff/60001/ios/clean/chrome/browse... File ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm (right): https://codereview.chromium.org/2741883002/diff/60001/ios/clean/chrome/browse... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:82: - (NSUInteger)numberOfTabsInTabGrid { On 2017/03/13 11:44:15, rohitrao wrote: > Should we rewrite these data source methods to use "int" instead of > "NSUInteger"? Done. https://codereview.chromium.org/2741883002/diff/60001/ios/clean/chrome/browse... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:87: int i = static_cast<int>(index); On 2017/03/13 08:30:55, sdefresne wrote: > Please DCHECK that index fits in an int: > > #include <stdint.h> > > - (NSString*)titleAtIndex:(NSInteger)index { > DCHECK_LE(index, INT_MAX); > int i = static_cast<int>(index); > ... Done. https://codereview.chromium.org/2741883002/diff/60001/ios/clean/chrome/browse... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:88: DCHECK(i < self.webStateList->count()); On 2017/03/13 08:30:55, sdefresne wrote: > This is not necessary, WebStateList::GetWebStateAt(i) already DCHECK that the > index is in bound. Done. https://codereview.chromium.org/2741883002/diff/60001/ios/clean/chrome/browse... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:106: DCHECK(index < self.webStateList->count()); On 2017/03/13 08:30:55, sdefresne wrote: > Ditto. Done. https://codereview.chromium.org/2741883002/diff/60001/ios/clean/chrome/browse... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:116: DCHECK(index < self.webStateList->count()); Also removed this DCHECK as DetachWebStateAt contains this. https://codereview.chromium.org/2741883002/diff/60001/ios/clean/chrome/browse... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:117: ignore_result(self.webStateList->DetachWebStateAt(index)); On 2017/03/13 08:30:56, sdefresne wrote: > This is incorrect and leak memory. You need to delete the returned object. This > simplest way to do that is to create a std::unique_ptr<> from the value returned > by DetachWebStateAt: > > std::unique_ptr<web::WebState> closedWebState( > self.webStateList->DetachWebStateAt(index)); Done.
lgtm with comments https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... File ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm (right): https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:40: @property(readonly) WebStateList& webStateList; Need to be "nonatomic" (as "atomic" is the default). https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:163: web::WebState* activeWebState = self.webStateList.GetActiveWebState(); WebStateList.GetActiveWebState() may return null if there are no active WebStates (i.e. if the WebStateList is empty or not WebState is selected). I think you should add a DCHECK that there is an active WebState (or support the case when there are none). DCHECK_NE(WebStateList::kInvalidIndex, self.webStateList.active_index()); https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... File ios/clean/chrome/browser/ui/tab_grid/tab_grid_view_controller.mm (right): https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... ios/clean/chrome/browser/ui/tab_grid/tab_grid_view_controller.mm:109: DCHECK_LE(tabs, NSIntegerMax); This is unnecessary, NSInteger is at least as large as int. From Objective-C documentation: > When building 32-bit applications, NSInteger is a 32-bit integer. > A 64-bit application treats NSInteger as a 64-bit integer. NSInteger is in fact a typedef for long, and the C (and C++) standard guarantees that long is at least as large as int (in fact, it order types in char, short, int, long, long long and guarantees that each is at least as large as the previous one and only gives lower bound on the type size). TL;DR: remove the DCHECK and cast here. https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... ios/clean/chrome/browser/ui/tab_grid/tab_grid_view_controller.mm:135: DCHECK_LE(tab, NSIntegerMax); ditto, remove the DCHECK and cast here (int -> NSInteger is safe) https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... ios/clean/chrome/browser/ui/tab_grid/tab_grid_view_controller.mm:177: DCHECK_LE(index, NSIntegerMax); ditto, remove the DCHECK and cast here (int -> NSInteger is safe) https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... ios/clean/chrome/browser/ui/tab_grid/tab_grid_view_controller.mm:200: DCHECK_LE(index, NSIntegerMax); ditto, remove the DCHECK and cast here (int -> NSInteger is safe)
lgtm https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... File ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm (right): https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:108: tabCoordinator.webState = self.webStateList.GetWebStateAt(index); This can be in a followup CL, but we should remove the webState property from TabCoordinator, and instead have it configure itself based on self.browser->web_state_list(). https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:112: self.webStateList.ActivateWebStateAt(index); Can we activate the new webstate before calling addChildCoordinator or start, so that the TabCoordinator sees the new state of the world? Does that cause any other issues?
https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... File ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm (right): https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:40: @property(readonly) WebStateList& webStateList; On 2017/03/14 09:04:08, sdefresne wrote: > Need to be "nonatomic" (as "atomic" is the default). Atomicity should only be relevant when you allow the compiler to generate getters and setters, since the compiler will insert locks for atomic properties. But since we override the getter, and disable the setter, nonatomic has no meaning here. https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:108: tabCoordinator.webState = self.webStateList.GetWebStateAt(index); On 2017/03/14 11:41:23, rohitrao wrote: > This can be in a followup CL, but we should remove the webState property from > TabCoordinator, and instead have it configure itself based on > self.browser->web_state_list(). Done. Added a PLACEHOLDER note. https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:112: self.webStateList.ActivateWebStateAt(index); On 2017/03/14 11:41:23, rohitrao wrote: > Can we activate the new webstate before calling addChildCoordinator or start, so > that the TabCoordinator sees the new state of the world? Does that cause any > other issues? Done. No other issues caused as far as I can tell. https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:163: web::WebState* activeWebState = self.webStateList.GetActiveWebState(); On 2017/03/14 09:04:08, sdefresne wrote: > WebStateList.GetActiveWebState() may return null if there are no active > WebStates (i.e. if the WebStateList is empty or not WebState is selected). I > think you should add a DCHECK that there is an active WebState (or support the > case when there are none). > > DCHECK_NE(WebStateList::kInvalidIndex, self.webStateList.active_index()); Done. https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... File ios/clean/chrome/browser/ui/tab_grid/tab_grid_view_controller.mm (right): https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... ios/clean/chrome/browser/ui/tab_grid/tab_grid_view_controller.mm:109: DCHECK_LE(tabs, NSIntegerMax); On 2017/03/14 09:04:08, sdefresne wrote: > This is unnecessary, NSInteger is at least as large as int. > > From Objective-C documentation: > > When building 32-bit applications, NSInteger is a 32-bit integer. > > A 64-bit application treats NSInteger as a 64-bit integer. > > NSInteger is in fact a typedef for long, and the C (and C++) standard guarantees > that long is at least as large as int (in fact, it order types in char, short, > int, long, long long and guarantees that each is at least as large as the > previous one and only gives lower bound on the type size). > > TL;DR: remove the DCHECK and cast here. Done.
https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... File ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm (right): https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:40: @property(readonly) WebStateList& webStateList; On 2017/03/14 16:02:42, edchin wrote: > On 2017/03/14 09:04:08, sdefresne wrote: > > Need to be "nonatomic" (as "atomic" is the default). > > Atomicity should only be relevant when you allow the compiler to generate > getters and setters, since the compiler will insert locks for atomic properties. > But since we override the getter, and disable the setter, nonatomic has no > meaning here. I know, however the style guide requires the properties to be marked as nonatomic even if they are generated (and this is how we use the annotation everywhere in the code): > Be aware of the overhead of properties. By default, all synthesized setters > and getters are atomic. This gives each set and get calls a substantial > amount of synchronization overhead. Declare your properties nonatomic > unless you require atomicity.
Patchset #5 (id:160001) has been deleted
https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... File ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm (right): https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:40: @property(readonly) WebStateList& webStateList; On 2017/03/14 16:34:34, sdefresne wrote: > On 2017/03/14 16:02:42, edchin wrote: > > On 2017/03/14 09:04:08, sdefresne wrote: > > > Need to be "nonatomic" (as "atomic" is the default). > > > > Atomicity should only be relevant when you allow the compiler to generate > > getters and setters, since the compiler will insert locks for atomic > properties. > > But since we override the getter, and disable the setter, nonatomic has no > > meaning here. > > I know, however the style guide requires the properties to be marked as > nonatomic even if they are generated (and this is how we use the annotation > everywhere in the code): > > > Be aware of the overhead of properties. By default, all synthesized setters > > and getters are atomic. This gives each set and get calls a substantial > > amount of synchronization overhead. Declare your properties nonatomic > > unless you require atomicity. > Done. https://codereview.chromium.org/2741883002/diff/140001/ios/clean/chrome/brows... ios/clean/chrome/browser/ui/tab_grid/tab_grid_coordinator.mm:163: web::WebState* activeWebState = self.webStateList.GetActiveWebState(); On 2017/03/14 09:04:08, sdefresne wrote: > WebStateList.GetActiveWebState() may return null if there are no active > WebStates (i.e. if the WebStateList is empty or not WebState is selected). I > think you should add a DCHECK that there is an active WebState (or support the > case when there are none). > > DCHECK_NE(WebStateList::kInvalidIndex, self.webStateList.active_index()); I just read the URLOpening protocol comments which say that this method should fail silently. Instead of this DCHECK, I put in an early return.
The CQ bit was checked by edchin@chromium.org
The patchset sent to the CQ was uploaded after l-g-t-m from sczs@chromium.org, sdefresne@chromium.org, rohitrao@chromium.org Link to the patchset: https://codereview.chromium.org/2741883002/#ps180001 (title: "Address comments")
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by edchin@chromium.org
The latest patch adds a constant for an invalid index in the TabGridDataSource protocol. Previously, it used NSNotFound, which is only used in NSInteger.
The CQ bit was checked by edchin@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: This issue passed the CQ dry run.
The CQ bit was checked by edchin@chromium.org
The patchset sent to the CQ was uploaded after l-g-t-m from sczs@chromium.org, sdefresne@chromium.org, rohitrao@chromium.org Link to the patchset: https://codereview.chromium.org/2741883002/#ps200001 (title: "Add constant for invalid index")
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
CQ is committing da patch. Bot data: {"patchset_id": 200001, "attempt_start_ts": 1489521880692470, "parent_rev": "cbb4ab906568a80aa3e7a314e6570cc3b8900777", "commit_rev": "5ddc2d6d65793379648307792c763f92cfe92574"}
Message was sent while issue was closed.
Description was changed from ========== [ios] Use WebStateList to back the tab grid. BUG=686770 ========== to ========== [ios] Use WebStateList to back the tab grid. BUG=686770 Review-Url: https://codereview.chromium.org/2741883002 Cr-Commit-Position: refs/heads/master@{#456805} Committed: https://chromium.googlesource.com/chromium/src/+/5ddc2d6d65793379648307792c76... ==========
Message was sent while issue was closed.
Committed patchset #6 (id:200001) as https://chromium.googlesource.com/chromium/src/+/5ddc2d6d65793379648307792c76...
Message was sent while issue was closed.
Description was changed from ========== [ios] Use WebStateList to back the tab grid. BUG=686770 Review-Url: https://codereview.chromium.org/2741883002 Cr-Commit-Position: refs/heads/master@{#456805} Committed: https://chromium.googlesource.com/chromium/src/+/5ddc2d6d65793379648307792c76... ========== to ========== [ios] Use WebStateList to back the tab grid. BUG=686770 Review-Url: https://codereview.chromium.org/2741883002 Cr-Commit-Position: refs/heads/master@{#456805} Committed: https://chromium.googlesource.com/chromium/src/+/5ddc2d6d65793379648307792c76... ==========
Message was sent while issue was closed.
lpromero@chromium.org changed reviewers: - lpromero@chromium.org |