Chromium Code Reviews| Index: components/password_manager/core/browser/login_database.cc |
| diff --git a/components/password_manager/core/browser/login_database.cc b/components/password_manager/core/browser/login_database.cc |
| index 050bf8a5e48cb42bf4daae2d2c4b3774a9ea15ca..6b28702c990c71f041f1a100e8043838eb9b6289 100644 |
| --- a/components/password_manager/core/browser/login_database.cc |
| +++ b/components/password_manager/core/browser/login_database.cc |
| @@ -13,8 +13,10 @@ |
| #include "base/metrics/histogram.h" |
| #include "base/pickle.h" |
| #include "base/strings/string_util.h" |
| +#include "base/strings/stringprintf.h" |
| #include "base/time/time.h" |
| #include "components/autofill/core/common/password_form.h" |
| +#include "components/password_manager/core/browser/password_manager_client.h" |
| #include "google_apis/gaia/gaia_auth_util.h" |
| #include "google_apis/gaia/gaia_urls.h" |
| #include "sql/connection.h" |
| @@ -115,6 +117,22 @@ void AddCallback(int err, sql::Statement* /*stmt*/) { |
| DLOG(WARNING) << "LoginDatabase::AddLogin updated an existing form"; |
| } |
| +// UMA_* macros assume that the name never changes. This is a helper function |
| +// where this assumption doesn't hold. |
| +void LogDynamicUMAStat(const std::string& name, |
| + int sample, |
| + int min, |
| + int max, |
| + int bucket_size) { |
| + base::HistogramBase* counter = base::Histogram::FactoryGet( |
| + name, |
| + min, |
| + max, |
| + bucket_size, |
| + base::HistogramBase::kUmaTargetedHistogramFlag); |
| + counter->Add(sample); |
| +} |
| + |
| } // namespace |
| LoginDatabase::LoginDatabase() { |
| @@ -281,7 +299,7 @@ bool LoginDatabase::InitLoginsTable() { |
| return true; |
| } |
| -void LoginDatabase::ReportMetrics(const std::string& sync_username) { |
| +void LoginDatabase::ReportMetrics(PasswordManagerClient* client) { |
| sql::Statement s(db_.GetCachedStatement( |
| SQL_FROM_HERE, |
| "SELECT signon_realm, blacklisted_by_user, COUNT(username_value) " |
| @@ -290,6 +308,11 @@ void LoginDatabase::ReportMetrics(const std::string& sync_username) { |
| if (!s.is_valid()) |
| return; |
| + std::string custom_passphrase = "WithoutCustomPassphrase"; |
| + if (client->IsPasswordSyncEnabled(ONLY_CUSTOM_PASSPHRASE)) { |
| + custom_passphrase = "WithCustomPassphrase"; |
| + } |
| + |
| int total_accounts = 0; |
| int blacklisted_sites = 0; |
| while (s.Step()) { |
| @@ -299,14 +322,26 @@ void LoginDatabase::ReportMetrics(const std::string& sync_username) { |
| ++blacklisted_sites; |
| } else { |
| total_accounts += accounts_per_site; |
| - UMA_HISTOGRAM_CUSTOM_COUNTS("PasswordManager.AccountsPerSite", |
| - accounts_per_site, 0, 32, 6); |
| + LogDynamicUMAStat(base::StringPrintf("PasswordManager.AccountsPerSite%s", |
| + custom_passphrase.c_str()), |
| + accounts_per_site, |
| + 0, |
| + 32, |
| + 6); |
| } |
| } |
| - UMA_HISTOGRAM_CUSTOM_COUNTS("PasswordManager.TotalAccounts", |
| - total_accounts, 0, 32, 6); |
| - UMA_HISTOGRAM_CUSTOM_COUNTS("PasswordManager.BlacklistedSites", |
| - blacklisted_sites, 0, 32, 6); |
| + LogDynamicUMAStat(base::StringPrintf("PasswordManager.TotalAccounts%s", |
| + custom_passphrase.c_str()), |
| + total_accounts, |
| + 0, |
| + 32, |
| + 6); |
| + LogDynamicUMAStat(base::StringPrintf("PasswordManager.BlacklistedSites%s", |
| + custom_passphrase.c_str()), |
| + blacklisted_sites, |
| + 0, |
| + 32, |
| + 6); |
| sql::Statement usage_statement(db_.GetCachedStatement( |
| SQL_FROM_HERE, |
| @@ -320,17 +355,26 @@ void LoginDatabase::ReportMetrics(const std::string& sync_username) { |
| usage_statement.ColumnInt(0)); |
| if (type == PasswordForm::TYPE_GENERATED) { |
| - UMA_HISTOGRAM_CUSTOM_COUNTS( |
| - "PasswordManager.TimesGeneratedPasswordUsed", |
| - usage_statement.ColumnInt(1), 0, 100, 10); |
| + LogDynamicUMAStat( |
| + base::StringPrintf("PasswordManager.TimesGeneratedPasswordUsed%s", |
| + custom_passphrase.c_str()), |
| + usage_statement.ColumnInt(1), |
| + 0, |
| + 100, |
| + 10); |
| } else { |
| - UMA_HISTOGRAM_CUSTOM_COUNTS( |
| - "PasswordManager.TimesPasswordUsed", |
| - usage_statement.ColumnInt(1), 0, 100, 10); |
| + LogDynamicUMAStat( |
| + base::StringPrintf("PasswordManager.TimesPasswordUsed%s", |
| + custom_passphrase.c_str()), |
| + usage_statement.ColumnInt(1), |
| + 0, |
| + 100, |
| + 10); |
|
Alexei Svitkine (slow)
2014/10/15 15:15:31
Instead of repeating these params, how about makin
Garrett Casto
2014/10/16 22:52:10
Done.
|
| } |
| } |
| bool syncing_account_saved = false; |
| + std::string sync_username = client->GetSyncUsername(); |
| if (!sync_username.empty()) { |
| sql::Statement sync_statement(db_.GetCachedStatement( |
| SQL_FROM_HERE, |