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.h" | 7 #include "base/metrics/histogram.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" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 tab_data_.engagement_score_ = | 91 tab_data_.engagement_score_ = |
92 service->GetScore(web_contents()->GetLastCommittedURL()); | 92 service->GetScore(web_contents()->GetLastCommittedURL()); |
93 UMA_HISTOGRAM_COUNTS_100( | 93 UMA_HISTOGRAM_COUNTS_100( |
94 "TabManager.Discarding.DiscardedEngagementScore", | 94 "TabManager.Discarding.DiscardedEngagementScore", |
95 tab_data_.engagement_score_); | 95 tab_data_.engagement_score_); |
96 } | 96 } |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 tab_data_.is_discarded_ = state; | 100 tab_data_.is_discarded_ = state; |
101 | 101 g_browser_process->GetTabManager()->OnDiscardedStateChange(web_contents(), |
102 // TabManager could not exist in tests. | 102 state); |
103 if (g_browser_process->GetTabManager()) { | |
104 g_browser_process->GetTabManager()->OnDiscardedStateChange(web_contents(), | |
105 state); | |
106 } | |
107 } | 103 } |
108 | 104 |
109 int TabManager::WebContentsData::DiscardCount() { | 105 int TabManager::WebContentsData::DiscardCount() { |
110 return tab_data_.discard_count_; | 106 return tab_data_.discard_count_; |
111 } | 107 } |
112 | 108 |
113 void TabManager::WebContentsData::IncrementDiscardCount() { | 109 void TabManager::WebContentsData::IncrementDiscardCount() { |
114 tab_data_.discard_count_++; | 110 tab_data_.discard_count_++; |
115 } | 111 } |
116 | 112 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 161 } |
166 | 162 |
167 TabManager::WebContentsData::Data::Data() | 163 TabManager::WebContentsData::Data::Data() |
168 : is_discarded_(false), | 164 : is_discarded_(false), |
169 discard_count_(0), | 165 discard_count_(0), |
170 is_recently_audible_(false), | 166 is_recently_audible_(false), |
171 last_audio_change_time_(TimeTicks::UnixEpoch()), | 167 last_audio_change_time_(TimeTicks::UnixEpoch()), |
172 last_discard_time_(TimeTicks::UnixEpoch()), | 168 last_discard_time_(TimeTicks::UnixEpoch()), |
173 last_reload_time_(TimeTicks::UnixEpoch()), | 169 last_reload_time_(TimeTicks::UnixEpoch()), |
174 last_inactive_time_(TimeTicks::UnixEpoch()), | 170 last_inactive_time_(TimeTicks::UnixEpoch()), |
175 engagement_score_(-1.0) {} | 171 engagement_score_(-1.0), |
| 172 is_auto_discardable(true) {} |
176 | 173 |
177 bool TabManager::WebContentsData::Data::operator==(const Data& right) const { | 174 bool TabManager::WebContentsData::Data::operator==(const Data& right) const { |
178 return is_discarded_ == right.is_discarded_ && | 175 return is_discarded_ == right.is_discarded_ && |
179 is_recently_audible_ == right.is_recently_audible_ && | 176 is_recently_audible_ == right.is_recently_audible_ && |
180 last_audio_change_time_ == right.last_audio_change_time_ && | 177 last_audio_change_time_ == right.last_audio_change_time_ && |
181 last_discard_time_ == right.last_discard_time_ && | 178 last_discard_time_ == right.last_discard_time_ && |
182 last_reload_time_ == right.last_reload_time_ && | 179 last_reload_time_ == right.last_reload_time_ && |
183 last_inactive_time_ == right.last_inactive_time_ && | 180 last_inactive_time_ == right.last_inactive_time_ && |
184 engagement_score_ == right.engagement_score_; | 181 engagement_score_ == right.engagement_score_; |
185 } | 182 } |
186 | 183 |
187 bool TabManager::WebContentsData::Data::operator!=(const Data& right) const { | 184 bool TabManager::WebContentsData::Data::operator!=(const Data& right) const { |
188 return !(*this == right); | 185 return !(*this == right); |
189 } | 186 } |
190 | 187 |
| 188 void TabManager::WebContentsData::SetAutoDiscardableState(bool state) { |
| 189 if (tab_data_.is_auto_discardable == state) |
| 190 return; |
| 191 |
| 192 tab_data_.is_auto_discardable = state; |
| 193 g_browser_process->GetTabManager()->OnAutoDiscardableStateChange( |
| 194 web_contents(), state); |
| 195 } |
| 196 |
| 197 bool TabManager::WebContentsData::IsAutoDiscardable() { |
| 198 return tab_data_.is_auto_discardable; |
| 199 } |
| 200 |
191 } // namespace memory | 201 } // namespace memory |
OLD | NEW |