diff options
author | avi <avi@chromium.org> | 2015-06-18 17:01:11 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-19 00:01:51 +0000 |
commit | 2fc587ca7953483ebd9e8d71636d2a1b28a59c06 (patch) | |
tree | fd4451263ef7c27f903692d114e1e568c80009d9 | |
parent | 7cf9b878a2804b6cbbfb88985ebc579bfa008db5 (diff) | |
download | chromium_src-2fc587ca7953483ebd9e8d71636d2a1b28a59c06.zip chromium_src-2fc587ca7953483ebd9e8d71636d2a1b28a59c06.tar.gz chromium_src-2fc587ca7953483ebd9e8d71636d2a1b28a59c06.tar.bz2 |
Use scoped_ptr for NavigationEntries.
BUG=none
TEST=none
Review URL: https://codereview.chromium.org/1191893009
Cr-Commit-Position: refs/heads/master@{#335167}
19 files changed, 310 insertions, 251 deletions
diff --git a/android_webview/native/state_serializer.cc b/android_webview/native/state_serializer.cc index 50dfd34..36589a1 100644 --- a/android_webview/native/state_serializer.cc +++ b/android_webview/native/state_serializer.cc @@ -110,7 +110,7 @@ bool RestoreFromPickle(base::PickleIterator* iterator, controller.Restore( selected_entry, content::NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, - &restored_entries.get()); + &restored_entries); DCHECK_EQ(0u, restored_entries.size()); if (controller.GetActiveEntry()) { diff --git a/base/memory/scoped_vector.h b/base/memory/scoped_vector.h index 173ea5a..e1e5c72 100644 --- a/base/memory/scoped_vector.h +++ b/base/memory/scoped_vector.h @@ -106,6 +106,10 @@ class ScopedVector { return v_.insert(position, x); } + iterator insert(iterator position, scoped_ptr<T> x) { + return v_.insert(position, x.release()); + } + // Lets the ScopedVector take ownership of elements in [first,last). template<typename InputIterator> void insert(iterator position, InputIterator first, InputIterator last) { diff --git a/chrome/browser/android/tab_state.cc b/chrome/browser/android/tab_state.cc index 052e28e..f726643 100644 --- a/chrome/browser/android/tab_state.cc +++ b/chrome/browser/android/tab_state.cc @@ -429,8 +429,6 @@ WebContents* WebContentsState::RestoreContentsFromByteBuffer( ScopedVector<content::NavigationEntry> scoped_entries = sessions::ContentSerializedNavigationBuilder::ToNavigationEntries( navigations, profile); - std::vector<content::NavigationEntry*> entries; - scoped_entries.release(&entries); if (is_off_the_record) profile = profile->GetOffTheRecordProfile(); @@ -440,7 +438,7 @@ WebContents* WebContentsState::RestoreContentsFromByteBuffer( web_contents->GetController().Restore( current_entry_index, NavigationController::RESTORE_CURRENT_SESSION, - &entries); + &scoped_entries); return web_contents.release(); } diff --git a/chrome/browser/search/search_unittest.cc b/chrome/browser/search/search_unittest.cc index 90007c8..1b33a79 100644 --- a/chrome/browser/search/search_unittest.cc +++ b/chrome/browser/search/search_unittest.cc @@ -24,6 +24,7 @@ #include "components/search_engines/search_engines_switches.h" #include "components/search_engines/template_url_service.h" #include "components/variations/entropy_provider.h" +#include "content/public/browser/navigation_entry.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/site_instance.h" diff --git a/chrome/browser/sessions/session_restore_android.cc b/chrome/browser/sessions/session_restore_android.cc index 424f7e2..5085b3d 100644 --- a/chrome/browser/sessions/session_restore_android.cc +++ b/chrome/browser/sessions/session_restore_android.cc @@ -34,16 +34,13 @@ content::WebContents* SessionRestore::RestoreForeignSessionTab( ScopedVector<content::NavigationEntry> scoped_entries = sessions::ContentSerializedNavigationBuilder::ToNavigationEntries( session_tab.navigations, profile); - // NavigationController::Restore() expects to take ownership of the entries. - std::vector<content::NavigationEntry*> entries; - scoped_entries.release(&entries); content::WebContents* new_web_contents = content::WebContents::Create( content::WebContents::CreateParams(context)); int selected_index = session_tab.normalized_navigation_index(); new_web_contents->GetController().Restore( selected_index, content::NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, - &entries); + &scoped_entries); TabAndroid* current_tab = TabAndroid::FromWebContents(web_contents); DCHECK(current_tab); diff --git a/chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc b/chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc index c11c8d9..4d2e573 100644 --- a/chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc +++ b/chrome/browser/sync/sessions/sessions_sync_manager_unittest.cc @@ -377,8 +377,8 @@ class SyncedTabDelegateFake : public SyncedTabDelegate { return (size < i + 1) ? NULL : entries_[i]; } - void AppendEntry(content::NavigationEntry* entry) { - entries_.push_back(entry); + void AppendEntry(scoped_ptr<content::NavigationEntry> entry) { + entries_.push_back(entry.Pass()); } int GetEntryCount() const override { return entries_.size(); } @@ -452,22 +452,25 @@ TEST_F(SessionsSyncManagerTest, ValidTabs) { tab.reset(); // A chrome:// entry isn't valid. - content::NavigationEntry* entry(content::NavigationEntry::Create()); + scoped_ptr<content::NavigationEntry> entry( + content::NavigationEntry::Create()); entry->SetVirtualURL(GURL("chrome://preferences/")); - tab.AppendEntry(entry); + tab.AppendEntry(entry.Pass()); EXPECT_FALSE(tab.ShouldSync()); // A file:// entry isn't valid, even in addition to another entry. - content::NavigationEntry* entry2(content::NavigationEntry::Create()); + scoped_ptr<content::NavigationEntry> entry2( + content::NavigationEntry::Create()); entry2->SetVirtualURL(GURL("file://bla")); - tab.AppendEntry(entry2); + tab.AppendEntry(entry2.Pass()); EXPECT_FALSE(tab.ShouldSync()); // Add a valid scheme entry to tab, making the tab valid. - content::NavigationEntry* entry3(content::NavigationEntry::Create()); + scoped_ptr<content::NavigationEntry> entry3( + content::NavigationEntry::Create()); entry3->SetVirtualURL(GURL("http://www.google.com")); - tab.AppendEntry(entry3); + tab.AppendEntry(entry3.Pass()); EXPECT_FALSE(tab.ShouldSync()); } @@ -475,20 +478,24 @@ TEST_F(SessionsSyncManagerTest, ValidTabs) { // entry if the current entry is pending. TEST_F(SessionsSyncManagerTest, GetCurrentVirtualURLPending) { SyncedTabDelegateFake tab; - content::NavigationEntry* entry(content::NavigationEntry::Create()); - entry->SetVirtualURL(GURL("http://www.google.com")); - tab.AppendEntry(entry); - EXPECT_EQ(entry->GetVirtualURL(), manager()->GetCurrentVirtualURL(tab)); + scoped_ptr<content::NavigationEntry> entry( + content::NavigationEntry::Create()); + GURL url("http://www.google.com/"); + entry->SetVirtualURL(url); + tab.AppendEntry(entry.Pass()); + EXPECT_EQ(url, manager()->GetCurrentVirtualURL(tab)); } // Make sure GetCurrentVirtualURL() returns the virtual URL of the current // entry if the current entry is non-pending. TEST_F(SessionsSyncManagerTest, GetCurrentVirtualURLNonPending) { SyncedTabDelegateFake tab; - content::NavigationEntry* entry(content::NavigationEntry::Create()); - entry->SetVirtualURL(GURL("http://www.google.com")); - tab.AppendEntry(entry); - EXPECT_EQ(entry->GetVirtualURL(), manager()->GetCurrentVirtualURL(tab)); + scoped_ptr<content::NavigationEntry> entry( + content::NavigationEntry::Create()); + GURL url("http://www.google.com/"); + entry->SetVirtualURL(url); + tab.AppendEntry(entry.Pass()); + EXPECT_EQ(url, manager()->GetCurrentVirtualURL(tab)); } static const base::Time kTime0 = base::Time::FromInternalValue(100); @@ -508,22 +515,28 @@ static const base::Time kTime9 = base::Time::FromInternalValue(190); TEST_F(SessionsSyncManagerTest, SetSessionTabFromDelegate) { // Create a tab with three valid entries. SyncedTabDelegateFake tab; - content::NavigationEntry* entry1(content::NavigationEntry::Create()); - entry1->SetVirtualURL(GURL("http://www.google.com")); + scoped_ptr<content::NavigationEntry> entry1( + content::NavigationEntry::Create()); + GURL url1("http://www.google.com/"); + entry1->SetVirtualURL(url1); entry1->SetTimestamp(kTime1); entry1->SetHttpStatusCode(200); - content::NavigationEntry* entry2(content::NavigationEntry::Create()); - entry2->SetVirtualURL(GURL("http://www.noodle.com")); + scoped_ptr<content::NavigationEntry> entry2( + content::NavigationEntry::Create()); + GURL url2("http://www.noodle.com/"); + entry2->SetVirtualURL(url2); entry2->SetTimestamp(kTime2); entry2->SetHttpStatusCode(201); - content::NavigationEntry* entry3(content::NavigationEntry::Create()); - entry3->SetVirtualURL(GURL("http://www.doodle.com")); + scoped_ptr<content::NavigationEntry> entry3( + content::NavigationEntry::Create()); + GURL url3("http://www.doodle.com/"); + entry3->SetVirtualURL(url3); entry3->SetTimestamp(kTime3); entry3->SetHttpStatusCode(202); - tab.AppendEntry(entry1); - tab.AppendEntry(entry2); - tab.AppendEntry(entry3); + tab.AppendEntry(entry1.Pass()); + tab.AppendEntry(entry2.Pass()); + tab.AppendEntry(entry3.Pass()); tab.set_current_entry_index(2); sessions::SessionTab session_tab; @@ -550,12 +563,9 @@ TEST_F(SessionsSyncManagerTest, SetSessionTabFromDelegate) { EXPECT_TRUE(session_tab.user_agent_override.empty()); EXPECT_EQ(kTime4, session_tab.timestamp); ASSERT_EQ(3u, session_tab.navigations.size()); - EXPECT_EQ(entry1->GetVirtualURL(), - session_tab.navigations[0].virtual_url()); - EXPECT_EQ(entry2->GetVirtualURL(), - session_tab.navigations[1].virtual_url()); - EXPECT_EQ(entry3->GetVirtualURL(), - session_tab.navigations[2].virtual_url()); + EXPECT_EQ(url1, session_tab.navigations[0].virtual_url()); + EXPECT_EQ(url2, session_tab.navigations[1].virtual_url()); + EXPECT_EQ(url3, session_tab.navigations[2].virtual_url()); EXPECT_EQ(kTime1, session_tab.navigations[0].timestamp()); EXPECT_EQ(kTime2, session_tab.navigations[1].timestamp()); EXPECT_EQ(kTime3, session_tab.navigations[2].timestamp()); @@ -575,57 +585,77 @@ TEST_F(SessionsSyncManagerTest, SetSessionTabFromDelegate) { // stack gets trucated to +/- 6 entries. TEST_F(SessionsSyncManagerTest, SetSessionTabFromDelegateNavigationIndex) { SyncedTabDelegateFake tab; - content::NavigationEntry* entry0(content::NavigationEntry::Create()); - entry0->SetVirtualURL(GURL("http://www.google.com")); + scoped_ptr<content::NavigationEntry> entry0( + content::NavigationEntry::Create()); + GURL url0("http://www.google.com/"); + entry0->SetVirtualURL(url0); entry0->SetTimestamp(kTime0); entry0->SetHttpStatusCode(200); - content::NavigationEntry* entry1(content::NavigationEntry::Create()); - entry1->SetVirtualURL(GURL("http://www.zoogle.com")); + scoped_ptr<content::NavigationEntry> entry1( + content::NavigationEntry::Create()); + GURL url1("http://www.zoogle.com/"); + entry1->SetVirtualURL(url1); entry1->SetTimestamp(kTime1); entry1->SetHttpStatusCode(200); - content::NavigationEntry* entry2(content::NavigationEntry::Create()); - entry2->SetVirtualURL(GURL("http://www.noogle.com")); + scoped_ptr<content::NavigationEntry> entry2( + content::NavigationEntry::Create()); + GURL url2("http://www.noogle.com/"); + entry2->SetVirtualURL(url2); entry2->SetTimestamp(kTime2); entry2->SetHttpStatusCode(200); - content::NavigationEntry* entry3(content::NavigationEntry::Create()); - entry3->SetVirtualURL(GURL("http://www.doogle.com")); + scoped_ptr<content::NavigationEntry> entry3( + content::NavigationEntry::Create()); + GURL url3("http://www.doogle.com/"); + entry3->SetVirtualURL(url3); entry3->SetTimestamp(kTime3); entry3->SetHttpStatusCode(200); - content::NavigationEntry* entry4(content::NavigationEntry::Create()); - entry4->SetVirtualURL(GURL("http://www.yoogle.com")); + scoped_ptr<content::NavigationEntry> entry4( + content::NavigationEntry::Create()); + GURL url4("http://www.yoogle.com/"); + entry4->SetVirtualURL(url4); entry4->SetTimestamp(kTime4); entry4->SetHttpStatusCode(200); - content::NavigationEntry* entry5(content::NavigationEntry::Create()); - entry5->SetVirtualURL(GURL("http://www.foogle.com")); + scoped_ptr<content::NavigationEntry> entry5( + content::NavigationEntry::Create()); + GURL url5("http://www.foogle.com/"); + entry5->SetVirtualURL(url5); entry5->SetTimestamp(kTime5); entry5->SetHttpStatusCode(200); - content::NavigationEntry* entry6(content::NavigationEntry::Create()); - entry6->SetVirtualURL(GURL("http://www.boogle.com")); + scoped_ptr<content::NavigationEntry> entry6( + content::NavigationEntry::Create()); + GURL url6("http://www.boogle.com/"); + entry6->SetVirtualURL(url6); entry6->SetTimestamp(kTime6); entry6->SetHttpStatusCode(200); - content::NavigationEntry* entry7(content::NavigationEntry::Create()); - entry7->SetVirtualURL(GURL("http://www.moogle.com")); + scoped_ptr<content::NavigationEntry> entry7( + content::NavigationEntry::Create()); + GURL url7("http://www.moogle.com/"); + entry7->SetVirtualURL(url7); entry7->SetTimestamp(kTime7); entry7->SetHttpStatusCode(200); - content::NavigationEntry* entry8(content::NavigationEntry::Create()); - entry8->SetVirtualURL(GURL("http://www.poogle.com")); + scoped_ptr<content::NavigationEntry> entry8( + content::NavigationEntry::Create()); + GURL url8("http://www.poogle.com/"); + entry8->SetVirtualURL(url8); entry8->SetTimestamp(kTime8); entry8->SetHttpStatusCode(200); - content::NavigationEntry* entry9(content::NavigationEntry::Create()); - entry9->SetVirtualURL(GURL("http://www.roogle.com")); + scoped_ptr<content::NavigationEntry> entry9( + content::NavigationEntry::Create()); + GURL url9("http://www.roogle.com/"); + entry9->SetVirtualURL(url9); entry9->SetTimestamp(kTime9); entry9->SetHttpStatusCode(200); - tab.AppendEntry(entry0); - tab.AppendEntry(entry1); - tab.AppendEntry(entry2); - tab.AppendEntry(entry3); - tab.AppendEntry(entry4); - tab.AppendEntry(entry5); - tab.AppendEntry(entry6); - tab.AppendEntry(entry7); - tab.AppendEntry(entry8); - tab.AppendEntry(entry9); + tab.AppendEntry(entry0.Pass()); + tab.AppendEntry(entry1.Pass()); + tab.AppendEntry(entry2.Pass()); + tab.AppendEntry(entry3.Pass()); + tab.AppendEntry(entry4.Pass()); + tab.AppendEntry(entry5.Pass()); + tab.AppendEntry(entry6.Pass()); + tab.AppendEntry(entry7.Pass()); + tab.AppendEntry(entry8.Pass()); + tab.AppendEntry(entry9.Pass()); tab.set_current_entry_index(8); sessions::SessionTab session_tab; @@ -633,39 +663,40 @@ TEST_F(SessionsSyncManagerTest, SetSessionTabFromDelegateNavigationIndex) { EXPECT_EQ(6, session_tab.current_navigation_index); ASSERT_EQ(8u, session_tab.navigations.size()); - EXPECT_EQ(entry2->GetVirtualURL(), - session_tab.navigations[0].virtual_url()); - EXPECT_EQ(entry3->GetVirtualURL(), - session_tab.navigations[1].virtual_url()); - EXPECT_EQ(entry4->GetVirtualURL(), - session_tab.navigations[2].virtual_url()); + EXPECT_EQ(url2, session_tab.navigations[0].virtual_url()); + EXPECT_EQ(url3, session_tab.navigations[1].virtual_url()); + EXPECT_EQ(url4, session_tab.navigations[2].virtual_url()); } // Ensure the current_navigation_index gets set to the end of the navigation // stack if the current navigation is invalid. TEST_F(SessionsSyncManagerTest, SetSessionTabFromDelegateCurrentInvalid) { SyncedTabDelegateFake tab; - content::NavigationEntry* entry0(content::NavigationEntry::Create()); + scoped_ptr<content::NavigationEntry> entry0( + content::NavigationEntry::Create()); entry0->SetVirtualURL(GURL("http://www.google.com")); entry0->SetTimestamp(kTime0); entry0->SetHttpStatusCode(200); - content::NavigationEntry* entry1(content::NavigationEntry::Create()); + scoped_ptr<content::NavigationEntry> entry1( + content::NavigationEntry::Create()); entry1->SetVirtualURL(GURL("")); entry1->SetTimestamp(kTime1); entry1->SetHttpStatusCode(200); - content::NavigationEntry* entry2(content::NavigationEntry::Create()); + scoped_ptr<content::NavigationEntry> entry2( + content::NavigationEntry::Create()); entry2->SetVirtualURL(GURL("http://www.noogle.com")); entry2->SetTimestamp(kTime2); entry2->SetHttpStatusCode(200); - content::NavigationEntry* entry3(content::NavigationEntry::Create()); + scoped_ptr<content::NavigationEntry> entry3( + content::NavigationEntry::Create()); entry3->SetVirtualURL(GURL("http://www.doogle.com")); entry3->SetTimestamp(kTime3); entry3->SetHttpStatusCode(200); - tab.AppendEntry(entry0); - tab.AppendEntry(entry1); - tab.AppendEntry(entry2); - tab.AppendEntry(entry3); + tab.AppendEntry(entry0.Pass()); + tab.AppendEntry(entry1.Pass()); + tab.AppendEntry(entry2.Pass()); + tab.AppendEntry(entry3.Pass()); tab.set_current_entry_index(1); sessions::SessionTab session_tab; @@ -703,20 +734,26 @@ TEST_F(SessionsSyncManagerTest, SetVariationIds) { // as such, while regular navigations are marked as allowed. TEST_F(SessionsSyncManagerTest, BlockedNavigations) { SyncedTabDelegateFake tab; - content::NavigationEntry* entry1(content::NavigationEntry::Create()); - entry1->SetVirtualURL(GURL("http://www.google.com")); + scoped_ptr<content::NavigationEntry> entry1( + content::NavigationEntry::Create()); + GURL url1("http://www.google.com/"); + entry1->SetVirtualURL(url1); entry1->SetTimestamp(kTime1); - tab.AppendEntry(entry1); + tab.AppendEntry(entry1.Pass()); - content::NavigationEntry* entry2 = content::NavigationEntry::Create(); - entry2->SetVirtualURL(GURL("http://blocked.com/foo")); + scoped_ptr<content::NavigationEntry> entry2( + content::NavigationEntry::Create()); + GURL url2("http://blocked.com/foo"); + entry2->SetVirtualURL(url2); entry2->SetTimestamp(kTime2); - content::NavigationEntry* entry3 = content::NavigationEntry::Create(); - entry3->SetVirtualURL(GURL("http://evil.com")); + scoped_ptr<content::NavigationEntry> entry3( + content::NavigationEntry::Create()); + GURL url3("http://evil.com/"); + entry3->SetVirtualURL(url3); entry3->SetTimestamp(kTime3); ScopedVector<const content::NavigationEntry> blocked_navigations; - blocked_navigations.push_back(entry2); - blocked_navigations.push_back(entry3); + blocked_navigations.push_back(entry2.Pass()); + blocked_navigations.push_back(entry3.Pass()); tab.set_is_supervised(true); tab.set_blocked_navigations(&blocked_navigations.get()); @@ -745,12 +782,9 @@ TEST_F(SessionsSyncManagerTest, BlockedNavigations) { EXPECT_TRUE(session_tab.user_agent_override.empty()); EXPECT_EQ(kTime4, session_tab.timestamp); ASSERT_EQ(3u, session_tab.navigations.size()); - EXPECT_EQ(entry1->GetVirtualURL(), - session_tab.navigations[0].virtual_url()); - EXPECT_EQ(entry2->GetVirtualURL(), - session_tab.navigations[1].virtual_url()); - EXPECT_EQ(entry3->GetVirtualURL(), - session_tab.navigations[2].virtual_url()); + EXPECT_EQ(url1, session_tab.navigations[0].virtual_url()); + EXPECT_EQ(url2, session_tab.navigations[1].virtual_url()); + EXPECT_EQ(url3, session_tab.navigations[2].virtual_url()); EXPECT_EQ(kTime1, session_tab.navigations[0].timestamp()); EXPECT_EQ(kTime2, session_tab.navigations[1].timestamp()); EXPECT_EQ(kTime3, session_tab.navigations[2].timestamp()); @@ -1200,7 +1234,7 @@ TEST_F(SessionsSyncManagerTest, WriteForeignSessionToNodeTabsFirst) { std::string tag = "tag1"; SessionID::id_type nums1[] = {5, 10, 13, 17}; std::vector<sync_pb::SessionSpecifics> tabs1; - std::vector<SessionID::id_type> tab_list1 (nums1, nums1 + arraysize(nums1)); + std::vector<SessionID::id_type> tab_list1(nums1, nums1 + arraysize(nums1)); sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( tag, tab_list1, &tabs1)); @@ -1227,7 +1261,7 @@ TEST_F(SessionsSyncManagerTest, WriteForeignSessionToNodeMissingTabs) { std::string tag = "tag1"; SessionID::id_type nums1[] = {5, 10, 13, 17}; std::vector<sync_pb::SessionSpecifics> tabs1; - std::vector<SessionID::id_type> tab_list1 (nums1, nums1 + arraysize(nums1)); + std::vector<SessionID::id_type> tab_list1(nums1, nums1 + arraysize(nums1)); sync_pb::SessionSpecifics meta(helper()->BuildForeignSession( tag, tab_list1, &tabs1)); // Add a second window, but this time only create two tab nodes, despite the diff --git a/chrome/browser/ui/browser_tabrestore.cc b/chrome/browser/ui/browser_tabrestore.cc index c7fdf730..5943f38 100644 --- a/chrome/browser/ui/browser_tabrestore.cc +++ b/chrome/browser/ui/browser_tabrestore.cc @@ -75,14 +75,11 @@ WebContents* CreateRestoredTab( ScopedVector<NavigationEntry> scoped_entries = ContentSerializedNavigationBuilder::ToNavigationEntries( navigations, browser->profile()); - // NavigationController::Restore() expects to take ownership of the entries. - std::vector<NavigationEntry*> entries; - scoped_entries.release(&entries); web_contents->SetUserAgentOverride(user_agent_override); web_contents->GetController().Restore( selected_navigation, GetRestoreType(browser, from_last_session), - &entries); - DCHECK_EQ(0u, entries.size()); + &scoped_entries); + DCHECK_EQ(0u, scoped_entries.size()); return web_contents; } diff --git a/chrome/browser/ui/search/instant_controller.cc b/chrome/browser/ui/search/instant_controller.cc index d878b34..26c0917 100644 --- a/chrome/browser/ui/search/instant_controller.cc +++ b/chrome/browser/ui/search/instant_controller.cc @@ -52,15 +52,16 @@ void EnsureSearchTermsAreSet(content::WebContents* contents, return; const content::NavigationEntry* entry = controller->GetLastCommittedEntry(); - content::NavigationEntry* transient = controller->CreateNavigationEntry( - entry->GetURL(), - entry->GetReferrer(), - entry->GetTransitionType(), - false, - std::string(), - contents->GetBrowserContext()); + scoped_ptr<content::NavigationEntry> transient = + controller->CreateNavigationEntry( + entry->GetURL(), + entry->GetReferrer(), + entry->GetTransitionType(), + false, + std::string(), + contents->GetBrowserContext()); transient->SetExtraData(sessions::kSearchTermsKey, search_terms); - controller->SetTransientEntry(transient); + controller->SetTransientEntry(transient.Pass()); SearchTabHelper::FromWebContents(contents)->NavigationEntryUpdated(); } diff --git a/content/browser/frame_host/interstitial_page_impl.cc b/content/browser/frame_host/interstitial_page_impl.cc index 88d720f..5ea2162 100644 --- a/content/browser/frame_host/interstitial_page_impl.cc +++ b/content/browser/frame_host/interstitial_page_impl.cc @@ -234,15 +234,16 @@ void InterstitialPageImpl::Show() { (*g_web_contents_to_interstitial_page)[web_contents_] = this; if (new_navigation_) { - NavigationEntryImpl* entry = new NavigationEntryImpl; + scoped_ptr<NavigationEntryImpl> entry = + make_scoped_ptr(new NavigationEntryImpl); entry->SetURL(url_); entry->SetVirtualURL(url_); entry->set_page_type(PAGE_TYPE_INTERSTITIAL); // Give delegates a chance to set some states on the navigation entry. - delegate_->OverrideEntry(entry); + delegate_->OverrideEntry(entry.get()); - controller_->SetTransientEntry(entry); + controller_->SetTransientEntry(entry.Pass()); } DCHECK(!render_view_host_); diff --git a/content/browser/frame_host/navigation_controller_impl.cc b/content/browser/frame_host/navigation_controller_impl.cc index 3581367..4e610e8 100644 --- a/content/browser/frame_host/navigation_controller_impl.cc +++ b/content/browser/frame_host/navigation_controller_impl.cc @@ -94,7 +94,7 @@ NavigationEntryImpl::RestoreType ControllerRestoreTypeToEntryType( // Configure all the NavigationEntries in entries for restore. This resets // the transition type to reload and makes sure the content state isn't empty. void ConfigureEntriesForRestore( - std::vector<linked_ptr<NavigationEntryImpl> >* entries, + ScopedVector<NavigationEntryImpl>* entries, NavigationController::RestoreType type) { for (size_t i = 0; i < entries->size(); ++i) { // Use a transition type of reload so that we don't incorrectly increase @@ -102,7 +102,7 @@ void ConfigureEntriesForRestore( (*entries)[i]->SetTransitionType(ui::PAGE_TRANSITION_RELOAD); (*entries)[i]->set_restore_type(ControllerRestoreTypeToEntryType(type)); // NOTE(darin): This code is only needed for backwards compat. - SetPageStateIfEmpty((*entries)[i].get()); + SetPageStateIfEmpty((*entries)[i]); } } @@ -127,7 +127,7 @@ size_t NavigationControllerImpl::max_entry_count_for_testing_ = static bool g_check_for_repost = true; // static -NavigationEntry* NavigationController::CreateNavigationEntry( +scoped_ptr<NavigationEntry> NavigationController::CreateNavigationEntry( const GURL& url, const Referrer& referrer, ui::PageTransition transition, @@ -162,7 +162,7 @@ NavigationEntry* NavigationController::CreateNavigationEntry( entry->set_user_typed_url(dest_url); entry->set_update_virtual_url_with_url(reverse_on_redirect); entry->set_extra_headers(extra_headers); - return entry; + return make_scoped_ptr(entry); } // static @@ -228,7 +228,7 @@ void NavigationControllerImpl::SetBrowserContext( void NavigationControllerImpl::Restore( int selected_navigation, RestoreType type, - std::vector<NavigationEntry*>* entries) { + ScopedVector<NavigationEntry>* entries) { // Verify that this controller is unused and that the input is valid. DCHECK(GetEntryCount() == 0 && !GetPendingEntry()); DCHECK(selected_navigation >= 0 && @@ -238,9 +238,9 @@ void NavigationControllerImpl::Restore( for (size_t i = 0; i < entries->size(); ++i) { NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry((*entries)[i]); - entries_.push_back(linked_ptr<NavigationEntryImpl>(entry)); + entries_.push_back(entry); } - entries->clear(); + entries->weak_clear(); // And finish the restore. FinishRestore(selected_navigation, type); @@ -331,11 +331,13 @@ void NavigationControllerImpl::ReloadInternal(bool check_for_repost, if (!is_for_guests_only && site_instance && site_instance->HasWrongProcessForURL(entry->GetURL())) { // Create a navigation entry that resembles the current one, but do not - // copy page id, site instance, content state, or timestamp. + // copy page id, site instance, content state, or timestamp. TODO(avi): + // This seems wrong. We're setting |pending_entry_| to a different value + // than what |pending_entry_index_| points to. Doesn't this leak? NavigationEntryImpl* nav_entry = NavigationEntryImpl::FromNavigationEntry( CreateNavigationEntry( entry->GetURL(), entry->GetReferrer(), entry->GetTransitionType(), - false, entry->extra_headers(), browser_context_)); + false, entry->extra_headers(), browser_context_).release()); // Mark the reload type as NO_RELOAD, so navigation will not be considered // a reload in the renderer. @@ -381,7 +383,7 @@ bool NavigationControllerImpl::IsInitialNavigation() const { NavigationEntryImpl* NavigationControllerImpl::GetEntryWithPageID( SiteInstance* instance, int32 page_id) const { int index = GetEntryIndexWithPageID(instance, page_id); - return (index != -1) ? entries_[index].get() : NULL; + return (index != -1) ? entries_[index] : nullptr; } bool NavigationControllerImpl::HasCommittedRealLoad( @@ -390,26 +392,28 @@ bool NavigationControllerImpl::HasCommittedRealLoad( return last_committed && last_committed->HasFrameEntry(frame_tree_node); } -void NavigationControllerImpl::LoadEntry(NavigationEntryImpl* entry) { +void NavigationControllerImpl::LoadEntry( + scoped_ptr<NavigationEntryImpl> entry) { // When navigating to a new page, we don't know for sure if we will actually // end up leaving the current page. The new page load could for example // result in a download or a 'no content' response (e.g., a mailto: URL). - SetPendingEntry(entry); + SetPendingEntry(entry.Pass()); NavigateToPendingEntry(NO_RELOAD); } -void NavigationControllerImpl::SetPendingEntry(NavigationEntryImpl* entry) { +void NavigationControllerImpl::SetPendingEntry( + scoped_ptr<NavigationEntryImpl> entry) { DiscardNonCommittedEntriesInternal(); - pending_entry_ = entry; + pending_entry_ = entry.release(); NotificationService::current()->Notify( NOTIFICATION_NAV_ENTRY_PENDING, Source<NavigationController>(this), - Details<NavigationEntry>(entry)); + Details<NavigationEntry>(pending_entry_)); } NavigationEntryImpl* NavigationControllerImpl::GetActiveEntry() const { if (transient_entry_index_ != -1) - return entries_[transient_entry_index_].get(); + return entries_[transient_entry_index_]; if (pending_entry_) return pending_entry_; return GetLastCommittedEntry(); @@ -417,7 +421,7 @@ NavigationEntryImpl* NavigationControllerImpl::GetActiveEntry() const { NavigationEntryImpl* NavigationControllerImpl::GetVisibleEntry() const { if (transient_entry_index_ != -1) - return entries_[transient_entry_index_].get(); + return entries_[transient_entry_index_]; // The pending entry is safe to return for new (non-history), browser- // initiated navigations. Most renderer-initiated navigations should not // show the pending entry, to prevent URL spoof attacks. @@ -459,7 +463,7 @@ int NavigationControllerImpl::GetCurrentEntryIndex() const { NavigationEntryImpl* NavigationControllerImpl::GetLastCommittedEntry() const { if (last_committed_entry_index_ == -1) return NULL; - return entries_[last_committed_entry_index_].get(); + return entries_[last_committed_entry_index_]; } bool NavigationControllerImpl::CanViewSource() const { @@ -483,16 +487,19 @@ int NavigationControllerImpl::GetEntryCount() const { NavigationEntryImpl* NavigationControllerImpl::GetEntryAtIndex( int index) const { - return entries_.at(index).get(); + if (index < 0 || index >= GetEntryCount()) + return nullptr; + + return entries_[index]; } NavigationEntryImpl* NavigationControllerImpl::GetEntryAtOffset( int offset) const { int index = GetIndexForOffset(offset); if (index < 0 || index >= GetEntryCount()) - return NULL; + return nullptr; - return entries_[index].get(); + return entries_[index]; } int NavigationControllerImpl::GetIndexForOffset(int offset) const { @@ -695,14 +702,14 @@ void NavigationControllerImpl::LoadURLWithParams(const LoadURLParams& params) { break; } - NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( - CreateNavigationEntry( + scoped_ptr<NavigationEntryImpl> entry + (NavigationEntryImpl::FromNavigationEntry(CreateNavigationEntry( params.url, params.referrer, params.transition_type, params.is_renderer_initiated, params.extra_headers, - browser_context_)); + browser_context_))); if (!params.frame_name.empty()) { // This is only used for navigating subframes in tests. FrameTreeNode* named_frame = @@ -751,7 +758,7 @@ void NavigationControllerImpl::LoadURLWithParams(const LoadURLParams& params) { break; }; - LoadEntry(entry); + LoadEntry(entry.Pass()); } bool NavigationControllerImpl::RendererDidNavigate( @@ -1006,7 +1013,7 @@ NavigationType NavigationControllerImpl::ClassifyNavigation( rfh->render_view_host()->Send(new ViewMsg_TempCrashWithData(url)); return NAVIGATION_TYPE_NAV_IGNORE; } - NavigationEntryImpl* existing_entry = entries_[existing_entry_index].get(); + NavigationEntryImpl* existing_entry = entries_[existing_entry_index]; if (rfh->GetParent()) { // All manual subframes would get new IDs and were handled above, so we @@ -1175,7 +1182,7 @@ void NavigationControllerImpl::RendererDidNavigateToNewPage( RenderFrameHostImpl* rfh, const FrameHostMsg_DidCommitProvisionalLoad_Params& params, bool replace_entry) { - NavigationEntryImpl* new_entry; + scoped_ptr<NavigationEntryImpl> new_entry; bool update_virtual_url; // Only make a copy of the pending entry if it is appropriate for the new page // that was just loaded. We verify this at a coarse grain by checking that @@ -1187,7 +1194,7 @@ void NavigationControllerImpl::RendererDidNavigateToNewPage( update_virtual_url = new_entry->update_virtual_url_with_url(); } else { - new_entry = new NavigationEntryImpl; + new_entry = make_scoped_ptr(new NavigationEntryImpl); // Find out whether the new entry needs to update its virtual URL on URL // change and set up the entry accordingly. This is needed to correctly @@ -1212,7 +1219,7 @@ void NavigationControllerImpl::RendererDidNavigateToNewPage( : PAGE_TYPE_NORMAL); new_entry->SetURL(params.url); if (update_virtual_url) - UpdateVirtualURLToURL(new_entry, params.url); + UpdateVirtualURLToURL(new_entry.get(), params.url); new_entry->SetReferrer(params.referrer); new_entry->SetPageID(params.page_id); new_entry->SetTransitionType(params.transition); @@ -1241,7 +1248,7 @@ void NavigationControllerImpl::RendererDidNavigateToNewPage( last_committed_entry_index_ = -1; } - InsertOrReplaceEntry(new_entry, replace_entry); + InsertOrReplaceEntry(new_entry.Pass(), replace_entry); } void NavigationControllerImpl::RendererDidNavigateToExistingPage( @@ -1257,7 +1264,7 @@ void NavigationControllerImpl::RendererDidNavigateToExistingPage( params.page_id); DCHECK(entry_index >= 0 && entry_index < static_cast<int>(entries_.size())); - NavigationEntryImpl* entry = entries_[entry_index].get(); + NavigationEntryImpl* entry = entries_[entry_index]; // The URL may have changed due to redirects. entry->set_page_type(params.url_is_unreachable ? PAGE_TYPE_ERROR @@ -1394,7 +1401,7 @@ void NavigationControllerImpl::RendererDidNavigateNewSubframe( DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee " << "that a last committed entry exists."; - NavigationEntryImpl* new_entry = nullptr; + scoped_ptr<NavigationEntryImpl> new_entry; if (base::CommandLine::ForCurrentProcess()->HasSwitch( switches::kSitePerProcess)) { // Make sure new_entry takes ownership of frame_entry in a scoped_refptr. @@ -1409,7 +1416,7 @@ void NavigationControllerImpl::RendererDidNavigateNewSubframe( } new_entry->SetPageID(params.page_id); - InsertOrReplaceEntry(new_entry, false); + InsertOrReplaceEntry(new_entry.Pass(), false); } bool NavigationControllerImpl::RendererDidNavigateAutoSubframe( @@ -1780,15 +1787,15 @@ int NavigationControllerImpl::GetPendingEntryIndex() const { return pending_entry_index_; } -void NavigationControllerImpl::InsertOrReplaceEntry(NavigationEntryImpl* entry, - bool replace) { +void NavigationControllerImpl::InsertOrReplaceEntry( + scoped_ptr<NavigationEntryImpl> entry, bool replace) { DCHECK(entry->GetTransitionType() != ui::PAGE_TRANSITION_AUTO_SUBFRAME); // Copy the pending entry's unique ID to the committed entry. // I don't know if pending_entry_index_ can be other than -1 here. const NavigationEntryImpl* const pending_entry = (pending_entry_index_ == -1) ? - pending_entry_ : entries_[pending_entry_index_].get(); + pending_entry_ : entries_[pending_entry_index_]; if (pending_entry) entry->set_unique_id(pending_entry->GetUniqueID()); @@ -1818,11 +1825,12 @@ void NavigationControllerImpl::InsertOrReplaceEntry(NavigationEntryImpl* entry, PruneOldestEntryIfFull(); - entries_.push_back(linked_ptr<NavigationEntryImpl>(entry)); + int32 page_id = entry->GetPageID(); + entries_.push_back(entry.Pass()); last_committed_entry_index_ = static_cast<int>(entries_.size()) - 1; // This is a new page ID, so we need everybody to know about it. - delegate_->UpdateMaxPageID(entry->GetPageID()); + delegate_->UpdateMaxPageID(page_id); } void NavigationControllerImpl::PruneOldestEntryIfFull() { @@ -1872,7 +1880,7 @@ void NavigationControllerImpl::NavigateToPendingEntry(ReloadType reload_type) { // For session history navigations only the pending_entry_index_ is set. if (!pending_entry_) { DCHECK_NE(pending_entry_index_, -1); - pending_entry_ = entries_[pending_entry_index_].get(); + pending_entry_ = entries_[pending_entry_index_]; } // This call does not support re-entrancy. See http://crbug.com/347742. @@ -2017,18 +2025,18 @@ int NavigationControllerImpl::GetEntryIndexWithUniqueID( NavigationEntryImpl* NavigationControllerImpl::GetTransientEntry() const { if (transient_entry_index_ == -1) return NULL; - return entries_[transient_entry_index_].get(); + return entries_[transient_entry_index_]; } -void NavigationControllerImpl::SetTransientEntry(NavigationEntry* entry) { +void NavigationControllerImpl::SetTransientEntry( + scoped_ptr<NavigationEntry> entry) { // Discard any current transient entry, we can only have one at a time. int index = 0; if (last_committed_entry_index_ != -1) index = last_committed_entry_index_ + 1; DiscardTransientEntry(); - entries_.insert( - entries_.begin() + index, linked_ptr<NavigationEntryImpl>( - NavigationEntryImpl::FromNavigationEntry(entry))); + entries_.insert(entries_.begin() + index, + NavigationEntryImpl::FromNavigationEntry(entry.release())); transient_entry_index_ = index; delegate_->NotifyNavigationStateChanged(INVALIDATE_TYPE_ALL); } @@ -2040,13 +2048,12 @@ void NavigationControllerImpl::InsertEntriesFrom( size_t insert_index = 0; for (int i = 0; i < max_index; i++) { // When cloning a tab, copy all entries except interstitial pages. - if (source.entries_[i].get()->GetPageType() != PAGE_TYPE_INTERSTITIAL) { + if (source.entries_[i]->GetPageType() != PAGE_TYPE_INTERSTITIAL) { // TODO(creis): Once we start sharing FrameNavigationEntries between // NavigationEntries, it will not be safe to share them with another tab. // Must have a version of Clone that recreates them. entries_.insert(entries_.begin() + insert_index++, - linked_ptr<NavigationEntryImpl>( - source.entries_[i]->Clone())); + source.entries_[i]->Clone().Pass()); } } } diff --git a/content/browser/frame_host/navigation_controller_impl.h b/content/browser/frame_host/navigation_controller_impl.h index 91fb27d..7be667f 100644 --- a/content/browser/frame_host/navigation_controller_impl.h +++ b/content/browser/frame_host/navigation_controller_impl.h @@ -8,7 +8,7 @@ #include "base/callback.h" #include "base/compiler_specific.h" #include "base/gtest_prod_util.h" -#include "base/memory/linked_ptr.h" +#include "base/memory/scoped_vector.h" #include "base/time/time.h" #include "build/build_config.h" #include "content/browser/frame_host/navigation_controller_delegate.h" @@ -40,7 +40,7 @@ class CONTENT_EXPORT NavigationControllerImpl void SetBrowserContext(BrowserContext* browser_context) override; void Restore(int selected_navigation, RestoreType type, - std::vector<NavigationEntry*>* entries) override; + ScopedVector<NavigationEntry>* entries) override; NavigationEntryImpl* GetActiveEntry() const override; NavigationEntryImpl* GetVisibleEntry() const override; int GetCurrentEntryIndex() const override; @@ -54,7 +54,7 @@ class CONTENT_EXPORT NavigationControllerImpl NavigationEntryImpl* GetPendingEntry() const override; int GetPendingEntryIndex() const override; NavigationEntryImpl* GetTransientEntry() const override; - void SetTransientEntry(NavigationEntry* entry) override; + void SetTransientEntry(scoped_ptr<NavigationEntry> entry) override; void LoadURL(const GURL& url, const Referrer& referrer, ui::PageTransition type, @@ -130,7 +130,7 @@ class CONTENT_EXPORT NavigationControllerImpl // Allow renderer-initiated navigations to create a pending entry when the // provisional load starts. - void SetPendingEntry(content::NavigationEntryImpl* entry); + void SetPendingEntry(scoped_ptr<NavigationEntryImpl> entry); // Handles updating the navigation state after the renderer has navigated. // This is used by the WebContentsImpl. @@ -249,7 +249,7 @@ class CONTENT_EXPORT NavigationControllerImpl // Causes the controller to load the specified entry. The function assumes // ownership of the pointer since it is put in the navigation list. // NOTE: Do not pass an entry that the controller already owns! - void LoadEntry(NavigationEntryImpl* entry); + void LoadEntry(scoped_ptr<NavigationEntryImpl> entry); // Handlers for the different types of navigation types. They will actually // handle the navigations corresponding to the different NavClasses above. @@ -306,7 +306,8 @@ class CONTENT_EXPORT NavigationControllerImpl // Inserts a new entry or replaces the current entry with a new one, removing // all entries after it. The new entry will become the active one. - void InsertOrReplaceEntry(NavigationEntryImpl* entry, bool replace); + void InsertOrReplaceEntry(scoped_ptr<NavigationEntryImpl> entry, + bool replace); // Removes the entry at |index|, as long as it is not the current entry. void RemoveEntryAtIndexInternal(int index); @@ -348,7 +349,7 @@ class CONTENT_EXPORT NavigationControllerImpl BrowserContext* browser_context_; // List of NavigationEntry for this tab - typedef std::vector<linked_ptr<NavigationEntryImpl> > NavigationEntries; + using NavigationEntries = ScopedVector<NavigationEntryImpl>; NavigationEntries entries_; // An entry we haven't gotten a response for yet. This will be discarded diff --git a/content/browser/frame_host/navigation_controller_impl_unittest.cc b/content/browser/frame_host/navigation_controller_impl_unittest.cc index 1d855cf..a006219 100644 --- a/content/browser/frame_host/navigation_controller_impl_unittest.cc +++ b/content/browser/frame_host/navigation_controller_impl_unittest.cc @@ -2833,16 +2833,17 @@ TEST_F(NavigationControllerTest, EnforceMaxNavigationCount) { TEST_F(NavigationControllerTest, RestoreNavigate) { // Create a NavigationController with a restored set of tabs. GURL url("http://foo"); - std::vector<NavigationEntry*> entries; - NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( - url, Referrer(), ui::PAGE_TRANSITION_RELOAD, false, std::string(), - browser_context()); + ScopedVector<NavigationEntry> entries; + scoped_ptr<NavigationEntry> entry = + NavigationControllerImpl::CreateNavigationEntry( + url, Referrer(), ui::PAGE_TRANSITION_RELOAD, false, std::string(), + browser_context()); entry->SetPageID(0); entry->SetTitle(base::ASCIIToUTF16("Title")); entry->SetPageState(PageState::CreateFromEncodedData("state")); const base::Time timestamp = base::Time::Now(); entry->SetTimestamp(timestamp); - entries.push_back(entry); + entries.push_back(entry.Pass()); scoped_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( WebContents::Create(WebContents::CreateParams(browser_context())))); NavigationControllerImpl& our_controller = our_contents->GetController(); @@ -2909,14 +2910,15 @@ TEST_F(NavigationControllerTest, RestoreNavigate) { TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { // Create a NavigationController with a restored set of tabs. GURL url("http://foo"); - std::vector<NavigationEntry*> entries; - NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( - url, Referrer(), ui::PAGE_TRANSITION_RELOAD, false, std::string(), - browser_context()); - entry->SetPageID(0); - entry->SetTitle(base::ASCIIToUTF16("Title")); - entry->SetPageState(PageState::CreateFromEncodedData("state")); - entries.push_back(entry); + ScopedVector<NavigationEntry> entries; + scoped_ptr<NavigationEntry> new_entry = + NavigationControllerImpl::CreateNavigationEntry( + url, Referrer(), ui::PAGE_TRANSITION_RELOAD, false, std::string(), + browser_context()); + new_entry->SetPageID(0); + new_entry->SetTitle(base::ASCIIToUTF16("Title")); + new_entry->SetPageState(PageState::CreateFromEncodedData("state")); + entries.push_back(new_entry.Pass()); scoped_ptr<WebContentsImpl> our_contents(static_cast<WebContentsImpl*>( WebContents::Create(WebContents::CreateParams(browser_context())))); NavigationControllerImpl& our_controller = our_contents->GetController(); @@ -2930,7 +2932,7 @@ TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { // Before navigating to the restored entry, it should have a restore_type // and no SiteInstance. - entry = our_controller.GetEntryAtIndex(0); + NavigationEntry* entry = our_controller.GetEntryAtIndex(0); EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY, our_controller.GetEntryAtIndex(0)->restore_type()); EXPECT_FALSE(our_controller.GetEntryAtIndex(0)->site_instance()); @@ -3159,9 +3161,9 @@ TEST_F(NavigationControllerTest, TransientEntry) { notifications.Reset(); // Adding a transient with no pending entry. - NavigationEntryImpl* transient_entry = new NavigationEntryImpl; + scoped_ptr<NavigationEntry> transient_entry(new NavigationEntryImpl); transient_entry->SetURL(transient_url); - controller.SetTransientEntry(transient_entry); + controller.SetTransientEntry(transient_entry.Pass()); // We should not have received any notifications. EXPECT_EQ(0U, notifications.size()); @@ -3189,9 +3191,9 @@ TEST_F(NavigationControllerTest, TransientEntry) { EXPECT_EQ(controller.GetEntryCount(), 3); // Add a transient again, then navigate with no pending entry this time. - transient_entry = new NavigationEntryImpl; + transient_entry.reset(new NavigationEntryImpl); transient_entry->SetURL(transient_url); - controller.SetTransientEntry(transient_entry); + controller.SetTransientEntry(transient_entry.Pass()); EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); main_test_rfh()->SendRendererInitiatedNavigationRequest(url3, true); main_test_rfh()->PrepareForCommit(); @@ -3204,9 +3206,9 @@ TEST_F(NavigationControllerTest, TransientEntry) { controller.LoadURL( url4, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); entry_id = controller.GetPendingEntry()->GetUniqueID(); - transient_entry = new NavigationEntryImpl; + transient_entry.reset(new NavigationEntryImpl); transient_entry->SetURL(transient_url); - controller.SetTransientEntry(transient_entry); + controller.SetTransientEntry(transient_entry.Pass()); EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); main_test_rfh()->PrepareForCommit(); main_test_rfh()->SendNavigate(4, entry_id, true, url4); @@ -3214,9 +3216,9 @@ TEST_F(NavigationControllerTest, TransientEntry) { EXPECT_EQ(controller.GetEntryCount(), 5); // Add a transient and go back. This should simply remove the transient. - transient_entry = new NavigationEntryImpl; + transient_entry.reset(new NavigationEntryImpl); transient_entry->SetURL(transient_url); - controller.SetTransientEntry(transient_entry); + controller.SetTransientEntry(transient_entry.Pass()); EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); EXPECT_TRUE(controller.CanGoBack()); EXPECT_FALSE(controller.CanGoForward()); @@ -3232,9 +3234,9 @@ TEST_F(NavigationControllerTest, TransientEntry) { main_test_rfh()->SendNavigate(3, entry_id, false, url3); // Add a transient and go to an entry before the current one. - transient_entry = new NavigationEntryImpl; + transient_entry.reset(new NavigationEntryImpl); transient_entry->SetURL(transient_url); - controller.SetTransientEntry(transient_entry); + controller.SetTransientEntry(transient_entry.Pass()); EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); controller.GoToIndex(1); entry_id = controller.GetPendingEntry()->GetUniqueID(); @@ -3248,9 +3250,9 @@ TEST_F(NavigationControllerTest, TransientEntry) { EXPECT_EQ(url1, controller.GetVisibleEntry()->GetURL()); // Add a transient and go to an entry after the current one. - transient_entry = new NavigationEntryImpl; + transient_entry.reset(new NavigationEntryImpl); transient_entry->SetURL(transient_url); - controller.SetTransientEntry(transient_entry); + controller.SetTransientEntry(transient_entry.Pass()); EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); controller.GoToIndex(3); entry_id = controller.GetPendingEntry()->GetUniqueID(); @@ -3264,9 +3266,9 @@ TEST_F(NavigationControllerTest, TransientEntry) { EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); // Add a transient and go forward. - transient_entry = new NavigationEntryImpl; + transient_entry.reset(new NavigationEntryImpl); transient_entry->SetURL(transient_url); - controller.SetTransientEntry(transient_entry); + controller.SetTransientEntry(transient_entry.Pass()); EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); EXPECT_TRUE(controller.CanGoForward()); controller.GoForward(); @@ -3280,9 +3282,9 @@ TEST_F(NavigationControllerTest, TransientEntry) { EXPECT_EQ(url3, controller.GetVisibleEntry()->GetURL()); // Add a transient and do an in-page navigation, replacing the current entry. - transient_entry = new NavigationEntryImpl; + transient_entry.reset(new NavigationEntryImpl); transient_entry->SetURL(transient_url); - controller.SetTransientEntry(transient_entry); + controller.SetTransientEntry(transient_entry.Pass()); EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); main_test_rfh()->SendRendererInitiatedNavigationRequest(url3_ref, false); @@ -3318,9 +3320,9 @@ TEST_F(NavigationControllerTest, ReloadTransient) { url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); // A transient entry is added, interrupting the navigation. - NavigationEntryImpl* transient_entry = new NavigationEntryImpl; + scoped_ptr<NavigationEntry> transient_entry(new NavigationEntryImpl); transient_entry->SetURL(transient_url); - controller.SetTransientEntry(transient_entry); + controller.SetTransientEntry(transient_entry.Pass()); EXPECT_TRUE(controller.GetTransientEntry()); EXPECT_EQ(transient_url, controller.GetVisibleEntry()->GetURL()); @@ -3811,7 +3813,7 @@ TEST_F(NavigationControllerTest, CloneOmitsInterstitials) { // Add an interstitial entry. Should be deleted with controller. NavigationEntryImpl* interstitial_entry = new NavigationEntryImpl(); interstitial_entry->set_page_type(PAGE_TYPE_INTERSTITIAL); - controller.SetTransientEntry(interstitial_entry); + controller.SetTransientEntry(make_scoped_ptr(interstitial_entry)); scoped_ptr<WebContents> clone(controller.GetWebContents()->Clone()); @@ -4407,13 +4409,14 @@ TEST_F(NavigationControllerTest, CopyRestoredStateAndNavigate) { }; const GURL kInitialUrl("http://site3.com"); - std::vector<NavigationEntry*> entries; + ScopedVector<NavigationEntry> entries; for (size_t i = 0; i < arraysize(kRestoredUrls); ++i) { - NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( - kRestoredUrls[i], Referrer(), ui::PAGE_TRANSITION_RELOAD, false, - std::string(), browser_context()); + scoped_ptr<NavigationEntry> entry = + NavigationControllerImpl::CreateNavigationEntry( + kRestoredUrls[i], Referrer(), ui::PAGE_TRANSITION_RELOAD, false, + std::string(), browser_context()); entry->SetPageID(static_cast<int>(i)); - entries.push_back(entry); + entries.push_back(entry.Pass()); } // Create a WebContents with restored entries. diff --git a/content/browser/frame_host/navigation_entry_impl.cc b/content/browser/frame_host/navigation_entry_impl.cc index d170f4d..76d7306 100644 --- a/content/browser/frame_host/navigation_entry_impl.cc +++ b/content/browser/frame_host/navigation_entry_impl.cc @@ -68,8 +68,8 @@ NavigationEntryImpl::TreeNode::CloneAndReplace( return copy.Pass(); } -NavigationEntry* NavigationEntry::Create() { - return new NavigationEntryImpl(); +scoped_ptr<NavigationEntry> NavigationEntry::Create() { + return make_scoped_ptr(new NavigationEntryImpl()).Pass(); } NavigationEntryImpl* NavigationEntryImpl::FromNavigationEntry( @@ -82,6 +82,11 @@ const NavigationEntryImpl* NavigationEntryImpl::FromNavigationEntry( return static_cast<const NavigationEntryImpl*>(entry); } +scoped_ptr<NavigationEntryImpl> NavigationEntryImpl::FromNavigationEntry( + scoped_ptr<NavigationEntry> entry) { + return make_scoped_ptr(FromNavigationEntry(entry.release())); +} + NavigationEntryImpl::NavigationEntryImpl() : NavigationEntryImpl(nullptr, -1, GURL(), Referrer(), base::string16(), ui::PAGE_TRANSITION_LINK, false) { @@ -365,14 +370,15 @@ void NavigationEntryImpl::ClearExtraData(const std::string& key) { extra_data_.erase(key); } -NavigationEntryImpl* NavigationEntryImpl::Clone() const { +scoped_ptr<NavigationEntryImpl> NavigationEntryImpl::Clone() const { return NavigationEntryImpl::CloneAndReplace(nullptr, nullptr); } -NavigationEntryImpl* NavigationEntryImpl::CloneAndReplace( +scoped_ptr<NavigationEntryImpl> NavigationEntryImpl::CloneAndReplace( FrameTreeNode* frame_tree_node, FrameNavigationEntry* frame_navigation_entry) const { - NavigationEntryImpl* copy = new NavigationEntryImpl(); + scoped_ptr<NavigationEntryImpl> copy = + make_scoped_ptr(new NavigationEntryImpl()); // TODO(creis): Only share the same FrameNavigationEntries if cloning within // the same tab. @@ -413,7 +419,7 @@ NavigationEntryImpl* NavigationEntryImpl::CloneAndReplace( // ResetForCommit: intent_received_timestamp_ copy->extra_data_ = extra_data_; - return copy; + return copy.Pass(); } CommonNavigationParams NavigationEntryImpl::ConstructCommonNavigationParams( diff --git a/content/browser/frame_host/navigation_entry_impl.h b/content/browser/frame_host/navigation_entry_impl.h index a5ce6fc..e3b685c 100644 --- a/content/browser/frame_host/navigation_entry_impl.h +++ b/content/browser/frame_host/navigation_entry_impl.h @@ -59,6 +59,8 @@ class CONTENT_EXPORT NavigationEntryImpl static NavigationEntryImpl* FromNavigationEntry(NavigationEntry* entry); static const NavigationEntryImpl* FromNavigationEntry( const NavigationEntry* entry); + static scoped_ptr<NavigationEntryImpl> FromNavigationEntry( + scoped_ptr<NavigationEntry> entry); // The value of bindings() before it is set during commit. static int kInvalidBindings; @@ -128,7 +130,7 @@ class CONTENT_EXPORT NavigationEntryImpl // Creates a copy of this NavigationEntryImpl that can be modified // independently from the original. Does not copy any value that would be // cleared in ResetForCommit. - NavigationEntryImpl* Clone() const; + scoped_ptr<NavigationEntryImpl> Clone() const; // Like |Clone|, but replaces the FrameNavigationEntry corresponding to // |frame_tree_node| (and all its children) with |frame_entry|. @@ -136,8 +138,8 @@ class CONTENT_EXPORT NavigationEntryImpl // NavigationEntryImpls, we will need to support two versions of Clone: one // that shares the existing FrameNavigationEntries (for use within the same // tab) and one that draws them from a different pool (for use in a new tab). - NavigationEntryImpl* CloneAndReplace(FrameTreeNode* frame_tree_node, - FrameNavigationEntry* frame_entry) const; + scoped_ptr<NavigationEntryImpl> CloneAndReplace( + FrameTreeNode* frame_tree_node, FrameNavigationEntry* frame_entry) const; // Helper functions to construct NavigationParameters for a navigation to this // NavigationEntry. diff --git a/content/browser/frame_host/navigator_impl.cc b/content/browser/frame_host/navigator_impl.cc index 4b3143d..f82be14 100644 --- a/content/browser/frame_host/navigator_impl.cc +++ b/content/browser/frame_host/navigator_impl.cc @@ -897,11 +897,12 @@ void NavigatorImpl::DidStartMainFrameNavigation( bool has_browser_initiated_pending_entry = pending_entry && !pending_entry->is_renderer_initiated(); if (!has_browser_initiated_pending_entry) { - NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( - controller_->CreateNavigationEntry( - url, content::Referrer(), ui::PAGE_TRANSITION_LINK, - true /* is_renderer_initiated */, std::string(), - controller_->GetBrowserContext())); + scoped_ptr<NavigationEntryImpl> entry = + NavigationEntryImpl::FromNavigationEntry( + controller_->CreateNavigationEntry( + url, content::Referrer(), ui::PAGE_TRANSITION_LINK, + true /* is_renderer_initiated */, std::string(), + controller_->GetBrowserContext())); entry->set_site_instance(site_instance); // TODO(creis): If there's a pending entry already, find a safe way to // update it instead of replacing it and copying over things like this. @@ -911,7 +912,7 @@ void NavigatorImpl::DidStartMainFrameNavigation( entry->set_should_replace_entry(pending_entry->should_replace_entry()); entry->SetRedirectChain(pending_entry->GetRedirectChain()); } - controller_->SetPendingEntry(entry); + controller_->SetPendingEntry(entry.Pass()); if (delegate_) delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL); } diff --git a/content/browser/site_instance_impl_unittest.cc b/content/browser/site_instance_impl_unittest.cc index 4f90163..7267449e 100644 --- a/content/browser/site_instance_impl_unittest.cc +++ b/content/browser/site_instance_impl_unittest.cc @@ -243,27 +243,27 @@ TEST_F(SiteInstanceTest, CloneNavigationEntry) { TestSiteInstance::CreateTestSiteInstance(NULL, &site_delete_counter2, &browsing_delete_counter); - NavigationEntryImpl* e1 = new NavigationEntryImpl( + scoped_ptr<NavigationEntryImpl> e1 = make_scoped_ptr(new NavigationEntryImpl( instance1, 0, url, Referrer(), base::string16(), ui::PAGE_TRANSITION_LINK, - false); - // Clone the entry - NavigationEntryImpl* e2 = e1->Clone(); + false)); + // Clone the entry. + scoped_ptr<NavigationEntryImpl> e2 = e1->Clone(); // Should be able to change the SiteInstance of the cloned entry. e2->set_site_instance(instance2); - // The first SiteInstance should go away after deleting e1, since e2 should + // The first SiteInstance should go away after resetting e1, since e2 should // no longer be referencing it. - delete e1; + e1.reset(); EXPECT_EQ(1, site_delete_counter1); EXPECT_EQ(0, site_delete_counter2); - // The second SiteInstance should go away after deleting e2. - delete e2; + // The second SiteInstance should go away after resetting e2. + e2.reset(); EXPECT_EQ(1, site_delete_counter1); EXPECT_EQ(1, site_delete_counter2); - // Both BrowsingInstances are also now deleted + // Both BrowsingInstances are also now deleted. EXPECT_EQ(2, browsing_delete_counter); DrainMessageLoops(); diff --git a/content/browser/web_contents/web_contents_impl_unittest.cc b/content/browser/web_contents/web_contents_impl_unittest.cc index 7bd11f6..b44270f 100644 --- a/content/browser/web_contents/web_contents_impl_unittest.cc +++ b/content/browser/web_contents/web_contents_impl_unittest.cc @@ -804,20 +804,22 @@ TEST_F(WebContentsImplTest, NavigateFromRestoredSitelessUrl) { // SiteInstance. browser_client.set_assign_site_for_url(false); const GURL native_url("non-site-url://stuffandthings"); - std::vector<NavigationEntry*> entries; - NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( - native_url, Referrer(), ui::PAGE_TRANSITION_LINK, false, std::string(), - browser_context()); - entry->SetPageID(0); - entries.push_back(entry); + ScopedVector<NavigationEntry> entries; + scoped_ptr<NavigationEntry> new_entry = + NavigationControllerImpl::CreateNavigationEntry( + native_url, Referrer(), ui::PAGE_TRANSITION_LINK, false, + std::string(), browser_context()); + new_entry->SetPageID(0); + entries.push_back(new_entry.Pass()); controller().Restore( 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries); ASSERT_EQ(0u, entries.size()); ASSERT_EQ(1, controller().GetEntryCount()); + controller().GoToIndex(0); - entry = controller().GetPendingEntry(); + NavigationEntry* entry = controller().GetPendingEntry(); orig_rfh->PrepareForCommit(); contents()->TestDidNavigate(orig_rfh, 0, entry->GetUniqueID(), false, native_url, ui::PAGE_TRANSITION_RELOAD); @@ -852,20 +854,22 @@ TEST_F(WebContentsImplTest, NavigateFromRestoredRegularUrl) { // ShouldAssignSiteForUrl override is disabled (i.e. returns true). browser_client.set_assign_site_for_url(true); const GURL regular_url("http://www.yahoo.com"); - std::vector<NavigationEntry*> entries; - NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry( - regular_url, Referrer(), ui::PAGE_TRANSITION_LINK, false, std::string(), - browser_context()); - entry->SetPageID(0); - entries.push_back(entry); + ScopedVector<NavigationEntry> entries; + scoped_ptr<NavigationEntry> new_entry = + NavigationControllerImpl::CreateNavigationEntry( + regular_url, Referrer(), ui::PAGE_TRANSITION_LINK, false, + std::string(), browser_context()); + new_entry->SetPageID(0); + entries.push_back(new_entry.Pass()); controller().Restore( 0, NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY, &entries); ASSERT_EQ(0u, entries.size()); + ASSERT_EQ(1, controller().GetEntryCount()); controller().GoToIndex(0); - entry = controller().GetPendingEntry(); + NavigationEntry* entry = controller().GetPendingEntry(); orig_rfh->PrepareForCommit(); contents()->TestDidNavigate(orig_rfh, 0, entry->GetUniqueID(), false, regular_url, ui::PAGE_TRANSITION_RELOAD); diff --git a/content/public/browser/navigation_controller.h b/content/public/browser/navigation_controller.h index 7d890d5..9faceb4 100644 --- a/content/public/browser/navigation_controller.h +++ b/content/public/browser/navigation_controller.h @@ -10,6 +10,7 @@ #include <vector> #include "base/memory/ref_counted.h" +#include "base/memory/scoped_vector.h" #include "base/strings/string16.h" #include "content/common/content_export.h" #include "content/public/browser/global_request_id.h" @@ -102,7 +103,7 @@ class NavigationController { // Creates a navigation entry and translates the virtual url to a real one. // This is a general call; prefer LoadURL[FromRenderer]/TransferURL below. // Extra headers are separated by \n. - CONTENT_EXPORT static NavigationEntry* CreateNavigationEntry( + CONTENT_EXPORT static scoped_ptr<NavigationEntry> CreateNavigationEntry( const GURL& url, const Referrer& referrer, ui::PageTransition transition, @@ -217,11 +218,11 @@ class NavigationController { // using |selected_navigation| as the currently loaded entry. Before this call // the controller should be unused (there should be no current entry). |type| // indicates where the restor comes from. This takes ownership of the - // NavigationEntrys in |entries| and clears it out. This is used for session + // NavigationEntrys in |entries| and clears it out. This is used for session // restore. virtual void Restore(int selected_navigation, RestoreType type, - std::vector<NavigationEntry*>* entries) = 0; + ScopedVector<NavigationEntry>* entries) = 0; // Entries ------------------------------------------------------------------- @@ -310,7 +311,7 @@ class NavigationController { // represented as an entry, but should go away when the user navigates away // from them. // Note that adding a transient entry does not change the active contents. - virtual void SetTransientEntry(NavigationEntry* entry) = 0; + virtual void SetTransientEntry(scoped_ptr<NavigationEntry> entry) = 0; // New navigations ----------------------------------------------------------- diff --git a/content/public/browser/navigation_entry.h b/content/public/browser/navigation_entry.h index 9345f0f..7730281 100644 --- a/content/public/browser/navigation_entry.h +++ b/content/public/browser/navigation_entry.h @@ -8,6 +8,7 @@ #include <string> #include "base/memory/ref_counted_memory.h" +#include "base/memory/scoped_ptr.h" #include "base/strings/string16.h" #include "base/time/time.h" #include "content/common/content_export.h" @@ -31,7 +32,7 @@ class NavigationEntry { public: virtual ~NavigationEntry() {} - CONTENT_EXPORT static NavigationEntry* Create(); + CONTENT_EXPORT static scoped_ptr<NavigationEntry> Create(); // Page-related stuff -------------------------------------------------------- |