Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 SetPurgeState(bool state) { purge_state_ = state; } |
|
Wez
2017/03/02 02:28:32
Similar to below, this can be set_is_purged()
tasak
2017/03/02 09:22:47
Done.
| |
| 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 IsPurged() const { return purge_state_; } |
|
Wez
2017/03/02 02:28:33
This can be hacker_case is_purged()
tasak
2017/03/02 09:22:47
Done.
| |
| 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 SetTimeToPurge(const base::TimeDelta& time_to_purge) { |
|
Wez
2017/03/02 02:28:32
These can be hacker_case setter and getter.
tasak
2017/03/02 09:22:47
Done.
| |
| 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 TimeToPurge() 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 Loading... | |
| 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 // The current state of purge. True means PURGED, and false means NOT PURGED. |
| 148 PurgeAndSuspendState purge_and_suspend_state_; | 146 // Initially purge_state_ is false. |
|
Wez
2017/03/02 02:28:32
This isn't very clear; I think you want to say som
tasak
2017/03/02 09:22:47
Done.
| |
| 147 // false => true | |
| 148 // - A tab is kept inactive and background for more than time-to-purge time. | |
| 149 // true => false | |
| 150 // - When ActiveTabChaged, the newly activated tab's state will be false. | |
| 151 // No need to be copied by CopyState, because CopyState is used when a tab is | |
| 152 // discarded. Instead, we make purge_state_ true. | |
| 153 bool purge_state_; | |
|
Wez
2017/03/02 02:28:33
Rename this is_purged_, to match the getter & sett
tasak
2017/03/02 09:22:47
Done.
| |
| 149 | 154 |
| 150 DISALLOW_COPY_AND_ASSIGN(WebContentsData); | 155 DISALLOW_COPY_AND_ASSIGN(WebContentsData); |
| 151 }; | 156 }; |
| 152 | 157 |
| 153 } // namespace memory | 158 } // namespace memory |
| 154 | 159 |
| 155 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_WEB_CONTENTS_DATA_H_ | 160 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_WEB_CONTENTS_DATA_H_ |
| OLD | NEW |