| 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 #include "chrome/browser/memory/tab_manager_web_contents_data.h" | 5 #include "chrome/browser/memory/tab_manager_web_contents_data.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "base/time/tick_clock.h" | 8 #include "base/time/tick_clock.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/engagement/site_engagement_service.h" | 10 #include "chrome/browser/engagement/site_engagement_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 | 14 |
| 15 using base::TimeTicks; | 15 using base::TimeTicks; |
| 16 using content::WebContents; | 16 using content::WebContents; |
| 17 | 17 |
| 18 DEFINE_WEB_CONTENTS_USER_DATA_KEY(memory::TabManager::WebContentsData); | 18 DEFINE_WEB_CONTENTS_USER_DATA_KEY(memory::TabManager::WebContentsData); |
| 19 | 19 |
| 20 namespace memory { | 20 namespace memory { |
| 21 | 21 |
| 22 TabManager::WebContentsData::WebContentsData(content::WebContents* web_contents) | 22 TabManager::WebContentsData::WebContentsData(content::WebContents* web_contents) |
| 23 : WebContentsObserver(web_contents), | 23 : WebContentsObserver(web_contents), |
| 24 test_tick_clock_(nullptr), | 24 test_tick_clock_(nullptr), |
| 25 last_purge_and_suspend_modified_time_( | 25 time_to_purge_(base::TimeDelta::FromMinutes(30)), |
| 26 base::TimeTicks::FromInternalValue(0)), | 26 is_purged_(false) {} |
| 27 purge_and_suspend_state_(RUNNING) {} | |
| 28 | 27 |
| 29 TabManager::WebContentsData::~WebContentsData() {} | 28 TabManager::WebContentsData::~WebContentsData() {} |
| 30 | 29 |
| 31 void TabManager::WebContentsData::DidStartLoading() { | 30 void TabManager::WebContentsData::DidStartLoading() { |
| 32 // Marks the tab as no longer discarded if it has been reloaded from another | 31 // Marks the tab as no longer discarded if it has been reloaded from another |
| 33 // source (ie: context menu). | 32 // source (ie: context menu). |
| 34 SetDiscardState(false); | 33 SetDiscardState(false); |
| 35 } | 34 } |
| 36 | 35 |
| 37 void TabManager::WebContentsData::WebContentsDestroyed() { | 36 void TabManager::WebContentsData::WebContentsDestroyed() { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 194 |
| 196 tab_data_.is_auto_discardable = state; | 195 tab_data_.is_auto_discardable = state; |
| 197 g_browser_process->GetTabManager()->OnAutoDiscardableStateChange( | 196 g_browser_process->GetTabManager()->OnAutoDiscardableStateChange( |
| 198 web_contents(), state); | 197 web_contents(), state); |
| 199 } | 198 } |
| 200 | 199 |
| 201 bool TabManager::WebContentsData::IsAutoDiscardable() { | 200 bool TabManager::WebContentsData::IsAutoDiscardable() { |
| 202 return tab_data_.is_auto_discardable; | 201 return tab_data_.is_auto_discardable; |
| 203 } | 202 } |
| 204 | 203 |
| 205 void TabManager::WebContentsData::SetPurgeAndSuspendState( | |
| 206 PurgeAndSuspendState state) { | |
| 207 last_purge_and_suspend_modified_time_ = NowTicks(); | |
| 208 purge_and_suspend_state_ = state; | |
| 209 } | |
| 210 | |
| 211 base::TimeTicks TabManager::WebContentsData::LastPurgeAndSuspendModifiedTime() | |
| 212 const { | |
| 213 return last_purge_and_suspend_modified_time_; | |
| 214 } | |
| 215 | |
| 216 void TabManager::WebContentsData::SetLastPurgeAndSuspendModifiedTimeForTesting( | |
| 217 base::TimeTicks timestamp) { | |
| 218 last_purge_and_suspend_modified_time_ = timestamp; | |
| 219 } | |
| 220 | |
| 221 TabManager::PurgeAndSuspendState | |
| 222 TabManager::WebContentsData::GetPurgeAndSuspendState() const { | |
| 223 return purge_and_suspend_state_; | |
| 224 } | |
| 225 | |
| 226 } // namespace memory | 204 } // namespace memory |
| OLD | NEW |