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

Unified Diff: chrome/browser/sync/glue/synced_session_tracker.h

Issue 7966020: [Sync] Fix Session's handling of windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix typo Created 9 years, 3 months 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 side-by-side diff with in-line comments
Download patch
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..f86e2a7117703fc5a210acd188f7b5f11f44bfcd 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 SessionWindowWrapper/SessionTabWrapper 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,49 @@ 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 can be deleted (see ResetSessionTracking(..) and CleanupSession(..)
+ // above).
+ struct SessionTabWrapper {
+ SessionTabWrapper() : tab_ptr(NULL), used(false) {}
+ SessionTabWrapper(SessionTab* tab_ptr, bool used)
+ : tab_ptr(tab_ptr),
+ used(used) {}
+ SessionTab* tab_ptr;
+ bool used;
+ };
+ typedef std::map<SessionID::id_type, SessionTabWrapper> IDToSessionTabMap;
typedef std::map<std::string, IDToSessionTabMap*> SyncedTabMap;
+
+ struct SessionWindowWrapper {
+ SessionWindowWrapper() : window_ptr(NULL), used(false) {}
+ SessionWindowWrapper(SessionWindow* window_ptr, bool used)
+ : window_ptr(window_ptr),
+ used(used) {}
+ SessionWindow* window_ptr;
+ bool used;
+ };
+ typedef std::map<SessionID::id_type, SessionWindowWrapper>
+ IDToSessionWindowMap;
+ typedef std::map<std::string, IDToSessionWindowMap*> SyncedWindowMap;
+
typedef std::map<std::string, SyncedSession*> SyncedSessionMap;
+ // Helper methods for deleting SessionWindows and SessionTabs.
+ bool ClearUnusedSessionWindow(SessionWindowWrapper window_wrapper,
+ SyncedSession* session);
+ bool ClearUnusedSessionTab(SessionTabWrapper tab_wrapper);
+
// 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.

Powered by Google App Engine
This is Rietveld 408576698