Chromium Code Reviews| OLD | NEW |
|---|---|
| 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, | |
|
sky
2014/10/23 21:51:49
The style guide says, "Composition is often more a
Mr4D (OOO till 08-26)
2014/10/27 22:26:35
|BaseSessionService| and |SessionServiceCommands|
Mr4D (OOO till 08-26)
2014/10/28 21:45:38
Will create separate patch for this.
| |
| 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 |
| 77 // This may be NULL during testing. | 71 // This may be NULL during testing. |
| 78 Profile* profile() const { return profile_; } | 72 Profile* profile() const { return profile_; } |
| 79 | 73 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 void WindowClosed(const SessionID& window_id); | 131 void WindowClosed(const SessionID& window_id); |
| 138 | 132 |
| 139 // Called when a tab is inserted. | 133 // Called when a tab is inserted. |
| 140 void TabInserted(content::WebContents* contents); | 134 void TabInserted(content::WebContents* contents); |
| 141 | 135 |
| 142 // Called when a tab is closing. | 136 // Called when a tab is closing. |
| 143 void TabClosing(content::WebContents* contents); | 137 void TabClosing(content::WebContents* contents); |
| 144 | 138 |
| 145 // Sets the type of window. In order for the contents of a window to be | 139 // 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 | 140 // tracked SetWindowType must be invoked with a type we track |
| 147 // (should_track_changes_for_browser_type returns true). | 141 // (ShouldRestoreOfWindowType returns true). |
| 148 void SetWindowType(const SessionID& window_id, | 142 void SetWindowType(const SessionID& window_id, |
| 149 Browser::Type type, | 143 Browser::Type type, |
| 150 AppType app_type); | 144 AppType app_type); |
| 151 | 145 |
| 152 // Sets the application name of the specified window. | 146 // Sets the application name of the specified window. |
| 153 void SetWindowAppName(const SessionID& window_id, | 147 void SetWindowAppName(const SessionID& window_id, |
| 154 const std::string& app_name); | 148 const std::string& app_name); |
| 155 | 149 |
| 156 // Invoked when the NavigationController has removed entries from the back of | 150 // Invoked when the NavigationController has removed entries from the back of |
| 157 // the list. |count| gives the number of entries in the navigation controller. | 151 // the list. |count| gives the number of entries in the navigation controller. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 182 int index); | 176 int index); |
| 183 | 177 |
| 184 // Sets the index of the selected tab in the specified window. | 178 // Sets the index of the selected tab in the specified window. |
| 185 void SetSelectedTabInWindow(const SessionID& window_id, int index); | 179 void SetSelectedTabInWindow(const SessionID& window_id, int index); |
| 186 | 180 |
| 187 // Sets the user agent override of the specified tab. | 181 // Sets the user agent override of the specified tab. |
| 188 void SetTabUserAgentOverride(const SessionID& window_id, | 182 void SetTabUserAgentOverride(const SessionID& window_id, |
| 189 const SessionID& tab_id, | 183 const SessionID& tab_id, |
| 190 const std::string& user_agent_override); | 184 const std::string& user_agent_override); |
| 191 | 185 |
| 192 // Callback from GetLastSession. | 186 // Sets the application extension id of the specified tab. |
| 193 // The second parameter is the id of the window that was last active. | 187 void SetTabExtensionAppID(const SessionID& window_id, |
| 194 typedef base::Callback<void(ScopedVector<SessionWindow>, SessionID::id_type)> | 188 const SessionID& tab_id, |
| 195 SessionCallback; | 189 const std::string& extension_app_id); |
| 196 | 190 |
| 197 // Fetches the contents of the last session, notifying the callback when | 191 // Fetches the contents of the last session, notifying the callback when |
| 198 // done. If the callback is supplied an empty vector of SessionWindows | 192 // done. If the callback is supplied an empty vector of SessionWindows |
| 199 // it means the session could not be restored. | 193 // it means the session could not be restored. |
| 200 base::CancelableTaskTracker::TaskId GetLastSession( | 194 base::CancelableTaskTracker::TaskId GetLastSession( |
| 201 const SessionCallback& callback, | 195 const SessionCallback& callback, |
| 202 base::CancelableTaskTracker* tracker); | 196 base::CancelableTaskTracker* tracker); |
| 203 | 197 |
| 198 // SessionServiceCommands: | |
| 199 bool ShouldRestoreWindowOfType(SessionWindow::WindowType type, | |
| 200 AppType app_type) const override; | |
| 204 // Overridden from BaseSessionService because we want some UMA reporting on | 201 // Overridden from BaseSessionService because we want some UMA reporting on |
| 205 // session update activities. | 202 // session update activities. |
| 206 void Save() override; | 203 void Save() override; |
| 207 | 204 |
| 208 private: | 205 private: |
| 209 // Allow tests to access our innards for testing purposes. | 206 // Allow tests to access our innards for testing purposes. |
| 210 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation1); | 207 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation1); |
| 211 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation2); | 208 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation2); |
| 212 FRIEND_TEST_ALL_PREFIXES(NoStartupWindowTest, DontInitSessionServiceForApps); | 209 FRIEND_TEST_ALL_PREFIXES(NoStartupWindowTest, DontInitSessionServiceForApps); |
| 213 | 210 |
| 214 typedef std::map<SessionID::id_type, std::pair<int, int> > IdToRange; | 211 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 | 212 |
| 228 void Init(); | 213 void Init(); |
| 229 | 214 |
| 230 // Returns true if we have scheduled any commands, or any scheduled commands | 215 // Returns true if we have scheduled any commands, or any scheduled commands |
| 231 // have been saved. | 216 // have been saved. |
| 232 bool processed_any_commands(); | 217 bool processed_any_commands(); |
| 233 | 218 |
| 234 // Implementation of RestoreIfNecessary. If |browser| is non-null and we need | 219 // 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. | 220 // to restore, the tabs are added to it, otherwise a new browser is created. |
| 236 bool RestoreIfNecessary(const std::vector<GURL>& urls_to_open, | 221 bool RestoreIfNecessary(const std::vector<GURL>& urls_to_open, |
| 237 Browser* browser); | 222 Browser* browser); |
| 238 | 223 |
| 239 void Observe(int type, | 224 void Observe(int type, |
| 240 const content::NotificationSource& source, | 225 const content::NotificationSource& source, |
| 241 const content::NotificationDetails& details) override; | 226 const content::NotificationDetails& details) override; |
| 242 | 227 |
| 243 // chrome::BrowserListObserver | 228 // chrome::BrowserListObserver |
| 244 void OnBrowserAdded(Browser* browser) override {} | 229 void OnBrowserAdded(Browser* browser) override {} |
| 245 void OnBrowserRemoved(Browser* browser) override {} | 230 void OnBrowserRemoved(Browser* browser) override {} |
| 246 void OnBrowserSetLastActive(Browser* browser) override; | 231 void OnBrowserSetLastActive(Browser* browser) override; |
| 247 | 232 |
| 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. | 233 // Converts |commands| to SessionWindows and notifies the callback. |
| 289 void OnGotSessionCommands(const SessionCallback& callback, | 234 void OnGotSessionCommands(const SessionCallback& callback, |
| 290 ScopedVector<SessionCommand> commands); | 235 ScopedVector<SessionCommand> commands); |
| 291 | 236 |
| 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 | 237 // Adds commands to commands that will recreate the state of the specified |
| 354 // tab. This adds at most kMaxNavigationCountToPersist navigations (in each | 238 // tab. This adds at most kMaxNavigationCountToPersist navigations (in each |
| 355 // direction from the current navigation index). | 239 // direction from the current navigation index). |
| 356 // A pair is added to tab_to_available_range indicating the range of | 240 // A pair is added to tab_to_available_range indicating the range of |
| 357 // indices that were written. | 241 // indices that were written. |
| 358 void BuildCommandsForTab( | 242 void BuildCommandsForTab( |
| 359 const SessionID& window_id, | 243 const SessionID& window_id, |
| 360 content::WebContents* tab, | 244 content::WebContents* tab, |
| 361 int index_in_window, | 245 int index_in_window, |
| 362 bool is_pinned, | 246 bool is_pinned, |
| 363 std::vector<SessionCommand*>* commands, | 247 std::vector<SessionCommand*>* commands, |
| 364 IdToRange* tab_to_available_range); | 248 IdToRange* tab_to_available_range); |
| 365 | 249 |
| 366 // Adds commands to create the specified browser, and invokes | 250 // Adds commands to create the specified browser, and invokes |
| 367 // BuildCommandsForTab for each of the tabs in the browser. This ignores | 251 // BuildCommandsForTab for each of the tabs in the browser. This ignores |
| 368 // any tabs not in the profile we were created with. | 252 // any tabs not in the profile we were created with. |
| 369 void BuildCommandsForBrowser( | 253 void BuildCommandsForBrowser( |
| 370 Browser* browser, | 254 Browser* browser, |
| 371 std::vector<SessionCommand*>* commands, | 255 std::vector<SessionCommand*>* commands, |
| 372 IdToRange* tab_to_available_range, | 256 IdToRange* tab_to_available_range, |
| 373 std::set<SessionID::id_type>* windows_to_track); | 257 std::set<SessionID::id_type>* windows_to_track); |
| 374 | 258 |
| 375 // Iterates over all the known browsers invoking BuildCommandsForBrowser. | 259 // Iterates over all the known browsers invoking BuildCommandsForBrowser. |
| 376 // This only adds browsers that should be tracked | 260 // This only adds browsers that should be tracked (|ShouldRestoreWindowOfType| |
| 377 // (should_track_changes_for_browser_type returns true). All browsers that | 261 // 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). | 262 // (as long as it is non-null). |
| 379 void BuildCommandsFromBrowsers( | 263 void BuildCommandsFromBrowsers( |
| 380 std::vector<SessionCommand*>* commands, | 264 std::vector<SessionCommand*>* commands, |
| 381 IdToRange* tab_to_available_range, | 265 IdToRange* tab_to_available_range, |
| 382 std::set<SessionID::id_type>* windows_to_track); | 266 std::set<SessionID::id_type>* windows_to_track); |
| 383 | 267 |
| 384 // Schedules a reset. A reset means the contents of the file are recreated | 268 // Schedules a reset of the existing commands. A reset means the contents |
| 385 // from the state of the browser. | 269 // of the file are recreated from the state of the browser. |
| 386 void ScheduleReset(); | 270 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 | 271 |
| 393 // Schedules the specified command. This method takes ownership of the | 272 // Schedules the specified command. This method takes ownership of the |
| 394 // command. | 273 // command. |
| 395 void ScheduleCommand(SessionCommand* command) override; | 274 void ScheduleCommand(SessionCommand* command) override; |
| 396 | 275 |
| 397 // Converts all pending tab/window closes to commands and schedules them. | 276 // Converts all pending tab/window closes to commands and schedules them. |
| 398 void CommitPendingCloses(); | 277 void CommitPendingCloses(); |
| 399 | 278 |
| 400 // Returns true if there is only one window open with a single tab that shares | 279 // Returns true if there is only one window open with a single tab that shares |
| 401 // our profile. | 280 // our profile. |
| 402 bool IsOnlyOneTabLeft() const; | 281 bool IsOnlyOneTabLeft() const; |
| 403 | 282 |
| 404 // Returns true if there are open trackable browser windows whose ids do | 283 // 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 | 284 // match |window_id| with our profile. A trackable window is a window from |
| 406 // which |should_track_changes_for_browser_type| returns true. See | 285 // which |ShouldRestoreWindowOfType| returns true. See |
| 407 // |should_track_changes_for_browser_type| for details. | 286 // |ShouldRestoreWindowOfType| for details. |
| 408 bool HasOpenTrackableBrowsers(const SessionID& window_id) const; | 287 bool HasOpenTrackableBrowsers(const SessionID& window_id) const; |
| 409 | 288 |
| 410 // Returns true if changes to tabs in the specified window should be tracked. | 289 // Returns true if changes to tabs in the specified window should be tracked. |
| 411 bool ShouldTrackChangesToWindow(const SessionID& window_id) const; | 290 bool ShouldTrackChangesToWindow(const SessionID& window_id) const; |
| 412 | 291 |
| 413 // Returns true if we track changes to the specified browser. | 292 // Returns true if we track changes to the specified browser. |
| 414 bool ShouldTrackBrowser(Browser* browser) const; | 293 bool ShouldTrackBrowser(Browser* browser) const; |
| 415 | 294 |
| 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 | 295 // Call when certain session relevant notifications |
| 422 // (tab_closed, nav_list_pruned) occur. In addition, this is | 296 // (tab_closed, nav_list_pruned) occur. In addition, this is |
| 423 // currently called when Save() is called to compare how often the | 297 // 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. | 298 // session data is currently saved verses when we may want to save it. |
| 425 // It records the data in UMA stats. | 299 // It records the data in UMA stats. |
| 426 void RecordSessionUpdateHistogramData(int type, | 300 void RecordSessionUpdateHistogramData(int type, |
| 427 base::TimeTicks* last_updated_time); | 301 base::TimeTicks* last_updated_time); |
| 428 | 302 |
| 429 // Helper methods to record the histogram data | 303 // Helper methods to record the histogram data |
| 430 void RecordUpdatedTabClosed(base::TimeDelta delta, bool use_long_period); | 304 void RecordUpdatedTabClosed(base::TimeDelta delta, bool use_long_period); |
| 431 void RecordUpdatedNavListPruned(base::TimeDelta delta, bool use_long_period); | 305 void RecordUpdatedNavListPruned(base::TimeDelta delta, bool use_long_period); |
| 432 void RecordUpdatedNavEntryCommit(base::TimeDelta delta, bool use_long_period); | 306 void RecordUpdatedNavEntryCommit(base::TimeDelta delta, bool use_long_period); |
| 433 void RecordUpdatedSaveTime(base::TimeDelta delta, bool use_long_period); | 307 void RecordUpdatedSaveTime(base::TimeDelta delta, bool use_long_period); |
| 434 void RecordUpdatedSessionNavigationOrTab(base::TimeDelta delta, | 308 void RecordUpdatedSessionNavigationOrTab(base::TimeDelta delta, |
| 435 bool use_long_period); | 309 bool use_long_period); |
| 436 | 310 |
| 437 // Deletes session data if no windows are open for the current profile. | 311 // Deletes session data if no windows are open for the current profile. |
| 438 void MaybeDeleteSessionOnlyData(); | 312 void MaybeDeleteSessionOnlyData(); |
| 439 | 313 |
| 440 // Convert back/forward between the Browser and SessionService DB window | 314 // Convert back/forward between the Browser and SessionService DB window |
| 441 // types. | 315 // types. |
| 442 static WindowType WindowTypeForBrowserType(Browser::Type type); | 316 static SessionWindow::WindowType WindowTypeForBrowserType(Browser::Type type); |
| 443 static Browser::Type BrowserTypeForWindowType(WindowType type); | 317 static Browser::Type BrowserTypeForWindowType(SessionWindow::WindowType type); |
| 444 | 318 |
| 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 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 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 Loading... | |
| 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_ |
| OLD | NEW |