Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(483)

Side by Side Diff: chrome/browser/android/data_usage/data_use_tab_model.cc

Issue 1444133002: Add UMA histograms for data usage tab model (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/data_use_tab_model.h" 5 #include "chrome/browser/android/data_usage/data_use_tab_model.h"
6 6
7 #include "base/metrics/histogram_macros.h"
7 #include "base/time/time.h" 8 #include "base/time/time.h"
8 #include "chrome/browser/android/data_usage/external_data_use_observer.h" 9 #include "chrome/browser/android/data_usage/external_data_use_observer.h"
9 #include "chrome/browser/android/data_usage/tab_data_use_entry.h" 10 #include "chrome/browser/android/data_usage/tab_data_use_entry.h"
10 11
11 namespace { 12 namespace {
12 13
13 // TODO(rajendrant): To be changeable via field trial. 14 // TODO(rajendrant): To be changeable via field trial.
14 // Indicates the maximum number of tabs to maintain session information about. 15 // Indicates the maximum number of tabs to maintain session information about.
15 const size_t kMaxTabEntries = 200; 16 const size_t kMaxTabEntries = 200;
16 17
17 // Returns true if |tab_id| is a valid tab ID. 18 // Returns true if |tab_id| is a valid tab ID.
18 bool IsValidTabID(int32_t tab_id) { 19 bool IsValidTabID(int32_t tab_id) {
19 return tab_id >= 0; 20 return tab_id >= 0;
20 } 21 }
21 22
23 const char kUMAExpiredInactiveTabEntryRemovaltimeSecondsHistogram[] =
tbansal1 2015/11/16 17:17:38 May be remove Seconds from the variable names (if
Raj 2015/11/16 20:09:36 Not sure. Each UMA needs different precision.
24 "DataUse.TabModel.ExpiredInactiveTabEntryRemovaltime";
25 const char kUMAExpiredActiveTabEntryRemovaltimeHoursHistogram[] =
26 "DataUse.TabModel.ExpiredActiveTabEntryRemovaltime";
27 const char kUMAUnexpiredTabEntryRemovaltimeMinutesHistogram[] =
28 "DataUse.TabModel.UnexpiredTabEntryLifetime";
29
22 } // namespace 30 } // namespace
23 31
24 namespace chrome { 32 namespace chrome {
25 33
26 namespace android { 34 namespace android {
27 35
28 size_t DataUseTabModel::GetMaxTabEntriesForTests() { 36 size_t DataUseTabModel::GetMaxTabEntriesForTests() {
29 return kMaxTabEntries; 37 return kMaxTabEntries;
30 } 38 }
31 39
32 DataUseTabModel::DataUseTabModel( 40 DataUseTabModel::DataUseTabModel(
33 const ExternalDataUseObserver* data_use_observer, 41 const ExternalDataUseObserver* data_use_observer,
34 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) 42 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
35 : data_use_observer_(data_use_observer), 43 : data_use_observer_(data_use_observer),
36 observer_list_(new base::ObserverListThreadSafe<TabDataUseObserver>), 44 observer_list_(new base::ObserverListThreadSafe<TabDataUseObserver>),
37 weak_factory_(this) {} 45 weak_factory_(this) {}
38 46
39 DataUseTabModel::~DataUseTabModel() { 47 DataUseTabModel::~DataUseTabModel() {
40 DCHECK(thread_checker_.CalledOnValidThread()); 48 DCHECK(thread_checker_.CalledOnValidThread());
41 } 49 }
42 50
51 base::TimeTicks DataUseTabModel::Now() const {
tbansal1 2015/11/16 17:17:38 Follow the same order as in .h file. Declare befor
Raj 2015/11/16 20:09:36 Done.
52 return base::TimeTicks::Now();
53 }
54
43 base::WeakPtr<DataUseTabModel> DataUseTabModel::GetWeakPtr() { 55 base::WeakPtr<DataUseTabModel> DataUseTabModel::GetWeakPtr() {
44 DCHECK(thread_checker_.CalledOnValidThread()); 56 DCHECK(thread_checker_.CalledOnValidThread());
45 return weak_factory_.GetWeakPtr(); 57 return weak_factory_.GetWeakPtr();
46 } 58 }
47 59
48 void DataUseTabModel::OnNavigationEvent(int32_t tab_id, 60 void DataUseTabModel::OnNavigationEvent(int32_t tab_id,
49 TransitionType transition, 61 TransitionType transition,
50 const GURL& url, 62 const GURL& url,
51 const std::string& package) { 63 const std::string& package) {
52 DCHECK(thread_checker_.CalledOnValidThread()); 64 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 if (tab_entry_iterator != active_tabs_.end() && 173 if (tab_entry_iterator != active_tabs_.end() &&
162 tab_entry_iterator->second.EndTracking()) { 174 tab_entry_iterator->second.EndTracking()) {
163 NotifyObserversOfTrackingEnding(tab_id); 175 NotifyObserversOfTrackingEnding(tab_id);
164 } 176 }
165 } 177 }
166 178
167 void DataUseTabModel::CompactTabEntries() { 179 void DataUseTabModel::CompactTabEntries() {
168 // Remove expired tab entries. 180 // Remove expired tab entries.
169 for (TabEntryMap::iterator tab_entry_iterator = active_tabs_.begin(); 181 for (TabEntryMap::iterator tab_entry_iterator = active_tabs_.begin();
170 tab_entry_iterator != active_tabs_.end();) { 182 tab_entry_iterator != active_tabs_.end();) {
171 if (tab_entry_iterator->second.IsExpired()) 183 const auto& tab_entry = tab_entry_iterator->second;
172 active_tabs_.erase(tab_entry_iterator++); 184 if (tab_entry.IsExpired()) {
173 else 185 // Track the lifetime of expired tab entry.
174 ++tab_entry_iterator; 186 const base::TimeDelta removal_time =
187 Now() - tab_entry.GetLatestStartOrEndTime();
188 if (!tab_entry.IsTrackingDataUse()) {
189 UMA_HISTOGRAM_COUNTS_1000(
tbansal1 2015/11/16 17:17:38 Why not UMA_HISTOGRAM_TIMES, or its sibling UMA_HI
Raj 2015/11/16 20:09:36 Tracking expired inactive tab entry removal times
tbansal1 2015/11/16 21:09:13 UMA_HISTOGRAM_CUSTOM_TIMES?
Raj 2015/11/17 07:04:03 Done.
190 kUMAExpiredInactiveTabEntryRemovaltimeSecondsHistogram,
191 base::TimeDelta(removal_time).InSeconds());
192 } else {
193 UMA_HISTOGRAM_CUSTOM_COUNTS(
tbansal1 2015/11/16 17:17:38 Why not UMA_HISTOGRAM_TIMES?
Raj 2015/11/16 20:09:36 Tracking expired active tab entry removal times in
194 kUMAExpiredActiveTabEntryRemovaltimeHoursHistogram,
195 base::TimeDelta(removal_time).InHours(), 1, 120, 50);
196 }
197 active_tabs_.erase(tab_entry_iterator);
tbansal1 2015/11/16 17:17:38 Is this correct? Documentation for erase() says th
Raj 2015/11/16 20:09:36 Done.
198 }
199 ++tab_entry_iterator;
175 } 200 }
176 201
177 if (active_tabs_.size() <= kMaxTabEntries) 202 if (active_tabs_.size() <= kMaxTabEntries)
178 return; 203 return;
179 204
180 // Remove oldest unexpired tab entries. 205 // Remove oldest unexpired tab entries.
181 while (active_tabs_.size() > kMaxTabEntries) { 206 while (active_tabs_.size() > kMaxTabEntries) {
182 // Find oldest tab entry. 207 // Find oldest tab entry.
183 TabEntryMap::iterator oldest_tab_entry_iterator = active_tabs_.begin(); 208 TabEntryMap::iterator oldest_tab_entry_iterator = active_tabs_.begin();
184 for (TabEntryMap::iterator tab_entry_iterator = active_tabs_.begin(); 209 for (TabEntryMap::iterator tab_entry_iterator = active_tabs_.begin();
185 tab_entry_iterator != active_tabs_.end(); ++tab_entry_iterator) { 210 tab_entry_iterator != active_tabs_.end(); ++tab_entry_iterator) {
186 if (oldest_tab_entry_iterator->second.GetLatestStartOrEndTime() > 211 if (oldest_tab_entry_iterator->second.GetLatestStartOrEndTime() >
187 tab_entry_iterator->second.GetLatestStartOrEndTime()) { 212 tab_entry_iterator->second.GetLatestStartOrEndTime()) {
188 oldest_tab_entry_iterator = tab_entry_iterator; 213 oldest_tab_entry_iterator = tab_entry_iterator;
189 } 214 }
190 } 215 }
191 DCHECK(oldest_tab_entry_iterator != active_tabs_.end()); 216 DCHECK(oldest_tab_entry_iterator != active_tabs_.end());
217 UMA_HISTOGRAM_COUNTS_1000(
tbansal1 2015/11/16 17:17:38 Why not UMA_HISTOGRAM_TIMES?
Raj 2015/11/16 20:09:36 Tracking unexpired tab entry removal times in the
218 kUMAUnexpiredTabEntryRemovaltimeMinutesHistogram,
219 base::TimeDelta(
220 Now() - oldest_tab_entry_iterator->second.GetLatestStartOrEndTime())
221 .InMinutes());
192 active_tabs_.erase(oldest_tab_entry_iterator); 222 active_tabs_.erase(oldest_tab_entry_iterator);
193 } 223 }
194 } 224 }
195 225
196 } // namespace android 226 } // namespace android
197 227
198 } // namespace chrome 228 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698