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

Side by Side Diff: chrome/browser/password_manager/password_manager_metrics_util.cc

Issue 23140005: Added of new UMA signals in order to be able to discover early if the "save password" feature gets … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor changes Created 7 years, 3 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
(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/rand_util.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 namespace {
18
19 // The number of domain groups.
20 const size_t kNumGroups = 2 * kGroupsPerDomain;
21
22 size_t g_random_group_id = kGroupsPerDomain;
Ilya Sherman 2013/09/12 23:43:40 Please add documentation for this variable.
jdomingos 2013/09/13 21:56:23 Done.
23
24 } // namespace
25
26 // Contains a monitored domain name and all the group IDs which contain
27 // domain name.
28 struct DomainGroupsPair {
29 const char* const domain_name;
30 const size_t group_ids[kGroupsPerDomain];
31 };
32
33 size_t MonitoredDomainGroupId(const std::string& url_host) {
34 // This array contains each monitored website together with all ids of
35 // groups which contain the website. Each website appears in
36 // |kGroupsPerDomain| groups, and each group includes an equal number of
37 // websites, so that no two websites have the same set of groups that they
38 // belong to. All ids are in the range [1, |kNumGroups|].
39 // For more information about the algorithm used see http://goo.gl/vUuFd5.
40 static const DomainGroupsPair kDomainMapping[] = {
41 {"google.com", {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}},
42 {"yahoo.com", {1, 2, 3, 4, 5, 11, 12, 13, 14, 15}},
43 {"baidu.com", {1, 2, 3, 4, 6, 7, 11, 12, 16, 17}},
44 {"wikipedia.org", {1, 2, 3, 4, 5, 6, 11, 12, 16, 18}},
45 {"linkedin.com", {1, 6, 8, 11, 13, 14, 15, 16, 17, 19}},
46 {"twitter.com", {5, 6, 7, 8, 9, 11, 13, 17, 19, 20}},
47 {"live.com", {7, 8, 9, 10, 13, 14, 16, 17, 18, 20}},
48 {"amazon.com", {2, 5, 9, 10, 12, 14, 15, 18, 19, 20}},
49 {"ebay.com", {3, 7, 9, 10, 14, 15, 17, 18, 19, 20}},
50 {"tumblr.com", {4, 8, 10, 12, 13, 15, 16, 18, 19, 20}},
51 };
52 const size_t kDomainMappingLength = arraysize(kDomainMapping);
53
54 GenerateRandomId();
55
56 GURL url(url_host);
57 for (size_t i = 0; i < kDomainMappingLength; ++i) {
58 if (url.DomainIs(kDomainMapping[i].domain_name))
59 return kDomainMapping[i].group_ids[g_random_group_id];
60 }
61 return 0;
62 }
63
64 void LogUMAHistogramEnumeration(const std::string& name,
65 int sample,
66 int boundary_value) {
67 DCHECK_LT(sample, boundary_value);
68
69 // Note: This leaks memory, which is expected behavior.
70 base::HistogramBase* histogram =
71 base::LinearHistogram::FactoryGet(
72 name,
73 1,
74 boundary_value,
75 boundary_value + 1,
76 base::HistogramBase::kUmaTargetedHistogramFlag);
77 histogram->Add(sample);
78 }
79
80 void LogUMAHistogramBoolean(const std::string& name, bool sample) {
81 // Note: This leaks memory, which is expected behavior.
82 base::HistogramBase* histogram =
83 base::BooleanHistogram::FactoryGet(
84 name,
85 base::Histogram::kNoFlags);
86 histogram->AddBoolean(sample);
87 }
88
89 // Generate an id in range [0, |kGroupsPerDomain|).
90 // If the |random_group_id| is equal to its initial value (|kGroupsPerDomain|),
91 // the value of |random_id| is not changed.
92 void GenerateRandomId() {
93 // For each session, the user uses only one group for each website.
94 if (g_random_group_id == kGroupsPerDomain)
95 g_random_group_id = base::RandGenerator(kGroupsPerDomain);
96 }
97
98 void SetRandomIdForTesting(size_t value) {
99 g_random_group_id = value;
100 }
101
102 std::string GroupIdToString(size_t group_id) {
103 if (group_id > 0 && group_id <= kNumGroups)
Ilya Sherman 2013/09/12 23:43:40 nit: DCHECK_LE that group_id <= kNumGroups, since
jdomingos 2013/09/13 21:56:23 Done.
104 return "group_" + base::IntToString(group_id);
105 return "";
Ilya Sherman 2013/09/12 23:43:40 nit: return std::string();
jdomingos 2013/09/13 21:56:23 Done.
106 }
107
108 } // namespace password_manager_metrics_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698