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

Unified Diff: chrome/browser/sessions/session_service_commands.h

Issue 672083002: Refactoring of SessionService to get componentized. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: One more self nit 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
Index: chrome/browser/sessions/session_service_commands.h
diff --git a/chrome/browser/sessions/session_service_commands.h b/chrome/browser/sessions/session_service_commands.h
new file mode 100644
index 0000000000000000000000000000000000000000..770e11963c4ed740ee752123bb4cb8659ec9b570
--- /dev/null
+++ b/chrome/browser/sessions/session_service_commands.h
@@ -0,0 +1,187 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SESSIONS_SESSION_SERVICE_COMMANDS_H_
+#define CHROME_BROWSER_SESSIONS_SESSION_SERVICE_COMMANDS_H_
+
+#include <map>
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/memory/scoped_vector.h"
+#include "base/memory/weak_ptr.h"
+#include "base/task/cancelable_task_tracker.h"
+#include "chrome/browser/sessions/base_session_service.h"
+#include "chrome/browser/sessions/session_types.h"
+#include "ui/base/ui_base_types.h"
+
+class SessionCommand;
+class SessionServiceCommandsDelegate;
+
+// SessionServiceCommands ------------------------------------------------------
+
+// SessionServiceCommands supplies functions to create sequentialized change
+// commands which are required to reconstruct the current session state. It
+// furthermore offers a |RestoreSessionFromCommands| function which will create
+// |SessionWindow| and |SessionTab| data structures from a list of commands.
+//
+class SessionServiceCommands {
+ public:
+ // Used to distinguish an application from a ordinary content window.
+ enum AppType {
+ TYPE_APP,
+ TYPE_NORMAL
+ };
+
+ // The passed delegate remains owned by the caller.
+ explicit SessionServiceCommands(SessionServiceCommandsDelegate* delegate);
+ virtual ~SessionServiceCommands();
+
+ // Methods to create the various commands. It is up to the caller to delete
+ // the returned SessionCommand* object.
+ scoped_ptr<SessionCommand>CreateSetSelectedTabInWindowCommand(
+ const SessionID& window_id,
+ int index);
+ scoped_ptr<SessionCommand> CreateSetTabWindowCommand(
+ const SessionID& window_id,
+ const SessionID& tab_id);
+ scoped_ptr<SessionCommand>CreateSetWindowBoundsCommand(
+ const SessionID& window_id,
+ const gfx::Rect& bounds,
+ ui::WindowShowState show_state);
+ scoped_ptr<SessionCommand> CreateSetTabIndexInWindowCommand(
+ const SessionID& tab_id,
+ int new_index);
+ scoped_ptr<SessionCommand> CreateTabClosedCommand(SessionID::id_type tab_id);
+ scoped_ptr<SessionCommand> CreateWindowClosedCommand(
+ SessionID::id_type tab_id);
+ scoped_ptr<SessionCommand> CreateSetSelectedNavigationIndexCommand(
+ const SessionID& tab_id,
+ int index);
+ scoped_ptr<SessionCommand> CreateSetWindowTypeCommand(
+ const SessionID& window_id,
+ SessionWindow::WindowType type);
+ scoped_ptr<SessionCommand> CreatePinnedStateCommand(const SessionID& tab_id,
+ bool is_pinned);
+ scoped_ptr<SessionCommand> CreateSessionStorageAssociatedCommand(
+ const SessionID& tab_id,
+ const std::string& session_storage_persistent_id);
+ scoped_ptr<SessionCommand> CreateSetActiveWindowCommand(
+ const SessionID& window_id);
+ scoped_ptr<SessionCommand> CreateTabNavigationPathPrunedFromBackCommand(
+ const SessionID& tab_id,
+ int count);
+ scoped_ptr<SessionCommand> CreateTabNavigationPathPrunedFromFrontCommand(
+ const SessionID& tab_id,
+ int count);
+ scoped_ptr<SessionCommand> CreateUpdateTabNavigationCommand(
+ const SessionID& tab_id,
+ const sessions::SerializedNavigationEntry& navigation);
+ scoped_ptr<SessionCommand> CreateSetTabExtensionAppIDCommand(
+ const SessionID& tab_id,
+ const std::string& extension_id);
+ scoped_ptr<SessionCommand> CreateSetTabUserAgentOverrideCommand(
+ const SessionID& tab_id,
+ const std::string& user_agent_override);
+ scoped_ptr<SessionCommand> CreateSetWindowAppNameCommand(
+ const SessionID& window_id,
+ const std::string& app_name);
+
+ // Searches for a pending command in |pending_commands| that can be replaced
+ // with |command|. If one is found, pending command is removed, the command
+ // is added to the pending commands (taken ownership) and true is returned.
+ bool ReplacePendingCommand(
+ scoped_ptr<SessionCommand>* command,
+ ScopedVector<SessionCommand>& pending_commands);
+
+ // Returns true if provided |command| either closes a window or a tab.
+ bool IsClosingCommand(SessionCommand* command) const;
+
+ // 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 ScopedVector<SessionCommand>& commands,
+ std::vector<SessionWindow*>* valid_windows,
+ SessionID::id_type* active_window_id);
+
+ private:
+ typedef std::map<SessionID::id_type, SessionTab*> IdToSessionTab;
+ typedef std::map<SessionID::id_type, SessionWindow*> IdToSessionWindow;
+
+ // 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 ScopedVector<SessionCommand>& data,
+ std::map<int, SessionTab*>* tabs,
+ std::map<int, SessionWindow*>* windows,
+ SessionID::id_type* active_window_id);
+
+ SessionServiceCommandsDelegate* delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(SessionServiceCommands);
+};
+
+// SessionServiceCommandsDelegate ----------------------------------------------
+
+// This delegate gets passed to the SessionServiceCommands constructor. It is
+// used to determine if a window of a certain type / app has to be used for a
+// restore operation or not.
+class SessionServiceCommandsDelegate {
+ public:
+ // Returns true if a window of given |window_type| and |app_type| should get
+ // restored upon session restore.
+ virtual bool ShouldRestoreWindowOfType(
+ SessionWindow::WindowType type,
+ SessionServiceCommands::AppType app_type) const = 0;
+};
+
+#endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_COMMANDS_H_

Powered by Google App Engine
This is Rietveld 408576698