OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "ios/chrome/browser/ui/ntp/recent_tabs/synced_sessions.h" | 5 #include "ios/chrome/browser/ui/ntp/recent_tabs/synced_sessions.h" |
6 | 6 |
7 #include <functional> | 7 #include <functional> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 DistantSession::DistantSession() {} | 68 DistantSession::DistantSession() {} |
69 | 69 |
70 DistantSession::DistantSession(syncer::SyncService* sync_service, | 70 DistantSession::DistantSession(syncer::SyncService* sync_service, |
71 const std::string& tag) { | 71 const std::string& tag) { |
72 if (sync_service->CanSyncStart() && sync_service->GetOpenTabsUIDelegate()) { | 72 if (sync_service->CanSyncStart() && sync_service->GetOpenTabsUIDelegate()) { |
73 sync_sessions::OpenTabsUIDelegate* open_tabs = | 73 sync_sessions::OpenTabsUIDelegate* open_tabs = |
74 sync_service->GetOpenTabsUIDelegate(); | 74 sync_service->GetOpenTabsUIDelegate(); |
75 | 75 |
76 std::vector<const sync_sessions::SyncedSession*> sessions; | 76 std::vector<const sync_sessions::SyncedSession*> sessions; |
77 open_tabs->GetAllForeignSessions(&sessions); | 77 open_tabs->GetAllForeignSessions(&sessions); |
78 for (const auto& session : sessions) { | 78 for (const auto* session : sessions) { |
79 if (tag == session->session_tag) { | 79 if (tag == session->session_tag) { |
80 this->InitWithSyncedSession(session, open_tabs); | 80 this->InitWithSyncedSession(session, open_tabs); |
81 } | 81 } |
82 } | 82 } |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 DistantSession::~DistantSession() {} | 86 DistantSession::~DistantSession() {} |
87 | 87 |
88 void DistantSession::InitWithSyncedSession( | 88 void DistantSession::InitWithSyncedSession( |
89 const sync_sessions::SyncedSession* synced_session, | 89 const sync_sessions::SyncedSession* synced_session, |
90 sync_sessions::OpenTabsUIDelegate* open_tabs) { | 90 sync_sessions::OpenTabsUIDelegate* open_tabs) { |
91 tag = synced_session->session_tag; | 91 tag = synced_session->session_tag; |
92 name = synced_session->session_name; | 92 name = synced_session->session_name; |
93 modified_time = synced_session->modified_time; | 93 modified_time = synced_session->modified_time; |
94 device_type = synced_session->device_type; | 94 device_type = synced_session->device_type; |
95 | 95 |
96 const std::string group_name = | 96 const std::string group_name = |
97 base::FieldTrialList::FindFullName("TabSyncByRecency"); | 97 base::FieldTrialList::FindFullName("TabSyncByRecency"); |
98 if (group_name == "Enabled") { | 98 if (group_name == "Enabled") { |
99 // Order tabs by recency. | 99 // Order tabs by recency. |
100 std::vector<const sessions::SessionTab*> session_tabs; | 100 std::vector<const sessions::SessionTab*> session_tabs; |
101 open_tabs->GetForeignSessionTabs(synced_session->session_tag, | 101 open_tabs->GetForeignSessionTabs(synced_session->session_tag, |
102 &session_tabs); | 102 &session_tabs); |
103 for (const auto& session_tab : session_tabs) { | 103 for (const auto* session_tab : session_tabs) { |
104 AddTabToDistantSession(*session_tab, synced_session->session_tag, this); | 104 AddTabToDistantSession(*session_tab, synced_session->session_tag, this); |
105 } | 105 } |
106 } else { | 106 } else { |
107 // Order tabs by their visual position within window. | 107 // Order tabs by their visual position within window. |
108 for (const auto& kv : synced_session->windows) { | 108 for (const auto& kv : synced_session->windows) { |
109 for (const auto& session_tab : kv.second->tabs) { | 109 for (const auto& session_tab : kv.second->tabs) { |
110 AddTabToDistantSession(*session_tab, synced_session->session_tag, this); | 110 AddTabToDistantSession(*session_tab, synced_session->session_tag, this); |
111 } | 111 } |
112 } | 112 } |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 SyncedSessions::SyncedSessions() {} | 116 SyncedSessions::SyncedSessions() {} |
117 | 117 |
118 SyncedSessions::SyncedSessions(syncer::SyncService* sync_service) { | 118 SyncedSessions::SyncedSessions(syncer::SyncService* sync_service) { |
119 DCHECK(sync_service); | 119 DCHECK(sync_service); |
120 // Reload Sync open tab sesions. | 120 // Reload Sync open tab sesions. |
121 if (sync_service->CanSyncStart() && sync_service->GetOpenTabsUIDelegate()) { | 121 if (sync_service->CanSyncStart() && sync_service->GetOpenTabsUIDelegate()) { |
122 sync_sessions::OpenTabsUIDelegate* open_tabs = | 122 sync_sessions::OpenTabsUIDelegate* open_tabs = |
123 sync_service->GetOpenTabsUIDelegate(); | 123 sync_service->GetOpenTabsUIDelegate(); |
124 | 124 |
125 // Iterating through all remote sessions, then all remote windows, then all | 125 // Iterating through all remote sessions, then all remote windows, then all |
126 // remote tabs to retrieve the tabs to display to the user. This will | 126 // remote tabs to retrieve the tabs to display to the user. This will |
127 // flatten all of those data into a sequential vector of tabs. | 127 // flatten all of those data into a sequential vector of tabs. |
128 | 128 |
129 std::vector<const sync_sessions::SyncedSession*> sessions; | 129 std::vector<const sync_sessions::SyncedSession*> sessions; |
130 open_tabs->GetAllForeignSessions(&sessions); | 130 open_tabs->GetAllForeignSessions(&sessions); |
131 for (const auto& session : sessions) { | 131 for (const auto* session : sessions) { |
132 std::unique_ptr<DistantSession> distant_session(new DistantSession()); | 132 std::unique_ptr<DistantSession> distant_session(new DistantSession()); |
133 distant_session->InitWithSyncedSession(session, open_tabs); | 133 distant_session->InitWithSyncedSession(session, open_tabs); |
134 // Don't display sessions with no tabs. | 134 // Don't display sessions with no tabs. |
135 if (distant_session->tabs.size() > 0) | 135 if (distant_session->tabs.size() > 0) |
136 sessions_.push_back(std::move(distant_session)); | 136 sessions_.push_back(std::move(distant_session)); |
137 } | 137 } |
138 } | 138 } |
139 std::sort(sessions_.begin(), sessions_.end(), SortSessionsByTime); | 139 std::sort(sessions_.begin(), sessions_.end(), SortSessionsByTime); |
140 } | 140 } |
141 | 141 |
(...skipping 25 matching lines...) Expand all Loading... |
167 DCHECK_LE(index, GetSessionCount()); | 167 DCHECK_LE(index, GetSessionCount()); |
168 sessions_.erase(sessions_.begin() + index); | 168 sessions_.erase(sessions_.begin() + index); |
169 } | 169 } |
170 | 170 |
171 void SyncedSessions::AddDistantSessionForTest( | 171 void SyncedSessions::AddDistantSessionForTest( |
172 std::unique_ptr<const DistantSession> distant_session) { | 172 std::unique_ptr<const DistantSession> distant_session) { |
173 sessions_.push_back(std::move(distant_session)); | 173 sessions_.push_back(std::move(distant_session)); |
174 } | 174 } |
175 | 175 |
176 } // synced_sessions namespace | 176 } // synced_sessions namespace |
OLD | NEW |