OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_SWITCHER_MODEL_H_ |
| 6 #define IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_SWITCHER_MODEL_H_ |
| 7 |
| 8 #import <Foundation/Foundation.h> |
| 9 |
| 10 #include <string> |
| 11 #include "base/ios/block_types.h" |
| 12 #include "base/mac/scoped_nsobject.h" |
| 13 #import "ios/chrome/browser/tabs/tab_model_observer.h" |
| 14 #import "ios/chrome/browser/ui/ntp/recent_tabs/synced_sessions.h" |
| 15 #import "ios/chrome/browser/ui/ntp/recent_tabs/synced_sessions_bridge.h" |
| 16 #import "ios/chrome/browser/ui/tab_switcher/tab_model_snapshot.h" |
| 17 |
| 18 @class TabModel; |
| 19 @class TabSwitcherCache; |
| 20 |
| 21 enum class TabSwitcherSignInPanelsType { |
| 22 PANEL_USER_SIGNED_OUT, |
| 23 PANEL_USER_SIGNED_IN_SYNC_OFF, |
| 24 PANEL_USER_SIGNED_IN_SYNC_IN_PROGRESS, |
| 25 PANEL_USER_SIGNED_IN_SYNC_ON_NO_SESSIONS, |
| 26 NO_PANEL, |
| 27 }; |
| 28 |
| 29 namespace ios_internal { |
| 30 |
| 31 enum class SessionType { |
| 32 OFF_THE_RECORD_SESSION, |
| 33 REGULAR_SESSION, |
| 34 DISTANT_SESSION |
| 35 }; |
| 36 |
| 37 class ChromeBrowserState; |
| 38 |
| 39 // Returns true if the session type is a local session. A local session is a |
| 40 // "regular session" or an "off the record" session. |
| 41 bool IsLocalSession(SessionType sessionType); |
| 42 |
| 43 } // namespace ios_internal |
| 44 |
| 45 // Protocol to observe changes to the TabSwitcherModel. |
| 46 @protocol TabSwitcherModelDelegate<NSObject> |
| 47 // Called when distant sessions were removed or inserted. |removedIndexes| and |
| 48 // |insertedIndexes| contains indexes in ascending order. |
| 49 - (void)distantSessionsRemovedAtSortedIndexes:(NSArray*)removedIndexes |
| 50 insertedAtSortedIndexes:(NSArray*)insertedIndexes; |
| 51 // Called when the distant session with the tag |tag| may need to be updated. |
| 52 - (void)distantSessionMayNeedUpdate:(std::string const&)tag; |
| 53 // Called when a local session of type |type| needs to be updated. |
| 54 - (void)localSessionMayNeedUpdate:(ios_internal::SessionType)type; |
| 55 // Called when the signed-in panel (if any) must change. |
| 56 - (void)signInPanelChangedTo:(TabSwitcherSignInPanelsType)panelType; |
| 57 // Called to retrieve the size of the item at the |index| in |session|. |
| 58 - (CGSize)sizeForItemAtIndex:(NSUInteger)index |
| 59 inSession:(ios_internal::SessionType)session; |
| 60 @end |
| 61 |
| 62 // This class serves as a bridge between Chrome-level data (CLD), and what is |
| 63 // presented on screen in the Tab Switcher. |
| 64 // The CLD is: |
| 65 // -The "distant sessions", i.e. the list of Chrome instances the user is |
| 66 // signed-in, and the tabs each of the session contains. |
| 67 // -The non incognito/incognito tab models. Also known as the "local sessions". |
| 68 // |
| 69 // The TabSwitcher observes changes in the CLD, and takes snapshots of its |
| 70 // state. |
| 71 // Whenever the delegate can be notified, the TabSwitcher computes a diff |
| 72 // and notifies the delegate of the changes. |
| 73 @interface TabSwitcherModel : NSObject<SyncedSessionsObserver, TabModelObserver> |
| 74 |
| 75 @property(nonatomic, readonly) TabModel* mainTabModel; |
| 76 @property(nonatomic, readonly) TabModel* otrTabModel; |
| 77 |
| 78 // Default initializer. |browserState| must not be nullptr, |delegate| must not |
| 79 // be nil. |
| 80 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState |
| 81 delegate:(id<TabSwitcherModelDelegate>)delegate |
| 82 mainTabModel:(TabModel*)mainTabModel |
| 83 otrTabModel:(TabModel*)otrTabModel |
| 84 withCache:(TabSwitcherCache*)cache; |
| 85 // Sets the main and incognito tab models, and notify the delegate of changes, |
| 86 // if any. |mainTabModel| and |otrTabModel| can be nil. |
| 87 - (void)setMainTabModel:(TabModel*)mainTabModel |
| 88 otrTabModel:(TabModel*)otrTabModel; |
| 89 // Returns the browserState. |
| 90 - (ios::ChromeBrowserState*)browserState; |
| 91 // Returns the latest data for the local session of type |type|. |
| 92 - (std::unique_ptr<TabModelSnapshot>)tabModelSnapshotForLocalSession: |
| 93 (ios_internal::SessionType)type; |
| 94 // Returns the latest data for the distant session of tag |tag|. |
| 95 - (std::unique_ptr<const synced_sessions::DistantSession>)distantSessionForTag: |
| 96 (std::string const&)tag; |
| 97 |
| 98 // Returns the current count of sessions including main and incognito. |
| 99 - (NSInteger)sessionCount; |
| 100 // Returns the current count of distant sessions. |
| 101 - (NSInteger)distantSessionCount; |
| 102 // Returns the type of the sign in panel. |
| 103 - (TabSwitcherSignInPanelsType)signInPanelType; |
| 104 // Returns the tag of the session at index |index|. |
| 105 - (std::string const&)tagOfDistantSessionAtIndex:(int)index; |
| 106 // Notifies the delegate that changes occured for the distant sessions. |
| 107 - (void)syncedSessionsChanged; |
| 108 @end |
| 109 |
| 110 #endif // IOS_CHROME_BROWSER_UI_TAB_SWITCHER_TAB_SWITCHER_MODEL_H_ |
OLD | NEW |