blob: b9d36ec4f0824ae5dc6ea97d0d8e699d9e098485 [file] [log] [blame]
[email protected]a636d8e52012-02-28 15:40:411// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]169627b2008-12-06 19:30:195#ifndef CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_
6#define CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_
initial.commit09911bf2008-07-26 23:55:297
8#include <map>
[email protected]23da84e152010-07-14 01:29:059#include <string>
initial.commit09911bf2008-07-26 23:55:2910
11#include "base/basictypes.h"
[email protected]f9ffb892011-11-28 18:57:3112#include "base/callback.h"
[email protected]70eb8ed92010-06-10 18:13:1213#include "base/time.h"
[email protected]982921f12009-10-27 21:43:5314#include "chrome/browser/defaults.h"
[email protected]926bfeb2009-02-14 23:19:4715#include "chrome/browser/sessions/base_session_service.h"
[email protected]169627b2008-12-06 19:30:1916#include "chrome/browser/sessions/session_id.h"
[email protected]2ad4a902010-11-17 06:05:1317#include "chrome/browser/ui/browser.h"
18#include "chrome/browser/ui/browser_list.h"
[email protected]bf219e9eb2012-10-10 15:20:3819#include "chrome/browser/ui/browser_list_observer.h"
[email protected]6c2381d2011-10-19 02:52:5320#include "content/public/browser/notification_observer.h"
21#include "content/public/browser/notification_registrar.h"
[email protected]400eaf82011-08-22 15:47:3922#include "ui/base/ui_base_types.h"
initial.commit09911bf2008-07-26 23:55:2923
initial.commit09911bf2008-07-26 23:55:2924class Profile;
initial.commit09911bf2008-07-26 23:55:2925class SessionCommand;
[email protected]c36a9e1d2012-06-05 14:31:0226class TabContents;
[email protected]169627b2008-12-06 19:30:1927struct SessionTab;
28struct SessionWindow;
[email protected]ad23a092011-12-28 07:02:0429
30namespace content {
31class NavigationEntry;
[email protected]40600152012-09-26 10:04:3132class WebContents;
[email protected]ad23a092011-12-28 07:02:0433}
initial.commit09911bf2008-07-26 23:55:2934
35// SessionService ------------------------------------------------------------
36
37// SessionService is responsible for maintaining the state of open windows
[email protected]6ea265a2008-10-30 02:58:3638// and tabs so that they can be restored at a later date. The state of the
39// currently open browsers is referred to as the current session.
initial.commit09911bf2008-07-26 23:55:2940//
[email protected]668cd422011-04-06 21:00:0141// SessionService supports restoring from the last session. The last session
42// typically corresponds to the last run of the browser, but not always. For
43// example, if the user has a tabbed browser and app window running, closes the
44// tabbed browser, then creates a new tabbed browser the current session is made
45// the last session and the current session reset. This is done to provide the
46// illusion that app windows run in separate processes. Similar behavior occurs
47// with incognito windows.
initial.commit09911bf2008-07-26 23:55:2948//
49// SessionService itself maintains a set of SessionCommands that allow
50// SessionService to rebuild the open state of the browser (as
51// SessionWindow, SessionTab and TabNavigation). The commands are periodically
52// flushed to SessionBackend and written to a file. Every so often
53// SessionService rebuilds the contents of the file from the open state
54// of the browser.
[email protected]169627b2008-12-06 19:30:1955class SessionService : public BaseSessionService,
[email protected]bf219e9eb2012-10-10 15:20:3856 public content::NotificationObserver,
57 public chrome::BrowserListObserver {
[email protected]86ef6a392012-05-11 22:03:1158 friend class SessionServiceTestHelper;
initial.commit09911bf2008-07-26 23:55:2959 public:
[email protected]a636d8e52012-02-28 15:40:4160 // Used to distinguish an application window from a normal one.
61 enum AppType {
62 TYPE_APP,
63 TYPE_NORMAL
64 };
65
initial.commit09911bf2008-07-26 23:55:2966 // Creates a SessionService for the specified profile.
67 explicit SessionService(Profile* profile);
68 // For testing.
[email protected]5a82010a2009-02-14 01:33:0269 explicit SessionService(const FilePath& save_path);
initial.commit09911bf2008-07-26 23:55:2970
[email protected]f0a58a382011-04-26 16:09:2971 virtual ~SessionService();
72
[email protected]8ddbb642011-09-01 02:52:2073 // Returns true if a new window opening should really be treated like the
74 // start of a session (with potential session restore, startup URLs, etc.).
75 // In particular, this is true if there are no tabbed browsers running
76 // currently (eg. because only background or other app pages are running).
77 bool ShouldNewWindowStartSession();
78
[email protected]c9b19942010-03-26 15:58:0879 // Invoke at a point when you think session restore might occur. For example,
80 // during startup and window creation this is invoked to see if a session
81 // needs to be restored. If a session needs to be restored it is done so
82 // asynchronously and true is returned. If false is returned the session was
83 // not restored and the caller needs to create a new window.
84 bool RestoreIfNecessary(const std::vector<GURL>& urls_to_open);
85
initial.commit09911bf2008-07-26 23:55:2986 // Resets the contents of the file from the current state of all open
87 // browsers whose profile matches our profile.
88 void ResetFromCurrentBrowsers();
89
90 // Moves the current session to the last session. This is useful when a
91 // checkpoint occurs, such as when the user launches the app and no tabbed
92 // browsers are running.
93 void MoveCurrentSessionToLastSession();
94
95 // Associates a tab with a window.
96 void SetTabWindow(const SessionID& window_id,
97 const SessionID& tab_id);
98
99 // Sets the bounds of a window.
100 void SetWindowBounds(const SessionID& window_id,
101 const gfx::Rect& bounds,
[email protected]400eaf82011-08-22 15:47:39102 ui::WindowShowState show_state);
initial.commit09911bf2008-07-26 23:55:29103
104 // Sets the visual index of the tab in its parent window.
105 void SetTabIndexInWindow(const SessionID& window_id,
106 const SessionID& tab_id,
107 int new_index);
108
[email protected]5c0e6482009-07-14 20:20:09109 // Sets the pinned state of the tab.
110 void SetPinnedState(const SessionID& window_id,
111 const SessionID& tab_id,
112 bool is_pinned);
113
[email protected]c0e3ee42010-05-26 22:11:07114 // Notification that a tab has been closed. |closed_by_user_gesture| comes
[email protected]e6ff1d52012-04-17 20:00:40115 // from |WebContents::closed_by_user_gesture|; see it for details.
initial.commit09911bf2008-07-26 23:55:29116 //
117 // Note: this is invoked from the NavigationController's destructor, which is
118 // after the actual tab has been removed.
[email protected]c0e3ee42010-05-26 22:11:07119 void TabClosed(const SessionID& window_id,
120 const SessionID& tab_id,
121 bool closed_by_user_gesture);
initial.commit09911bf2008-07-26 23:55:29122
123 // Notification the window is about to close.
124 void WindowClosing(const SessionID& window_id);
125
126 // Notification a window has finished closing.
127 void WindowClosed(const SessionID& window_id);
128
[email protected]40600152012-09-26 10:04:31129 // Called when a tab is inserted.
130 void TabInserted(content::WebContents* contents);
131
132 // Called when a tab is closing.
133 void TabClosing(content::WebContents* contents);
134
initial.commit09911bf2008-07-26 23:55:29135 // Sets the type of window. In order for the contents of a window to be
136 // tracked SetWindowType must be invoked with a type we track
137 // (should_track_changes_for_browser_type returns true).
[email protected]a636d8e52012-02-28 15:40:41138 void SetWindowType(const SessionID& window_id,
139 Browser::Type type,
140 AppType app_type);
141
142 // Sets the application name of the specified window.
143 void SetWindowAppName(const SessionID& window_id,
144 const std::string& app_name);
initial.commit09911bf2008-07-26 23:55:29145
[email protected]c12bf1a12008-09-17 16:28:49146 // Invoked when the NavigationController has removed entries from the back of
147 // the list. |count| gives the number of entries in the navigation controller.
148 void TabNavigationPathPrunedFromBack(const SessionID& window_id,
149 const SessionID& tab_id,
150 int count);
151
152 // Invoked when the NavigationController has removed entries from the front of
153 // the list. |count| gives the number of entries that were removed.
154 void TabNavigationPathPrunedFromFront(const SessionID& window_id,
155 const SessionID& tab_id,
156 int count);
initial.commit09911bf2008-07-26 23:55:29157
158 // Updates the navigation entry for the specified tab.
159 void UpdateTabNavigation(const SessionID& window_id,
160 const SessionID& tab_id,
[email protected]9dd1d582012-09-19 04:04:16161 const TabNavigation& navigation);
initial.commit09911bf2008-07-26 23:55:29162
163 // Notification that a tab has restored its entries or a closed tab is being
164 // reused.
[email protected]337a286e2012-06-09 00:01:45165 void TabRestored(TabContents* tab, bool pinned);
initial.commit09911bf2008-07-26 23:55:29166
167 // Sets the index of the selected entry in the navigation controller for the
168 // specified tab.
169 void SetSelectedNavigationIndex(const SessionID& window_id,
170 const SessionID& tab_id,
171 int index);
172
173 // Sets the index of the selected tab in the specified window.
174 void SetSelectedTabInWindow(const SessionID& window_id, int index);
175
[email protected]8d0f3312012-08-18 01:47:53176 // Sets the user agent override of the specified tab.
177 void SetTabUserAgentOverride(const SessionID& window_id,
178 const SessionID& tab_id,
179 const std::string& user_agent_override);
180
initial.commit09911bf2008-07-26 23:55:29181 // Callback from GetSavedSession of GetLastSession.
182 //
183 // The contents of the supplied vector are deleted after the callback is
184 // notified. To take ownership of the vector clear it before returning.
185 //
[email protected]bf219e9eb2012-10-10 15:20:38186 // The session ID is the id of the window that was last active.
187 typedef base::Callback<void(Handle,
188 std::vector<SessionWindow*>*,
189 SessionID::id_type)> SessionCallback;
initial.commit09911bf2008-07-26 23:55:29190
191 // Fetches the contents of the last session, notifying the callback when
192 // done. If the callback is supplied an empty vector of SessionWindows
193 // it means the session could not be restored.
[email protected]169627b2008-12-06 19:30:19194 //
195 // The created request does NOT directly invoke the callback, rather the
196 // callback invokes OnGotSessionCommands from which we map the
197 // SessionCommands to browser state, then notify the callback.
initial.commit09911bf2008-07-26 23:55:29198 Handle GetLastSession(CancelableRequestConsumerBase* consumer,
[email protected]f9ffb892011-11-28 18:57:31199 const SessionCallback& callback);
[email protected]3acb70ef2010-03-01 18:44:38200
[email protected]70eb8ed92010-06-10 18:13:12201 // Overridden from BaseSessionService because we want some UMA reporting on
202 // session update activities.
[email protected]49fd7e22011-11-21 16:52:21203 virtual void Save() OVERRIDE;
[email protected]70eb8ed92010-06-10 18:13:12204
initial.commit09911bf2008-07-26 23:55:29205 private:
[email protected]bf219e9eb2012-10-10 15:20:38206 // Allow tests to access our innards for testing purposes.
207 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation1);
208 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation2);
209
[email protected]23da84e152010-07-14 01:29:05210 typedef std::map<SessionID::id_type, std::pair<int, int> > IdToRange;
211 typedef std::map<SessionID::id_type, SessionTab*> IdToSessionTab;
212 typedef std::map<SessionID::id_type, SessionWindow*> IdToSessionWindow;
213
initial.commit09911bf2008-07-26 23:55:29214
[email protected]97d2c1e2009-11-05 03:55:05215 // These types mirror Browser::Type, but are re-defined here because these
216 // specific enumeration _values_ are written into the session database and
217 // are needed to maintain forward compatibility.
[email protected]b35b26b32011-05-05 20:35:14218 // Note that we only store browsers of type TYPE_TABBED and TYPE_POPUP.
[email protected]97d2c1e2009-11-05 03:55:05219 enum WindowType {
[email protected]b35b26b32011-05-05 20:35:14220 TYPE_TABBED = 0,
221 TYPE_POPUP = 1
[email protected]97d2c1e2009-11-05 03:55:05222 };
223
[email protected]169627b2008-12-06 19:30:19224 void Init();
initial.commit09911bf2008-07-26 23:55:29225
[email protected]c9b19942010-03-26 15:58:08226 // Implementation of RestoreIfNecessary. If |browser| is non-null and we need
227 // to restore, the tabs are added to it, otherwise a new browser is created.
228 bool RestoreIfNecessary(const std::vector<GURL>& urls_to_open,
229 Browser* browser);
230
[email protected]432115822011-07-10 15:52:27231 virtual void Observe(int type,
[email protected]6c2381d2011-10-19 02:52:53232 const content::NotificationSource& source,
[email protected]49fd7e22011-11-21 16:52:21233 const content::NotificationDetails& details) OVERRIDE;
[email protected]534e54b2008-08-13 15:40:09234
[email protected]bf219e9eb2012-10-10 15:20:38235 // chrome::BrowserListObserver
236 virtual void OnBrowserAdded(Browser* browser) OVERRIDE {}
237 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE {}
238 virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE;
239
[email protected]fca656c2010-02-10 20:30:10240 // Sets the application extension id of the specified tab.
[email protected]98aa0b52010-05-06 17:03:08241 void SetTabExtensionAppID(const SessionID& window_id,
[email protected]fca656c2010-02-10 20:30:10242 const SessionID& tab_id,
[email protected]98aa0b52010-05-06 17:03:08243 const std::string& extension_app_id);
[email protected]fca656c2010-02-10 20:30:10244
initial.commit09911bf2008-07-26 23:55:29245 // Methods to create the various commands. It is up to the caller to delete
246 // the returned the SessionCommand* object.
247 SessionCommand* CreateSetSelectedTabInWindow(const SessionID& window_id,
248 int index);
249
250 SessionCommand* CreateSetTabWindowCommand(const SessionID& window_id,
251 const SessionID& tab_id);
252
253 SessionCommand* CreateSetWindowBoundsCommand(const SessionID& window_id,
254 const gfx::Rect& bounds,
[email protected]400eaf82011-08-22 15:47:39255 ui::WindowShowState show_state);
initial.commit09911bf2008-07-26 23:55:29256
257 SessionCommand* CreateSetTabIndexInWindowCommand(const SessionID& tab_id,
258 int new_index);
259
260 SessionCommand* CreateTabClosedCommand(SessionID::id_type tab_id);
261
262 SessionCommand* CreateWindowClosedCommand(SessionID::id_type tab_id);
263
initial.commit09911bf2008-07-26 23:55:29264 SessionCommand* CreateSetSelectedNavigationIndexCommand(
265 const SessionID& tab_id,
266 int index);
267
268 SessionCommand* CreateSetWindowTypeCommand(const SessionID& window_id,
[email protected]97d2c1e2009-11-05 03:55:05269 WindowType type);
initial.commit09911bf2008-07-26 23:55:29270
[email protected]5c0e6482009-07-14 20:20:09271 SessionCommand* CreatePinnedStateCommand(const SessionID& tab_id,
272 bool is_pinned);
273
[email protected]9cc8fd92012-06-22 21:20:55274 SessionCommand* CreateSessionStorageAssociatedCommand(
275 const SessionID& tab_id,
276 const std::string& session_storage_persistent_id);
277
[email protected]bf219e9eb2012-10-10 15:20:38278 SessionCommand* CreateSetActiveWindowCommand(const SessionID& window_id);
279
[email protected]668cd422011-04-06 21:00:01280 // Callback from the backend for getting the commands from the save file.
281 // Converts the commands in SessionWindows and notifies the real callback.
[email protected]3acb70ef2010-03-01 18:44:38282 void OnGotSessionCommands(
initial.commit09911bf2008-07-26 23:55:29283 Handle handle,
[email protected]169627b2008-12-06 19:30:19284 scoped_refptr<InternalGetCommandsRequest> request);
initial.commit09911bf2008-07-26 23:55:29285
286 // Converts the commands into SessionWindows. On return any valid
287 // windows are added to valid_windows. It is up to the caller to delete
[email protected]bf219e9eb2012-10-10 15:20:38288 // the windows added to valid_windows. |active_window_id| will be set with the
289 // id of the last active window, but it's only valid when this id corresponds
290 // to the id of one of the windows in valid_windows.
initial.commit09911bf2008-07-26 23:55:29291 void RestoreSessionFromCommands(const std::vector<SessionCommand*>& commands,
[email protected]bf219e9eb2012-10-10 15:20:38292 std::vector<SessionWindow*>* valid_windows,
293 SessionID::id_type* active_window_id);
initial.commit09911bf2008-07-26 23:55:29294
295 // Iterates through the vector updating the selected_tab_index of each
296 // SessionWindow based on the actual tabs that were restored.
297 void UpdateSelectedTabIndex(std::vector<SessionWindow*>* windows);
298
299 // Returns the window in windows with the specified id. If a window does
300 // not exist, one is created.
301 SessionWindow* GetWindow(SessionID::id_type window_id,
302 IdToSessionWindow* windows);
303
304 // Returns the tab with the specified id in tabs. If a tab does not exist,
305 // it is created.
306 SessionTab* GetTab(SessionID::id_type tab_id,
307 IdToSessionTab* tabs);
308
309 // Returns an iterator into navigations pointing to the navigation whose
310 // index matches |index|. If no navigation index matches |index|, the first
311 // navigation with an index > |index| is returned.
312 //
313 // This assumes the navigations are ordered by index in ascending order.
314 std::vector<TabNavigation>::iterator FindClosestNavigationWithIndex(
315 std::vector<TabNavigation>* navigations,
316 int index);
317
318 // Does the following:
319 // . Deletes and removes any windows with no tabs or windows with types other
320 // than tabbed_browser or browser. NOTE: constrained windows that have
321 // been dragged out are of type browser. As such, this preserves any dragged
322 // out constrained windows (aka popups that have been dragged out).
323 // . Sorts the tabs in windows with valid tabs based on the tabs
324 // visual order, and adds the valid windows to windows.
325 void SortTabsBasedOnVisualOrderAndPrune(
[email protected]23da84e152010-07-14 01:29:05326 std::map<int, SessionWindow*>* windows,
initial.commit09911bf2008-07-26 23:55:29327 std::vector<SessionWindow*>* valid_windows);
328
329 // Adds tabs to their parent window based on the tab's window_id. This
330 // ignores tabs with no navigations.
[email protected]23da84e152010-07-14 01:29:05331 void AddTabsToWindows(std::map<int, SessionTab*>* tabs,
332 std::map<int, SessionWindow*>* windows);
initial.commit09911bf2008-07-26 23:55:29333
[email protected]bf219e9eb2012-10-10 15:20:38334 // Creates tabs and windows from the commands specified in |data|. The created
335 // tabs and windows are added to |tabs| and |windows| respectively, with the
336 // id of the active window set in |active_window_id|. It is up to the caller
337 // to delete the tabs and windows added to |tabs| and |windows|.
initial.commit09911bf2008-07-26 23:55:29338 //
339 // This does NOT add any created SessionTabs to SessionWindow.tabs, that is
340 // done by AddTabsToWindows.
341 bool CreateTabsAndWindows(const std::vector<SessionCommand*>& data,
[email protected]23da84e152010-07-14 01:29:05342 std::map<int, SessionTab*>* tabs,
[email protected]bf219e9eb2012-10-10 15:20:38343 std::map<int, SessionWindow*>* windows,
344 SessionID::id_type* active_window_id);
initial.commit09911bf2008-07-26 23:55:29345
346 // Adds commands to commands that will recreate the state of the specified
[email protected]81898992011-06-14 22:15:00347 // tab. This adds at most kMaxNavigationCountToPersist navigations (in each
348 // direction from the current navigation index).
initial.commit09911bf2008-07-26 23:55:29349 // A pair is added to tab_to_available_range indicating the range of
350 // indices that were written.
351 void BuildCommandsForTab(
352 const SessionID& window_id,
[email protected]337a286e2012-06-09 00:01:45353 TabContents* tab,
initial.commit09911bf2008-07-26 23:55:29354 int index_in_window,
[email protected]5c0e6482009-07-14 20:20:09355 bool is_pinned,
initial.commit09911bf2008-07-26 23:55:29356 std::vector<SessionCommand*>* commands,
357 IdToRange* tab_to_available_range);
358
359 // Adds commands to create the specified browser, and invokes
360 // BuildCommandsForTab for each of the tabs in the browser. This ignores
361 // any tabs not in the profile we were created with.
362 void BuildCommandsForBrowser(
363 Browser* browser,
364 std::vector<SessionCommand*>* commands,
365 IdToRange* tab_to_available_range,
366 std::set<SessionID::id_type>* windows_to_track);
367
368 // Iterates over all the known browsers invoking BuildCommandsForBrowser.
369 // This only adds browsers that should be tracked
370 // (should_track_changes_for_browser_type returns true). All browsers that
371 // are tracked are added to windows_to_track (as long as it is non-null).
372 void BuildCommandsFromBrowsers(
373 std::vector<SessionCommand*>* commands,
374 IdToRange* tab_to_available_range,
375 std::set<SessionID::id_type>* windows_to_track);
376
377 // Schedules a reset. A reset means the contents of the file are recreated
378 // from the state of the browser.
379 void ScheduleReset();
380
381 // Searches for a pending command that can be replaced with command.
382 // If one is found, pending command is removed, command is added to
383 // the pending commands and true is returned.
384 bool ReplacePendingCommand(SessionCommand* command);
385
386 // Schedules the specified command. This method takes ownership of the
387 // command.
[email protected]49fd7e22011-11-21 16:52:21388 virtual void ScheduleCommand(SessionCommand* command) OVERRIDE;
initial.commit09911bf2008-07-26 23:55:29389
390 // Converts all pending tab/window closes to commands and schedules them.
391 void CommitPendingCloses();
392
initial.commit09911bf2008-07-26 23:55:29393 // Returns true if there is only one window open with a single tab that shares
394 // our profile.
[email protected]bf219e9eb2012-10-10 15:20:38395 bool IsOnlyOneTabLeft() const;
initial.commit09911bf2008-07-26 23:55:29396
[email protected]982921f12009-10-27 21:43:53397 // Returns true if there are open trackable browser windows whose ids do
398 // match |window_id| with our profile. A trackable window is a window from
399 // which |should_track_changes_for_browser_type| returns true. See
400 // |should_track_changes_for_browser_type| for details.
[email protected]bf219e9eb2012-10-10 15:20:38401 bool HasOpenTrackableBrowsers(const SessionID& window_id) const;
initial.commit09911bf2008-07-26 23:55:29402
403 // Returns true if changes to tabs in the specified window should be tracked.
[email protected]bf219e9eb2012-10-10 15:20:38404 bool ShouldTrackChangesToWindow(const SessionID& window_id) const;
405
406 // Returns true if we track changes to the specified browser.
407 bool ShouldTrackBrowser(Browser* browser) const;
initial.commit09911bf2008-07-26 23:55:29408
409 // Returns true if we track changes to the specified browser type.
[email protected]a636d8e52012-02-28 15:40:41410 static bool should_track_changes_for_browser_type(
411 Browser::Type type,
412 AppType app_type);
initial.commit09911bf2008-07-26 23:55:29413
[email protected]4070a6b2009-11-05 23:33:55414 // Returns true if we should record a window close as pending.
415 // |has_open_trackable_browsers_| must be up-to-date before calling this.
416 bool should_record_close_as_pending() const {
417 // When this is called, the browser window being closed is still open, hence
418 // still in the browser list. If there is a browser window other than the
419 // one being closed but no trackable windows, then the others must be App
420 // windows or similar. In this case, we record the close as pending.
421 return !has_open_trackable_browsers_ &&
422 (!browser_defaults::kBrowserAliveWithNoWindows ||
[email protected]c4340bc02012-04-25 02:49:38423 force_browser_not_alive_with_no_windows_ ||
[email protected]4070a6b2009-11-05 23:33:55424 BrowserList::size() > 1);
[email protected]70eb8ed92010-06-10 18:13:12425 }
426
[email protected]23da84e152010-07-14 01:29:05427 // Call when certain session relevant notifications
428 // (tab_closed, nav_list_pruned) occur. In addition, this is
429 // currently called when Save() is called to compare how often the
430 // session data is currently saved verses when we may want to save it.
431 // It records the data in UMA stats.
[email protected]432115822011-07-10 15:52:27432 void RecordSessionUpdateHistogramData(int type,
[email protected]23da84e152010-07-14 01:29:05433 base::TimeTicks* last_updated_time);
434
435 // Helper methods to record the histogram data
436 void RecordUpdatedTabClosed(base::TimeDelta delta, bool use_long_period);
437 void RecordUpdatedNavListPruned(base::TimeDelta delta, bool use_long_period);
438 void RecordUpdatedNavEntryCommit(base::TimeDelta delta, bool use_long_period);
439 void RecordUpdatedSaveTime(base::TimeDelta delta, bool use_long_period);
440 void RecordUpdatedSessionNavigationOrTab(base::TimeDelta delta,
441 bool use_long_period);
[email protected]4070a6b2009-11-05 23:33:55442
[email protected]97d2c1e2009-11-05 03:55:05443 // Convert back/forward between the Browser and SessionService DB window
444 // types.
445 static WindowType WindowTypeForBrowserType(Browser::Type type);
446 static Browser::Type BrowserTypeForWindowType(WindowType type);
447
[email protected]6c2381d2011-10-19 02:52:53448 content::NotificationRegistrar registrar_;
[email protected]6a02963e2009-01-06 16:58:03449
initial.commit09911bf2008-07-26 23:55:29450 // Maps from session tab id to the range of navigation entries that has
451 // been written to disk.
452 //
453 // This is only used if not all the navigation entries have been
454 // written.
455 IdToRange tab_to_available_range_;
456
[email protected]6ea265a2008-10-30 02:58:36457 // When the user closes the last window, where the last window is the
initial.commit09911bf2008-07-26 23:55:29458 // last tabbed browser and no more tabbed browsers are open with the same
459 // profile, the window ID is added here. These IDs are only committed (which
460 // marks them as closed) if the user creates a new tabbed browser.
461 typedef std::set<SessionID::id_type> PendingWindowCloseIDs;
462 PendingWindowCloseIDs pending_window_close_ids_;
463
464 // Set of tabs that have been closed by way of the last window or last tab
465 // closing, but not yet committed.
466 typedef std::set<SessionID::id_type> PendingTabCloseIDs;
467 PendingTabCloseIDs pending_tab_close_ids_;
468
469 // 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.
471 typedef std::set<SessionID::id_type> WindowClosingIDs;
472 WindowClosingIDs window_closing_ids_;
473
474 // Set of windows we're tracking changes to. This is only browsers that
475 // return true from should_track_changes_for_browser_type.
476 typedef std::set<SessionID::id_type> WindowsTracking;
477 WindowsTracking windows_tracking_;
478
[email protected]982921f12009-10-27 21:43:53479 // Are there any open trackable browsers?
480 bool has_open_trackable_browsers_;
initial.commit09911bf2008-07-26 23:55:29481
[email protected]6ea265a2008-10-30 02:58:36482 // If true and a new tabbed browser is created and there are no opened tabbed
[email protected]982921f12009-10-27 21:43:53483 // browser (has_open_trackable_browsers_ is false), then the current session
[email protected]668cd422011-04-06 21:00:01484 // is made the last session. See description above class for details on
485 // current/last session.
[email protected]6ea265a2008-10-30 02:58:36486 bool move_on_new_browser_;
[email protected]169627b2008-12-06 19:30:19487
[email protected]47db9a92011-01-24 20:10:13488 // Used for reporting frequency of session altering operations.
[email protected]23da84e152010-07-14 01:29:05489 base::TimeTicks last_updated_tab_closed_time_;
490 base::TimeTicks last_updated_nav_list_pruned_time_;
491 base::TimeTicks last_updated_nav_entry_commit_time_;
492 base::TimeTicks last_updated_save_time_;
493
494 // Constants used in calculating histogram data.
495 const base::TimeDelta save_delay_in_millis_;
496 const base::TimeDelta save_delay_in_mins_;
497 const base::TimeDelta save_delay_in_hrs_;
[email protected]70eb8ed92010-06-10 18:13:12498
[email protected]c4340bc02012-04-25 02:49:38499 // For browser_tests, since we want to simulate the browser shutting down
500 // without quitting.
501 bool force_browser_not_alive_with_no_windows_;
502
[email protected]169627b2008-12-06 19:30:19503 DISALLOW_COPY_AND_ASSIGN(SessionService);
initial.commit09911bf2008-07-26 23:55:29504};
505
[email protected]169627b2008-12-06 19:30:19506#endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_