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

Unified Diff: chrome/browser/ui/tabs/tab_strip_model.cc

Issue 1332003002: Add option to disallow the discarding of a tab that was previously discarded. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sky@ and rkaplow@ comments. Created 5 years, 3 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/ui/tabs/tab_strip_model.h ('k') | chrome/browser/ui/tabs/tab_strip_model_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/tabs/tab_strip_model.cc
diff --git a/chrome/browser/ui/tabs/tab_strip_model.cc b/chrome/browser/ui/tabs/tab_strip_model.cc
index e9dca654abf35c708487e4e82e49ecfef6c93ab5..a005461387077d52003010394282de5feb1b06ae 100644
--- a/chrome/browser/ui/tabs/tab_strip_model.cc
+++ b/chrome/browser/ui/tabs/tab_strip_model.cc
@@ -18,6 +18,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/tab_contents/core_tab_helper.h"
#include "chrome/browser/ui/tab_contents/core_tab_helper_delegate.h"
+#include "chrome/browser/ui/tabs/tab_discard_state.h"
#include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
#include "chrome/browser/ui/tabs/tab_strip_model_order_controller.h"
#include "chrome/browser/ui/tabs/tab_utils.h"
@@ -48,6 +49,11 @@ void RecordUMATabDiscarding(UMATabDiscarding event) {
UMA_TAB_DISCARDING_TAB_DISCARDING_MAX);
}
+// Records the number of discards that a tab has been through.
+void RecordUMADiscardCount(int discard_count) {
+ UMA_HISTOGRAM_COUNTS("Tab.Discarding.DiscardCount", discard_count);
+}
+
// Returns true if the specified transition is one of the types that cause the
// opener relationships for the tab in which the transition occurred to be
// forgotten. This is generally any navigation that isn't a link click (i.e.
@@ -169,8 +175,6 @@ class TabStripModel::WebContentsData : public content::WebContentsObserver {
void set_pinned(bool value) { pinned_ = value; }
bool blocked() const { return blocked_; }
void set_blocked(bool value) { blocked_ = value; }
- bool discarded() const { return discarded_; }
- void set_discarded(bool value) { discarded_ = value; }
private:
// Make sure that if someone deletes this WebContents out from under us, it
@@ -218,9 +222,6 @@ class TabStripModel::WebContentsData : public content::WebContentsObserver {
// Is the tab interaction blocked by a modal dialog?
bool blocked_;
- // Has the tab data been discarded to save memory?
- bool discarded_;
-
DISALLOW_COPY_AND_ASSIGN(WebContentsData);
};
@@ -233,9 +234,7 @@ TabStripModel::WebContentsData::WebContentsData(TabStripModel* tab_strip_model,
opener_(NULL),
reset_group_on_select_(false),
pinned_(false),
- blocked_(false),
- discarded_(false) {
-}
+ blocked_(false) {}
void TabStripModel::WebContentsData::SetWebContents(WebContents* contents) {
contents_ = contents;
@@ -253,7 +252,7 @@ void TabStripModel::WebContentsData::WebContentsDestroyed() {
}
void TabStripModel::WebContentsData::DidStartLoading() {
- set_discarded(false);
+ TabDiscardState::SetDiscardState(contents_, false);
}
///////////////////////////////////////////////////////////////////////////////
@@ -401,13 +400,17 @@ WebContents* TabStripModel::DiscardWebContentsAt(int index) {
// Make sure we persist the last active time property.
null_contents->SetLastActiveTime(old_contents->GetLastActiveTime());
+ // Copy over the discard count.
+ TabDiscardState::CopyState(old_contents, null_contents);
// Replace the tab we're discarding with the null version.
ReplaceWebContentsAt(index, null_contents);
// Mark the tab so it will reload when we click.
- if (!contents_data_[index]->discarded()) {
- contents_data_[index]->set_discarded(true);
+ if (!TabDiscardState::IsDiscarded(null_contents)) {
+ TabDiscardState::SetDiscardState(null_contents, true);
+ TabDiscardState::IncrementDiscardCount(null_contents);
RecordUMATabDiscarding(UMA_TAB_DISCARDING_DISCARD_TAB);
+ RecordUMADiscardCount(TabDiscardState::DiscardCount(null_contents));
if (is_playing_audio)
RecordUMATabDiscarding(UMA_TAB_DISCARDING_DISCARD_TAB_AUDIO);
}
@@ -732,10 +735,6 @@ bool TabStripModel::IsTabBlocked(int index) const {
return contents_data_[index]->blocked();
}
-bool TabStripModel::IsTabDiscarded(int index) const {
- return contents_data_[index]->discarded();
-}
-
int TabStripModel::IndexOfFirstNonPinnedTab() const {
for (size_t i = 0; i < contents_data_.size(); ++i) {
if (!IsTabPinned(static_cast<int>(i)))
@@ -1327,13 +1326,7 @@ void TabStripModel::NotifyIfActiveTabChanged(WebContents* old_contents,
active_index(),
reason));
in_notify_ = false;
- // Activating a discarded tab reloads it, so it is no longer discarded.
- if (contents_data_[active_index()]->discarded()) {
- contents_data_[active_index()]->set_discarded(false);
- RecordUMATabDiscarding(UMA_TAB_DISCARDING_SWITCH_TO_DISCARDED_TAB);
- } else {
- RecordUMATabDiscarding(UMA_TAB_DISCARDING_SWITCH_TO_LOADED_TAB);
- }
+ TabDiscardState::SetDiscardState(new_contents, false);
}
}
« no previous file with comments | « chrome/browser/ui/tabs/tab_strip_model.h ('k') | chrome/browser/ui/tabs/tab_strip_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698