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

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: Address comments 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..4fc8f46655dd545d393e193ec414a3b3368a67ab 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>
akalin 2011/09/29 21:59:55 no need for this anymore
Nicolas Zea 2011/09/30 22:52:59 Done.
#include <vector>
#include "base/basictypes.h"
@@ -55,22 +56,43 @@ class SyncedSessionTracker {
SessionID::id_type tab_id,
const SessionTab** tab);
akalin 2011/09/29 21:59:55 make const?
Nicolas Zea 2011/09/30 22:52:59 Done.
- // 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.
akalin 2011/09/29 21:59:55 Given the changes below, is this function needed a
Nicolas Zea 2011/09/30 22:52:59 We still need to get the session itself to set som
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,
akalin 2011/09/29 21:59:55 Change this to something like: PutWindowInSession
Nicolas Zea 2011/09/30 22:52:59 Done.
+ 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,
akalin 2011/09/29 21:59:55 Similarly, change this to something like: PutTabI
Nicolas Zea 2011/09/30 22:52:59 Done.
+ 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,
akalin 2011/09/29 21:59:55 Comment that ownership of the SessionTab stays wit
Nicolas Zea 2011/09/30 22:52:59 Done.
+ SessionID::id_type tab_id);
// Free the memory for all dynamically allocated objects and clear the
// tracking structures.
@@ -88,22 +110,56 @@ class SyncedSessionTracker {
// Returns the number of tabs associated with the specified session tag.
inline size_t num_synced_tabs(const std::string& session_tag) {
akalin 2011/09/29 21:59:55 make const
Nicolas Zea 2011/09/30 22:52:59 Done.
if (synced_tab_map_.find(session_tag) != synced_tab_map_.end()) {
akalin 2011/09/29 21:59:55 probably need to store the iterator in a var and d
Nicolas Zea 2011/09/30 22:52:59 Done.
- return synced_tab_map_[session_tag]->size();
+ return synced_tab_map_[session_tag].size();
} else {
return 0;
}
}
private:
// Datatypes for accessing session data.
- typedef std::map<SessionID::id_type, SessionTab*> IDToSessionTabMap;
- typedef std::map<std::string, IDToSessionTabMap*> SyncedTabMap;
+ // 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).
akalin 2011/09/29 21:59:55 comment that SessionTabWrapper doesn't take owners
Nicolas Zea 2011/09/30 22:52:59 Done.
+ 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 {
akalin 2011/09/29 21:59:55 comment that SessionWindowWrapper doesn't take own
Nicolas Zea 2011/09/30 22:52:59 Done.
+ SessionWindowWrapper() : window_ptr(NULL), used(false) {}
akalin 2011/09/29 21:59:55 used -> owner?
Nicolas Zea 2011/09/30 22:52:59 Done.
+ 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.
+ // Value: Tab id to SessionTabWrapper map.
SyncedTabMap synced_tab_map_;
+ // Per client mapping of the window id's to their SessionWindow objects.
+ // Key: session_tag
+ // Value: Window id to SessionWindowWrapper map.
+ 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