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

Unified Diff: chrome/browser/sessions/session_restore.cc

Issue 5705004: [SYNC] Sessions datatype refactor. Most things related to sessions under-the-... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Rebase Created 9 years, 11 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.h ('k') | chrome/browser/sessions/session_types.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sessions/session_restore.cc
===================================================================
--- chrome/browser/sessions/session_restore.cc (revision 70604)
+++ chrome/browser/sessions/session_restore.cc (working copy)
@@ -300,33 +300,42 @@
}
}
- void RestoreForeignSession(std::vector<SessionWindow*>* windows) {
- tab_loader_.reset(new TabLoader());
+ // Restore window(s) from a foreign session.
+ void RestoreForeignSession(
+ std::vector<SessionWindow*>::const_iterator begin,
+ std::vector<SessionWindow*>::const_iterator end) {
+ StartTabCreation();
// 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();
+ for (std::vector<SessionWindow*>::const_iterator i = begin;
+ i != end; ++i) {
+ Browser* browser = CreateRestoredBrowser(
+ static_cast<Browser::Type>((*i)->type),
+ (*i)->bounds,
+ (*i)->is_maximized);
// 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);
+ ShowBrowser(browser, initial_tab_count, (*i)->selected_tab_index);
NotifySessionServiceOfRestoredTabs(browser, initial_tab_count);
}
- FinishedTabCreation(true, has_tabbed_browser);
+
+ // Always create in a new window
+ FinishedTabCreation(true, true);
}
+ // Restore a single tab from a foreign session.
+ // Note: we currently restore the tab to the last active browser.
+ void RestoreForeignTab(const SessionTab& tab) {
+ StartTabCreation();
+ Browser* current_browser =
+ browser_ ? browser_ : BrowserList::GetLastActive();
+ RestoreTab(tab, current_browser->tab_count(), current_browser);
+ NotifySessionServiceOfRestoredTabs(current_browser,
+ current_browser->tab_count());
+ FinishedTabCreation(true, true);
+ }
+
~SessionRestoreImpl() {
STLDeleteElements(&windows_);
restoring = false;
@@ -347,6 +356,11 @@
}
private:
+ // Invoked when beginning to create new tabs. Resets the tab_loader_.
+ void StartTabCreation() {
+ tab_loader_.reset(new TabLoader());
+ }
+
// Invoked when done with creating all the tabs/browsers.
//
// |created_tabbed_browser| indicates whether a tabbed browser was created,
@@ -401,7 +415,7 @@
return;
}
- tab_loader_.reset(new TabLoader());
+ StartTabCreation();
Browser* current_browser =
browser_ ? browser_ : BrowserList::GetLastActive();
@@ -425,12 +439,10 @@
}
}
if (!browser) {
- 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();
+ browser = CreateRestoredBrowser(
+ static_cast<Browser::Type>((*i)->type),
+ (*i)->bounds,
+ (*i)->is_maximized);
}
if ((*i)->type == Browser::TYPE_NORMAL)
last_browser = browser;
@@ -460,24 +472,42 @@
for (std::vector<SessionTab*>::const_iterator i = window.tabs.begin();
i != window.tabs.end(); ++i) {
const SessionTab& tab = *(*i);
- DCHECK(!tab.navigations.empty());
- int selected_index = tab.current_navigation_index;
- selected_index = std::max(
- 0,
- std::min(selected_index,
- static_cast<int>(tab.navigations.size() - 1)));
- tab_loader_->ScheduleLoad(
- &browser->AddRestoredTab(tab.navigations,
- static_cast<int>(i - window.tabs.begin()),
- selected_index,
- tab.extension_app_id,
- false,
- tab.pinned,
- true,
- NULL)->controller());
+ RestoreTab(tab, static_cast<int>(i - window.tabs.begin()), browser);
}
}
+ void RestoreTab(const SessionTab& tab,
+ const int tab_index,
+ Browser* browser) {
+ DCHECK(!tab.navigations.empty());
+ int selected_index = tab.current_navigation_index;
+ selected_index = std::max(
+ 0,
+ std::min(selected_index,
+ static_cast<int>(tab.navigations.size() - 1)));
+ tab_loader_->ScheduleLoad(
+ &browser->AddRestoredTab(tab.navigations,
+ tab_index,
+ selected_index,
+ tab.extension_app_id,
+ false,
+ tab.pinned,
+ true,
+ NULL)->controller());
+ }
+
+ Browser* CreateRestoredBrowser(Browser::Type type,
+ gfx::Rect bounds,
+ bool is_maximized) {
+ Browser* browser = new Browser(type, profile_);
+ browser->set_override_bounds(bounds);
+ browser->set_maximized_state(is_maximized ?
+ Browser::MAXIMIZED_STATE_MAXIMIZED :
+ Browser::MAXIMIZED_STATE_UNMAXIMIZED);
+ browser->CreateBrowserWindow();
+ return browser;
+ }
+
void ShowBrowser(Browser* browser,
int initial_tab_count,
int selected_session_index) {
@@ -601,16 +631,28 @@
}
// static
-void SessionRestore::RestoreForeignSessionWindows(Profile* profile,
- std::vector<SessionWindow*>* windows) {
+void SessionRestore::RestoreForeignSessionWindows(
+ Profile* profile,
+ std::vector<SessionWindow*>::const_iterator begin,
+ std::vector<SessionWindow*>::const_iterator end) {
// 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);
+ restorer.RestoreForeignSession(begin, end);
}
// static
+void SessionRestore::RestoreForeignSessionTab(Profile* profile,
+ const SessionTab& tab) {
+ // 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.RestoreForeignTab(tab);
+}
+
+// static
void SessionRestore::RestoreSessionSynchronously(
Profile* profile,
const std::vector<GURL>& urls_to_open) {
« no previous file with comments | « chrome/browser/sessions/session_restore.h ('k') | chrome/browser/sessions/session_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698