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

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

Issue 141113003: Refactor base/safe_numerics.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/password_manager/password_manager_metrics_util.h" 5 #include "chrome/browser/password_manager/password_manager_metrics_util.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/numerics/safe_conversions.h"
9 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
10 #include "base/prefs/scoped_user_pref_update.h" 11 #include "base/prefs/scoped_user_pref_update.h"
11 #include "base/rand_util.h" 12 #include "base/rand_util.h"
12 #include "base/safe_numerics.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "url/gurl.h" 18 #include "url/gurl.h"
19 19
20 using base::ListValue; 20 using base::ListValue;
21 using base::FundamentalValue; 21 using base::FundamentalValue;
22 22
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 DCHECK_LT(domain_index, kNumDomains); 58 DCHECK_LT(domain_index, kNumDomains);
59 59
60 const base::ListValue* group_indices = 60 const base::ListValue* group_indices =
61 pref_service->GetList(prefs::kPasswordManagerGroupsForDomains); 61 pref_service->GetList(prefs::kPasswordManagerGroupsForDomains);
62 int result = 0; 62 int result = 0;
63 if (!group_indices->GetInteger(domain_index, &result)) { 63 if (!group_indices->GetInteger(domain_index, &result)) {
64 ListPrefUpdate group_indices_updater( 64 ListPrefUpdate group_indices_updater(
65 pref_service, prefs::kPasswordManagerGroupsForDomains); 65 pref_service, prefs::kPasswordManagerGroupsForDomains);
66 // This value has not been generated yet. 66 // This value has not been generated yet.
67 result = 67 result =
68 base::checked_numeric_cast<int>(base::RandGenerator(kGroupsPerDomain)); 68 base::checked_cast<int>(base::RandGenerator(kGroupsPerDomain));
69 group_indices_updater->Set(domain_index, new FundamentalValue(result)); 69 group_indices_updater->Set(domain_index, new FundamentalValue(result));
70 } 70 }
71 return base::checked_numeric_cast<size_t>(result); 71 return base::checked_cast<size_t>(result);
72 } 72 }
73 73
74 } // namespace 74 } // namespace
75 75
76 size_t MonitoredDomainGroupId(const std::string& url_host, 76 size_t MonitoredDomainGroupId(const std::string& url_host,
77 PrefService* pref_service) { 77 PrefService* pref_service) {
78 GURL url(url_host); 78 GURL url(url_host);
79 for (size_t i = 0; i < kNumDomains; ++i) { 79 for (size_t i = 0; i < kNumDomains; ++i) {
80 if (url.DomainIs(kDomainMapping[i].domain_name)) 80 if (url.DomainIs(kDomainMapping[i].domain_name))
81 return kDomainMapping[i].group_ids[GetGroupIndex(i, pref_service)]; 81 return kDomainMapping[i].group_ids[GetGroupIndex(i, pref_service)];
(...skipping 27 matching lines...) Expand all
109 } 109 }
110 110
111 std::string GroupIdToString(size_t group_id) { 111 std::string GroupIdToString(size_t group_id) {
112 DCHECK_LE(group_id, kNumGroups); 112 DCHECK_LE(group_id, kNumGroups);
113 if (group_id > 0) 113 if (group_id > 0)
114 return "group_" + base::IntToString(group_id); 114 return "group_" + base::IntToString(group_id);
115 return std::string(); 115 return std::string();
116 } 116 }
117 117
118 } // namespace password_manager_metrics_util 118 } // namespace password_manager_metrics_util
OLDNEW
« no previous file with comments | « chrome/browser/net/crl_set_fetcher.cc ('k') | chrome/browser/password_manager/password_manager_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698