Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/password_manager/password_manager_metrics_util.h" | |
| 6 | |
| 7 #include "base/basictypes.h" | |
| 8 #include "base/metrics/histogram.h" | |
| 9 #include "base/process/process_handle.h" | |
| 10 #include "base/strings/string_number_conversions.h" | |
| 11 #include "base/strings/string_util.h" | |
| 12 #include "base/time/time.h" | |
| 13 #include "url/gurl.h" | |
| 14 | |
| 15 namespace password_manager_metrics_util { | |
| 16 | |
| 17 std::string IsDomainNameMonitored(const std::string& url_host) { | |
| 18 static const size_t kBucketsPerDomain = 10u; | |
|
Ilya Sherman
2013/09/10 22:30:54
This terminology is a little confusing, as "bucket
jdomingos
2013/09/11 15:50:30
Done.
| |
| 19 // This array contains each monitored websites together with all id of | |
| 20 // buckets which contain the website. | |
| 21 static const struct DomainBucketsPair kInfos[] = { | |
|
Ilya Sherman
2013/09/10 22:30:54
nit: Extraneous "struct"
Ilya Sherman
2013/09/10 22:30:54
nit: Perhaps |kDomainMapping|?
jdomingos
2013/09/11 15:50:30
Done.
jdomingos
2013/09/11 15:50:30
Done.
| |
| 22 {"google.com", {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}}, | |
| 23 {"yahoo.com", {1, 2, 3, 4, 5, 11, 12, 13, 14, 15}}, | |
| 24 {"baidu.com", {1, 2, 3, 4, 6, 7, 11, 12, 16, 17}}, | |
| 25 {"wikipedia.org", {1, 2, 3, 4, 5, 6, 11, 12, 16, 18}}, | |
| 26 {"linkedin.com", {1, 6, 8, 11, 13, 14, 15, 16, 17, 19}}, | |
| 27 {"twitter.com", {5, 6, 7, 8, 9, 11, 13, 17, 19, 20}}, | |
| 28 {"live.com", {7, 8, 9, 10, 13, 14, 16, 17, 18, 20}}, | |
| 29 {"amazon.com", {2, 5, 9, 10, 12, 14, 15, 18, 19, 20}}, | |
| 30 {"ebay.com", {13, 7, 9, 10, 14, 15, 17, 18, 19, 20}}, | |
| 31 {"tumblr.com", {4, 8, 10, 12, 13, 15, 16, 18, 19, 20}}, | |
|
Ilya Sherman
2013/09/10 22:30:54
This bucket distribution doesn't really seem well
vabr (Chromium)
2013/09/11 07:25:43
Good catch, Ilya!
ebay.com should have started wit
jdomingos
2013/09/11 15:50:30
Thanks Ilya and Vaclav.
I am going to double-check
| |
| 32 }; | |
| 33 const size_t kInfosLength = arraysize(kInfos); | |
|
Ilya Sherman
2013/09/10 22:30:54
This needs a lot more documentation. Please expla
Ilya Sherman
2013/09/10 22:30:54
Suppose we wanted to add tracking for an additiona
vabr (Chromium)
2013/09/11 07:25:43
Jordy is putting all of it in the design doc (curr
vabr (Chromium)
2013/09/11 07:25:43
Unfortunately, there is no way to add websites whi
jdomingos
2013/09/11 15:50:30
Done.
jdomingos
2013/09/11 15:50:30
Facebook is not already included because the save
| |
| 34 | |
| 35 GURL url(url_host); | |
| 36 for (size_t i = 0; i < kInfosLength; ++i) { | |
| 37 std::string domain = kInfos[i].domain_name; | |
| 38 // For each session, the user uses only one bucket for each website. | |
| 39 if (url.DomainIs(domain.c_str())) { | |
| 40 // Use GetCurrentProcId % kBucketsPerDomain to get a number which: | |
| 41 // 1. Is stable during the lifetime of the browser. | |
| 42 // 2. Is sufficiently random, in both the sense that | |
| 43 // 2a. it's not easy to predict for a specific user, and | |
| 44 // 2b. all kBucketsPerDomain possible values are roughly uniformly | |
| 45 // used across all users. | |
|
Ilya Sherman
2013/09/10 22:30:54
Why not just compute a truly random number once pe
vabr (Chromium)
2013/09/11 07:25:43
Seems like a good idea!
jdomingos
2013/09/11 15:50:30
Done.
| |
| 46 return "bucket_" + | |
| 47 base::IntToString( | |
| 48 kInfos[i] | |
| 49 .bucket_ids[base::GetCurrentProcId() % kBucketsPerDomain]); | |
|
Ilya Sherman
2013/09/10 22:30:54
Rather than splitting this statement over four lin
jdomingos
2013/09/11 15:50:30
Done.
jdomingos
2013/09/11 15:50:30
Done.
| |
| 50 } | |
| 51 } | |
| 52 return std::string(); | |
| 53 } | |
| 54 | |
| 55 void LogUMAHistogramEnumeration(const std::string& name, | |
| 56 int sample, | |
| 57 int boundary_value) { | |
| 58 DCHECK_LT(sample, boundary_value); | |
| 59 | |
| 60 // Note: This leaks memory, which is expected behavior. | |
| 61 base::HistogramBase* histogram = | |
| 62 base::LinearHistogram::FactoryGet( | |
| 63 name, | |
| 64 1, | |
| 65 boundary_value, | |
| 66 boundary_value + 1, | |
| 67 base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 68 histogram->Add(sample); | |
| 69 } | |
| 70 | |
| 71 void LogUMAHistogramTimes(const std::string& name, | |
| 72 const base::TimeDelta& duration) { | |
| 73 // Note: This leaks memory, which is expected behavior. | |
| 74 base::HistogramBase* histogram = | |
| 75 base::Histogram::FactoryTimeGet( | |
| 76 name, | |
| 77 base::TimeDelta::FromMilliseconds(1), | |
| 78 base::TimeDelta::FromSeconds(10), | |
| 79 50, | |
| 80 base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 81 histogram->AddTime(duration); | |
| 82 } | |
| 83 | |
| 84 void LogUMAHistogramCount(const std::string& name, int sample) { | |
| 85 // Note: This leaks memory, which is expected behavior. | |
| 86 base::HistogramBase* histogram = | |
| 87 base::Histogram::FactoryGet( | |
| 88 name, | |
| 89 1, | |
| 90 1000000, | |
| 91 50, | |
| 92 base::HistogramBase::kUmaTargetedHistogramFlag); | |
| 93 histogram->Add(sample); | |
| 94 } | |
| 95 | |
| 96 } // namespace password_manager_metrics_util | |
| OLD | NEW |