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

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

Issue 10989027: Split TabRestoreService into InMemoryTRS and PersistentTRS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Split TRS into InMemoryTRS and PersistentTRS Created 8 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/in_memory_tab_restore_service.h
diff --git a/chrome/browser/sessions/in_memory_tab_restore_service.h b/chrome/browser/sessions/in_memory_tab_restore_service.h
new file mode 100644
index 0000000000000000000000000000000000000000..ef7be44a55e54a3b8eb2e56f45554a2a0238df83
--- /dev/null
+++ b/chrome/browser/sessions/in_memory_tab_restore_service.h
@@ -0,0 +1,180 @@
+// Copyright (c) 2012 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_IN_MEMORY_TAB_RESTORE_SERVICE_H_
+#define CHROME_BROWSER_SESSIONS_IN_MEMORY_TAB_RESTORE_SERVICE_H_
+
+#include <map>
+#include <set>
+
+#include "base/gtest_prod_util.h"
+#include "base/observer_list.h"
+#include "base/time.h"
+#include "chrome/browser/profiles/profile_keyed_service.h"
+#include "chrome/browser/sessions/base_session_service.h"
+#include "chrome/browser/sessions/session_id.h"
+#include "chrome/browser/sessions/session_types.h"
+#include "chrome/browser/sessions/tab_restore_service.h"
+
+class Profile;
+class TabRestoreServiceDelegate;
+class TabRestoreServiceObserver;
+struct SessionWindow;
+
+namespace content {
+class NavigationController;
+class SessionStorageNamespace;
+class WebContents;
+}
+
+// TODO
+class InMemoryTabRestoreService : public TabRestoreService {
+ public:
+ // Creates a new TabRestoreService and provides an object that provides the
+ // current time. The TabRestoreService does not take ownership of the
+ // |time_factory_|.
+ InMemoryTabRestoreService(Profile* profile,
+ TimeFactory* time_factory_ = NULL);
+
+ virtual ~InMemoryTabRestoreService();
+
+ // TabRestoreService:
+ virtual void AddObserver(TabRestoreServiceObserver* observer) OVERRIDE;
+ virtual void RemoveObserver(TabRestoreServiceObserver* observer) OVERRIDE;
+ virtual void CreateHistoricalTab(content::WebContents* contents,
+ int index) OVERRIDE;
+ virtual void BrowserClosing(TabRestoreServiceDelegate* delegate) OVERRIDE;
+ virtual void BrowserClosed(TabRestoreServiceDelegate* delegate) OVERRIDE;
+ virtual void ClearEntries() OVERRIDE;
+ virtual const Entries& entries() const OVERRIDE;
+ virtual void RestoreMostRecentEntry(
+ TabRestoreServiceDelegate* delegate) OVERRIDE;
+ virtual Tab* RemoveTabEntryById(SessionID::id_type id) OVERRIDE;
+ virtual void RestoreEntryById(TabRestoreServiceDelegate* delegate,
+ SessionID::id_type id,
+ WindowOpenDisposition disposition) OVERRIDE;
+ virtual void LoadTabsFromLastSession() OVERRIDE;
+ virtual bool IsLoaded() const OVERRIDE;
+ virtual void DeleteLastSession() OVERRIDE;
+ virtual void Shutdown() OVERRIDE;
+
+ protected:
+ typedef std::map<SessionID::id_type, TabRestoreService::Entry*> IDToEntry;
+
+ // Max number of entries we'll keep around.
+ enum {
+ kMaxEntries = 25,
+ };
+
+ // Returns an iterator into entries_ whose id matches |id|. If |id| identifies
+ // a Window, then its iterator position will be returned. If it identifies a
+ // tab, then the iterator position of the Window in which the Tab resides is
+ // returned.
+ Entries::iterator GetEntryIteratorById(SessionID::id_type id);
+
+ // Adds |entry| to the list of entries and takes ownership. If |prune| is true
+ // |PruneAndNotify| is invoked. If |to_front| is true the entry is added to
+ // the front, otherwise the back. Normal closes go to the front, but
+ // tab/window closes from the previous session are added to the back.
+ void AddEntry(Entry* entry, bool prune, bool to_front);
+
+ // Prunes entries_ to contain only kMaxEntries, and removes uninteresting
+ // entries.
+ void PruneEntries();
+
+ // Notifies observers the tabs have changed.
+ void NotifyTabsChanged();
+
+ // Converts a SessionWindow into a Window, returning true on success. We use 0
+ // as the timestamp here since we do not know when the window/tab was closed.
+ bool ConvertSessionWindowToWindow(
+ SessionWindow* session_window,
+ Window* window);
+
+ // Calls either ValidateTab or ValidateWindow as appropriate.
+ static bool ValidateEntry(Entry* entry);
+
+ // Methods than can be overridden by subclasses to add some behavior (e.g.
+ // persistence).
+ virtual void OnClearEntries() {}
+ virtual void OnRestoreEntryById(SessionID::id_type id,
+ Entries::const_iterator entry_iterator) {}
+ virtual void OnAddEntry() {}
+
+ private:
+ friend class TabRestoreServiceTest;
+ FRIEND_TEST_ALL_PREFIXES(TabRestoreServiceTest, PruneEntries);
+ FRIEND_TEST_ALL_PREFIXES(TabRestoreServiceTest, PruneIsCalled);
+
+ // Populates the tab's navigations from the NavigationController, and its
+ // browser_id and pinned state from the browser.
+ void PopulateTab(Tab* tab,
+ int index,
+ TabRestoreServiceDelegate* delegate,
+ content::NavigationController* controller);
+
+ // This is a helper function for RestoreEntryById() for restoring a single
+ // tab. If |delegate| is NULL, this creates a new window for the entry. This
+ // returns the TabRestoreServiceDelegate into which the tab was restored.
+ // |disposition| will be respected, but if it is UNKNOWN then the tab's
+ // original attributes will be respected instead.
+ TabRestoreServiceDelegate* RestoreTab(const Tab& tab,
+ TabRestoreServiceDelegate* delegate,
+ WindowOpenDisposition disposition);
+
+ // Returns true if |tab| has more than one navigation. If |tab| has more
+ // than one navigation |tab->current_navigation_index| is constrained based
+ // on the number of navigations.
+ static bool ValidateTab(Tab* tab);
+
+ // Validates all the tabs in a window, plus the window's active tab index.
+ static bool ValidateWindow(Window* window);
+
+ // Returns true if |tab| is one we care about restoring.
+ static bool IsTabInteresting(const Tab* tab);
+
+ // Checks whether |window| is interesting --- if it only contains a single,
+ // uninteresting tab, it's not interesting.
+ static bool IsWindowInteresting(const Window* window);
+
+ // Validates and checks |entry| for interesting.
+ static bool FilterEntry(Entry* entry);
+
+ // Finds tab entries with the old browser_id and sets it to the new one.
+ void UpdateTabBrowserIDs(SessionID::id_type old_id,
+ SessionID::id_type new_id);
+
+ // Invoked when previous tabs or session is loaded. If both have finished
+ // loading the entries in staging_entries_ are added to entries_ and
+ // observers are notified.
+ void LoadStateChanged();
+
+ // Gets the current time. This uses the time_factory_ if there is one.
+ base::Time TimeNow() const;
+
+ Profile* const profile_;
+
+ // Set of entries. They are ordered from most to least recent.
+ Entries entries_;
+
+ // Are we restoring a tab? If this is true we ignore requests to create a
+ // historical tab.
+ bool restoring_;
+
+ ObserverList<TabRestoreServiceObserver> observer_list_;
+
+ // Set of delegates that we've received a BrowserClosing method for but no
+ // corresponding BrowserClosed. We cache the set of delegates closing to
+ // avoid creating historical tabs for them.
+ std::set<TabRestoreServiceDelegate*> closing_delegates_;
+
+ // Used when loading open tabs/session when recovering from a crash.
+ CancelableRequestConsumer crash_consumer_;
+
+ TimeFactory* time_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(InMemoryTabRestoreService);
+};
+
+#endif // CHROME_BROWSER_SESSIONS_IN_MEMORY_TAB_RESTORE_SERVICE_H_

Powered by Google App Engine
This is Rietveld 408576698