| 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 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 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 // True if the tab has been purged. |
| 148 PurgeAndSuspendState purge_and_suspend_state_; | 146 bool is_purged_; |
| 149 | 147 |
| 150 DISALLOW_COPY_AND_ASSIGN(WebContentsData); | 148 DISALLOW_COPY_AND_ASSIGN(WebContentsData); |
| 151 }; | 149 }; |
| 152 | 150 |
| 153 } // namespace memory | 151 } // namespace memory |
| 154 | 152 |
| 155 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_WEB_CONTENTS_DATA_H_ | 153 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_WEB_CONTENTS_DATA_H_ |
| OLD | NEW |