summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tabs/tab_strip_model.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-20 19:55:57 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-20 19:55:57 +0000
commitce3fa3c831cba1f44d34c1c66020f830be33a068 (patch)
treeda18dbdfb081c17949dca2dcfa0633142a63a868 /chrome/browser/tabs/tab_strip_model.cc
parent6ee6368c466235c5919c9b4d5cfe11f8e48b29ca (diff)
downloadchromium_src-ce3fa3c831cba1f44d34c1c66020f830be33a068.zip
chromium_src-ce3fa3c831cba1f44d34c1c66020f830be33a068.tar.gz
chromium_src-ce3fa3c831cba1f44d34c1c66020f830be33a068.tar.bz2
Re-land my change to clean up TabContents/WebContents ownership. This
is the same except in tab_strip_model_unittest I fixed a leak by making a WebContents on the stack, I added a factory to the SiteInstance unittest to prevent another leak, and I re-added a NULL set to the external_tab_container. Fix the ownership model of TabContents and NavigationController. Previously the NavigationController owned the TabContents, and there were extra steps required at creation and destruction to clean everything up properly. NavigationController is now a member of TabContents, and there is no setup or tear down necessary other than the constructor and destructor. I could remove the tab contents creation in the NavigationController, as well as all the weird destruction code in WebContents which got moved to the destructor. I made the controller getter return a reference since the ownership is clear and there is no possibility of NULL. This required changing a lot of tiles, but many of them were simplified since they no longer have to NULL check. Previous review URL: http://codereview.chromium.org/69043 Review URL: http://codereview.chromium.org/67294 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14053 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tabs/tab_strip_model.cc')
-rw-r--r--chrome/browser/tabs/tab_strip_model.cc26
1 files changed, 12 insertions, 14 deletions
diff --git a/chrome/browser/tabs/tab_strip_model.cc b/chrome/browser/tabs/tab_strip_model.cc
index 2fc7e51..0470efa 100644
--- a/chrome/browser/tabs/tab_strip_model.cc
+++ b/chrome/browser/tabs/tab_strip_model.cc
@@ -94,7 +94,7 @@ void TabStripModel::InsertTabContentsAt(int index,
ForgetAllOpeners();
}
// Anything opened by a link we deem to have an opener.
- data->SetGroup(selected_contents->controller());
+ data->SetGroup(&selected_contents->controller());
}
contents_data_.insert(contents_data_.begin() + index, data);
@@ -198,7 +198,7 @@ int TabStripModel::GetIndexOfController(
int index = 0;
TabContentsDataVector::const_iterator iter = contents_data_.begin();
for (; iter != contents_data_.end(); ++iter, ++index) {
- if ((*iter)->contents->controller() == controller)
+ if (&(*iter)->contents->controller() == controller)
return index;
}
return kNoTab;
@@ -403,10 +403,8 @@ bool TabStripModel::IsContextMenuCommandEnabled(
case CommandCloseTabsToRight:
return context_index < (count() - 1);
case CommandCloseTabsOpenedBy: {
- NavigationController* opener =
- GetTabContentsAt(context_index)->controller();
- int next_index =
- GetIndexOfNextTabContentsOpenedBy(opener, context_index, true);
+ int next_index = GetIndexOfNextTabContentsOpenedBy(
+ &GetTabContentsAt(context_index)->controller(), context_index, true);
return next_index != kNoTab;
}
case CommandDuplicate:
@@ -429,7 +427,7 @@ void TabStripModel::ExecuteContextMenuCommand(
break;
case CommandReload:
UserMetrics::RecordAction(L"TabContextMenu_Reload", profile_);
- GetContentsAt(context_index)->controller()->Reload(true);
+ GetContentsAt(context_index)->controller().Reload(true);
break;
case CommandDuplicate:
UserMetrics::RecordAction(L"TabContextMenu_Duplicate", profile_);
@@ -457,7 +455,7 @@ void TabStripModel::ExecuteContextMenuCommand(
case CommandCloseTabsOpenedBy: {
UserMetrics::RecordAction(L"TabContextMenu_CloseTabsOpenedBy", profile_);
NavigationController* opener =
- GetTabContentsAt(context_index)->controller();
+ &GetTabContentsAt(context_index)->controller();
for (int i = count() - 1; i >= 0; --i) {
if (OpenerMatches(contents_data_.at(i), opener, true))
@@ -478,7 +476,7 @@ void TabStripModel::ExecuteContextMenuCommand(
std::vector<int> TabStripModel::GetIndexesOpenedBy(int index) const {
std::vector<int> indices;
- NavigationController* opener = GetTabContentsAt(index)->controller();
+ NavigationController* opener = &GetTabContentsAt(index)->controller();
for (int i = count() - 1; i >= 0; --i) {
if (OpenerMatches(contents_data_.at(i), opener, true))
indices.push_back(i);
@@ -511,7 +509,7 @@ bool TabStripModel::IsNewTabAtEndOfTabStrip(TabContents* contents) const {
return LowerCaseEqualsASCII(contents->GetURL().spec(),
chrome::kChromeUINewTabURL) &&
contents == GetContentsAt(count() - 1) &&
- contents->controller()->entry_count() == 1;
+ contents->controller().entry_count() == 1;
}
bool TabStripModel::InternalCloseTabContentsAt(int index,
@@ -534,9 +532,9 @@ bool TabStripModel::InternalCloseTabContentsAt(int index,
if (create_historical_tab)
delegate_->CreateHistoricalTab(detached_contents);
- detached_contents->CloseContents();
- // Closing the TabContents will later call back to us via
- // NotificationObserver and detach it.
+ // Deleting the TabContents will call back to us via NotificationObserver
+ // and detach it.
+ delete detached_contents;
}
return true;
}
@@ -564,7 +562,7 @@ void TabStripModel::ChangeSelectedContentsFrom(
void TabStripModel::SetOpenerForContents(TabContents* contents,
TabContents* opener) {
int index = GetIndexOfTabContents(contents);
- contents_data_.at(index)->opener = opener->controller();
+ contents_data_.at(index)->opener = &opener->controller();
}
// static