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

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

Issue 2810193002: [ObjC ARC] Converts ios/chrome/browser/ui/tab_switcher:tab_switcher to ARC. (Closed)
Patch Set: comment Created 3 years, 7 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/tab_model_snapshot.h" 21 #import "ios/chrome/browser/ui/tab_switcher/tab_model_snapshot.h"
22 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_cache.h" 22 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_cache.h"
23 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_model_private.h" 23 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_model_private.h"
24 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_cell.h" 24 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_cell.h"
25 25
26 #if !defined(__has_feature) || !__has_feature(objc_arc)
27 #error "This file requires ARC support."
28 #endif
29
26 bool TabSwitcherSessionTypeIsLocalSession(TabSwitcherSessionType sessionType) { 30 bool TabSwitcherSessionTypeIsLocalSession(TabSwitcherSessionType sessionType) {
27 return sessionType == TabSwitcherSessionType::OFF_THE_RECORD_SESSION || 31 return sessionType == TabSwitcherSessionType::OFF_THE_RECORD_SESSION ||
28 sessionType == TabSwitcherSessionType::REGULAR_SESSION; 32 sessionType == TabSwitcherSessionType::REGULAR_SESSION;
29 } 33 }
30 34
31 namespace { 35 namespace {
32 36
33 class TagAndIndex { 37 class TagAndIndex {
34 public: 38 public:
35 TagAndIndex(std::string const& tag, size_t index) 39 TagAndIndex(std::string const& tag, size_t index)
(...skipping 11 matching lines...) Expand all
47 set->insert(TagAndIndex(sessions.GetSession(i)->tag, i)); 51 set->insert(TagAndIndex(sessions.GetSession(i)->tag, i));
48 } 52 }
49 } 53 }
50 54
51 } // namespace 55 } // namespace
52 56
53 @interface TabSwitcherModel () { 57 @interface TabSwitcherModel () {
54 // The browser state. 58 // The browser state.
55 ios::ChromeBrowserState* _browserState; // weak 59 ios::ChromeBrowserState* _browserState; // weak
56 // The tab models. 60 // The tab models.
57 TabModel* _mainTabModel; // weak 61 __weak TabModel* _mainTabModel;
58 TabModel* _otrTabModel; // weak 62 __weak TabModel* _otrTabModel;
59 // The delegate for event callbacks. 63 // The delegate for event callbacks.
60 id<TabSwitcherModelDelegate> _delegate; // weak, owns us. 64 __weak id<TabSwitcherModelDelegate> _delegate;
61 // The synced sessions. Must never be null. 65 // The synced sessions. Must never be null.
62 std::unique_ptr<synced_sessions::SyncedSessions> _syncedSessions; 66 std::unique_ptr<synced_sessions::SyncedSessions> _syncedSessions;
63 // The synced sessions change observer. 67 // The synced sessions change observer.
64 std::unique_ptr<synced_sessions::SyncedSessionsObserverBridge> 68 std::unique_ptr<synced_sessions::SyncedSessionsObserverBridge>
65 _syncedSessionsObserver; 69 _syncedSessionsObserver;
66 // Snapshots of the |_mainTabModel| and |_otrTabModel|. 70 // Snapshots of the |_mainTabModel| and |_otrTabModel|.
67 std::unique_ptr<TabModelSnapshot> _mainTabModelSnapshot; 71 std::unique_ptr<TabModelSnapshot> _mainTabModelSnapshot;
68 std::unique_ptr<TabModelSnapshot> _otrTabModelSnapshot; 72 std::unique_ptr<TabModelSnapshot> _otrTabModelSnapshot;
69 // The cache holding resized tabs snapshots. 73 // The cache holding resized tabs snapshots.
70 base::scoped_nsobject<TabSwitcherCache> _cache; 74 TabSwitcherCache* _cache;
71 } 75 }
72 76
73 // Returns the type of the local session corresponding to the given |tabModel|. 77 // Returns the type of the local session corresponding to the given |tabModel|.
74 // |tabModel| MUST be equal to either |_mainTabModel|, or |_otrTabModel|. 78 // |tabModel| MUST be equal to either |_mainTabModel|, or |_otrTabModel|.
75 - (TabSwitcherSessionType)typeOfLocalSessionForTabModel:(TabModel*)tabModel; 79 - (TabSwitcherSessionType)typeOfLocalSessionForTabModel:(TabModel*)tabModel;
76 @end 80 @end
77 81
78 @implementation TabSwitcherModel 82 @implementation TabSwitcherModel
79 83
80 @synthesize mainTabModel = _mainTabModel; 84 @synthesize mainTabModel = _mainTabModel;
(...skipping 13 matching lines...) Expand all
94 _delegate = delegate; 98 _delegate = delegate;
95 _syncedSessions.reset(new synced_sessions::SyncedSessions()); 99 _syncedSessions.reset(new synced_sessions::SyncedSessions());
96 _syncedSessionsObserver.reset( 100 _syncedSessionsObserver.reset(
97 new synced_sessions::SyncedSessionsObserverBridge(self, _browserState)); 101 new synced_sessions::SyncedSessionsObserverBridge(self, _browserState));
98 _mainTabModel = mainTabModel; 102 _mainTabModel = mainTabModel;
99 _otrTabModel = otrTabModel; 103 _otrTabModel = otrTabModel;
100 _mainTabModelSnapshot.reset(new TabModelSnapshot(mainTabModel)); 104 _mainTabModelSnapshot.reset(new TabModelSnapshot(mainTabModel));
101 _otrTabModelSnapshot.reset(new TabModelSnapshot(otrTabModel)); 105 _otrTabModelSnapshot.reset(new TabModelSnapshot(otrTabModel));
102 [_mainTabModel addObserver:self]; 106 [_mainTabModel addObserver:self];
103 [_otrTabModel addObserver:self]; 107 [_otrTabModel addObserver:self];
104 _cache.reset([cache retain]); 108 _cache = cache;
105 } 109 }
106 return self; 110 return self;
107 } 111 }
108 112
109 - (void)setMainTabModel:(TabModel*)mainTabModel 113 - (void)setMainTabModel:(TabModel*)mainTabModel
110 otrTabModel:(TabModel*)otrTabModel { 114 otrTabModel:(TabModel*)otrTabModel {
111 [self replaceOldTabModel:&_mainTabModel withTabModel:mainTabModel]; 115 [self replaceMainTabModelWithTabModel:mainTabModel];
112 [self replaceOldTabModel:&_otrTabModel withTabModel:otrTabModel]; 116 [self replaceOTRTabModelWithTabModel:otrTabModel];
113 } 117 }
114 118
115 - (void)replaceOldTabModel:(TabModel**)oldTabModel 119 - (void)replaceMainTabModelWithTabModel:(TabModel*)newTabModel {
116 withTabModel:(TabModel*)newTabModel { 120 if (_mainTabModel == newTabModel)
117 if (*oldTabModel == newTabModel)
118 return; 121 return;
119 [*oldTabModel removeObserver:self]; 122 [_mainTabModel removeObserver:self];
120 *oldTabModel = newTabModel; 123 _mainTabModel = newTabModel;
121 [newTabModel addObserver:self]; 124 [newTabModel addObserver:self];
122 // Calling |tabModelChanged:| may trigger an animated refresh of the 125 // Calling |tabModelChanged:| may trigger an animated refresh of the
123 // Tab Switcher's collection view. 126 // Tab Switcher's collection view.
127 // Here in |replaceOldTabModel:withTabModel:| the animation is undesirable.
128 [UIView performWithoutAnimation:^{
129 [self tabModelChanged:newTabModel];
130 }];
131 }
132
133 - (void)replaceOTRTabModelWithTabModel:(TabModel*)newTabModel {
134 if (_otrTabModel == newTabModel)
135 return;
136 [_otrTabModel removeObserver:self];
137 _otrTabModel = newTabModel;
138 [newTabModel addObserver:self];
139 // Calling |tabModelChanged:| may trigger an animated refresh of the
140 // Tab Switcher's collection view.
124 // Here in |replaceOldTabModel:withTabModel:| the animation is undesirable. 141 // Here in |replaceOldTabModel:withTabModel:| the animation is undesirable.
125 [UIView performWithoutAnimation:^{ 142 [UIView performWithoutAnimation:^{
126 [self tabModelChanged:newTabModel]; 143 [self tabModelChanged:newTabModel];
127 }]; 144 }];
128 } 145 }
129 146
130 - (void)dealloc { 147 - (void)dealloc {
131 [_mainTabModel removeObserver:self]; 148 [_mainTabModel removeObserver:self];
132 [_otrTabModel removeObserver:self]; 149 [_otrTabModel removeObserver:self];
133 [super dealloc];
134 } 150 }
135 151
136 - (NSInteger)sessionCount { 152 - (NSInteger)sessionCount {
137 const NSInteger mainTabModelSessionCount = 1; 153 const NSInteger mainTabModelSessionCount = 1;
138 const NSInteger otrTabModelSessionCount = 1; 154 const NSInteger otrTabModelSessionCount = 1;
139 return mainTabModelSessionCount + otrTabModelSessionCount + 155 return mainTabModelSessionCount + otrTabModelSessionCount +
140 [self distantSessionCount]; 156 [self distantSessionCount];
141 } 157 }
142 158
143 - (NSInteger)distantSessionCount { 159 - (NSInteger)distantSessionCount {
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 [self tabModelChanged:model]; 410 [self tabModelChanged:model];
395 } 411 }
396 412
397 - (void)tabModel:(TabModel*)model 413 - (void)tabModel:(TabModel*)model
398 didChangeTabSnapshot:(Tab*)tab 414 didChangeTabSnapshot:(Tab*)tab
399 withImage:(UIImage*)image { 415 withImage:(UIImage*)image {
400 [self tabModelChanged:model]; 416 [self tabModelChanged:model];
401 } 417 }
402 418
403 @end 419 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698