diff options
Diffstat (limited to 'chrome/browser/sessions')
-rw-r--r-- | chrome/browser/sessions/session_restore.cc | 37 | ||||
-rw-r--r-- | chrome/browser/sessions/session_restore.h | 6 | ||||
-rw-r--r-- | chrome/browser/sessions/session_types.cc | 10 | ||||
-rw-r--r-- | chrome/browser/sessions/session_types.h | 14 | ||||
-rw-r--r-- | chrome/browser/sessions/tab_restore_service.h | 9 |
5 files changed, 70 insertions, 6 deletions
diff --git a/chrome/browser/sessions/session_restore.cc b/chrome/browser/sessions/session_restore.cc index a75f7de..9a20e65 100644 --- a/chrome/browser/sessions/session_restore.cc +++ b/chrome/browser/sessions/session_restore.cc @@ -298,6 +298,33 @@ class SessionRestoreImpl : public NotificationObserver { } } + void RestoreForeignSession(std::vector<SessionWindow*>* windows) { + tab_loader_.reset(new TabLoader()); + // Create a browser instance to put the restored tabs in. + bool has_tabbed_browser = false; + for (std::vector<SessionWindow*>::iterator i = (*windows).begin(); + i != (*windows).end(); ++i) { + Browser* browser = NULL; + if (!has_tabbed_browser && (*i)->type == Browser::TYPE_NORMAL) + has_tabbed_browser = true; + browser = new Browser(static_cast<Browser::Type>((*i)->type), + profile_); + browser->set_override_bounds((*i)->bounds); + browser->set_maximized_state((*i)->is_maximized ? + Browser::MAXIMIZED_STATE_MAXIMIZED : + Browser::MAXIMIZED_STATE_UNMAXIMIZED); + browser->CreateBrowserWindow(); + + // Restore and show the browser. + const int initial_tab_count = browser->tab_count(); + RestoreTabsToBrowser(*(*i), browser); + ShowBrowser(browser, initial_tab_count, + (*i)->selected_tab_index); + NotifySessionServiceOfRestoredTabs(browser, initial_tab_count); + FinishedTabCreation(true, has_tabbed_browser); + } + } + ~SessionRestoreImpl() { STLDeleteElements(&windows_); restoring = false; @@ -614,6 +641,16 @@ void SessionRestore::RestoreSession(Profile* profile, } // static +void SessionRestore::RestoreForeignSessionWindows(Profile* profile, + std::vector<SessionWindow*>* windows) { + // Create a SessionRestore object to eventually restore the tabs. + std::vector<GURL> gurls; + SessionRestoreImpl restorer(profile, + static_cast<Browser*>(NULL), true, false, true, gurls); + restorer.RestoreForeignSession(windows); +} + +// static void SessionRestore::RestoreSessionSynchronously( Profile* profile, const std::vector<GURL>& urls_to_open) { diff --git a/chrome/browser/sessions/session_restore.h b/chrome/browser/sessions/session_restore.h index 8ce01d2f..bb08868 100644 --- a/chrome/browser/sessions/session_restore.h +++ b/chrome/browser/sessions/session_restore.h @@ -9,6 +9,7 @@ #include <vector> #include "chrome/browser/history/history.h" +#include "chrome/browser/sessions/session_types.h" #include "base/basictypes.h" class Browser; @@ -35,6 +36,11 @@ class SessionRestore { bool always_create_tabbed_browser, const std::vector<GURL>& urls_to_open); + // Specifically used in the restoration of a foreign session. This method + // restores the given session windows to a browser. + static void RestoreForeignSessionWindows(Profile* profile, + std::vector<SessionWindow*>* windows); + // Synchronously restores the last session. At least one tabbed browser is // created, even if there is an error in restoring. // diff --git a/chrome/browser/sessions/session_types.cc b/chrome/browser/sessions/session_types.cc index 6cf193c..cdf77f6 100644 --- a/chrome/browser/sessions/session_types.cc +++ b/chrome/browser/sessions/session_types.cc @@ -51,3 +51,13 @@ SessionWindow::SessionWindow() SessionWindow::~SessionWindow() { STLDeleteElements(&tabs); } + +// ForeignSession -------------------------------------------------------------- + +ForeignSession::ForeignSession() : foreign_tession_tag("invalid") { +} + +ForeignSession::~ForeignSession() { + STLDeleteElements(&windows); +} + diff --git a/chrome/browser/sessions/session_types.h b/chrome/browser/sessions/session_types.h index 2ea0757..07dbae4 100644 --- a/chrome/browser/sessions/session_types.h +++ b/chrome/browser/sessions/session_types.h @@ -88,7 +88,7 @@ class TabNavigation { // This is used when determining the selected TabNavigation and only useful // by BaseSessionService and SessionService. void set_index(int index) { index_ = index; } - int index() { return index_; } + int index() const { return index_; } private: friend class BaseSessionService; @@ -189,4 +189,16 @@ struct SessionWindow { DISALLOW_COPY_AND_ASSIGN(SessionWindow); }; +// Defines a foreign session for session sync. A foreign session is a session +// on a remote chrome instance. +struct ForeignSession { + ForeignSession(); + ~ForeignSession(); + + // Unique tag for each session. + std::string foreign_tession_tag; + std::vector<SessionWindow*> windows; +}; + #endif // CHROME_BROWSER_SESSIONS_SESSION_TYPES_H_ + diff --git a/chrome/browser/sessions/tab_restore_service.h b/chrome/browser/sessions/tab_restore_service.h index 31f22e4..e12b9d1 100644 --- a/chrome/browser/sessions/tab_restore_service.h +++ b/chrome/browser/sessions/tab_restore_service.h @@ -175,6 +175,10 @@ class TabRestoreService : public BaseSessionService { // Max number of entries we'll keep around. static const size_t kMaxEntries; + // Creates and add entries to |entries| for each of the windows in |windows|. + void CreateEntriesFromWindows(std::vector<SessionWindow*>* windows, + std::vector<Entry*>* entries); + protected: virtual void Save(); @@ -291,11 +295,6 @@ class TabRestoreService : public BaseSessionService { void OnGotPreviousSession(Handle handle, std::vector<SessionWindow*>* windows); - // Creates and add entries to |entries| for each of the windows in |windows|. - void CreateEntriesFromWindows( - std::vector<SessionWindow*>* windows, - std::vector<Entry*>* entries); - // 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( |