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

Side by Side Diff: chrome/browser/memory/tab_manager_web_contents_data.h

Issue 2898033002: [TabManager] Move TabManager into chrome/browser/resource_coordinator. (Closed)
Patch Set: rebase Created 3 years, 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_MEMORY_TAB_MANAGER_WEB_CONTENTS_DATA_H_
6 #define CHROME_BROWSER_MEMORY_TAB_MANAGER_WEB_CONTENTS_DATA_H_
7
8 #include "base/macros.h"
9 #include "base/time/time.h"
10 #include "chrome/browser/memory/tab_manager.h"
11 #include "content/public/browser/web_contents_observer.h"
12 #include "content/public/browser/web_contents_user_data.h"
13
14 namespace base {
15 class TickClock;
16 }
17
18 namespace content {
19 class WebContents;
20 }
21
22 namespace memory {
23
24 // Internal class used by TabManager to record the needed data for
25 // WebContentses.
26 class TabManager::WebContentsData
27 : public content::WebContentsObserver,
28 public content::WebContentsUserData<TabManager::WebContentsData> {
29 public:
30 explicit WebContentsData(content::WebContents* web_contents);
31 ~WebContentsData() override;
32
33 // WebContentsObserver implementation:
34 void DidStartLoading() override;
35 void WebContentsDestroyed() override;
36
37 // Returns true if the tab has been discarded to save memory.
38 bool IsDiscarded();
39
40 // Sets/clears the discard state of the tab.
41 void SetDiscardState(bool state);
42
43 // Returns the number of times the tab has been discarded.
44 int DiscardCount();
45
46 // Increments the number of times the tab has been discarded.
47 void IncrementDiscardCount();
48
49 // Returns true if audio has recently been audible.
50 bool IsRecentlyAudible();
51
52 // Set/clears the state of whether audio has recently been audible.
53 void SetRecentlyAudible(bool state);
54
55 // Returns the timestamp of the last time the tab changed its audio state.
56 base::TimeTicks LastAudioChangeTime();
57
58 // Sets the timestamp of the last time the tab changed its audio state.
59 void SetLastAudioChangeTime(base::TimeTicks timestamp);
60
61 // Returns the timestamp of the last time the tab changed became inactive.
62 base::TimeTicks LastInactiveTime();
63
64 // Sets the timestamp of the last time the tab became inactive.
65 void SetLastInactiveTime(base::TimeTicks timestamp);
66
67 // Copies the discard state from |old_contents| to |new_contents|.
68 static void CopyState(content::WebContents* old_contents,
69 content::WebContents* new_contents);
70
71 // Used to set the test TickClock, which then gets used by NowTicks(). See
72 // |test_tick_clock_| for more details.
73 void set_test_tick_clock(base::TickClock* test_tick_clock);
74
75 // Returns the auto-discardable state of the tab.
76 // See tab_manager.h for more information.
77 bool IsAutoDiscardable();
78
79 // Sets/clears the auto-discardable state of the tab.
80 void SetAutoDiscardableState(bool state);
81
82 // Sets the current purge state.
83 // TODO(tasak): remove this after the logic is moved into
84 // MemoryCoordinator.
85 void set_is_purged(bool state) { is_purged_ = state; }
86
87 // Returns the current state of purge.
88 // TODO(tasak): remove this after the logic is moved into
89 // MemoryCoordinator.
90 bool is_purged() const { return is_purged_; }
91
92 // Sets the time to purge after the tab is backgrounded.
93 void set_time_to_purge(const base::TimeDelta& time_to_purge) {
94 time_to_purge_ = time_to_purge;
95 }
96
97 // Returns the time to first purge after the tab is backgrounded.
98 base::TimeDelta time_to_purge() const { return time_to_purge_; }
99
100 private:
101 // Needed to access tab_data_.
102 FRIEND_TEST_ALL_PREFIXES(TabManagerWebContentsDataTest, CopyState);
103
104 struct Data {
105 Data();
106 bool operator==(const Data& right) const;
107 bool operator!=(const Data& right) const;
108
109 // Is the tab currently discarded?
110 bool is_discarded;
111 // Number of times the tab has been discarded.
112 int discard_count;
113 // Is the tab playing audio?
114 bool is_recently_audible;
115 // Last time the tab started or stopped playing audio (we record the
116 // transition time).
117 base::TimeTicks last_audio_change_time;
118 // The last time the tab was discarded.
119 base::TimeTicks last_discard_time;
120 // The last time the tab was reloaded after being discarded.
121 base::TimeTicks last_reload_time;
122 // The last time the tab switched from being active to inactive.
123 base::TimeTicks last_inactive_time;
124 // Site Engagement score (set to -1 if not available).
125 double engagement_score;
126 // Is tab eligible for auto discarding? Defaults to true.
127 bool is_auto_discardable;
128 };
129
130 // Returns either the system's clock or the test clock. See |test_tick_clock_|
131 // for more details.
132 base::TimeTicks NowTicks() const;
133
134 // Contains all the needed data for the tab.
135 Data tab_data_;
136
137 // Pointer to a test clock. If this is set, NowTicks() returns the value of
138 // this test clock. Otherwise it returns the system clock's value.
139 base::TickClock* test_tick_clock_;
140
141 // The time to purge after the tab is backgrounded.
142 base::TimeDelta time_to_purge_;
143
144 // True if the tab has been purged.
145 bool is_purged_;
146
147 DISALLOW_COPY_AND_ASSIGN(WebContentsData);
148 };
149
150 } // namespace memory
151
152 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_WEB_CONTENTS_DATA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698