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

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

Issue 2711093002: Purge once random minutes(between 30min and 60min) after backgrounded. (Closed)
Patch Set: Added a browser test. Created 3 years, 9 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_MEMORY_TAB_MANAGER_WEB_CONTENTS_DATA_H_ 5 #ifndef CHROME_BROWSER_MEMORY_TAB_MANAGER_WEB_CONTENTS_DATA_H_
6 #define CHROME_BROWSER_MEMORY_TAB_MANAGER_WEB_CONTENTS_DATA_H_ 6 #define CHROME_BROWSER_MEMORY_TAB_MANAGER_WEB_CONTENTS_DATA_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "chrome/browser/memory/tab_manager.h" 10 #include "chrome/browser/memory/tab_manager.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // |test_tick_clock_| for more details. 72 // |test_tick_clock_| for more details.
73 void set_test_tick_clock(base::TickClock* test_tick_clock); 73 void set_test_tick_clock(base::TickClock* test_tick_clock);
74 74
75 // Returns the auto-discardable state of the tab. 75 // Returns the auto-discardable state of the tab.
76 // See tab_manager.h for more information. 76 // See tab_manager.h for more information.
77 bool IsAutoDiscardable(); 77 bool IsAutoDiscardable();
78 78
79 // Sets/clears the auto-discardable state of the tab. 79 // Sets/clears the auto-discardable state of the tab.
80 void SetAutoDiscardableState(bool state); 80 void SetAutoDiscardableState(bool state);
81 81
82 // Sets the current purge-and-suspend state, and update the timestamp, 82 // Sets the current purge state.
83 // i.e. the last purge-and-suspend modified time. 83 // TODO(tasak): remove this after the logic is moved into
84 // TODO(tasak): remove this after PurgeAndSuspend code is moved into
85 // MemoryCoordinator. 84 // MemoryCoordinator.
86 void SetPurgeAndSuspendState(TabManager::PurgeAndSuspendState state); 85 void set_is_purged(bool state) { is_purged_ = state; }
87 86
88 // Returns the last purge-and-suspend modified time. 87 // Returns the current state of purge.
89 // TODO(tasak): remove this after PurgeAndSuspend code is moved into 88 // TODO(tasak): remove this after the logic is moved into
90 // MemoryCoordinator. 89 // MemoryCoordinator.
91 base::TimeTicks LastPurgeAndSuspendModifiedTime() const; 90 bool is_purged() const { return is_purged_; }
92 91
93 // Sets the timestamp of the last modified time the purge-and-suspend state 92 // Sets the time to purge after the tab is backgrounded.
94 // of the tab was changed for testing. 93 void set_time_to_purge(const base::TimeDelta& time_to_purge) {
95 void SetLastPurgeAndSuspendModifiedTimeForTesting(base::TimeTicks timestamp); 94 time_to_purge_ = time_to_purge;
95 }
96 96
97 // Returns the current state of purge-and-suspend. 97 // Returns the time to first purge after the tab is backgrounded.
98 // TODO(tasak): remove this after PurgeAndSuspend code is moved into 98 base::TimeDelta time_to_purge() const { return time_to_purge_; }
99 // MemoryCoordinator.
100 TabManager::PurgeAndSuspendState GetPurgeAndSuspendState() const;
101 99
102 private: 100 private:
103 // Needed to access tab_data_. 101 // Needed to access tab_data_.
104 FRIEND_TEST_ALL_PREFIXES(TabManagerWebContentsDataTest, CopyState); 102 FRIEND_TEST_ALL_PREFIXES(TabManagerWebContentsDataTest, CopyState);
105 103
106 struct Data { 104 struct Data {
107 Data(); 105 Data();
108 bool operator==(const Data& right) const; 106 bool operator==(const Data& right) const;
109 bool operator!=(const Data& right) const; 107 bool operator!=(const Data& right) const;
110 108
(...skipping 23 matching lines...) Expand all
134 // for more details. 132 // for more details.
135 base::TimeTicks NowTicks() const; 133 base::TimeTicks NowTicks() const;
136 134
137 // Contains all the needed data for the tab. 135 // Contains all the needed data for the tab.
138 Data tab_data_; 136 Data tab_data_;
139 137
140 // Pointer to a test clock. If this is set, NowTicks() returns the value of 138 // Pointer to a test clock. If this is set, NowTicks() returns the value of
141 // this test clock. Otherwise it returns the system clock's value. 139 // this test clock. Otherwise it returns the system clock's value.
142 base::TickClock* test_tick_clock_; 140 base::TickClock* test_tick_clock_;
143 141
144 // The last time purge-and-suspend state was modified. 142 // The time to purge after the tab is backgrounded.
145 base::TimeTicks last_purge_and_suspend_modified_time_; 143 base::TimeDelta time_to_purge_;
146 144
147 // The current state of purge-and-suspend. 145 // True if the tab has been purged since it was last active, and should
148 PurgeAndSuspendState purge_and_suspend_state_; 146 // therefore not be purged again.
147 // The rest of the detail of the algorithm doesn't belong here; the only
148 // detail to keep here would be:
Wez 2017/03/03 21:06:51 I would actually remove these transition descripti
tasak 2017/03/06 10:30:19 I moved the document to TabManager::ActiveTabChang
149 // false => true
150 // - A tab is kept inactive and background for more than time-to-purge time.
151 // true => false
152 // - When ActiveTabChaged, the newly activated tab's state will be false.
153 // When a discarded tab is restored, we set |is_purged_=true|,
154 // since purging the newly-created renderer doesn't make sense.
155 bool is_purged_;
149 156
150 DISALLOW_COPY_AND_ASSIGN(WebContentsData); 157 DISALLOW_COPY_AND_ASSIGN(WebContentsData);
151 }; 158 };
152 159
153 } // namespace memory 160 } // namespace memory
154 161
155 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_WEB_CONTENTS_DATA_H_ 162 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_WEB_CONTENTS_DATA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698