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

Side by Side Diff: ios/chrome/browser/ui/tab_switcher/tab_switcher_model.mm

Issue 2608253003: [ios] Moves tab_switcher code out of the ios_internal namespace. (Closed)
Patch Set: Created 3 years, 11 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 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_model.h" 5 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_model.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "components/browser_sync/profile_sync_service.h" 10 #include "components/browser_sync/profile_sync_service.h"
11 #include "components/sessions/core/session_id.h" 11 #include "components/sessions/core/session_id.h"
12 #include "components/signin/core/browser/signin_manager.h" 12 #include "components/signin/core/browser/signin_manager.h"
13 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 13 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
14 #include "ios/chrome/browser/signin/signin_manager_factory.h" 14 #include "ios/chrome/browser/signin/signin_manager_factory.h"
15 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" 15 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h"
16 #include "ios/chrome/browser/sync/sync_setup_service.h" 16 #include "ios/chrome/browser/sync/sync_setup_service.h"
17 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" 17 #include "ios/chrome/browser/sync/sync_setup_service_factory.h"
18 #import "ios/chrome/browser/tabs/tab.h" 18 #import "ios/chrome/browser/tabs/tab.h"
19 #import "ios/chrome/browser/tabs/tab_model.h" 19 #import "ios/chrome/browser/tabs/tab_model.h"
20 #include "ios/chrome/browser/ui/ntp/recent_tabs/synced_sessions.h" 20 #include "ios/chrome/browser/ui/ntp/recent_tabs/synced_sessions.h"
21 #import "ios/chrome/browser/ui/tab_switcher/session_changes.h" 21 #import "ios/chrome/browser/ui/tab_switcher/session_changes.h"
22 #import "ios/chrome/browser/ui/tab_switcher/tab_model_snapshot.h" 22 #import "ios/chrome/browser/ui/tab_switcher/tab_model_snapshot.h"
23 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_cache.h" 23 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_cache.h"
24 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_model_private.h" 24 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_model_private.h"
25 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_cell.h" 25 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_cell.h"
26 26
27 namespace ios_internal { 27 bool SessionTypeIsLocalSession(SessionType sessionType) {
28
29 bool IsLocalSession(SessionType sessionType) {
30 return sessionType == SessionType::OFF_THE_RECORD_SESSION || 28 return sessionType == SessionType::OFF_THE_RECORD_SESSION ||
31 sessionType == SessionType::REGULAR_SESSION; 29 sessionType == SessionType::REGULAR_SESSION;
32 } 30 }
33 31
34 } // namespace ios_internal
35
36 namespace { 32 namespace {
37 33
38 class TagAndIndex { 34 class TagAndIndex {
39 public: 35 public:
40 TagAndIndex(std::string const& tag, size_t index) 36 TagAndIndex(std::string const& tag, size_t index)
41 : tag_(tag), index_(index) {} 37 : tag_(tag), index_(index) {}
42 std::string tag_; 38 std::string tag_;
43 size_t index_; 39 size_t index_;
44 bool operator<(const TagAndIndex& other) const { return tag_ < other.tag_; } 40 bool operator<(const TagAndIndex& other) const { return tag_ < other.tag_; }
45 }; 41 };
(...skipping 24 matching lines...) Expand all
70 _syncedSessionsObserver; 66 _syncedSessionsObserver;
71 // Snapshots of the |_mainTabModel| and |_otrTabModel|. 67 // Snapshots of the |_mainTabModel| and |_otrTabModel|.
72 std::unique_ptr<TabModelSnapshot> _mainTabModelSnapshot; 68 std::unique_ptr<TabModelSnapshot> _mainTabModelSnapshot;
73 std::unique_ptr<TabModelSnapshot> _otrTabModelSnapshot; 69 std::unique_ptr<TabModelSnapshot> _otrTabModelSnapshot;
74 // The cache holding resized tabs snapshots. 70 // The cache holding resized tabs snapshots.
75 base::scoped_nsobject<TabSwitcherCache> _cache; 71 base::scoped_nsobject<TabSwitcherCache> _cache;
76 } 72 }
77 73
78 // Returns the type of the local session corresponding to the given |tabModel|. 74 // Returns the type of the local session corresponding to the given |tabModel|.
79 // |tabModel| MUST be equal to either |_mainTabModel|, or |_otrTabModel|. 75 // |tabModel| MUST be equal to either |_mainTabModel|, or |_otrTabModel|.
80 - (ios_internal::SessionType)typeOfLocalSessionForTabModel:(TabModel*)tabModel; 76 - (SessionType)typeOfLocalSessionForTabModel:(TabModel*)tabModel;
81 @end 77 @end
82 78
83 @implementation TabSwitcherModel 79 @implementation TabSwitcherModel
84 80
85 @synthesize mainTabModel = _mainTabModel; 81 @synthesize mainTabModel = _mainTabModel;
86 @synthesize otrTabModel = _otrTabModel; 82 @synthesize otrTabModel = _otrTabModel;
87 83
88 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState 84 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState
89 delegate:(id<TabSwitcherModelDelegate>)delegate 85 delegate:(id<TabSwitcherModelDelegate>)delegate
90 mainTabModel:(TabModel*)mainTabModel 86 mainTabModel:(TabModel*)mainTabModel
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 142 }
147 143
148 - (NSInteger)distantSessionCount { 144 - (NSInteger)distantSessionCount {
149 return _syncedSessions->GetSessionCount(); 145 return _syncedSessions->GetSessionCount();
150 } 146 }
151 147
152 - (ios::ChromeBrowserState*)browserState { 148 - (ios::ChromeBrowserState*)browserState {
153 return _browserState; 149 return _browserState;
154 } 150 }
155 151
156 - (TabModel*)tabModelForSessionOfType:(ios_internal::SessionType)type { 152 - (TabModel*)tabModelForSessionOfType:(SessionType)type {
157 DCHECK(type == ios_internal::SessionType::OFF_THE_RECORD_SESSION || 153 DCHECK(type == SessionType::OFF_THE_RECORD_SESSION ||
sdefresne 2017/01/03 16:04:30 nit: this could be rewritten like this DCHECK(S
rohitrao (ping after 24h) 2017/01/04 13:36:37 Acknowledged.
158 type == ios_internal::SessionType::REGULAR_SESSION); 154 type == SessionType::REGULAR_SESSION);
159 return type == ios_internal::SessionType::OFF_THE_RECORD_SESSION 155 return type == SessionType::OFF_THE_RECORD_SESSION ? _otrTabModel
160 ? _otrTabModel 156 : _mainTabModel;
161 : _mainTabModel;
162 } 157 }
163 158
164 - (NSInteger)numberOfTabsInLocalSessionOfType:(ios_internal::SessionType)type { 159 - (NSInteger)numberOfTabsInLocalSessionOfType:(SessionType)type {
165 TabModelSnapshot* tabModelSnapshot = [self tabModelSnapshotForSession:type]; 160 TabModelSnapshot* tabModelSnapshot = [self tabModelSnapshotForSession:type];
166 return tabModelSnapshot->tabs().size(); 161 return tabModelSnapshot->tabs().size();
167 } 162 }
168 163
169 - (Tab*)tabAtIndex:(NSUInteger)index 164 - (Tab*)tabAtIndex:(NSUInteger)index inLocalSessionOfType:(SessionType)type {
170 inLocalSessionOfType:(ios_internal::SessionType)type {
171 TabModelSnapshot* tabModelSnapshot = [self tabModelSnapshotForSession:type]; 165 TabModelSnapshot* tabModelSnapshot = [self tabModelSnapshotForSession:type];
172 return tabModelSnapshot->tabs()[index]; 166 return tabModelSnapshot->tabs()[index];
173 } 167 }
174 168
175 - (std::unique_ptr<TabModelSnapshot>)tabModelSnapshotForLocalSession: 169 - (std::unique_ptr<TabModelSnapshot>)tabModelSnapshotForLocalSession:
176 (ios_internal::SessionType)type { 170 (SessionType)type {
177 TabModel* tm = nullptr; 171 TabModel* tm = nullptr;
178 switch (type) { 172 switch (type) {
179 case ios_internal::SessionType::OFF_THE_RECORD_SESSION: 173 case SessionType::OFF_THE_RECORD_SESSION:
180 tm = _otrTabModel; 174 tm = _otrTabModel;
181 break; 175 break;
182 case ios_internal::SessionType::REGULAR_SESSION: 176 case SessionType::REGULAR_SESSION:
183 tm = _mainTabModel; 177 tm = _mainTabModel;
184 break; 178 break;
185 default: 179 default:
186 NOTREACHED(); 180 NOTREACHED();
187 break; 181 break;
188 } 182 }
189 return base::MakeUnique<TabModelSnapshot>(tm); 183 return base::MakeUnique<TabModelSnapshot>(tm);
190 } 184 }
191 185
192 - (std::unique_ptr<const synced_sessions::DistantSession>)distantSessionForTag: 186 - (std::unique_ptr<const synced_sessions::DistantSession>)distantSessionForTag:
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 std::set<TagAndIndex> tagsOfOtherSessions; 303 std::set<TagAndIndex> tagsOfOtherSessions;
310 std::set_intersection( 304 std::set_intersection(
311 tagsOfNewSessions.begin(), tagsOfNewSessions.end(), 305 tagsOfNewSessions.begin(), tagsOfNewSessions.end(),
312 tagsOfOldSessions.begin(), tagsOfOldSessions.end(), 306 tagsOfOldSessions.begin(), tagsOfOldSessions.end(),
313 std::inserter(tagsOfOtherSessions, tagsOfOtherSessions.end())); 307 std::inserter(tagsOfOtherSessions, tagsOfOtherSessions.end()));
314 for (TagAndIndex const& tagAndIndexOfSession : tagsOfOtherSessions) { 308 for (TagAndIndex const& tagAndIndexOfSession : tagsOfOtherSessions) {
315 [delegate distantSessionMayNeedUpdate:tagAndIndexOfSession.tag_]; 309 [delegate distantSessionMayNeedUpdate:tagAndIndexOfSession.tag_];
316 } 310 }
317 } 311 }
318 312
319 - (ios_internal::SessionType)typeOfLocalSessionForTabModel:(TabModel*)tabModel { 313 - (SessionType)typeOfLocalSessionForTabModel:(TabModel*)tabModel {
320 DCHECK(tabModel == _mainTabModel || tabModel == _otrTabModel); 314 DCHECK(tabModel == _mainTabModel || tabModel == _otrTabModel);
321 if (tabModel == _otrTabModel) 315 if (tabModel == _otrTabModel)
322 return ios_internal::SessionType::OFF_THE_RECORD_SESSION; 316 return SessionType::OFF_THE_RECORD_SESSION;
323 return ios_internal::SessionType::REGULAR_SESSION; 317 return SessionType::REGULAR_SESSION;
324 } 318 }
325 319
326 - (TabModelSnapshot*)tabModelSnapshotForSession: 320 - (TabModelSnapshot*)tabModelSnapshotForSession:(SessionType)type {
327 (ios_internal::SessionType)type {
328 switch (type) { 321 switch (type) {
329 case ios_internal::SessionType::OFF_THE_RECORD_SESSION: 322 case SessionType::OFF_THE_RECORD_SESSION:
330 return _otrTabModelSnapshot.get(); 323 return _otrTabModelSnapshot.get();
331 case ios_internal::SessionType::REGULAR_SESSION: 324 case SessionType::REGULAR_SESSION:
332 return _mainTabModelSnapshot.get(); 325 return _mainTabModelSnapshot.get();
333 default: 326 default:
334 NOTREACHED(); 327 NOTREACHED();
335 return nullptr; 328 return nullptr;
336 break; 329 break;
337 } 330 }
338 } 331 }
339 332
340 - (void)setTabModelSnapshot:(std::unique_ptr<TabModelSnapshot>)tabModelSnapshot 333 - (void)setTabModelSnapshot:(std::unique_ptr<TabModelSnapshot>)tabModelSnapshot
341 forSession:(ios_internal::SessionType)type { 334 forSession:(SessionType)type {
342 switch (type) { 335 switch (type) {
343 case ios_internal::SessionType::OFF_THE_RECORD_SESSION: 336 case SessionType::OFF_THE_RECORD_SESSION:
344 _otrTabModelSnapshot = std::move(tabModelSnapshot); 337 _otrTabModelSnapshot = std::move(tabModelSnapshot);
345 break; 338 break;
346 case ios_internal::SessionType::REGULAR_SESSION: 339 case SessionType::REGULAR_SESSION:
347 _mainTabModelSnapshot = std::move(tabModelSnapshot); 340 _mainTabModelSnapshot = std::move(tabModelSnapshot);
348 break; 341 break;
349 default: 342 default:
350 NOTREACHED(); 343 NOTREACHED();
351 break; 344 break;
352 } 345 }
353 } 346 }
354 347
355 - (void)tabModelChanged:(TabModel*)tabModel { 348 - (void)tabModelChanged:(TabModel*)tabModel {
356 ios_internal::SessionType sessionType = 349 SessionType sessionType = [self typeOfLocalSessionForTabModel:tabModel];
357 [self typeOfLocalSessionForTabModel:tabModel];
358 [_delegate localSessionMayNeedUpdate:sessionType]; 350 [_delegate localSessionMayNeedUpdate:sessionType];
359 } 351 }
360 352
361 #pragma mark - SyncedSessionsObserver 353 #pragma mark - SyncedSessionsObserver
362 354
363 - (void)reloadSessions { 355 - (void)reloadSessions {
364 [self syncedSessionsChanged]; 356 [self syncedSessionsChanged];
365 } 357 }
366 358
367 - (void)onSyncStateChanged { 359 - (void)onSyncStateChanged {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 [self tabModelChanged:model]; 393 [self tabModelChanged:model];
402 } 394 }
403 395
404 - (void)tabModel:(TabModel*)model 396 - (void)tabModel:(TabModel*)model
405 didChangeTabSnapshot:(Tab*)tab 397 didChangeTabSnapshot:(Tab*)tab
406 withImage:(UIImage*)image { 398 withImage:(UIImage*)image {
407 [self tabModelChanged:model]; 399 [self tabModelChanged:model];
408 } 400 }
409 401
410 @end 402 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698