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

Side by Side Diff: components/sync_sessions/synced_session_tracker.h

Issue 2494533002: [Sync] Put session tracker in charge of maintaining local state. (Closed)
Patch Set: Rebase and update comment Created 4 years, 1 month 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 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
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
136 // Fills |tab_node_ids| with the tab node ids (see GetTab) for all the tabs* 145 // Fills |tab_node_ids| with the tab node ids (see GetTab) for all the tabs*
137 // associated with the session having tag |session_tag|. 146 // associated with the session having tag |session_tag|.
138 void LookupTabNodeIds(const std::string& session_tag, 147 void LookupTabNodeIds(const std::string& session_tag,
139 std::set<int>* tab_node_ids); 148 std::set<int>* tab_node_ids);
140 149
141 // Free the memory for all dynamically allocated objects and clear the 150 // Free the memory for all dynamically allocated objects and clear the
142 // tracking structures. 151 // tracking structures.
143 void Clear(); 152 void Clear();
144 153
145 bool Empty() const { 154 bool Empty() const {
(...skipping 15 matching lines...) Expand all
161 170
162 private: 171 private:
163 // Implementation for GetTab(...) above, permits invalid tab_node_id. 172 // Implementation for GetTab(...) above, permits invalid tab_node_id.
164 sessions::SessionTab* GetTabImpl(const std::string& session_tag, 173 sessions::SessionTab* GetTabImpl(const std::string& session_tag,
165 SessionID::id_type tab_id, 174 SessionID::id_type tab_id,
166 int tab_node_id); 175 int tab_node_id);
167 176
168 // The client of the sync sessions datatype. 177 // The client of the sync sessions datatype.
169 SyncSessionsClient* const sessions_client_; 178 SyncSessionsClient* const sessions_client_;
170 179
171 // The mapping of tab/window ids to their SessionTab/SessionWindow objects. 180 // The mapping of tab/window to their SessionTab/SessionWindow objects.
172 // The SessionTab/SessionWindow objects referred to may be owned either by the 181 // The SessionTab/SessionWindow objects referred to may be owned either by the
173 // session in the |synced_session_map_| or be temporarily unmapped and live in 182 // session in the |synced_session_map_| or be temporarily unmapped and live in
174 // the |unmapped_tabs_|/|unmapped_windows_| collections. 183 // the |unmapped_tabs_|/|unmapped_windows_| collections.
175 // 184 //
176 // Map: session tag -> (tab/window id -> SessionTab*/SessionWindow*) 185 // Map: session tag -> (tab/window -> SessionTab*/SessionWindow*)
177 std::map<std::string, std::map<SessionID::id_type, sessions::SessionTab*>> 186 std::map<std::string, std::map<SessionID::id_type, sessions::SessionTab*>>
178 synced_tab_map_; 187 synced_tab_map_;
179 std::map<std::string, std::map<SessionID::id_type, sessions::SessionWindow*>> 188 std::map<std::string, std::map<SessionID::id_type, sessions::SessionWindow*>>
180 synced_window_map_; 189 synced_window_map_;
181 190
182 // The collection that owns the SyncedSessions, and transitively, all of the 191 // The collection that owns the SyncedSessions, and transitively, all of the
183 // windows and tabs they contain. 192 // windows and tabs they contain.
184 // 193 //
185 // Map: session tag -> owned SyncedSession 194 // Map: session tag -> owned SyncedSession
186 std::map<std::string, std::unique_ptr<SyncedSession>> synced_session_map_; 195 std::map<std::string, std::unique_ptr<SyncedSession>> synced_session_map_;
(...skipping 15 matching lines...) Expand all
202 // The tag for this machine's local session, so we can distinguish the foreign 211 // The tag for this machine's local session, so we can distinguish the foreign
203 // sessions. 212 // sessions.
204 std::string local_session_tag_; 213 std::string local_session_tag_;
205 214
206 DISALLOW_COPY_AND_ASSIGN(SyncedSessionTracker); 215 DISALLOW_COPY_AND_ASSIGN(SyncedSessionTracker);
207 }; 216 };
208 217
209 } // namespace sync_sessions 218 } // namespace sync_sessions
210 219
211 #endif // COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_TRACKER_H_ 220 #endif // COMPONENTS_SYNC_SESSIONS_SYNCED_SESSION_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698