diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-19 20:34:47 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-19 20:34:47 +0000 |
commit | c08337fd2ff0b856071081839ada86c0e7302e8c (patch) | |
tree | 2ca0d9bc4dfc799a4b7d3ae5ec49ce1e34570d9d /chrome/browser/sessions | |
parent | 3a0f412def9fee68d6a5a57350e7e95c4d1cb80e (diff) | |
download | chromium_src-c08337fd2ff0b856071081839ada86c0e7302e8c.zip chromium_src-c08337fd2ff0b856071081839ada86c0e7302e8c.tar.gz chromium_src-c08337fd2ff0b856071081839ada86c0e7302e8c.tar.bz2 |
Replace usage of browser::FindBrowserForController with browser::FindBrowserWithWebContents
http://crbug.com/133414
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10536196
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143039 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sessions')
5 files changed, 31 insertions, 27 deletions
diff --git a/chrome/browser/sessions/session_restore.cc b/chrome/browser/sessions/session_restore.cc index 465bbfd..9d68815 100644 --- a/chrome/browser/sessions/session_restore.cc +++ b/chrome/browser/sessions/session_restore.cc @@ -262,10 +262,10 @@ void TabLoader::LoadNextTab() { max_parallel_tab_loads_ = tabs_loading_.size(); tabs_to_load_.pop_front(); tab->LoadIfNecessary(); - if (tab->GetWebContents()) { - int tab_index; - Browser* browser = browser::FindBrowserForController(tab, &tab_index); - if (browser && browser->active_index() != tab_index) { + content::WebContents* contents = tab->GetWebContents(); + if (contents) { + Browser* browser = browser::FindBrowserWithWebContents(contents); + if (browser && browser->GetActiveWebContents() != contents) { // By default tabs are marked as visible. As only the active tab is // visible we need to explicitly tell non-active tabs they are hidden. // Without this call non-active tabs are not marked as backgrounded. @@ -273,7 +273,7 @@ void TabLoader::LoadNextTab() { // NOTE: We need to do this here rather than when the tab is added to // the Browser as at that time not everything has been created, so that // the call would do nothing. - tab->GetWebContents()->WasHidden(); + contents->WasHidden(); } } } diff --git a/chrome/browser/sessions/tab_restore_service.cc b/chrome/browser/sessions/tab_restore_service.cc index 0b72271..04a3f34 100644 --- a/chrome/browser/sessions/tab_restore_service.cc +++ b/chrome/browser/sessions/tab_restore_service.cc @@ -219,18 +219,18 @@ void TabRestoreService::RemoveObserver(TabRestoreServiceObserver* observer) { observer_list_.RemoveObserver(observer); } -void TabRestoreService::CreateHistoricalTab(NavigationController* tab, +void TabRestoreService::CreateHistoricalTab(content::WebContents* contents, int index) { if (restoring_) return; TabRestoreServiceDelegate* delegate = - TabRestoreServiceDelegate::FindDelegateForController(tab, NULL); + TabRestoreServiceDelegate::FindDelegateForWebContents(contents); if (closing_delegates_.find(delegate) != closing_delegates_.end()) return; scoped_ptr<Tab> local_tab(new Tab()); - PopulateTab(local_tab.get(), index, delegate, tab); + PopulateTab(local_tab.get(), index, delegate, &contents->GetController()); if (local_tab->navigations.empty()) return; diff --git a/chrome/browser/sessions/tab_restore_service.h b/chrome/browser/sessions/tab_restore_service.h index 4518170..aba0d77 100644 --- a/chrome/browser/sessions/tab_restore_service.h +++ b/chrome/browser/sessions/tab_restore_service.h @@ -27,6 +27,7 @@ struct SessionWindow; namespace content { class NavigationController; class SessionStorageNamespace; +class WebContents; } // TabRestoreService is responsible for maintaining the most recently closed @@ -138,9 +139,9 @@ class TabRestoreService : public BaseSessionService { void AddObserver(TabRestoreServiceObserver* observer); void RemoveObserver(TabRestoreServiceObserver* observer); - // Creates a Tab to represent |tab| and notifies observers the list of + // Creates a Tab to represent |contents| and notifies observers the list of // entries has changed. - void CreateHistoricalTab(content::NavigationController* tab, int index); + void CreateHistoricalTab(content::WebContents* contents, int index); // Invoked when a browser is closing. If |delegate| is a tabbed browser with // at least one tab, a Window is created, added to entries and observers are diff --git a/chrome/browser/sessions/tab_restore_service_browsertest.cc b/chrome/browser/sessions/tab_restore_service_browsertest.cc index d62c5243..31d9167 100644 --- a/chrome/browser/sessions/tab_restore_service_browsertest.cc +++ b/chrome/browser/sessions/tab_restore_service_browsertest.cc @@ -17,11 +17,13 @@ #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/testing_profile.h" #include "chrome/test/base/ui_test_utils.h" +#include "content/public/browser/browser_thread.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" #include "content/public/test/render_view_test.h" +#include "content/public/test/test_browser_thread.h" #include "content/public/test/web_contents_tester.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" @@ -50,7 +52,8 @@ class TabRestoreTimeFactory : public TabRestoreService::TimeFactory { class TabRestoreServiceTest : public ChromeRenderViewHostTestHarness { public: - TabRestoreServiceTest() { + TabRestoreServiceTest() + : ui_thread_(content::BrowserThread::UI, &message_loop_) { url1_ = GURL("http://1"); url2_ = GURL("http://2"); url3_ = GURL("http://3"); @@ -140,13 +143,14 @@ class TabRestoreServiceTest : public ChromeRenderViewHostTestHarness { TabRestoreTimeFactory* time_factory_; content::RenderViewTest::RendererWebKitPlatformSupportImplNoSandbox webkit_platform_support_; + content::TestBrowserThread ui_thread_; }; TEST_F(TabRestoreServiceTest, Basic) { AddThreeNavigations(); // Have the service record the tab. - service_->CreateHistoricalTab(&controller(), -1); + service_->CreateHistoricalTab(contents(), -1); // Make sure an entry was created. ASSERT_EQ(1U, service_->entries().size()); @@ -168,7 +172,7 @@ TEST_F(TabRestoreServiceTest, Basic) { NavigateToIndex(1); // And check again. - service_->CreateHistoricalTab(&controller(), -1); + service_->CreateHistoricalTab(contents(), -1); // There should be two entries now. ASSERT_EQ(2U, service_->entries().size()); @@ -190,7 +194,7 @@ TEST_F(TabRestoreServiceTest, Basic) { // Make sure TabRestoreService doesn't create an entry for a tab with no // navigations. TEST_F(TabRestoreServiceTest, DontCreateEmptyTab) { - service_->CreateHistoricalTab(&controller(), -1); + service_->CreateHistoricalTab(contents(), -1); EXPECT_TRUE(service_->entries().empty()); } @@ -199,7 +203,7 @@ TEST_F(TabRestoreServiceTest, Restore) { AddThreeNavigations(); // Have the service record the tab. - service_->CreateHistoricalTab(&controller(), -1); + service_->CreateHistoricalTab(contents(), -1); // Recreate the service and have it load the tabs. RecreateService(); @@ -226,7 +230,7 @@ TEST_F(TabRestoreServiceTest, RestorePinnedAndApp) { AddThreeNavigations(); // Have the service record the tab. - service_->CreateHistoricalTab(&controller(), -1); + service_->CreateHistoricalTab(contents(), -1); // One entry should be created. ASSERT_EQ(1U, service_->entries().size()); @@ -297,7 +301,7 @@ TEST_F(TabRestoreServiceTest, DontPersistPostData) { controller().GetEntryAtIndex(2)->SetHasPostData(true); // Have the service record the tab. - service_->CreateHistoricalTab(&controller(), -1); + service_->CreateHistoricalTab(contents(), -1); ASSERT_EQ(1U, service_->entries().size()); // Recreate the service and have it load the tabs. @@ -324,7 +328,7 @@ TEST_F(TabRestoreServiceTest, DontLoadTwice) { AddThreeNavigations(); // Have the service record the tab. - service_->CreateHistoricalTab(&controller(), -1); + service_->CreateHistoricalTab(contents(), -1); ASSERT_EQ(1U, service_->entries().size()); // Recreate the service and have it load the tabs. @@ -397,7 +401,7 @@ TEST_F(TabRestoreServiceTest, LoadPreviousSessionAndTabs) { AddThreeNavigations(); - service_->CreateHistoricalTab(&controller(), -1); + service_->CreateHistoricalTab(contents(), -1); RecreateService(); @@ -440,7 +444,7 @@ TEST_F(TabRestoreServiceTest, LoadPreviousSessionAndTabsPinned) { AddThreeNavigations(); - service_->CreateHistoricalTab(&controller(), -1); + service_->CreateHistoricalTab(contents(), -1); RecreateService(); @@ -484,7 +488,7 @@ TEST_F(TabRestoreServiceTest, ManyWindowsInSessionService) { AddThreeNavigations(); - service_->CreateHistoricalTab(&controller(), -1); + service_->CreateHistoricalTab(contents(), -1); RecreateService(); @@ -513,7 +517,7 @@ TEST_F(TabRestoreServiceTest, TimestampSurvivesRestore) { AddThreeNavigations(); // Have the service record the tab. - service_->CreateHistoricalTab(&controller(), -1); + service_->CreateHistoricalTab(contents(), -1); // Make sure an entry was created. ASSERT_EQ(1U, service_->entries().size()); @@ -639,7 +643,7 @@ TEST_F(TabRestoreServiceTest, PruneIsCalled) { const size_t max_entries = TabRestoreService::kMaxEntries; for (size_t i = 0; i < max_entries + 5; i++) { NavigateAndCommit(GURL(StringPrintf("http://%d", static_cast<int>(i)))); - service_->CreateHistoricalTab(&controller(), -1); + service_->CreateHistoricalTab(contents(), -1); } EXPECT_EQ(max_entries, service_->entries_.size()); diff --git a/chrome/browser/sessions/tab_restore_service_delegate.h b/chrome/browser/sessions/tab_restore_service_delegate.h index b46c05f..f2d9074 100644 --- a/chrome/browser/sessions/tab_restore_service_delegate.h +++ b/chrome/browser/sessions/tab_restore_service_delegate.h @@ -64,10 +64,9 @@ class TabRestoreServiceDelegate { static TabRestoreServiceDelegate* Create(Profile* profile, const std::string& app_name); - // see browser::FindBrowserForController - static TabRestoreServiceDelegate* FindDelegateForController( - const content::NavigationController* controller, - int* index); + // see browser::FindBrowserForWebContents + static TabRestoreServiceDelegate* FindDelegateForWebContents( + const content::WebContents* contents); // see browser::FindBrowserWithID static TabRestoreServiceDelegate* FindDelegateWithID( |