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

Unified 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: Fixing windows compile problem Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/sessions/session_restore.cc ('k') | chrome/browser/sessions/session_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sessions/session_service.h
diff --git a/chrome/browser/sessions/session_service.h b/chrome/browser/sessions/session_service.h
index d602669ea8aebd5c943ae437b61d310b5b0b600b..1398b4bc1b097787c4e6e50c2a2aec62041b17a7 100644
--- a/chrome/browser/sessions/session_service.h
+++ b/chrome/browser/sessions/session_service.h
@@ -16,11 +16,12 @@
#include "base/time/time.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/sessions/base_session_service.h"
+#include "chrome/browser/sessions/session_service_commands.h"
+#include "chrome/browser/sessions/session_service_utils.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list_observer.h"
#include "components/keyed_service/core/keyed_service.h"
-#include "components/sessions/session_id.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "ui/base/ui_base_types.h"
@@ -49,11 +50,11 @@ class WebContents;
// illusion that app windows run in separate processes. Similar behavior occurs
// with incognito windows.
//
-// SessionService itself maintains a set of SessionCommands that allow
-// SessionService to rebuild the open state of the browser (as SessionWindow,
-// SessionTab and SerializedNavigationEntry). The commands are periodically
-// flushed to SessionBackend and written to a file. Every so often
-// SessionService rebuilds the contents of the file from the open state of the
+// SessionService itself uses functions from session_service_commands to store
+// commands which can rebuild the open state of the browser (as |SessionWindow|,
+// |SessionTab| and |SerializedNavigationEntry|). The commands are periodically
+// flushed to |SessionBackend| and written to a file. Every so often
+// |SessionService| rebuilds the contents of the file from the open state of the
// browser.
class SessionService : public BaseSessionService,
public KeyedService,
@@ -61,7 +62,7 @@ class SessionService : public BaseSessionService,
public chrome::BrowserListObserver {
friend class SessionServiceTestHelper;
public:
- // Used to distinguish an application window from a normal one.
+ // Used to distinguish an application from a ordinary content window.
enum AppType {
TYPE_APP,
TYPE_NORMAL
@@ -144,7 +145,7 @@ class SessionService : public BaseSessionService,
// Sets the type of window. In order for the contents of a window to be
// tracked SetWindowType must be invoked with a type we track
- // (should_track_changes_for_browser_type returns true).
+ // (ShouldRestoreOfWindowType returns true).
void SetWindowType(const SessionID& window_id,
Browser::Type type,
AppType app_type);
@@ -189,6 +190,11 @@ class SessionService : public BaseSessionService,
const SessionID& tab_id,
const std::string& user_agent_override);
+ // Sets the application extension id of the specified tab.
+ void SetTabExtensionAppID(const SessionID& window_id,
+ const SessionID& tab_id,
+ const std::string& extension_app_id);
+
// Callback from GetLastSession.
// The second parameter is the id of the window that was last active.
typedef base::Callback<void(ScopedVector<SessionWindow>, SessionID::id_type)>
@@ -212,20 +218,16 @@ class SessionService : public BaseSessionService,
FRIEND_TEST_ALL_PREFIXES(NoStartupWindowTest, DontInitSessionServiceForApps);
typedef std::map<SessionID::id_type, std::pair<int, int> > IdToRange;
- typedef std::map<SessionID::id_type, SessionTab*> IdToSessionTab;
- typedef std::map<SessionID::id_type, SessionWindow*> IdToSessionWindow;
+ void Init();
- // These types mirror Browser::Type, but are re-defined here because these
- // specific enumeration _values_ are written into the session database and
- // are needed to maintain forward compatibility.
- // Note that we only store browsers of type TYPE_TABBED and TYPE_POPUP.
- enum WindowType {
- TYPE_TABBED = 0,
- TYPE_POPUP = 1
- };
+ // Returns true if a window of given |window_type| and |app_type| should get
+ // restored upon session restore.
+ bool ShouldRestoreWindowOfType(SessionWindow::WindowType type,
+ AppType app_type) const;
- void Init();
+ // Removes unrestorable windows from the previous windows list.
+ void RemoveUnusedRestoreWindows(std::vector<SessionWindow*>* window_list);
// Returns true if we have scheduled any commands, or any scheduled commands
// have been saved.
@@ -245,111 +247,10 @@ class SessionService : public BaseSessionService,
void OnBrowserRemoved(Browser* browser) override {}
void OnBrowserSetLastActive(Browser* browser) override;
- // Sets the application extension id of the specified tab.
- void SetTabExtensionAppID(const SessionID& window_id,
- const SessionID& tab_id,
- const std::string& extension_app_id);
-
- // Methods to create the various commands. It is up to the caller to delete
- // the returned the SessionCommand* object.
- SessionCommand* CreateSetSelectedTabInWindow(const SessionID& window_id,
- int index);
-
- SessionCommand* CreateSetTabWindowCommand(const SessionID& window_id,
- const SessionID& tab_id);
-
- SessionCommand* CreateSetWindowBoundsCommand(const SessionID& window_id,
- const gfx::Rect& bounds,
- ui::WindowShowState show_state);
-
- SessionCommand* CreateSetTabIndexInWindowCommand(const SessionID& tab_id,
- int new_index);
-
- SessionCommand* CreateTabClosedCommand(SessionID::id_type tab_id);
-
- SessionCommand* CreateWindowClosedCommand(SessionID::id_type tab_id);
-
- SessionCommand* CreateSetSelectedNavigationIndexCommand(
- const SessionID& tab_id,
- int index);
-
- SessionCommand* CreateSetWindowTypeCommand(const SessionID& window_id,
- WindowType type);
-
- SessionCommand* CreatePinnedStateCommand(const SessionID& tab_id,
- bool is_pinned);
-
- SessionCommand* CreateSessionStorageAssociatedCommand(
- const SessionID& tab_id,
- const std::string& session_storage_persistent_id);
-
- SessionCommand* CreateSetActiveWindowCommand(const SessionID& window_id);
-
// Converts |commands| to SessionWindows and notifies the callback.
void OnGotSessionCommands(const SessionCallback& callback,
ScopedVector<SessionCommand> commands);
- // Converts the commands into SessionWindows. On return any valid
- // windows are added to valid_windows. It is up to the caller to delete
- // the windows added to valid_windows. |active_window_id| will be set with the
- // id of the last active window, but it's only valid when this id corresponds
- // to the id of one of the windows in valid_windows.
- void RestoreSessionFromCommands(const std::vector<SessionCommand*>& commands,
- std::vector<SessionWindow*>* valid_windows,
- SessionID::id_type* active_window_id);
-
- // Iterates through the vector updating the selected_tab_index of each
- // SessionWindow based on the actual tabs that were restored.
- void UpdateSelectedTabIndex(std::vector<SessionWindow*>* windows);
-
- // Returns the window in windows with the specified id. If a window does
- // not exist, one is created.
- SessionWindow* GetWindow(SessionID::id_type window_id,
- IdToSessionWindow* windows);
-
- // Returns the tab with the specified id in tabs. If a tab does not exist,
- // it is created.
- SessionTab* GetTab(SessionID::id_type tab_id,
- IdToSessionTab* tabs);
-
- // Returns an iterator into navigations pointing to the navigation whose
- // index matches |index|. If no navigation index matches |index|, the first
- // navigation with an index > |index| is returned.
- //
- // This assumes the navigations are ordered by index in ascending order.
- std::vector<sessions::SerializedNavigationEntry>::iterator
- FindClosestNavigationWithIndex(
- std::vector<sessions::SerializedNavigationEntry>* navigations,
- int index);
-
- // Does the following:
- // . Deletes and removes any windows with no tabs or windows with types other
- // than tabbed_browser or browser. NOTE: constrained windows that have
- // been dragged out are of type browser. As such, this preserves any dragged
- // out constrained windows (aka popups that have been dragged out).
- // . Sorts the tabs in windows with valid tabs based on the tabs
- // visual order, and adds the valid windows to windows.
- void SortTabsBasedOnVisualOrderAndPrune(
- std::map<int, SessionWindow*>* windows,
- std::vector<SessionWindow*>* valid_windows);
-
- // Adds tabs to their parent window based on the tab's window_id. This
- // ignores tabs with no navigations.
- void AddTabsToWindows(std::map<int, SessionTab*>* tabs,
- std::map<int, SessionWindow*>* windows);
-
- // Creates tabs and windows from the commands specified in |data|. The created
- // tabs and windows are added to |tabs| and |windows| respectively, with the
- // id of the active window set in |active_window_id|. It is up to the caller
- // to delete the tabs and windows added to |tabs| and |windows|.
- //
- // This does NOT add any created SessionTabs to SessionWindow.tabs, that is
- // done by AddTabsToWindows.
- bool CreateTabsAndWindows(const std::vector<SessionCommand*>& data,
- std::map<int, SessionTab*>* tabs,
- std::map<int, SessionWindow*>* windows,
- SessionID::id_type* active_window_id);
-
// Adds commands to commands that will recreate the state of the specified
// tab. This adds at most kMaxNavigationCountToPersist navigations (in each
// direction from the current navigation index).
@@ -373,22 +274,17 @@ class SessionService : public BaseSessionService,
std::set<SessionID::id_type>* windows_to_track);
// Iterates over all the known browsers invoking BuildCommandsForBrowser.
- // This only adds browsers that should be tracked
- // (should_track_changes_for_browser_type returns true). All browsers that
- // are tracked are added to windows_to_track (as long as it is non-null).
+ // This only adds browsers that should be tracked (|ShouldRestoreWindowOfType|
+ // returns true). All browsers that are tracked are added to windows_to_track
+ // (as long as it is non-null).
void BuildCommandsFromBrowsers(
std::vector<SessionCommand*>* commands,
IdToRange* tab_to_available_range,
std::set<SessionID::id_type>* windows_to_track);
- // Schedules a reset. A reset means the contents of the file are recreated
- // from the state of the browser.
- void ScheduleReset();
-
- // Searches for a pending command that can be replaced with command.
- // If one is found, pending command is removed, command is added to
- // the pending commands and true is returned.
- bool ReplacePendingCommand(SessionCommand* command);
+ // Schedules a reset of the existing commands. A reset means the contents
+ // of the file are recreated from the state of the browser.
+ void ScheduleResetCommands();
// Schedules the specified command. This method takes ownership of the
// command.
@@ -403,8 +299,8 @@ class SessionService : public BaseSessionService,
// Returns true if there are open trackable browser windows whose ids do
// match |window_id| with our profile. A trackable window is a window from
- // which |should_track_changes_for_browser_type| returns true. See
- // |should_track_changes_for_browser_type| for details.
+ // which |ShouldRestoreWindowOfType| returns true. See
+ // |ShouldRestoreWindowOfType| for details.
bool HasOpenTrackableBrowsers(const SessionID& window_id) const;
// Returns true if changes to tabs in the specified window should be tracked.
@@ -413,11 +309,6 @@ class SessionService : public BaseSessionService,
// Returns true if we track changes to the specified browser.
bool ShouldTrackBrowser(Browser* browser) const;
- // Returns true if we track changes to the specified browser type.
- static bool should_track_changes_for_browser_type(
- Browser::Type type,
- AppType app_type);
-
// Call when certain session relevant notifications
// (tab_closed, nav_list_pruned) occur. In addition, this is
// currently called when Save() is called to compare how often the
@@ -437,11 +328,6 @@ class SessionService : public BaseSessionService,
// Deletes session data if no windows are open for the current profile.
void MaybeDeleteSessionOnlyData();
- // Convert back/forward between the Browser and SessionService DB window
- // types.
- static WindowType WindowTypeForBrowserType(Browser::Type type);
- static Browser::Type BrowserTypeForWindowType(WindowType type);
-
// The profile. This may be null during testing.
Profile* profile_;
@@ -472,7 +358,7 @@ class SessionService : public BaseSessionService,
WindowClosingIDs window_closing_ids_;
// Set of windows we're tracking changes to. This is only browsers that
- // return true from should_track_changes_for_browser_type.
+ // return true from |ShouldRestoreWindowOfType|.
typedef std::set<SessionID::id_type> WindowsTracking;
WindowsTracking windows_tracking_;
« no previous file with comments | « chrome/browser/sessions/session_restore.cc ('k') | chrome/browser/sessions/session_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698