OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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_NTP_RECENT_TABS_SYNCED_SESSIONS_H_ |
| 6 #define IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_SYNCED_SESSIONS_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/macros.h" |
| 13 #include "base/strings/string16.h" |
| 14 #include "base/time/time.h" |
| 15 #include "components/sessions/core/session_id.h" |
| 16 #include "components/sync_sessions/synced_session.h" |
| 17 #include "url/gurl.h" |
| 18 |
| 19 namespace syncer { |
| 20 class SyncService; |
| 21 } |
| 22 |
| 23 namespace sync_sessions { |
| 24 class OpenTabsUIDelegate; |
| 25 } |
| 26 |
| 27 namespace synced_sessions { |
| 28 |
| 29 // Data holder that contains the data of the distant tabs to show in the UI. |
| 30 struct DistantTab { |
| 31 DistantTab(); |
| 32 // Uniquely identifies the distant session this DistantTab belongs to. |
| 33 std::string session_tag; |
| 34 // Uniquely identifies this tab in its distant session. |
| 35 SessionID::id_type tab_id; |
| 36 // The title of the page shown in this DistantTab. |
| 37 base::string16 title; |
| 38 // The url shown in this DistantTab. |
| 39 GURL virtual_url; |
| 40 // Returns a hash the fields |virtual_url| and |title|. |
| 41 // By design, two tabs in the same distant session can have the same |
| 42 // |hashOfUserVisibleProperties|. |
| 43 size_t hashOfUserVisibleProperties(); |
| 44 |
| 45 DISALLOW_COPY_AND_ASSIGN(DistantTab); |
| 46 }; |
| 47 |
| 48 // Data holder that contains the data of the distant sessions and their tabs to |
| 49 // show in the UI. |
| 50 |
| 51 class DistantSession { |
| 52 public: |
| 53 DistantSession(); |
| 54 // Initialize with the session tagged with |tag| and obtained with |
| 55 // |sync_service|. |sync_service| must not be null. |
| 56 DistantSession(syncer::SyncService* sync_service, const std::string& tag); |
| 57 ~DistantSession(); |
| 58 void InitWithSyncedSession(const sync_sessions::SyncedSession* synced_session, |
| 59 sync_sessions::OpenTabsUIDelegate* open_tabs); |
| 60 std::string tag; |
| 61 std::string name; |
| 62 base::Time modified_time; |
| 63 sync_sessions::SyncedSession::DeviceType device_type; |
| 64 std::vector<std::unique_ptr<DistantTab>> tabs; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(DistantSession); |
| 67 }; |
| 68 |
| 69 // Class containing distant sessions. |
| 70 class SyncedSessions { |
| 71 public: |
| 72 // Initialize with no distant sessions. |
| 73 SyncedSessions(); |
| 74 // Initialize with all the distant sessions obtained from |sync_service|. |
| 75 // |sync_service| must not be null. |
| 76 explicit SyncedSessions(syncer::SyncService* sync_service); |
| 77 SyncedSessions(syncer::SyncService* sync_service, const std::string& tag); |
| 78 ~SyncedSessions(); |
| 79 DistantSession const* GetSession(size_t index) const; |
| 80 DistantSession const* GetSessionWithTag(const std::string& tag) const; |
| 81 size_t GetSessionCount() const; |
| 82 void EraseSession(size_t index); |
| 83 |
| 84 // Used by tests only. |
| 85 void AddDistantSessionForTest( |
| 86 std::unique_ptr<const DistantSession> distant_session); |
| 87 |
| 88 private: |
| 89 std::vector<std::unique_ptr<const DistantSession>> sessions_; |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(SyncedSessions); |
| 92 }; |
| 93 |
| 94 } // namespace synced_sessions |
| 95 |
| 96 #endif // IOS_CHROME_BROWSER_UI_NTP_RECENT_TABS_SYNCED_SESSIONS_H_ |
OLD | NEW |