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

Side by Side 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 perf tests Created 9 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <utility>
12 #include <vector> 13 #include <vector>
13 14
14 #include "base/basictypes.h" 15 #include "base/basictypes.h"
15 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
16 #include "chrome/browser/sessions/session_id.h" 17 #include "chrome/browser/sessions/session_id.h"
17 #include "chrome/browser/sessions/session_types.h" 18 #include "chrome/browser/sessions/session_types.h"
18 #include "chrome/browser/sync/glue/synced_session.h" 19 #include "chrome/browser/sync/glue/synced_session.h"
19 20
20 namespace browser_sync { 21 namespace browser_sync {
21 22
(...skipping 26 matching lines...) Expand all
48 49
49 // Attempts to look up the tab associated with the given tag and tab id. 50 // Attempts to look up the tab associated with the given tag and tab id.
50 // If lookup succeeds: 51 // If lookup succeeds:
51 // - Sets tab to point to the SessionTab, and returns true. 52 // - Sets tab to point to the SessionTab, and returns true.
52 // Else 53 // Else
53 // - Returns false, tab is set to NULL. 54 // - Returns false, tab is set to NULL.
54 bool LookupSessionTab(const std::string& session_tag, 55 bool LookupSessionTab(const std::string& session_tag,
55 SessionID::id_type tab_id, 56 SessionID::id_type tab_id,
56 const SessionTab** tab); 57 const SessionTab** tab);
57 58
58 // Returns a pointer to the SyncedSession object associated with session_tag. 59 // Returns a pointer to the SyncedSession object associated with
59 // If none exists, creates one and returns its pointer. 60 // |session_tag|. If none exists, creates one.
60 SyncedSession* GetSession(const std::string& session_tag); 61 SyncedSession* GetSession(const std::string& session_tag);
61 62
62 // Deletes the session associated with |session_tag| if it exists. 63 // Deletes the session associated with |session_tag| if it exists.
63 // Returns true if the session existed and was deleted, false otherwise. 64 // Returns true if the session existed and was deleted, false otherwise.
64 bool DeleteSession(const std::string& session_tag); 65 bool DeleteSession(const std::string& session_tag);
65 66
67 // Resets the tracking information for the session specified by |session_tag|.
68 // Once reset, all calls to GetWindow and GetTabForWindow will denote
69 // that the requested windows and tabs are in use (by setting the boolean
70 // in their SessionWindowPair/SessionTabPair to true). The next call to
71 // CleanupSession(...) will delete those windows and tabs not in use.
72 void ResetSessionTracking(const std::string& session_tag);
73
74 // Deletes those windows and tabs associated with |session_tag| that are no
75 // longer in use from memory (and removes unused windows from their
76 // SyncedSession object).
77 // See ResetSessionTracking(...).
78 void CleanupSession(const std::string& session_tag);
79
80 // Returns a pointer to the SessionWindow object associated with |window_id|
81 // for the session specified with |session_tag|. If none exists, creates one.
82 SessionWindow* GetWindow(const std::string& session_tag,
83 SessionID::id_type window_id);
84
85 // Same as GetTab, but internally notes that window |window_id| is now
86 // holding tab |tab_id|. As a result, when CleanupSession(...) is called,
87 // the tab will not be destroyed.
88 SessionTab* GetTabForWindow(const std::string& session_tag,
89 SessionID::id_type window_id,
90 SessionID::id_type tab_id);
91
66 // Returns a pointer to the SessionTab object associated with |tab_id| for 92 // Returns a pointer to the SessionTab object associated with |tab_id| for
67 // the session specified with |session_tag|. If none exists, creates one and 93 // the session specified with |session_tag|. If none exists, creates one.
68 // returns its pointer. 94 SessionTab* GetTab(const std::string& session_tag,
69 // |has_window| determines if newly created tabs are added to the pool of 95 SessionID::id_type tab_id);
70 // orphaned tabs (those which can't be reached by traversing sessions).
71 SessionTab* GetSessionTab(const std::string& session_tag,
72 SessionID::id_type tab_id,
73 bool has_window);
74 96
75 // Free the memory for all dynamically allocated objects and clear the 97 // Free the memory for all dynamically allocated objects and clear the
76 // tracking structures. 98 // tracking structures.
77 void clear(); 99 void clear();
78 100
79 inline bool empty() { 101 inline bool empty() {
80 return synced_tab_map_.empty() && synced_session_map_.empty(); 102 return synced_tab_map_.empty() && synced_session_map_.empty();
81 } 103 }
82 104
83 // Includes both foreign sessions and the local session. 105 // Includes both foreign sessions and the local session.
84 inline size_t num_synced_sessions() { 106 inline size_t num_synced_sessions() {
85 return synced_session_map_.size(); 107 return synced_session_map_.size();
86 } 108 }
87 109
88 // Returns the number of tabs associated with the specified session tag. 110 // Returns the number of tabs associated with the specified session tag.
89 inline size_t num_synced_tabs(const std::string& session_tag) { 111 inline size_t num_synced_tabs(const std::string& session_tag) {
90 if (synced_tab_map_.find(session_tag) != synced_tab_map_.end()) { 112 if (synced_tab_map_.find(session_tag) != synced_tab_map_.end()) {
91 return synced_tab_map_[session_tag]->size(); 113 return synced_tab_map_[session_tag]->size();
92 } else { 114 } else {
93 return 0; 115 return 0;
94 } 116 }
95 } 117 }
96 private: 118 private:
97 // Datatypes for accessing session data. 119 // Datatypes for accessing session data.
98 typedef std::map<SessionID::id_type, SessionTab*> IDToSessionTabMap; 120 // Note, we pair pointers with bools so that we can track what is in use and
121 // what should be deleted (see ResetSessionTracking(..) and CleanupSession(..)
122 // above).
123 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.
124 typedef std::map<SessionID::id_type, SessionTabPair> IDToSessionTabMap;
99 typedef std::map<std::string, IDToSessionTabMap*> SyncedTabMap; 125 typedef std::map<std::string, IDToSessionTabMap*> SyncedTabMap;
126
127 typedef std::pair<SessionWindow*, bool> SessionWindowPair;
akalin 2011/09/26 18:34:44 explicit struct
Nicolas Zea 2011/09/26 19:47:36 Done.
128 typedef std::map<SessionID::id_type, SessionWindowPair> IDToSessionWindowMap;
129 typedef std::map<std::string, IDToSessionWindowMap*> SyncedWindowMap;
130
100 typedef std::map<std::string, SyncedSession*> SyncedSessionMap; 131 typedef std::map<std::string, SyncedSession*> SyncedSessionMap;
101 132
133 // Helper methods for deleting SessionWindows and SessionTabs.
134 bool ClearUnusedSessionWindow(SessionWindowPair p,
135 SyncedSession* session);
136 bool ClearUnusedSessionTab(SessionTabPair p);
137
102 // Per client mapping of tab id's to their SessionTab objects. 138 // Per client mapping of tab id's to their SessionTab objects.
103 // Key: session tag. 139 // Key: session tag.
104 // Value: Tab id to SessionTab map pointer. 140 // Value: Tab id to SessionTab map pointer.
105 SyncedTabMap synced_tab_map_; 141 SyncedTabMap synced_tab_map_;
106 142
143 // Per client mapping of the window id's to their SessionWindow objects.
144 // Key: session_tag
145 // Value: Window id to SessionWindow map pointer.
146 SyncedWindowMap synced_window_map_;
147
107 // Per client mapping synced session objects. 148 // Per client mapping synced session objects.
108 // Key: session tag. 149 // Key: session tag.
109 // Value: SyncedSession object pointer. 150 // Value: SyncedSession object pointer.
110 SyncedSessionMap synced_session_map_; 151 SyncedSessionMap synced_session_map_;
111 152
112 // The set of tabs that we have seen, and created SessionTab objects for, but 153 // The set of tabs that we have seen, and created SessionTab objects for, but
113 // have not yet mapped to SyncedSessions. These are temporarily orphaned 154 // have not yet mapped to SyncedSessions. These are temporarily orphaned
114 // tabs, and won't be deleted if we delete synced_session_map_. 155 // tabs, and won't be deleted if we delete synced_session_map_.
115 std::set<SessionTab*> unmapped_tabs_; 156 std::set<SessionTab*> unmapped_tabs_;
116 157
117 // The tag for this machine's local session, so we can distinguish the foreign 158 // The tag for this machine's local session, so we can distinguish the foreign
118 // sessions. 159 // sessions.
119 std::string local_session_tag_; 160 std::string local_session_tag_;
120 161
121 DISALLOW_COPY_AND_ASSIGN(SyncedSessionTracker); 162 DISALLOW_COPY_AND_ASSIGN(SyncedSessionTracker);
122 }; 163 };
123 164
124 } // namespace browser_sync 165 } // namespace browser_sync
125 166
126 #endif // CHROME_BROWSER_SYNC_GLUE_SYNCED_SESSION_TRACKER_H_ 167 #endif // CHROME_BROWSER_SYNC_GLUE_SYNCED_SESSION_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698