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 #include "chrome/browser/android/data_usage/tab_data_use_entry.h" | 5 #include "chrome/browser/android/data_usage/tab_data_use_entry.h" |
| 6 | 6 |
| 7 #include "base/gtest_prod_util.h" | 7 #include "base/gtest_prod_util.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/metrics/histogram_macros.h" | |
| 9 | 10 |
| 10 namespace { | 11 namespace { |
| 11 | 12 |
| 12 // Indicates the maximum number of tracking session history to maintain per tab. | 13 // Indicates the maximum number of tracking session history to maintain per tab. |
| 13 const size_t kMaxSessionsPerTab = 5; | 14 const size_t kMaxSessionsPerTab = 5; |
| 14 | 15 |
| 15 // Indicates the expiration duration in seconds for a closed tab entry, after | 16 // Indicates the expiration duration in seconds for a closed tab entry, after |
| 16 // which it can be sweeped from history. | 17 // which it can be sweeped from history. |
| 17 const unsigned int kClosedTabExpirationDurationSeconds = 30; // 30 seconds. | 18 const unsigned int kClosedTabExpirationDurationSeconds = 30; // 30 seconds. |
| 18 | 19 |
| 19 // Indicates the expiration duration in seconds for an open tab entry, after | 20 // Indicates the expiration duration in seconds for an open tab entry, after |
| 20 // which it can be sweeped from history. | 21 // which it can be sweeped from history. |
| 21 const unsigned int kOpenTabExpirationDurationSeconds = | 22 const unsigned int kOpenTabExpirationDurationSeconds = |
| 22 60 * 60 * 24 * 5; // 5 days. | 23 60 * 60 * 24 * 5; // 5 days. |
| 23 | 24 |
| 25 const char kUMATrackingSessionLifetimeSecondsHistogram[] = | |
|
tbansal1
2015/11/16 17:17:38
Remove Seconds/Minutes etc. from the variable name
Raj
2015/11/16 20:09:37
Not sure. Each UMA needs different precision.
| |
| 26 "DataUse.TabModel.TrackingSessionLifetime"; | |
| 27 const char kUMAOldInactiveSessionRemovaltimeSecondsHistogram[] = | |
| 28 "DataUse.TabModel.OldInactiveSessionRemovaltime"; | |
| 29 | |
| 24 } // namespace | 30 } // namespace |
| 25 | 31 |
| 26 namespace chrome { | 32 namespace chrome { |
| 27 | 33 |
| 28 namespace android { | 34 namespace android { |
| 29 | 35 |
| 30 size_t TabDataUseEntry::GetMaxSessionsPerTabForTests() { | 36 size_t TabDataUseEntry::GetMaxSessionsPerTabForTests() { |
| 31 return kMaxSessionsPerTab; | 37 return kMaxSessionsPerTab; |
| 32 } | 38 } |
| 33 | 39 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 bool TabDataUseEntry::EndTracking() { | 74 bool TabDataUseEntry::EndTracking() { |
| 69 DCHECK(tab_close_time_.is_null()); | 75 DCHECK(tab_close_time_.is_null()); |
| 70 if (!IsTrackingDataUse()) | 76 if (!IsTrackingDataUse()) |
| 71 return false; // Duplicate end events. | 77 return false; // Duplicate end events. |
| 72 | 78 |
| 73 TabSessions::reverse_iterator back_iterator = sessions_.rbegin(); | 79 TabSessions::reverse_iterator back_iterator = sessions_.rbegin(); |
| 74 if (back_iterator == sessions_.rend()) | 80 if (back_iterator == sessions_.rend()) |
| 75 return false; | 81 return false; |
| 76 | 82 |
| 77 back_iterator->end_time = Now(); | 83 back_iterator->end_time = Now(); |
| 84 | |
| 85 UMA_HISTOGRAM_COUNTS_1000( | |
|
tbansal1
2015/11/16 17:17:38
TIMES?
Raj
2015/11/16 20:09:36
Tracking session lifetime in the range of 1 second
| |
| 86 kUMATrackingSessionLifetimeSecondsHistogram, | |
| 87 base::TimeDelta(back_iterator->end_time - back_iterator->start_time) | |
| 88 .InSeconds()); | |
| 89 | |
| 78 return true; | 90 return true; |
| 79 } | 91 } |
| 80 | 92 |
| 81 void TabDataUseEntry::OnTabCloseEvent() { | 93 void TabDataUseEntry::OnTabCloseEvent() { |
| 82 DCHECK(!IsTrackingDataUse()); | 94 DCHECK(!IsTrackingDataUse()); |
| 83 tab_close_time_ = Now(); | 95 tab_close_time_ = Now(); |
| 84 } | 96 } |
| 85 | 97 |
| 86 bool TabDataUseEntry::IsExpired() const { | 98 bool TabDataUseEntry::IsExpired() const { |
| 87 const base::TimeTicks now = Now(); | 99 const base::TimeTicks now = Now(); |
| 88 | 100 |
| 89 if (!tab_close_time_.is_null()) { | 101 if (!tab_close_time_.is_null()) { |
| 90 // Closed tab entry. | 102 // Closed tab entry. |
| 91 return ((now - tab_close_time_) > | 103 return ((now - tab_close_time_) > |
| 92 base::TimeDelta::FromSeconds(kClosedTabExpirationDurationSeconds)); | 104 base::TimeDelta::FromSeconds(kClosedTabExpirationDurationSeconds)); |
| 93 } | 105 } |
| 94 | 106 |
| 95 const base::TimeTicks latest_session_time = GetLatestStartOrEndTime(); | 107 const base::TimeTicks latest_session_time = GetLatestStartOrEndTime(); |
| 96 if (latest_session_time.is_null() || | 108 if (latest_session_time.is_null() || |
| 97 ((now - latest_session_time) > | 109 ((now - latest_session_time) > |
| 98 base::TimeDelta::FromSeconds(kOpenTabExpirationDurationSeconds))) { | 110 base::TimeDelta::FromSeconds(kOpenTabExpirationDurationSeconds))) { |
| 99 // TODO(rajendrant): Add UMA to track deletion of entries corresponding to | |
| 100 // existing tabs. | |
| 101 return true; | 111 return true; |
| 102 } | 112 } |
| 103 return false; | 113 return false; |
| 104 } | 114 } |
| 105 | 115 |
| 106 bool TabDataUseEntry::GetLabel(const base::TimeTicks& data_use_time, | 116 bool TabDataUseEntry::GetLabel(const base::TimeTicks& data_use_time, |
| 107 std::string* output_label) const { | 117 std::string* output_label) const { |
| 108 *output_label = ""; | 118 *output_label = ""; |
| 109 | 119 |
| 110 // Find a tracking session in history that was active at |data_use_time|. | 120 // Find a tracking session in history that was active at |data_use_time|. |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 139 if (back_iterator == sessions_.rend()) | 149 if (back_iterator == sessions_.rend()) |
| 140 return base::TimeTicks(); // No tab session found. | 150 return base::TimeTicks(); // No tab session found. |
| 141 if (!back_iterator->end_time.is_null()) | 151 if (!back_iterator->end_time.is_null()) |
| 142 return back_iterator->end_time; | 152 return back_iterator->end_time; |
| 143 | 153 |
| 144 DCHECK(!back_iterator->start_time.is_null()); | 154 DCHECK(!back_iterator->start_time.is_null()); |
| 145 return back_iterator->start_time; | 155 return back_iterator->start_time; |
| 146 } | 156 } |
| 147 | 157 |
| 148 void TabDataUseEntry::CompactSessionHistory() { | 158 void TabDataUseEntry::CompactSessionHistory() { |
| 149 // TODO(rajendrant): Add UMA to track how often old sessions are lost. | 159 while (sessions_.size() > kMaxSessionsPerTab) { |
| 150 while (sessions_.size() > kMaxSessionsPerTab) | 160 const auto& front = sessions_.front(); |
| 161 DCHECK(!front.end_time.is_null()); | |
| 162 // Track how often old sessions are lost. | |
| 163 UMA_HISTOGRAM_COUNTS_1000( | |
| 164 kUMAOldInactiveSessionRemovaltimeSecondsHistogram, | |
|
tbansal1
2015/11/16 17:17:38
TIMES?
Raj
2015/11/16 20:09:36
Tracking old inactive tracking session removal tim
| |
| 165 base::TimeDelta(Now() - front.end_time).InSeconds()); | |
| 151 sessions_.pop_front(); | 166 sessions_.pop_front(); |
| 167 } | |
| 152 } | 168 } |
| 153 | 169 |
| 154 } // namespace android | 170 } // namespace android |
| 155 | 171 |
| 156 } // namespace chrome | 172 } // namespace chrome |
| OLD | NEW |