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

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

Issue 1582043002: Add histograms for data usage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months 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_matcher.h" 5 #include "chrome/browser/android/data_usage/data_use_matcher.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/metrics/histogram_macros.h"
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 #include "base/time/default_tick_clock.h" 15 #include "base/time/default_tick_clock.h"
15 #include "base/time/tick_clock.h" 16 #include "base/time/tick_clock.h"
17 #include "base/time/time.h"
16 #include "chrome/browser/android/data_usage/external_data_use_observer.h" 18 #include "chrome/browser/android/data_usage/external_data_use_observer.h"
17 #include "third_party/re2/src/re2/re2.h" 19 #include "third_party/re2/src/re2/re2.h"
18 #include "url/gurl.h" 20 #include "url/gurl.h"
19 21
20 namespace chrome { 22 namespace chrome {
21 23
22 namespace android { 24 namespace android {
23 25
24 DataUseMatcher::DataUseMatcher( 26 DataUseMatcher::DataUseMatcher(
25 const base::WeakPtr<DataUseTabModel>& data_use_tab_model, 27 const base::WeakPtr<DataUseTabModel>& data_use_tab_model,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 matching_rules_.push_back(make_scoped_ptr(new MatchingRule( 75 matching_rules_.push_back(make_scoped_ptr(new MatchingRule(
74 app_package_name, std::move(pattern), labels.at(i), expiration))); 76 app_package_name, std::move(pattern), labels.at(i), expiration)));
75 77
76 removed_matching_rule_labels.erase(labels.at(i)); 78 removed_matching_rule_labels.erase(labels.at(i));
77 } 79 }
78 80
79 for (const std::string& label : removed_matching_rule_labels) { 81 for (const std::string& label : removed_matching_rule_labels) {
80 if (data_use_tab_model_) 82 if (data_use_tab_model_)
81 data_use_tab_model_->OnTrackingLabelRemoved(label); 83 data_use_tab_model_->OnTrackingLabelRemoved(label);
82 } 84 }
85 UMA_HISTOGRAM_COUNTS_100("DataUsage.MatchingRulesCount",
tbansal1 2016/01/13 18:06:52 Can you change this to a enumerated histogram with
tbansal1 2016/01/13 18:44:24 Sorry, better to create 2 histograms: DataUsage.Ma
Raj 2016/01/13 23:33:51 Done.
86 matching_rules_.size());
87
83 DCHECK(io_task_runner_); 88 DCHECK(io_task_runner_);
84 89
85 // Notify |external_data_use_observer_| if it should register as a data use 90 // Notify |external_data_use_observer_| if it should register as a data use
86 // observer. 91 // observer.
87 io_task_runner_->PostTask( 92 io_task_runner_->PostTask(
88 FROM_HERE, 93 FROM_HERE,
89 base::Bind(&ExternalDataUseObserver::ShouldRegisterAsDataUseObserver, 94 base::Bind(&ExternalDataUseObserver::ShouldRegisterAsDataUseObserver,
90 external_data_use_observer_, !matching_rules_.empty())); 95 external_data_use_observer_, !matching_rules_.empty()));
91 } 96 }
92 97
93 bool DataUseMatcher::MatchesURL(const GURL& url, std::string* label) const { 98 bool DataUseMatcher::MatchesURL(const GURL& url, std::string* label) const {
94 const base::TimeTicks now_ticks = tick_clock_->NowTicks(); 99 const base::TimeTicks now_ticks = tick_clock_->NowTicks();
95 DCHECK(thread_checker_.CalledOnValidThread()); 100 DCHECK(thread_checker_.CalledOnValidThread());
96 *label = ""; 101 *label = "";
97 102
98 if (!url.is_valid() || url.is_empty()) 103 if (!url.is_valid() || url.is_empty())
99 return false; 104 return false;
100 105
101 for (const auto& matching_rule : matching_rules_) { 106 for (const auto& matching_rule : matching_rules_) {
102 if (matching_rule->expiration() <= now_ticks) 107 if (matching_rule->expiration() <= now_ticks)
103 continue; // skip expired matching rules. 108 continue; // skip expired matching rules.
104 if (re2::RE2::FullMatch(url.spec(), *(matching_rule->pattern()))) { 109 base::TimeTicks begin = base::TimeTicks::Now();
tbansal1 2016/01/13 18:06:52 This might be more useful if it records the durati
Raj 2016/01/13 23:33:51 If there are multiple regexes, the total duration
110 bool match = re2::RE2::FullMatch(url.spec(), *(matching_rule->pattern()));
111 UMA_HISTOGRAM_TIMES("DataUsage.Perf.URLRegexMatchDuration",
112 base::TimeTicks::Now() - begin);
113 if (match) {
105 *label = matching_rule->label(); 114 *label = matching_rule->label();
106 return true; 115 return true;
107 } 116 }
108 } 117 }
109 118
110 return false; 119 return false;
111 } 120 }
112 121
113 bool DataUseMatcher::MatchesAppPackageName(const std::string& app_package_name, 122 bool DataUseMatcher::MatchesAppPackageName(const std::string& app_package_name,
114 std::string* label) const { 123 std::string* label) const {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 return label_; 197 return label_;
189 } 198 }
190 199
191 const base::TimeTicks& DataUseMatcher::MatchingRule::expiration() const { 200 const base::TimeTicks& DataUseMatcher::MatchingRule::expiration() const {
192 return expiration_; 201 return expiration_;
193 } 202 }
194 203
195 } // namespace android 204 } // namespace android
196 205
197 } // namespace chrome 206 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698