OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_TRACKER_H_ | 5 #ifndef COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_TRACKER_H_ |
6 #define COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_TRACKER_H_ | 6 #define COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_TRACKER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 size_t tab_index); | 126 size_t tab_index); |
127 | 127 |
128 // Returns a pointer to the SessionTab object associated with |tab_id| for | 128 // Returns a pointer to the SessionTab object associated with |tab_id| for |
129 // the session specified with |session_tag|. If none exists, creates one. | 129 // the session specified with |session_tag|. If none exists, creates one. |
130 // Ownership of the SessionTab remains within the SyncedSessionTracker. | 130 // Ownership of the SessionTab remains within the SyncedSessionTracker. |
131 // |tab_node_id| must be a valid node id for the node backing this tab. | 131 // |tab_node_id| must be a valid node id for the node backing this tab. |
132 sessions::SessionTab* GetTab(const std::string& session_tag, | 132 sessions::SessionTab* GetTab(const std::string& session_tag, |
133 SessionID::id_type tab_id, | 133 SessionID::id_type tab_id, |
134 int tab_node_id); | 134 int tab_node_id); |
135 | 135 |
136 // Reassociated the tab denoted by |old_tab_id| with a new tab id. | |
137 // This is useful on restart when sync needs to reassociate tabs from a | |
138 // previous session with newly restored tabs (and can be used in conjunction | |
139 // with PutTabInWindow). | |
140 // Returns whether the reassociation succeeded. | |
141 bool ReassociateTab(const std::string& session_tag, | |
142 SessionID::id_type old_tab_id, | |
143 SessionID::id_type new_tab_id); | |
144 | |
145 // Fills |tab_node_ids| with the tab node ids (see GetTab) for all the tabs* | 136 // Fills |tab_node_ids| with the tab node ids (see GetTab) for all the tabs* |
146 // associated with the session having tag |session_tag|. | 137 // associated with the session having tag |session_tag|. |
147 void LookupTabNodeIds(const std::string& session_tag, | 138 void LookupTabNodeIds(const std::string& session_tag, |
148 std::set<int>* tab_node_ids); | 139 std::set<int>* tab_node_ids); |
149 | 140 |
150 // Free the memory for all dynamically allocated objects and clear the | 141 // Free the memory for all dynamically allocated objects and clear the |
151 // tracking structures. | 142 // tracking structures. |
152 void Clear(); | 143 void Clear(); |
153 | 144 |
154 bool Empty() const { | 145 bool Empty() const { |
(...skipping 15 matching lines...) Expand all Loading... |
170 | 161 |
171 private: | 162 private: |
172 // Implementation for GetTab(...) above, permits invalid tab_node_id. | 163 // Implementation for GetTab(...) above, permits invalid tab_node_id. |
173 sessions::SessionTab* GetTabImpl(const std::string& session_tag, | 164 sessions::SessionTab* GetTabImpl(const std::string& session_tag, |
174 SessionID::id_type tab_id, | 165 SessionID::id_type tab_id, |
175 int tab_node_id); | 166 int tab_node_id); |
176 | 167 |
177 // The client of the sync sessions datatype. | 168 // The client of the sync sessions datatype. |
178 SyncSessionsClient* const sessions_client_; | 169 SyncSessionsClient* const sessions_client_; |
179 | 170 |
180 // The mapping of tab/window to their SessionTab/SessionWindow objects. | 171 // The mapping of tab/window ids to their SessionTab/SessionWindow objects. |
181 // The SessionTab/SessionWindow objects referred to may be owned either by the | 172 // The SessionTab/SessionWindow objects referred to may be owned either by the |
182 // session in the |synced_session_map_| or be temporarily unmapped and live in | 173 // session in the |synced_session_map_| or be temporarily unmapped and live in |
183 // the |unmapped_tabs_|/|unmapped_windows_| collections. | 174 // the |unmapped_tabs_|/|unmapped_windows_| collections. |
184 // | 175 // |
185 // Map: session tag -> (tab/window -> SessionTab*/SessionWindow*) | 176 // Map: session tag -> (tab/window id -> SessionTab*/SessionWindow*) |
186 std::map<std::string, std::map<SessionID::id_type, sessions::SessionTab*>> | 177 std::map<std::string, std::map<SessionID::id_type, sessions::SessionTab*>> |
187 synced_tab_map_; | 178 synced_tab_map_; |
188 std::map<std::string, std::map<SessionID::id_type, sessions::SessionWindow*>> | 179 std::map<std::string, std::map<SessionID::id_type, sessions::SessionWindow*>> |
189 synced_window_map_; | 180 synced_window_map_; |
190 | 181 |
191 // The collection that owns the SyncedSessions, and transitively, all of the | 182 // The collection that owns the SyncedSessions, and transitively, all of the |
192 // windows and tabs they contain. | 183 // windows and tabs they contain. |
193 // | 184 // |
194 // Map: session tag -> owned SyncedSession | 185 // Map: session tag -> owned SyncedSession |
195 std::map<std::string, std::unique_ptr<SyncedSession>> synced_session_map_; | 186 std::map<std::string, std::unique_ptr<SyncedSession>> synced_session_map_; |
(...skipping 15 matching lines...) Expand all Loading... |
211 // The tag for this machine's local session, so we can distinguish the foreign | 202 // The tag for this machine's local session, so we can distinguish the foreign |
212 // sessions. | 203 // sessions. |
213 std::string local_session_tag_; | 204 std::string local_session_tag_; |
214 | 205 |
215 DISALLOW_COPY_AND_ASSIGN(SyncedSessionTracker); | 206 DISALLOW_COPY_AND_ASSIGN(SyncedSessionTracker); |
216 }; | 207 }; |
217 | 208 |
218 } // namespace sync_sessions | 209 } // namespace sync_sessions |
219 | 210 |
220 #endif // COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_TRACKER_H_ | 211 #endif // COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_TRACKER_H_ |
OLD | NEW |