OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/password_manager/core/browser/login_database.h" | 5 #include "components/password_manager/core/browser/login_database.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/pickle.h" | 14 #include "base/pickle.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "components/autofill/core/common/password_form.h" | 17 #include "components/autofill/core/common/password_form.h" |
18 #include "google_apis/gaia/gaia_auth_util.h" | |
19 #include "google_apis/gaia/gaia_urls.h" | |
18 #include "sql/connection.h" | 20 #include "sql/connection.h" |
19 #include "sql/statement.h" | 21 #include "sql/statement.h" |
20 #include "sql/transaction.h" | 22 #include "sql/transaction.h" |
21 | 23 |
22 using autofill::PasswordForm; | 24 using autofill::PasswordForm; |
23 | 25 |
24 namespace password_manager { | 26 namespace password_manager { |
25 | 27 |
26 static const int kCurrentVersionNumber = 6; | 28 static const int kCurrentVersionNumber = 6; |
27 static const int kCompatibleVersionNumber = 1; | 29 static const int kCompatibleVersionNumber = 1; |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 } | 249 } |
248 if (!db_.Execute("CREATE INDEX logins_signon ON " | 250 if (!db_.Execute("CREATE INDEX logins_signon ON " |
249 "logins (signon_realm)")) { | 251 "logins (signon_realm)")) { |
250 NOTREACHED(); | 252 NOTREACHED(); |
251 return false; | 253 return false; |
252 } | 254 } |
253 } | 255 } |
254 return true; | 256 return true; |
255 } | 257 } |
256 | 258 |
257 void LoginDatabase::ReportMetrics() { | 259 void LoginDatabase::ReportMetrics(const std::string& sync_username, |
260 enum password_manager::SyncState sync_state) { | |
Ilya Sherman
2014/06/27 19:37:51
nit: I don't think you need the "enum" keyword her
Garrett Casto
2014/06/27 21:07:34
Done.
| |
258 sql::Statement s(db_.GetCachedStatement( | 261 sql::Statement s(db_.GetCachedStatement( |
259 SQL_FROM_HERE, | 262 SQL_FROM_HERE, |
260 "SELECT signon_realm, blacklisted_by_user, COUNT(username_value) " | 263 "SELECT signon_realm, blacklisted_by_user, COUNT(username_value) " |
261 "FROM logins GROUP BY signon_realm, blacklisted_by_user")); | 264 "FROM logins GROUP BY signon_realm, blacklisted_by_user")); |
262 | 265 |
263 if (!s.is_valid()) | 266 if (!s.is_valid()) |
264 return; | 267 return; |
265 | 268 |
266 int total_accounts = 0; | 269 int total_accounts = 0; |
267 int blacklisted_sites = 0; | 270 int blacklisted_sites = 0; |
(...skipping 27 matching lines...) Expand all Loading... | |
295 if (type == PasswordForm::TYPE_GENERATED) { | 298 if (type == PasswordForm::TYPE_GENERATED) { |
296 UMA_HISTOGRAM_CUSTOM_COUNTS( | 299 UMA_HISTOGRAM_CUSTOM_COUNTS( |
297 "PasswordManager.TimesGeneratedPasswordUsed", | 300 "PasswordManager.TimesGeneratedPasswordUsed", |
298 usage_statement.ColumnInt(1), 0, 100, 10); | 301 usage_statement.ColumnInt(1), 0, 100, 10); |
299 } else { | 302 } else { |
300 UMA_HISTOGRAM_CUSTOM_COUNTS( | 303 UMA_HISTOGRAM_CUSTOM_COUNTS( |
301 "PasswordManager.TimesPasswordUsed", | 304 "PasswordManager.TimesPasswordUsed", |
302 usage_statement.ColumnInt(1), 0, 100, 10); | 305 usage_statement.ColumnInt(1), 0, 100, 10); |
303 } | 306 } |
304 } | 307 } |
308 | |
309 bool syncing_account_saved = false; | |
310 int times_syncing_account_used = 0; | |
311 if (!sync_username.empty()) { | |
312 sql::Statement sync_statement(db_.GetCachedStatement( | |
313 SQL_FROM_HERE, | |
314 "SELECT username_value, times_used FROM logins " | |
315 "WHERE signon_realm == ?")); | |
316 sync_statement.BindString( | |
317 0, GaiaUrls::GetInstance()->gaia_url().GetOrigin().spec()); | |
318 | |
319 if (!sync_statement.is_valid()) | |
320 return; | |
321 | |
322 while (sync_statement.Step()) { | |
323 std::string username = sync_statement.ColumnString(0); | |
324 // It's possible to have multiple stored credentials that all reference | |
325 // the same account (different spelling of the same name or different | |
326 // URL). | |
327 if (gaia::AreEmailsSame(sync_username, username)) { | |
328 syncing_account_saved = true; | |
329 times_syncing_account_used += sync_statement.ColumnInt(1); | |
330 } | |
331 } | |
332 } | |
333 UMA_HISTOGRAM_ENUMERATION("PasswordManager.SyncingAccountState", | |
334 2 * sync_state + syncing_account_saved, | |
335 2 * password_manager::NUM_SYNC_STATES); | |
336 | |
337 if (syncing_account_saved) { | |
338 switch (sync_state) { | |
339 case password_manager::PASSWORD_SYNC_ENABLED: | |
340 UMA_HISTOGRAM_COUNTS_100( | |
341 "PasswordManager.PasswordSyncAccountTimesUsed", | |
342 times_syncing_account_used); | |
343 break; | |
344 case password_manager::PASSWORD_SYNC_DISABLED: | |
345 UMA_HISTOGRAM_COUNTS_100( | |
346 "PasswordManager.SyncAccountTimesUsed", | |
347 times_syncing_account_used); | |
348 break; | |
349 default: | |
Ilya Sherman
2014/06/27 19:37:51
Optional nit: I generally prefer to enumerate all
Garrett Casto
2014/06/27 21:07:34
Done.
| |
350 NOTREACHED(); | |
351 } | |
352 } | |
305 } | 353 } |
306 | 354 |
307 PasswordStoreChangeList LoginDatabase::AddLogin(const PasswordForm& form) { | 355 PasswordStoreChangeList LoginDatabase::AddLogin(const PasswordForm& form) { |
308 PasswordStoreChangeList list; | 356 PasswordStoreChangeList list; |
309 std::string encrypted_password; | 357 std::string encrypted_password; |
310 if (EncryptedString(form.password_value, &encrypted_password) != | 358 if (EncryptedString(form.password_value, &encrypted_password) != |
311 ENCRYPTION_RESULT_SUCCESS) | 359 ENCRYPTION_RESULT_SUCCESS) |
312 return list; | 360 return list; |
313 | 361 |
314 // You *must* change LoginTableColumns if this query changes. | 362 // You *must* change LoginTableColumns if this query changes. |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
689 | 737 |
690 bool LoginDatabase::DeleteAndRecreateDatabaseFile() { | 738 bool LoginDatabase::DeleteAndRecreateDatabaseFile() { |
691 DCHECK(db_.is_open()); | 739 DCHECK(db_.is_open()); |
692 meta_table_.Reset(); | 740 meta_table_.Reset(); |
693 db_.Close(); | 741 db_.Close(); |
694 sql::Connection::Delete(db_path_); | 742 sql::Connection::Delete(db_path_); |
695 return Init(db_path_); | 743 return Init(db_path_); |
696 } | 744 } |
697 | 745 |
698 } // namespace password_manager | 746 } // namespace password_manager |
OLD | NEW |