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

Side by Side Diff: chrome/browser/sessions/session_service.h

Issue 672083002: Refactoring of SessionService to get componentized. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Switched back to #2 and addressed points Created 6 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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_SESSIONS_SESSION_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_
6 #define CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ 6 #define CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/task/cancelable_task_tracker.h" 15 #include "base/task/cancelable_task_tracker.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "chrome/browser/defaults.h" 17 #include "chrome/browser/defaults.h"
18 #include "chrome/browser/sessions/base_session_service.h" 18 #include "chrome/browser/sessions/base_session_service.h"
19 #include "chrome/browser/sessions/session_service_commands.h"
19 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_finder.h" 21 #include "chrome/browser/ui/browser_finder.h"
21 #include "chrome/browser/ui/browser_list_observer.h" 22 #include "chrome/browser/ui/browser_list_observer.h"
22 #include "components/keyed_service/core/keyed_service.h" 23 #include "components/keyed_service/core/keyed_service.h"
23 #include "components/sessions/session_id.h"
24 #include "content/public/browser/notification_observer.h" 24 #include "content/public/browser/notification_observer.h"
25 #include "content/public/browser/notification_registrar.h" 25 #include "content/public/browser/notification_registrar.h"
26 #include "ui/base/ui_base_types.h" 26 #include "ui/base/ui_base_types.h"
27 27
28 class Profile; 28 class Profile;
29 class SessionCommand; 29 class SessionCommand;
30 struct SessionTab; 30 struct SessionTab;
31 struct SessionWindow; 31 struct SessionWindow;
32 32
33 namespace content { 33 namespace content {
34 class NavigationEntry; 34 class NavigationEntry;
35 class WebContents; 35 class WebContents;
36 } 36 }
37 37
38 // SessionService ------------------------------------------------------------ 38 // SessionService ------------------------------------------------------------
39 39
40 // SessionService is responsible for maintaining the state of open windows 40 // SessionService is responsible for maintaining the state of open windows
41 // and tabs so that they can be restored at a later date. The state of the 41 // and tabs so that they can be restored at a later date. The state of the
42 // currently open browsers is referred to as the current session. 42 // currently open browsers is referred to as the current session.
43 // 43 //
44 // SessionService supports restoring from the last session. The last session 44 // SessionService supports restoring from the last session. The last session
45 // typically corresponds to the last run of the browser, but not always. For 45 // typically corresponds to the last run of the browser, but not always. For
46 // example, if the user has a tabbed browser and app window running, closes the 46 // example, if the user has a tabbed browser and app window running, closes the
47 // tabbed browser, then creates a new tabbed browser the current session is made 47 // tabbed browser, then creates a new tabbed browser the current session is made
48 // the last session and the current session reset. This is done to provide the 48 // the last session and the current session reset. This is done to provide the
49 // illusion that app windows run in separate processes. Similar behavior occurs 49 // illusion that app windows run in separate processes. Similar behavior occurs
50 // with incognito windows. 50 // with incognito windows.
51 // 51 //
52 // SessionService itself maintains a set of SessionCommands that allow 52 // SessionService itself uses |SessionServiceCommands| to store commands which
53 // SessionService to rebuild the open state of the browser (as SessionWindow, 53 // can rebuild the open state of the browser (as |SessionWindow|, |SessionTab|
54 // SessionTab and SerializedNavigationEntry). The commands are periodically 54 // and |SerializedNavigationEntry|). The commands are periodically flushed to
55 // flushed to SessionBackend and written to a file. Every so often 55 // |SessionBackend| and written to a file. Every so often |SessionService|
56 // SessionService rebuilds the contents of the file from the open state of the 56 // rebuilds the contents of the file from the open state of the browser.
57 // browser.
58 class SessionService : public BaseSessionService, 57 class SessionService : public BaseSessionService,
58 public SessionServiceCommands,
59 public KeyedService, 59 public KeyedService,
60 public content::NotificationObserver, 60 public content::NotificationObserver,
61 public chrome::BrowserListObserver { 61 public chrome::BrowserListObserver {
62 friend class SessionServiceTestHelper; 62 friend class SessionServiceTestHelper;
63 public: 63 public:
64 // Used to distinguish an application window from a normal one.
65 enum AppType {
66 TYPE_APP,
67 TYPE_NORMAL
68 };
69
70 // Creates a SessionService for the specified profile. 64 // Creates a SessionService for the specified profile.
71 explicit SessionService(Profile* profile); 65 explicit SessionService(Profile* profile);
72 // For testing. 66 // For testing.
73 explicit SessionService(const base::FilePath& save_path); 67 explicit SessionService(const base::FilePath& save_path);
74 68
75 ~SessionService() override; 69 ~SessionService() override;
76 70
71 // Convert back/forward between the Browser and SessionService DB window
72 // types.
73 static SessionWindow::WindowType WindowTypeForBrowserType(Browser::Type type);
sky 2014/10/28 22:52:38 Move these to session_types, or create a new file
Mr4D (OOO till 08-26) 2014/10/29 02:04:13 We want to break the dependency to browser - so it
74 static Browser::Type BrowserTypeForWindowType(SessionWindow::WindowType type);
75
77 // This may be NULL during testing. 76 // This may be NULL during testing.
78 Profile* profile() const { return profile_; } 77 Profile* profile() const { return profile_; }
79 78
80 // Returns true if a new window opening should really be treated like the 79 // Returns true if a new window opening should really be treated like the
81 // start of a session (with potential session restore, startup URLs, etc.). 80 // start of a session (with potential session restore, startup URLs, etc.).
82 // In particular, this is true if there are no tabbed browsers running 81 // In particular, this is true if there are no tabbed browsers running
83 // currently (eg. because only background or other app pages are running). 82 // currently (eg. because only background or other app pages are running).
84 bool ShouldNewWindowStartSession(); 83 bool ShouldNewWindowStartSession();
85 84
86 // Invoke at a point when you think session restore might occur. For example, 85 // Invoke at a point when you think session restore might occur. For example,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 void WindowClosed(const SessionID& window_id); 136 void WindowClosed(const SessionID& window_id);
138 137
139 // Called when a tab is inserted. 138 // Called when a tab is inserted.
140 void TabInserted(content::WebContents* contents); 139 void TabInserted(content::WebContents* contents);
141 140
142 // Called when a tab is closing. 141 // Called when a tab is closing.
143 void TabClosing(content::WebContents* contents); 142 void TabClosing(content::WebContents* contents);
144 143
145 // Sets the type of window. In order for the contents of a window to be 144 // Sets the type of window. In order for the contents of a window to be
146 // tracked SetWindowType must be invoked with a type we track 145 // tracked SetWindowType must be invoked with a type we track
147 // (should_track_changes_for_browser_type returns true). 146 // (ShouldRestoreOfWindowType returns true).
148 void SetWindowType(const SessionID& window_id, 147 void SetWindowType(const SessionID& window_id,
149 Browser::Type type, 148 Browser::Type type,
150 AppType app_type); 149 AppType app_type);
151 150
152 // Sets the application name of the specified window. 151 // Sets the application name of the specified window.
153 void SetWindowAppName(const SessionID& window_id, 152 void SetWindowAppName(const SessionID& window_id,
154 const std::string& app_name); 153 const std::string& app_name);
155 154
156 // Invoked when the NavigationController has removed entries from the back of 155 // Invoked when the NavigationController has removed entries from the back of
157 // the list. |count| gives the number of entries in the navigation controller. 156 // the list. |count| gives the number of entries in the navigation controller.
(...skipping 24 matching lines...) Expand all
182 int index); 181 int index);
183 182
184 // Sets the index of the selected tab in the specified window. 183 // Sets the index of the selected tab in the specified window.
185 void SetSelectedTabInWindow(const SessionID& window_id, int index); 184 void SetSelectedTabInWindow(const SessionID& window_id, int index);
186 185
187 // Sets the user agent override of the specified tab. 186 // Sets the user agent override of the specified tab.
188 void SetTabUserAgentOverride(const SessionID& window_id, 187 void SetTabUserAgentOverride(const SessionID& window_id,
189 const SessionID& tab_id, 188 const SessionID& tab_id,
190 const std::string& user_agent_override); 189 const std::string& user_agent_override);
191 190
192 // Callback from GetLastSession. 191 // Sets the application extension id of the specified tab.
193 // The second parameter is the id of the window that was last active. 192 void SetTabExtensionAppID(const SessionID& window_id,
194 typedef base::Callback<void(ScopedVector<SessionWindow>, SessionID::id_type)> 193 const SessionID& tab_id,
195 SessionCallback; 194 const std::string& extension_app_id);
196 195
197 // Fetches the contents of the last session, notifying the callback when 196 // Fetches the contents of the last session, notifying the callback when
198 // done. If the callback is supplied an empty vector of SessionWindows 197 // done. If the callback is supplied an empty vector of SessionWindows
199 // it means the session could not be restored. 198 // it means the session could not be restored.
200 base::CancelableTaskTracker::TaskId GetLastSession( 199 base::CancelableTaskTracker::TaskId GetLastSession(
201 const SessionCallback& callback, 200 const SessionCallback& callback,
202 base::CancelableTaskTracker* tracker); 201 base::CancelableTaskTracker* tracker);
203 202
203 // SessionServiceCommands:
Mr4D (OOO till 08-26) 2014/10/28 21:45:38 Note: This function is very unfortunate and will b
204 bool ShouldRestoreWindowOfType(SessionWindow::WindowType type,
205 AppType app_type) const override;
204 // Overridden from BaseSessionService because we want some UMA reporting on 206 // Overridden from BaseSessionService because we want some UMA reporting on
205 // session update activities. 207 // session update activities.
206 void Save() override; 208 void Save() override;
207 209
208 private: 210 private:
209 // Allow tests to access our innards for testing purposes. 211 // Allow tests to access our innards for testing purposes.
210 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation1); 212 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation1);
211 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation2); 213 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation2);
212 FRIEND_TEST_ALL_PREFIXES(NoStartupWindowTest, DontInitSessionServiceForApps); 214 FRIEND_TEST_ALL_PREFIXES(NoStartupWindowTest, DontInitSessionServiceForApps);
213 215
214 typedef std::map<SessionID::id_type, std::pair<int, int> > IdToRange; 216 typedef std::map<SessionID::id_type, std::pair<int, int> > IdToRange;
215 typedef std::map<SessionID::id_type, SessionTab*> IdToSessionTab;
216 typedef std::map<SessionID::id_type, SessionWindow*> IdToSessionWindow;
217
218
219 // These types mirror Browser::Type, but are re-defined here because these
220 // specific enumeration _values_ are written into the session database and
221 // are needed to maintain forward compatibility.
222 // Note that we only store browsers of type TYPE_TABBED and TYPE_POPUP.
223 enum WindowType {
224 TYPE_TABBED = 0,
225 TYPE_POPUP = 1
226 };
227 217
228 void Init(); 218 void Init();
229 219
230 // Returns true if we have scheduled any commands, or any scheduled commands 220 // Returns true if we have scheduled any commands, or any scheduled commands
231 // have been saved. 221 // have been saved.
232 bool processed_any_commands(); 222 bool processed_any_commands();
233 223
234 // Implementation of RestoreIfNecessary. If |browser| is non-null and we need 224 // Implementation of RestoreIfNecessary. If |browser| is non-null and we need
235 // to restore, the tabs are added to it, otherwise a new browser is created. 225 // to restore, the tabs are added to it, otherwise a new browser is created.
236 bool RestoreIfNecessary(const std::vector<GURL>& urls_to_open, 226 bool RestoreIfNecessary(const std::vector<GURL>& urls_to_open,
237 Browser* browser); 227 Browser* browser);
238 228
239 void Observe(int type, 229 void Observe(int type,
240 const content::NotificationSource& source, 230 const content::NotificationSource& source,
241 const content::NotificationDetails& details) override; 231 const content::NotificationDetails& details) override;
242 232
243 // chrome::BrowserListObserver 233 // chrome::BrowserListObserver
244 void OnBrowserAdded(Browser* browser) override {} 234 void OnBrowserAdded(Browser* browser) override {}
245 void OnBrowserRemoved(Browser* browser) override {} 235 void OnBrowserRemoved(Browser* browser) override {}
246 void OnBrowserSetLastActive(Browser* browser) override; 236 void OnBrowserSetLastActive(Browser* browser) override;
247 237
248 // Sets the application extension id of the specified tab.
249 void SetTabExtensionAppID(const SessionID& window_id,
250 const SessionID& tab_id,
251 const std::string& extension_app_id);
252
253 // Methods to create the various commands. It is up to the caller to delete
254 // the returned the SessionCommand* object.
255 SessionCommand* CreateSetSelectedTabInWindow(const SessionID& window_id,
256 int index);
257
258 SessionCommand* CreateSetTabWindowCommand(const SessionID& window_id,
259 const SessionID& tab_id);
260
261 SessionCommand* CreateSetWindowBoundsCommand(const SessionID& window_id,
262 const gfx::Rect& bounds,
263 ui::WindowShowState show_state);
264
265 SessionCommand* CreateSetTabIndexInWindowCommand(const SessionID& tab_id,
266 int new_index);
267
268 SessionCommand* CreateTabClosedCommand(SessionID::id_type tab_id);
269
270 SessionCommand* CreateWindowClosedCommand(SessionID::id_type tab_id);
271
272 SessionCommand* CreateSetSelectedNavigationIndexCommand(
273 const SessionID& tab_id,
274 int index);
275
276 SessionCommand* CreateSetWindowTypeCommand(const SessionID& window_id,
277 WindowType type);
278
279 SessionCommand* CreatePinnedStateCommand(const SessionID& tab_id,
280 bool is_pinned);
281
282 SessionCommand* CreateSessionStorageAssociatedCommand(
283 const SessionID& tab_id,
284 const std::string& session_storage_persistent_id);
285
286 SessionCommand* CreateSetActiveWindowCommand(const SessionID& window_id);
287
288 // Converts |commands| to SessionWindows and notifies the callback. 238 // Converts |commands| to SessionWindows and notifies the callback.
289 void OnGotSessionCommands(const SessionCallback& callback, 239 void OnGotSessionCommands(const SessionCallback& callback,
290 ScopedVector<SessionCommand> commands); 240 ScopedVector<SessionCommand> commands);
291 241
292 // Converts the commands into SessionWindows. On return any valid
293 // windows are added to valid_windows. It is up to the caller to delete
294 // the windows added to valid_windows. |active_window_id| will be set with the
295 // id of the last active window, but it's only valid when this id corresponds
296 // to the id of one of the windows in valid_windows.
297 void RestoreSessionFromCommands(const std::vector<SessionCommand*>& commands,
298 std::vector<SessionWindow*>* valid_windows,
299 SessionID::id_type* active_window_id);
300
301 // Iterates through the vector updating the selected_tab_index of each
302 // SessionWindow based on the actual tabs that were restored.
303 void UpdateSelectedTabIndex(std::vector<SessionWindow*>* windows);
304
305 // Returns the window in windows with the specified id. If a window does
306 // not exist, one is created.
307 SessionWindow* GetWindow(SessionID::id_type window_id,
308 IdToSessionWindow* windows);
309
310 // Returns the tab with the specified id in tabs. If a tab does not exist,
311 // it is created.
312 SessionTab* GetTab(SessionID::id_type tab_id,
313 IdToSessionTab* tabs);
314
315 // Returns an iterator into navigations pointing to the navigation whose
316 // index matches |index|. If no navigation index matches |index|, the first
317 // navigation with an index > |index| is returned.
318 //
319 // This assumes the navigations are ordered by index in ascending order.
320 std::vector<sessions::SerializedNavigationEntry>::iterator
321 FindClosestNavigationWithIndex(
322 std::vector<sessions::SerializedNavigationEntry>* navigations,
323 int index);
324
325 // Does the following:
326 // . Deletes and removes any windows with no tabs or windows with types other
327 // than tabbed_browser or browser. NOTE: constrained windows that have
328 // been dragged out are of type browser. As such, this preserves any dragged
329 // out constrained windows (aka popups that have been dragged out).
330 // . Sorts the tabs in windows with valid tabs based on the tabs
331 // visual order, and adds the valid windows to windows.
332 void SortTabsBasedOnVisualOrderAndPrune(
333 std::map<int, SessionWindow*>* windows,
334 std::vector<SessionWindow*>* valid_windows);
335
336 // Adds tabs to their parent window based on the tab's window_id. This
337 // ignores tabs with no navigations.
338 void AddTabsToWindows(std::map<int, SessionTab*>* tabs,
339 std::map<int, SessionWindow*>* windows);
340
341 // Creates tabs and windows from the commands specified in |data|. The created
342 // tabs and windows are added to |tabs| and |windows| respectively, with the
343 // id of the active window set in |active_window_id|. It is up to the caller
344 // to delete the tabs and windows added to |tabs| and |windows|.
345 //
346 // This does NOT add any created SessionTabs to SessionWindow.tabs, that is
347 // done by AddTabsToWindows.
348 bool CreateTabsAndWindows(const std::vector<SessionCommand*>& data,
349 std::map<int, SessionTab*>* tabs,
350 std::map<int, SessionWindow*>* windows,
351 SessionID::id_type* active_window_id);
352
353 // Adds commands to commands that will recreate the state of the specified 242 // Adds commands to commands that will recreate the state of the specified
354 // tab. This adds at most kMaxNavigationCountToPersist navigations (in each 243 // tab. This adds at most kMaxNavigationCountToPersist navigations (in each
355 // direction from the current navigation index). 244 // direction from the current navigation index).
356 // A pair is added to tab_to_available_range indicating the range of 245 // A pair is added to tab_to_available_range indicating the range of
357 // indices that were written. 246 // indices that were written.
358 void BuildCommandsForTab( 247 void BuildCommandsForTab(
359 const SessionID& window_id, 248 const SessionID& window_id,
360 content::WebContents* tab, 249 content::WebContents* tab,
361 int index_in_window, 250 int index_in_window,
362 bool is_pinned, 251 bool is_pinned,
363 std::vector<SessionCommand*>* commands, 252 std::vector<SessionCommand*>* commands,
364 IdToRange* tab_to_available_range); 253 IdToRange* tab_to_available_range);
365 254
366 // Adds commands to create the specified browser, and invokes 255 // Adds commands to create the specified browser, and invokes
367 // BuildCommandsForTab for each of the tabs in the browser. This ignores 256 // BuildCommandsForTab for each of the tabs in the browser. This ignores
368 // any tabs not in the profile we were created with. 257 // any tabs not in the profile we were created with.
369 void BuildCommandsForBrowser( 258 void BuildCommandsForBrowser(
370 Browser* browser, 259 Browser* browser,
371 std::vector<SessionCommand*>* commands, 260 std::vector<SessionCommand*>* commands,
372 IdToRange* tab_to_available_range, 261 IdToRange* tab_to_available_range,
373 std::set<SessionID::id_type>* windows_to_track); 262 std::set<SessionID::id_type>* windows_to_track);
374 263
375 // Iterates over all the known browsers invoking BuildCommandsForBrowser. 264 // Iterates over all the known browsers invoking BuildCommandsForBrowser.
376 // This only adds browsers that should be tracked 265 // This only adds browsers that should be tracked (|ShouldRestoreWindowOfType|
377 // (should_track_changes_for_browser_type returns true). All browsers that 266 // returns true). All browsers that are tracked are added to windows_to_track
378 // are tracked are added to windows_to_track (as long as it is non-null). 267 // (as long as it is non-null).
379 void BuildCommandsFromBrowsers( 268 void BuildCommandsFromBrowsers(
380 std::vector<SessionCommand*>* commands, 269 std::vector<SessionCommand*>* commands,
381 IdToRange* tab_to_available_range, 270 IdToRange* tab_to_available_range,
382 std::set<SessionID::id_type>* windows_to_track); 271 std::set<SessionID::id_type>* windows_to_track);
383 272
384 // Schedules a reset. A reset means the contents of the file are recreated 273 // Schedules a reset of the existing commands. A reset means the contents
385 // from the state of the browser. 274 // of the file are recreated from the state of the browser.
386 void ScheduleReset(); 275 void ScheduleResetCommands();
387
388 // Searches for a pending command that can be replaced with command.
389 // If one is found, pending command is removed, command is added to
390 // the pending commands and true is returned.
391 bool ReplacePendingCommand(SessionCommand* command);
392 276
393 // Schedules the specified command. This method takes ownership of the 277 // Schedules the specified command. This method takes ownership of the
394 // command. 278 // command.
395 void ScheduleCommand(SessionCommand* command) override; 279 void ScheduleCommand(SessionCommand* command) override;
396 280
397 // Converts all pending tab/window closes to commands and schedules them. 281 // Converts all pending tab/window closes to commands and schedules them.
398 void CommitPendingCloses(); 282 void CommitPendingCloses();
399 283
400 // Returns true if there is only one window open with a single tab that shares 284 // Returns true if there is only one window open with a single tab that shares
401 // our profile. 285 // our profile.
402 bool IsOnlyOneTabLeft() const; 286 bool IsOnlyOneTabLeft() const;
403 287
404 // Returns true if there are open trackable browser windows whose ids do 288 // Returns true if there are open trackable browser windows whose ids do
405 // match |window_id| with our profile. A trackable window is a window from 289 // match |window_id| with our profile. A trackable window is a window from
406 // which |should_track_changes_for_browser_type| returns true. See 290 // which |ShouldRestoreWindowOfType| returns true. See
407 // |should_track_changes_for_browser_type| for details. 291 // |ShouldRestoreWindowOfType| for details.
408 bool HasOpenTrackableBrowsers(const SessionID& window_id) const; 292 bool HasOpenTrackableBrowsers(const SessionID& window_id) const;
409 293
410 // Returns true if changes to tabs in the specified window should be tracked. 294 // Returns true if changes to tabs in the specified window should be tracked.
411 bool ShouldTrackChangesToWindow(const SessionID& window_id) const; 295 bool ShouldTrackChangesToWindow(const SessionID& window_id) const;
412 296
413 // Returns true if we track changes to the specified browser. 297 // Returns true if we track changes to the specified browser.
414 bool ShouldTrackBrowser(Browser* browser) const; 298 bool ShouldTrackBrowser(Browser* browser) const;
415 299
416 // Returns true if we track changes to the specified browser type.
417 static bool should_track_changes_for_browser_type(
418 Browser::Type type,
419 AppType app_type);
420
421 // Call when certain session relevant notifications 300 // Call when certain session relevant notifications
422 // (tab_closed, nav_list_pruned) occur. In addition, this is 301 // (tab_closed, nav_list_pruned) occur. In addition, this is
423 // currently called when Save() is called to compare how often the 302 // currently called when Save() is called to compare how often the
424 // session data is currently saved verses when we may want to save it. 303 // session data is currently saved verses when we may want to save it.
425 // It records the data in UMA stats. 304 // It records the data in UMA stats.
426 void RecordSessionUpdateHistogramData(int type, 305 void RecordSessionUpdateHistogramData(int type,
427 base::TimeTicks* last_updated_time); 306 base::TimeTicks* last_updated_time);
428 307
429 // Helper methods to record the histogram data 308 // Helper methods to record the histogram data
430 void RecordUpdatedTabClosed(base::TimeDelta delta, bool use_long_period); 309 void RecordUpdatedTabClosed(base::TimeDelta delta, bool use_long_period);
431 void RecordUpdatedNavListPruned(base::TimeDelta delta, bool use_long_period); 310 void RecordUpdatedNavListPruned(base::TimeDelta delta, bool use_long_period);
432 void RecordUpdatedNavEntryCommit(base::TimeDelta delta, bool use_long_period); 311 void RecordUpdatedNavEntryCommit(base::TimeDelta delta, bool use_long_period);
433 void RecordUpdatedSaveTime(base::TimeDelta delta, bool use_long_period); 312 void RecordUpdatedSaveTime(base::TimeDelta delta, bool use_long_period);
434 void RecordUpdatedSessionNavigationOrTab(base::TimeDelta delta, 313 void RecordUpdatedSessionNavigationOrTab(base::TimeDelta delta,
435 bool use_long_period); 314 bool use_long_period);
436 315
437 // Deletes session data if no windows are open for the current profile. 316 // Deletes session data if no windows are open for the current profile.
438 void MaybeDeleteSessionOnlyData(); 317 void MaybeDeleteSessionOnlyData();
439 318
440 // Convert back/forward between the Browser and SessionService DB window
441 // types.
442 static WindowType WindowTypeForBrowserType(Browser::Type type);
443 static Browser::Type BrowserTypeForWindowType(WindowType type);
444
445 // The profile. This may be null during testing. 319 // The profile. This may be null during testing.
446 Profile* profile_; 320 Profile* profile_;
447 321
448 content::NotificationRegistrar registrar_; 322 content::NotificationRegistrar registrar_;
449 323
450 // Maps from session tab id to the range of navigation entries that has 324 // Maps from session tab id to the range of navigation entries that has
451 // been written to disk. 325 // been written to disk.
452 // 326 //
453 // This is only used if not all the navigation entries have been 327 // This is only used if not all the navigation entries have been
454 // written. 328 // written.
(...skipping 10 matching lines...) Expand all
465 // closing, but not yet committed. 339 // closing, but not yet committed.
466 typedef std::set<SessionID::id_type> PendingTabCloseIDs; 340 typedef std::set<SessionID::id_type> PendingTabCloseIDs;
467 PendingTabCloseIDs pending_tab_close_ids_; 341 PendingTabCloseIDs pending_tab_close_ids_;
468 342
469 // When a window other than the last window (see description of 343 // When a window other than the last window (see description of
470 // pending_window_close_ids) is closed, the id is added to this set. 344 // pending_window_close_ids) is closed, the id is added to this set.
471 typedef std::set<SessionID::id_type> WindowClosingIDs; 345 typedef std::set<SessionID::id_type> WindowClosingIDs;
472 WindowClosingIDs window_closing_ids_; 346 WindowClosingIDs window_closing_ids_;
473 347
474 // Set of windows we're tracking changes to. This is only browsers that 348 // Set of windows we're tracking changes to. This is only browsers that
475 // return true from should_track_changes_for_browser_type. 349 // return true from |ShouldRestoreWindowOfType|.
476 typedef std::set<SessionID::id_type> WindowsTracking; 350 typedef std::set<SessionID::id_type> WindowsTracking;
477 WindowsTracking windows_tracking_; 351 WindowsTracking windows_tracking_;
478 352
479 // Are there any open trackable browsers? 353 // Are there any open trackable browsers?
480 bool has_open_trackable_browsers_; 354 bool has_open_trackable_browsers_;
481 355
482 // If true and a new tabbed browser is created and there are no opened tabbed 356 // If true and a new tabbed browser is created and there are no opened tabbed
483 // browser (has_open_trackable_browsers_ is false), then the current session 357 // browser (has_open_trackable_browsers_ is false), then the current session
484 // is made the last session. See description above class for details on 358 // is made the last session. See description above class for details on
485 // current/last session. 359 // current/last session.
(...skipping 13 matching lines...) Expand all
499 // For browser_tests, since we want to simulate the browser shutting down 373 // For browser_tests, since we want to simulate the browser shutting down
500 // without quitting. 374 // without quitting.
501 bool force_browser_not_alive_with_no_windows_; 375 bool force_browser_not_alive_with_no_windows_;
502 376
503 base::WeakPtrFactory<SessionService> weak_factory_; 377 base::WeakPtrFactory<SessionService> weak_factory_;
504 378
505 DISALLOW_COPY_AND_ASSIGN(SessionService); 379 DISALLOW_COPY_AND_ASSIGN(SessionService);
506 }; 380 };
507 381
508 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ 382 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698