Chromium Code Reviews| Index: chrome/browser/sync/glue/synced_session_tracker.h |
| diff --git a/chrome/browser/sync/glue/synced_session_tracker.h b/chrome/browser/sync/glue/synced_session_tracker.h |
| index 5140f9000f6a48516346bc57341ce6a175dc2903..b1dbc35501952ad6c040a3e382c062e7a3b0152c 100644 |
| --- a/chrome/browser/sync/glue/synced_session_tracker.h |
| +++ b/chrome/browser/sync/glue/synced_session_tracker.h |
| @@ -9,6 +9,7 @@ |
| #include <map> |
| #include <set> |
| #include <string> |
| +#include <utility> |
| #include <vector> |
| #include "base/basictypes.h" |
| @@ -55,22 +56,43 @@ class SyncedSessionTracker { |
| SessionID::id_type tab_id, |
| const SessionTab** tab); |
| - // Returns a pointer to the SyncedSession object associated with session_tag. |
| - // If none exists, creates one and returns its pointer. |
| + // Returns a pointer to the SyncedSession object associated with |
| + // |session_tag|. If none exists, creates one. |
| SyncedSession* GetSession(const std::string& session_tag); |
| // Deletes the session associated with |session_tag| if it exists. |
| // Returns true if the session existed and was deleted, false otherwise. |
| bool DeleteSession(const std::string& session_tag); |
| + // Resets the tracking information for the session specified by |session_tag|. |
| + // Once reset, all calls to GetWindow and GetTabForWindow will denote |
| + // that the requested windows and tabs are in use (by setting the boolean |
| + // in their SessionWindowPair/SessionTabPair to true). The next call to |
| + // CleanupSession(...) will delete those windows and tabs not in use. |
| + void ResetSessionTracking(const std::string& session_tag); |
| + |
| + // Deletes those windows and tabs associated with |session_tag| that are no |
| + // longer in use from memory (and removes unused windows from their |
| + // SyncedSession object). |
| + // See ResetSessionTracking(...). |
| + void CleanupSession(const std::string& session_tag); |
| + |
| + // Returns a pointer to the SessionWindow object associated with |window_id| |
| + // for the session specified with |session_tag|. If none exists, creates one. |
| + SessionWindow* GetWindow(const std::string& session_tag, |
| + SessionID::id_type window_id); |
| + |
| + // Same as GetTab, but internally notes that window |window_id| is now |
| + // holding tab |tab_id|. As a result, when CleanupSession(...) is called, |
| + // the tab will not be destroyed. |
| + SessionTab* GetTabForWindow(const std::string& session_tag, |
| + SessionID::id_type window_id, |
| + SessionID::id_type tab_id); |
| + |
| // Returns a pointer to the SessionTab object associated with |tab_id| for |
| - // the session specified with |session_tag|. If none exists, creates one and |
| - // returns its pointer. |
| - // |has_window| determines if newly created tabs are added to the pool of |
| - // orphaned tabs (those which can't be reached by traversing sessions). |
| - SessionTab* GetSessionTab(const std::string& session_tag, |
| - SessionID::id_type tab_id, |
| - bool has_window); |
| + // the session specified with |session_tag|. If none exists, creates one. |
| + SessionTab* GetTab(const std::string& session_tag, |
| + SessionID::id_type tab_id); |
| // Free the memory for all dynamically allocated objects and clear the |
| // tracking structures. |
| @@ -95,15 +117,34 @@ class SyncedSessionTracker { |
| } |
| private: |
| // Datatypes for accessing session data. |
| - typedef std::map<SessionID::id_type, SessionTab*> IDToSessionTabMap; |
| + // Note, we pair pointers with bools so that we can track what is in use and |
| + // what should be deleted (see ResetSessionTracking(..) and CleanupSession(..) |
| + // above). |
| + typedef std::pair<SessionTab*, bool> SessionTabPair; |
|
akalin
2011/09/26 18:34:44
prefer an explicit struct, otherwise it gets confu
Nicolas Zea
2011/09/26 19:47:36
Done.
|
| + typedef std::map<SessionID::id_type, SessionTabPair> IDToSessionTabMap; |
| typedef std::map<std::string, IDToSessionTabMap*> SyncedTabMap; |
| + |
| + typedef std::pair<SessionWindow*, bool> SessionWindowPair; |
|
akalin
2011/09/26 18:34:44
explicit struct
Nicolas Zea
2011/09/26 19:47:36
Done.
|
| + typedef std::map<SessionID::id_type, SessionWindowPair> IDToSessionWindowMap; |
| + typedef std::map<std::string, IDToSessionWindowMap*> SyncedWindowMap; |
| + |
| typedef std::map<std::string, SyncedSession*> SyncedSessionMap; |
| + // Helper methods for deleting SessionWindows and SessionTabs. |
| + bool ClearUnusedSessionWindow(SessionWindowPair p, |
| + SyncedSession* session); |
| + bool ClearUnusedSessionTab(SessionTabPair p); |
| + |
| // Per client mapping of tab id's to their SessionTab objects. |
| // Key: session tag. |
| // Value: Tab id to SessionTab map pointer. |
| SyncedTabMap synced_tab_map_; |
| + // Per client mapping of the window id's to their SessionWindow objects. |
| + // Key: session_tag |
| + // Value: Window id to SessionWindow map pointer. |
| + SyncedWindowMap synced_window_map_; |
| + |
| // Per client mapping synced session objects. |
| // Key: session tag. |
| // Value: SyncedSession object pointer. |