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

Unified Diff: chrome/browser/memory/tab_manager_web_contents_data.h

Issue 1427613002: [TabManager] Move remaining discard logic from TabStripModel to TabManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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_web_contents_data.h
diff --git a/chrome/browser/memory/tab_manager_web_contents_data.h b/chrome/browser/memory/tab_manager_web_contents_data.h
index 649da9815a2d943ee8a5a2eba020334a1d00d4c5..70efea89b01cf0d8b100b222423a1775ffd40020 100644
--- a/chrome/browser/memory/tab_manager_web_contents_data.h
+++ b/chrome/browser/memory/tab_manager_web_contents_data.h
@@ -5,9 +5,11 @@
#ifndef CHROME_BROWSER_MEMORY_TAB_MANAGER_WEB_CONTENTS_DATA_H_
#define CHROME_BROWSER_MEMORY_TAB_MANAGER_WEB_CONTENTS_DATA_H_
-#include "base/supports_user_data.h"
+#include "base/macros.h"
#include "base/time/time.h"
#include "chrome/browser/memory/tab_manager.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/browser/web_contents_user_data.h"
namespace content {
class WebContents;
@@ -15,69 +17,67 @@ class WebContents;
namespace memory {
-// Manages the information about the discarding state of a tab. This data is
-// stored in WebContents.
-class TabManager::WebContentsData : public base::SupportsUserData::Data {
+// Internal class used by TabManager to record the needed data for
+// WebContentses.
+class TabManager::WebContentsData
+ : public content::WebContentsObserver,
+ public content::WebContentsUserData<TabManager::WebContentsData> {
public:
- // Returns the WebContentsData associated with |web_contents|. It will create
- // one if none exists.
- static WebContentsData* Get(content::WebContents* web_contents);
+ explicit WebContentsData(content::WebContents* web_contents)
+ : WebContentsObserver(web_contents) {}
sky 2015/10/27 21:16:46 Don't inline this, and I wouldn't inline the destr
Georges Khalil 2015/10/30 14:17:44 Done.
- // Sets the WebContentsData of a |web_contents|. The object referenced by
- // |state| is now owned by |web_contents|
- static void Set(content::WebContents* web_contents, WebContentsData* state);
-
- // Copies the discard state from |old_contents| to |new_contents|.
- static void CopyState(content::WebContents* old_contents,
- content::WebContents* new_contents);
+ // WebContentsObserver implementation:
+ void DidStartLoading() override;
// Returns true if |web_contents| has been discarded to save memory.
- static bool IsDiscarded(content::WebContents* web_contents);
+ bool IsDiscarded();
// Sets/clears the discard state of |web_contents|.
- static void SetDiscardState(content::WebContents* web_contents, bool state);
+ void SetDiscardState(bool state);
// Returns the number of times |web_contents| has been discarded.
- static int DiscardCount(content::WebContents* web_contents);
+ int DiscardCount();
// Increments the number of times |web_contents| has been discarded.
- static void IncrementDiscardCount(content::WebContents* web_contents);
+ void IncrementDiscardCount();
// Returns true if audio has recently been audible from the WebContents.
- static bool IsRecentlyAudible(content::WebContents* web_contents);
+ bool IsRecentlyAudible();
// Set/clears the state of whether audio has recently been audible from the
// WebContents.
- static void SetRecentlyAudible(content::WebContents* web_contents,
- bool state);
+ void SetRecentlyAudible(bool state);
// Returns the timestamp of the last time |web_contents| changed its audio
// state.
- static base::TimeTicks LastAudioChangeTime(
- content::WebContents* web_contents);
+ base::TimeTicks LastAudioChangeTime();
// Sets the timestamp of the last time |web_contents| changed its audio state.
- static void SetLastAudioChangeTime(content::WebContents* web_contents,
- base::TimeTicks timestamp);
-
- private:
- WebContentsData();
-
- // Is the tab currently discarded?
- bool is_discarded_;
+ void SetLastAudioChangeTime(base::TimeTicks timestamp);
- // Number of times the tab has been discarded.
- int discard_count_;
-
- // Is the tab playing audio?
- bool is_recently_audible_;
-
- // Last time the tab started or stopped playing audio (we record the
- // transition time).
- base::TimeTicks last_audio_change_time_;
+ // Copies the discard state from |old_contents| to |new_contents|.
+ static void CopyState(content::WebContents* old_contents,
+ content::WebContents* new_contents);
- // The last time the tab was discarded.
- base::TimeTicks last_discard_time_;
+ private:
+ struct Data {
+ Data();
+ // Is the tab currently discarded?
+ bool is_discarded_;
+ // Number of times the tab has been discarded.
+ int discard_count_;
+ // Is the tab playing audio?
+ bool is_recently_audible_;
+ // Last time the tab started or stopped playing audio (we record the
+ // transition time).
+ base::TimeTicks last_audio_change_time_;
+ // The last time the tab was discarded.
+ base::TimeTicks last_discard_time_;
+ };
+
+ Data tab_data_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebContentsData);
};
} // namespace memory

Powered by Google App Engine
This is Rietveld 408576698