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

Unified Diff: chrome/browser/memory/tab_manager.cc

Issue 2250183002: New Public IdFromWebContents method on TabManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: implemented suggestion Created 4 years, 4 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
Index: chrome/browser/memory/tab_manager.cc
diff --git a/chrome/browser/memory/tab_manager.cc b/chrome/browser/memory/tab_manager.cc
index a99e6abdc048bd79f91e73bd4fe68c6b523fc5f1..8e0550808951784eb8a714cc38bdc4eec8342b36 100644
--- a/chrome/browser/memory/tab_manager.cc
+++ b/chrome/browser/memory/tab_manager.cc
@@ -88,12 +88,6 @@ const int kSuspendThresholdSeconds = kAdjustmentIntervalSeconds * 4;
// audible.
const int kAudioProtectionTimeSeconds = 60;
-// Returns a unique ID for a WebContents. Do not cast back to a pointer, as
-// the WebContents could be deleted if the user closed the tab.
-int64_t IdFromWebContents(WebContents* web_contents) {
- return reinterpret_cast<int64_t>(web_contents);
-}
-
int FindTabStripModelById(int64_t target_web_contents_id,
TabStripModel** model) {
DCHECK(model);
@@ -101,7 +95,7 @@ int FindTabStripModelById(int64_t target_web_contents_id,
TabStripModel* local_model = browser->tab_strip_model();
for (int idx = 0; idx < local_model->count(); idx++) {
WebContents* web_contents = local_model->GetWebContentsAt(idx);
- int64_t web_contents_id = IdFromWebContents(web_contents);
+ int64_t web_contents_id = TabManager::IdFromWebContents(web_contents);
if (web_contents_id == target_web_contents_id) {
*model = local_model;
return idx;
@@ -352,7 +346,7 @@ WebContents* TabManager::DiscardTabById(int64_t target_web_contents_id) {
WebContents* TabManager::DiscardTabByExtension(content::WebContents* contents) {
if (contents)
- return DiscardTabById(reinterpret_cast<int64_t>(contents));
+ return DiscardTabById(IdFromWebContents(contents));
return DiscardTabImpl();
}
@@ -465,6 +459,11 @@ bool TabManager::CompareTabStats(const TabStats& first,
return first.last_active > second.last_active;
}
+// static
+int64_t TabManager::IdFromWebContents(WebContents* web_contents) {
+ return reinterpret_cast<int64_t>(web_contents);
+}
+
///////////////////////////////////////////////////////////////////////////////
// TabManager, private:

Powered by Google App Engine
This is Rietveld 408576698