OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/tab_switcher/tab_switcher_panel_controller.h" | 5 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_controller.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
10 #import "ios/chrome/browser/tabs/tab.h" | 10 #import "ios/chrome/browser/tabs/tab.h" |
11 #include "ios/chrome/browser/ui/ntp/recent_tabs/synced_sessions.h" | 11 #include "ios/chrome/browser/ui/ntp/recent_tabs/synced_sessions.h" |
12 #import "ios/chrome/browser/ui/tab_switcher/session_changes.h" | |
13 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_cache.h" | 12 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_cache.h" |
14 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_cell.h" | 13 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_cell.h" |
15 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_overlay_view.h" | 14 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_overlay_view.h" |
16 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_view.h" | 15 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_view.h" |
| 16 #include "ios/chrome/browser/ui/tab_switcher/tab_switcher_session_changes.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 void FillVectorWithHashesUsingDistantSession( | 20 void FillVectorWithHashesUsingDistantSession( |
21 synced_sessions::DistantSession const& session, | 21 synced_sessions::DistantSession const& session, |
22 std::vector<size_t>* hashes) { | 22 std::vector<size_t>* hashes) { |
23 DCHECK(hashes); | 23 DCHECK(hashes); |
24 DCHECK(hashes->empty()); | 24 DCHECK(hashes->empty()); |
25 for (size_t i = 0; i < session.tabs.size(); ++i) { | 25 for (size_t i = 0; i < session.tabs.size(); ++i) { |
26 hashes->push_back(session.tabs[i]->hashOfUserVisibleProperties()); | 26 hashes->push_back(session.tabs[i]->hashOfUserVisibleProperties()); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 if (_sessionType == TabSwitcherSessionType::DISTANT_SESSION) { | 102 if (_sessionType == TabSwitcherSessionType::DISTANT_SESSION) { |
103 return NO; | 103 return NO; |
104 } else { | 104 } else { |
105 return ![self isOverlayVisible]; | 105 return ![self isOverlayVisible]; |
106 } | 106 } |
107 } | 107 } |
108 | 108 |
109 - (void)updateCollectionViewIfNeeded { | 109 - (void)updateCollectionViewIfNeeded { |
110 if (_sessionType == TabSwitcherSessionType::DISTANT_SESSION) { | 110 if (_sessionType == TabSwitcherSessionType::DISTANT_SESSION) { |
111 UICollectionView* collectionView = [_panelView collectionView]; | 111 UICollectionView* collectionView = [_panelView collectionView]; |
112 // TODO(crbug.com/633928) Compute SessionChanges outside of the | 112 // TODO(crbug.com/633928) Compute TabSwitcherSessionChanges outside of the |
113 // updateBlock. | 113 // updateBlock. |
114 auto updateBlock = ^{ | 114 auto updateBlock = ^{ |
115 std::unique_ptr<const synced_sessions::DistantSession> newDistantSession = | 115 std::unique_ptr<const synced_sessions::DistantSession> newDistantSession = |
116 [_model distantSessionForTag:_sessionTag]; | 116 [_model distantSessionForTag:_sessionTag]; |
117 std::vector<size_t> oldTabsHashes; | 117 std::vector<size_t> oldTabsHashes; |
118 std::vector<size_t> newTabsHashes; | 118 std::vector<size_t> newTabsHashes; |
119 FillVectorWithHashesUsingDistantSession(*_distantSession.get(), | 119 FillVectorWithHashesUsingDistantSession(*_distantSession.get(), |
120 &oldTabsHashes); | 120 &oldTabsHashes); |
121 FillVectorWithHashesUsingDistantSession(*newDistantSession.get(), | 121 FillVectorWithHashesUsingDistantSession(*newDistantSession.get(), |
122 &newTabsHashes); | 122 &newTabsHashes); |
123 SessionChanges changes(oldTabsHashes, newTabsHashes); | 123 TabSwitcherSessionChanges changes(oldTabsHashes, newTabsHashes); |
124 if (changes.hasChanges()) { | 124 if (changes.HasChanges()) { |
125 _distantSession = std::move(newDistantSession); | 125 _distantSession = std::move(newDistantSession); |
126 [self applyChanges:changes toCollectionView:collectionView]; | 126 [self applyChanges:changes toCollectionView:collectionView]; |
127 } | 127 } |
128 }; | 128 }; |
129 [collectionView performBatchUpdates:updateBlock completion:nil]; | 129 [collectionView performBatchUpdates:updateBlock completion:nil]; |
130 } else { | 130 } else { |
131 UICollectionView* collectionView = [_panelView collectionView]; | 131 UICollectionView* collectionView = [_panelView collectionView]; |
132 auto updateBlock = ^{ | 132 auto updateBlock = ^{ |
133 std::unique_ptr<const TabModelSnapshot> newLocalSession = | 133 std::unique_ptr<const TabModelSnapshot> newLocalSession = |
134 [_model tabModelSnapshotForLocalSession:_sessionType]; | 134 [_model tabModelSnapshotForLocalSession:_sessionType]; |
135 SessionChanges changes(_localSession->hashes(), | 135 TabSwitcherSessionChanges changes(_localSession->hashes(), |
136 newLocalSession->hashes()); | 136 newLocalSession->hashes()); |
137 if (changes.hasChanges()) { | 137 if (changes.HasChanges()) { |
138 _localSession = std::move(newLocalSession); | 138 _localSession = std::move(newLocalSession); |
139 [self applyChanges:changes toCollectionView:collectionView]; | 139 [self applyChanges:changes toCollectionView:collectionView]; |
140 } | 140 } |
141 }; | 141 }; |
142 [collectionView performBatchUpdates:updateBlock completion:nil]; | 142 [collectionView performBatchUpdates:updateBlock completion:nil]; |
143 } | 143 } |
144 } | 144 } |
145 | 145 |
146 - (void)applyChanges:(SessionChanges&)changes | 146 - (void)applyChanges:(TabSwitcherSessionChanges&)changes |
147 toCollectionView:(UICollectionView*)collectionView { | 147 toCollectionView:(UICollectionView*)collectionView { |
148 NSMutableArray* deletedIndexes = [NSMutableArray array]; | 148 NSMutableArray* deletedIndexes = [NSMutableArray array]; |
149 NSMutableArray* insertedIndexes = [NSMutableArray array]; | 149 NSMutableArray* insertedIndexes = [NSMutableArray array]; |
150 NSMutableArray* updatedIndexes = [NSMutableArray array]; | 150 NSMutableArray* updatedIndexes = [NSMutableArray array]; |
151 for (size_t i : changes.deletions()) { | 151 for (size_t i : changes.deletions()) { |
152 NSInteger deletedTabIndex = static_cast<NSInteger>(i); | 152 NSInteger deletedTabIndex = static_cast<NSInteger>(i); |
153 [deletedIndexes | 153 [deletedIndexes |
154 addObject:[NSIndexPath indexPathForItem:deletedTabIndex inSection:0]]; | 154 addObject:[NSIndexPath indexPathForItem:deletedTabIndex inSection:0]]; |
155 } | 155 } |
156 for (size_t i : changes.insertions()) { | 156 for (size_t i : changes.insertions()) { |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 _panelView.reset( | 326 _panelView.reset( |
327 [[TabSwitcherPanelView alloc] initWithSessionType:_sessionType]); | 327 [[TabSwitcherPanelView alloc] initWithSessionType:_sessionType]); |
328 _panelView.get().collectionView.dataSource = self; | 328 _panelView.get().collectionView.dataSource = self; |
329 } | 329 } |
330 | 330 |
331 - (synced_sessions::DistantSession const*)distantSession { | 331 - (synced_sessions::DistantSession const*)distantSession { |
332 return _distantSession.get(); | 332 return _distantSession.get(); |
333 } | 333 } |
334 | 334 |
335 @end | 335 @end |
OLD | NEW |