| 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 CHROME_BROWSER_SYNC_GLUE_SYNCED_SESSION_TRACKER_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_SYNCED_SESSION_TRACKER_H_ |
| 6 #define CHROME_BROWSER_SYNC_GLUE_SYNCED_SESSION_TRACKER_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_SYNCED_SESSION_TRACKER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "components/sessions/core/session_id.h" | 14 #include "components/sessions/core/session_id.h" |
| 15 #include "components/sessions/core/session_types.h" | 15 #include "components/sessions/core/session_types.h" |
| 16 #include "components/sync_driver/glue/synced_session.h" | 16 #include "components/sync_driver/glue/synced_session.h" |
| 17 #include "components/sync_driver/tab_node_pool.h" | 17 #include "components/sync_driver/tab_node_pool.h" |
| 18 | 18 |
| 19 namespace sync_sessions { |
| 20 class SyncSessionsClient; |
| 21 } |
| 22 |
| 19 namespace browser_sync { | 23 namespace browser_sync { |
| 20 | 24 |
| 21 // Class to manage synced sessions. The tracker will own all SyncedSession | 25 // Class to manage synced sessions. The tracker will own all SyncedSession |
| 22 // and SyncedSessionTab objects it creates, and deletes them appropriately on | 26 // and SyncedSessionTab objects it creates, and deletes them appropriately on |
| 23 // destruction. | 27 // destruction. |
| 24 // Note: SyncedSession objects are created for all synced sessions, including | 28 // Note: SyncedSession objects are created for all synced sessions, including |
| 25 // the local session (whose tag we maintain separately). | 29 // the local session (whose tag we maintain separately). |
| 26 class SyncedSessionTracker { | 30 class SyncedSessionTracker { |
| 27 public: | 31 public: |
| 28 SyncedSessionTracker(); | 32 explicit SyncedSessionTracker( |
| 33 sync_sessions::SyncSessionsClient* sessions_client); |
| 29 ~SyncedSessionTracker(); | 34 ~SyncedSessionTracker(); |
| 30 | 35 |
| 31 // We track and distinguish the local session from foreign sessions. | 36 // We track and distinguish the local session from foreign sessions. |
| 32 void SetLocalSessionTag(const std::string& local_session_tag); | 37 void SetLocalSessionTag(const std::string& local_session_tag); |
| 33 | 38 |
| 34 // Fill a preallocated vector with all foreign sessions we're tracking (skips | 39 // Fill a preallocated vector with all foreign sessions we're tracking (skips |
| 35 // the local session object). SyncedSession ownership remains within the | 40 // the local session object). SyncedSession ownership remains within the |
| 36 // SyncedSessionTracker. | 41 // SyncedSessionTracker. |
| 37 // Returns true if we had foreign sessions to fill it with, false otherwise. | 42 // Returns true if we had foreign sessions to fill it with, false otherwise. |
| 38 bool LookupAllForeignSessions( | 43 bool LookupAllForeignSessions( |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 221 |
| 217 // Helper methods for deleting SessionWindows and SessionTabs without owners. | 222 // Helper methods for deleting SessionWindows and SessionTabs without owners. |
| 218 bool DeleteOldSessionWindowIfNecessary(SessionWindowWrapper window_wrapper); | 223 bool DeleteOldSessionWindowIfNecessary(SessionWindowWrapper window_wrapper); |
| 219 bool DeleteOldSessionTabIfNecessary(SessionTabWrapper tab_wrapper); | 224 bool DeleteOldSessionTabIfNecessary(SessionTabWrapper tab_wrapper); |
| 220 | 225 |
| 221 // Implementation for GetTab(...) above, permits invalid tab_node_id. | 226 // Implementation for GetTab(...) above, permits invalid tab_node_id. |
| 222 sessions::SessionTab* GetTabImpl(const std::string& session_tag, | 227 sessions::SessionTab* GetTabImpl(const std::string& session_tag, |
| 223 SessionID::id_type tab_id, | 228 SessionID::id_type tab_id, |
| 224 int tab_node_id); | 229 int tab_node_id); |
| 225 | 230 |
| 231 // The client of the sync sessions datatype. |
| 232 sync_sessions::SyncSessionsClient* const sessions_client_; |
| 233 |
| 226 // Per client mapping of tab id's to their SessionTab objects. | 234 // Per client mapping of tab id's to their SessionTab objects. |
| 227 // Key: session tag. | 235 // Key: session tag. |
| 228 // Value: Tab id to SessionTabWrapper map. | 236 // Value: Tab id to SessionTabWrapper map. |
| 229 SyncedTabMap synced_tab_map_; | 237 SyncedTabMap synced_tab_map_; |
| 230 | 238 |
| 231 // Per client mapping of the window id's to their SessionWindow objects. | 239 // Per client mapping of the window id's to their SessionWindow objects. |
| 232 // Key: session_tag | 240 // Key: session_tag |
| 233 // Value: Window id to SessionWindowWrapper map. | 241 // Value: Window id to SessionWindowWrapper map. |
| 234 SyncedWindowMap synced_window_map_; | 242 SyncedWindowMap synced_window_map_; |
| 235 | 243 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 247 // The tag for this machine's local session, so we can distinguish the foreign | 255 // The tag for this machine's local session, so we can distinguish the foreign |
| 248 // sessions. | 256 // sessions. |
| 249 std::string local_session_tag_; | 257 std::string local_session_tag_; |
| 250 | 258 |
| 251 DISALLOW_COPY_AND_ASSIGN(SyncedSessionTracker); | 259 DISALLOW_COPY_AND_ASSIGN(SyncedSessionTracker); |
| 252 }; | 260 }; |
| 253 | 261 |
| 254 } // namespace browser_sync | 262 } // namespace browser_sync |
| 255 | 263 |
| 256 #endif // CHROME_BROWSER_SYNC_GLUE_SYNCED_SESSION_TRACKER_H_ | 264 #endif // CHROME_BROWSER_SYNC_GLUE_SYNCED_SESSION_TRACKER_H_ |
| OLD | NEW |