summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_restore_service.h
diff options
context:
space:
mode:
authorinitial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-26 23:55:29 +0000
committerinitial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-26 23:55:29 +0000
commit09911bf300f1a419907a9412154760efd0b7abc3 (patch)
treef131325fb4e2ad12c6d3504ab75b16dd92facfed /chrome/browser/tab_restore_service.h
parent586acc5fe142f498261f52c66862fa417c3d52d2 (diff)
downloadchromium_src-09911bf300f1a419907a9412154760efd0b7abc3.zip
chromium_src-09911bf300f1a419907a9412154760efd0b7abc3.tar.gz
chromium_src-09911bf300f1a419907a9412154760efd0b7abc3.tar.bz2
Add chrome to the repository.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_restore_service.h')
-rw-r--r--chrome/browser/tab_restore_service.h170
1 files changed, 170 insertions, 0 deletions
diff --git a/chrome/browser/tab_restore_service.h b/chrome/browser/tab_restore_service.h
new file mode 100644
index 0000000..17cca7f
--- /dev/null
+++ b/chrome/browser/tab_restore_service.h
@@ -0,0 +1,170 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef CHROME_BROWSER_TAB_RESTORE_SERVICE_H__
+#define CHROME_BROWSER_TAB_RESTORE_SERVICE_H__
+
+#include <list>
+
+#include "base/observer_list.h"
+#include "base/time.h"
+#include "chrome/browser/session_service.h"
+
+class NavigationController;
+class Profile;
+
+// TabRestoreService is responsible for maintaining the most recently closed
+// tabs. When the user closes a tab TabRestoreService::CreateHistoricalTab is
+// invoked and a HistoricalTab is created to represent the tab.
+//
+// TabRestoreService can recreate tabs from the previous session as well.
+// LoadPreviousSessionTabs loads (asynchronously) the tabs from the previous
+// session. When done, the observer is notified.
+//
+// To restore a tab from the TabRestoreService invoke AddRestoredTab on the
+// Browser you want to restore the tab to, followed by RemoveHistoricalTabById
+// to remove the tab from the restore service.
+//
+// To listen for changes to the set of tabs managed by the TabRestoreService
+// add an observer.
+
+class TabRestoreService {
+ public:
+ // Observer is notified when the set of tabs managed by TabRestoreService
+ // changes in some way.
+ class Observer {
+ public:
+ // Sent when the internal tab state changed
+ virtual void TabRestoreServiceChanged(TabRestoreService* service) = 0;
+
+ // Sent to all remaining Observers when TabRestoreService's
+ // destructor is run.
+ virtual void TabRestoreServiceDestroyed(TabRestoreService* service) = 0;
+ };
+
+ // Represents a previously open tab.
+ struct HistoricalTab {
+ HistoricalTab();
+
+ // Time the tab was closed.
+ Time close_time;
+
+ // If true, this is a historical session and not a closed tab.
+ bool from_last_session;
+
+ // The navigations.
+ // WARNING: navigations may be empty.
+ std::vector<TabNavigation> navigations;
+
+ // Index of the selected navigation in navigations.
+ int current_navigation_index;
+
+ // Unique id for the closed tab. This is guaranteed to be unique for
+ // a session.
+ const int id;
+ };
+
+ typedef std::list<HistoricalTab> Tabs;
+
+ // Creates a new TabRestoreService. This does not load tabs from the last
+ // session, you must explicitly invoke LoadPreviousSessionTabs to do that.
+ explicit TabRestoreService(Profile* profile);
+ ~TabRestoreService();
+
+ // Adds/removes an observer. TabRestoreService does not take ownership of
+ // the observer.
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
+ // If the previous session has not been loaded, it is loaded and the tabs
+ // from it are placed at the end of the queue.
+ void LoadPreviousSessionTabs();
+
+ // Returns true if loading the previous sessions tabs.
+ bool IsLoadingPreviousSessionTabs();
+
+ // Returns true if LoadPreviousSessionTabs will attempt to load any tabs.
+ bool WillLoadPreviousSessionTabs();
+
+ // Creates a HistoricalTab to represent the tab and notifies observers the
+ // list of tabs has changed.
+ void CreateHistoricalTab(NavigationController* tab);
+
+ // Removes the HistoricalTab with the specified id and notifies observers.
+ // Does nothing if id does not identify a valid historical tab id.
+ void RemoveHistoricalTabById(int id);
+
+ // Removes all HistoricalTabs from the list and notifies observers the list
+ // of tabs has changed.
+ void ClearHistoricalTabs();
+
+ // Returns the tabs, ordered with most recently closed tabs at the front.
+ const Tabs& tabs() const { return tabs_; }
+
+ private:
+ // Callback from loading the last session. As necessary adds the tabs to
+ // tabs_.
+ void OnGotLastSession(SessionService::Handle handle,
+ std::vector<SessionWindow*>* windows);
+
+ // Invoked from OnGotLastSession to add the necessary tabs from windows
+ // to tabs_.
+ void AddHistoricalTabs(std::vector<SessionWindow*>* windows);
+
+ // Creates a HistoricalTab from the tab.
+ void AppendHistoricalTabFromSessionTab(SessionTab* tab);
+
+ // Populates tabs->navigations from the NavigationController.
+ void PopulateTabFromController(NavigationController* controller,
+ HistoricalTab* tab);
+
+ // Populates tab->navigations from a previous sessions navigations.
+ void PopulateTabFromSessionTab(SessionTab* session_tab,
+ HistoricalTab* tab);
+
+ // Notifies observers the tabs have changed.
+ void NotifyTabsChanged();
+
+ Profile* profile_;
+
+ // Whether we've loaded the last session.
+ bool loaded_last_session_;
+
+ // Set of tabs. We own the NavigationControllers in this list.
+ Tabs tabs_;
+
+ // Used in requesting the last session.
+ CancelableRequestConsumer cancelable_consumer_;
+
+ ObserverList<Observer> observer_list_;
+
+ DISALLOW_EVIL_CONSTRUCTORS(TabRestoreService);
+};
+
+#endif // CHROME_BROWSER_TAB_RESTORE_SERVICE_H__