| Index: chrome/browser/sessions/tab_restore_service.cc
|
| diff --git a/chrome/browser/sessions/tab_restore_service.cc b/chrome/browser/sessions/tab_restore_service.cc
|
| index 33c3ffc556d39844bd14dcb57ed9df05482e48a4..123f5752f0634e464dbf176538e05898133115e3 100644
|
| --- a/chrome/browser/sessions/tab_restore_service.cc
|
| +++ b/chrome/browser/sessions/tab_restore_service.cc
|
| @@ -12,7 +12,6 @@
|
| #include "base/metrics/histogram.h"
|
| #include "base/scoped_vector.h"
|
| #include "base/stl_util-inl.h"
|
| -#include "chrome/browser/browser_list.h"
|
| #include "chrome/browser/browser_window.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| @@ -20,7 +19,6 @@
|
| #include "chrome/browser/sessions/session_command.h"
|
| #include "chrome/browser/sessions/session_types.h"
|
| #include "chrome/browser/sessions/tab_restore_service_observer.h"
|
| -#include "chrome/browser/tabs/tab_strip_model.h"
|
| #include "chrome/common/extensions/extension.h"
|
| #include "chrome/common/extensions/extension_constants.h"
|
| #include "content/browser/tab_contents/navigation_controller.h"
|
| @@ -152,9 +150,8 @@ void RemoveEntryByID(SessionID::id_type id,
|
| }
|
| }
|
|
|
| -void RecordAppLaunch(Browser* browser, const TabRestoreService::Tab& tab) {
|
| +void RecordAppLaunch(Profile* profile, const TabRestoreService::Tab& tab) {
|
| GURL url = tab.navigations.at(tab.current_navigation_index).virtual_url();
|
| - Profile* profile = browser->profile();
|
| DCHECK(profile->GetExtensionService());
|
| if (!profile->GetExtensionService()->IsInstalledApp(url))
|
| return;
|
| @@ -214,46 +211,45 @@ void TabRestoreService::RemoveObserver(TabRestoreServiceObserver* observer) {
|
| observer_list_.RemoveObserver(observer);
|
| }
|
|
|
| -void TabRestoreService::CreateHistoricalTab(NavigationController* tab) {
|
| +void TabRestoreService::CreateHistoricalTab(NavigationController* tab,
|
| + int index) {
|
| if (restoring_)
|
| return;
|
|
|
| - Browser* browser = Browser::GetBrowserForController(tab, NULL);
|
| + TabRestoreServiceDelegate* browser =
|
| + TabRestoreServiceDelegate::GetBrowserForController(tab, NULL);
|
| if (closing_browsers_.find(browser) != closing_browsers_.end())
|
| return;
|
|
|
| scoped_ptr<Tab> local_tab(new Tab());
|
| - PopulateTab(local_tab.get(), browser, tab);
|
| + PopulateTab(local_tab.get(), index, browser, tab);
|
| if (local_tab->navigations.empty())
|
| return;
|
|
|
| AddEntry(local_tab.release(), true, true);
|
| }
|
|
|
| -void TabRestoreService::BrowserClosing(Browser* browser) {
|
| - if (browser->type() != Browser::TYPE_NORMAL ||
|
| - browser->tab_count() == 0)
|
| - return;
|
| -
|
| +void TabRestoreService::BrowserClosing(TabRestoreServiceDelegate* browser) {
|
| closing_browsers_.insert(browser);
|
|
|
| scoped_ptr<Window> window(new Window());
|
| - window->selected_tab_index = browser->selected_index();
|
| + window->selected_tab_index = browser->GetSelectedIndex();
|
| window->timestamp = TimeNow();
|
| // Don't use std::vector::resize() because it will push copies of an empty tab
|
| // into the vector, which will give all tabs in a window the same ID.
|
| - for (int i = 0; i < browser->tab_count(); ++i) {
|
| + for (int i = 0; i < browser->GetTabCount(); ++i) {
|
| window->tabs.push_back(Tab());
|
| }
|
| size_t entry_index = 0;
|
| - for (int tab_index = 0; tab_index < browser->tab_count(); ++tab_index) {
|
| + for (int tab_index = 0; tab_index < browser->GetTabCount(); ++tab_index) {
|
| PopulateTab(&(window->tabs[entry_index]),
|
| + tab_index,
|
| browser,
|
| &browser->GetTabContentsAt(tab_index)->controller());
|
| if (window->tabs[entry_index].navigations.empty()) {
|
| window->tabs.erase(window->tabs.begin() + entry_index);
|
| } else {
|
| - window->tabs[entry_index].browser_id = browser->session_id().id();
|
| + window->tabs[entry_index].browser_id = browser->GetSessionID().id();
|
| entry_index++;
|
| }
|
| }
|
| @@ -270,7 +266,7 @@ void TabRestoreService::BrowserClosing(Browser* browser) {
|
| }
|
| }
|
|
|
| -void TabRestoreService::BrowserClosed(Browser* browser) {
|
| +void TabRestoreService::BrowserClosed(TabRestoreServiceDelegate* browser) {
|
| closing_browsers_.erase(browser);
|
| }
|
|
|
| @@ -296,14 +292,15 @@ const TabRestoreService::Entries& TabRestoreService::entries() const {
|
| return entries_;
|
| }
|
|
|
| -void TabRestoreService::RestoreMostRecentEntry(Browser* browser) {
|
| +void TabRestoreService::RestoreMostRecentEntry(
|
| + TabRestoreServiceDelegate* browser) {
|
| if (entries_.empty())
|
| return;
|
|
|
| RestoreEntryById(browser, entries_.front()->id, false);
|
| }
|
|
|
| -void TabRestoreService::RestoreEntryById(Browser* browser,
|
| +void TabRestoreService::RestoreEntryById(TabRestoreServiceDelegate* browser,
|
| SessionID::id_type id,
|
| bool replace_existing_tab) {
|
| Entries::iterator i = GetEntryIteratorById(id);
|
| @@ -338,20 +335,20 @@ void TabRestoreService::RestoreEntryById(Browser* browser,
|
| if (entry->type == TAB) {
|
| Tab* tab = static_cast<Tab*>(entry);
|
| browser = RestoreTab(*tab, browser, replace_existing_tab);
|
| - browser->window()->Show();
|
| + browser->ShowBrowserWindow();
|
| } else if (entry->type == WINDOW) {
|
| - Browser* current_browser = browser;
|
| + TabRestoreServiceDelegate* current_browser = browser;
|
| Window* window = static_cast<Window*>(entry);
|
|
|
| // When restoring a window, either the entire window can be restored, or a
|
| // single tab within it. If the entry's ID matches the one to restore, then
|
| // the entire window will be restored.
|
| if (!restoring_tab_in_window) {
|
| - browser = Browser::Create(profile());
|
| + browser = TabRestoreServiceDelegate::CreateBrowser(profile());
|
| for (size_t tab_i = 0; tab_i < window->tabs.size(); ++tab_i) {
|
| const Tab& tab = window->tabs[tab_i];
|
| TabContents* restored_tab =
|
| - browser->AddRestoredTab(tab.navigations, browser->tab_count(),
|
| + browser->AddRestoredTab(tab.navigations, browser->GetTabCount(),
|
| tab.current_navigation_index,
|
| tab.extension_app_id,
|
| (static_cast<int>(tab_i) ==
|
| @@ -360,13 +357,13 @@ void TabRestoreService::RestoreEntryById(Browser* browser,
|
| tab.session_storage_namespace);
|
| if (restored_tab) {
|
| restored_tab->controller().LoadIfNecessary();
|
| - RecordAppLaunch(browser, tab);
|
| + RecordAppLaunch(profile(), tab);
|
| }
|
| }
|
| // All the window's tabs had the same former browser_id.
|
| if (window->tabs[0].has_browser()) {
|
| UpdateTabBrowserIDs(window->tabs[0].browser_id,
|
| - browser->session_id().id());
|
| + browser->GetSessionID().id());
|
| }
|
| } else {
|
| // Restore a single tab from the window. Find the tab that matches the ID
|
| @@ -387,17 +384,17 @@ void TabRestoreService::RestoreEntryById(Browser* browser,
|
| // any one is restored, it goes into the same window as the tab
|
| // being restored now.
|
| UpdateTabBrowserIDs(tab.browser_id,
|
| - browser->session_id().id());
|
| + browser->GetSessionID().id());
|
| for (std::vector<Tab>::iterator tab_j = window->tabs.begin();
|
| tab_j != window->tabs.end(); ++tab_j) {
|
| - (*tab_j).browser_id = browser->session_id().id();
|
| + (*tab_j).browser_id = browser->GetSessionID().id();
|
| }
|
| }
|
| break;
|
| }
|
| }
|
| }
|
| - browser->window()->Show();
|
| + browser->ShowBrowserWindow();
|
|
|
| if (replace_existing_tab && current_browser &&
|
| current_browser->GetSelectedTabContents()) {
|
| @@ -476,7 +473,8 @@ void TabRestoreService::Save() {
|
| }
|
|
|
| void TabRestoreService::PopulateTab(Tab* tab,
|
| - Browser* browser,
|
| + int index,
|
| + TabRestoreServiceDelegate* browser,
|
| NavigationController* controller) {
|
| const int pending_index = controller->pending_entry_index();
|
| int entry_count = controller->entry_count();
|
| @@ -492,6 +490,7 @@ void TabRestoreService::PopulateTab(Tab* tab,
|
| tab->current_navigation_index = controller->GetCurrentEntryIndex();
|
| if (tab->current_navigation_index == -1 && entry_count > 0)
|
| tab->current_navigation_index = 0;
|
| + tab->tabstrip_index = index;
|
|
|
| const Extension* extension = controller->tab_contents()->extension_app();
|
| if (extension)
|
| @@ -501,10 +500,8 @@ void TabRestoreService::PopulateTab(Tab* tab,
|
|
|
| // Browser may be NULL during unit tests.
|
| if (browser) {
|
| - tab->browser_id = browser->session_id().id();
|
| - tab->tabstrip_index =
|
| - browser->tabstrip_model()->GetIndexOfController(controller);
|
| - tab->pinned = browser->tabstrip_model()->IsTabPinned(tab->tabstrip_index);
|
| + tab->browser_id = browser->GetSessionID().id();
|
| + tab->pinned = browser->IsTabPinned(tab->tabstrip_index);
|
| }
|
| }
|
|
|
| @@ -879,9 +876,9 @@ void TabRestoreService::CreateEntriesFromCommands(
|
| loaded_entries->swap(entries.get());
|
| }
|
|
|
| -Browser* TabRestoreService::RestoreTab(const Tab& tab,
|
| - Browser* browser,
|
| - bool replace_existing_tab) {
|
| +TabRestoreServiceDelegate* TabRestoreService::RestoreTab(const Tab& tab,
|
| + TabRestoreServiceDelegate* browser,
|
| + bool replace_existing_tab) {
|
| // |browser| will be NULL in cases where one isn't already available (eg,
|
| // when invoked on Mac OS X with no windows open). In this case, create a
|
| // new browser into which we restore the tabs.
|
| @@ -893,20 +890,20 @@ Browser* TabRestoreService::RestoreTab(const Tab& tab,
|
| tab.session_storage_namespace);
|
| } else {
|
| if (tab.has_browser())
|
| - browser = BrowserList::FindBrowserWithID(tab.browser_id);
|
| + browser = TabRestoreServiceDelegate::FindBrowserWithID(tab.browser_id);
|
|
|
| int tab_index = -1;
|
| if (browser) {
|
| tab_index = tab.tabstrip_index;
|
| } else {
|
| - browser = Browser::Create(profile());
|
| + browser = TabRestoreServiceDelegate::CreateBrowser(profile());
|
| if (tab.has_browser()) {
|
| - UpdateTabBrowserIDs(tab.browser_id, browser->session_id().id());
|
| + UpdateTabBrowserIDs(tab.browser_id, browser->GetSessionID().id());
|
| }
|
| }
|
|
|
| - if (tab_index < 0 || tab_index > browser->tab_count()) {
|
| - tab_index = browser->tab_count();
|
| + if (tab_index < 0 || tab_index > browser->GetTabCount()) {
|
| + tab_index = browser->GetTabCount();
|
| }
|
|
|
| browser->AddRestoredTab(tab.navigations,
|
| @@ -916,7 +913,7 @@ Browser* TabRestoreService::RestoreTab(const Tab& tab,
|
| true, tab.pinned, tab.from_last_session,
|
| tab.session_storage_namespace);
|
| }
|
| - RecordAppLaunch(browser, tab);
|
| + RecordAppLaunch(profile(), tab);
|
| return browser;
|
| }
|
|
|
|
|