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) { |
258 sql::Statement s(db_.GetCachedStatement( | 260 sql::Statement s(db_.GetCachedStatement( |
259 SQL_FROM_HERE, | 261 SQL_FROM_HERE, |
260 "SELECT signon_realm, blacklisted_by_user, COUNT(username_value) " | 262 "SELECT signon_realm, blacklisted_by_user, COUNT(username_value) " |
261 "FROM logins GROUP BY signon_realm, blacklisted_by_user")); | 263 "FROM logins GROUP BY signon_realm, blacklisted_by_user")); |
262 | 264 |
263 if (!s.is_valid()) | 265 if (!s.is_valid()) |
264 return; | 266 return; |
265 | 267 |
266 int total_accounts = 0; | 268 int total_accounts = 0; |
267 int blacklisted_sites = 0; | 269 int blacklisted_sites = 0; |
(...skipping 27 matching lines...) Expand all Loading... | |
295 if (type == PasswordForm::TYPE_GENERATED) { | 297 if (type == PasswordForm::TYPE_GENERATED) { |
296 UMA_HISTOGRAM_CUSTOM_COUNTS( | 298 UMA_HISTOGRAM_CUSTOM_COUNTS( |
297 "PasswordManager.TimesGeneratedPasswordUsed", | 299 "PasswordManager.TimesGeneratedPasswordUsed", |
298 usage_statement.ColumnInt(1), 0, 100, 10); | 300 usage_statement.ColumnInt(1), 0, 100, 10); |
299 } else { | 301 } else { |
300 UMA_HISTOGRAM_CUSTOM_COUNTS( | 302 UMA_HISTOGRAM_CUSTOM_COUNTS( |
301 "PasswordManager.TimesPasswordUsed", | 303 "PasswordManager.TimesPasswordUsed", |
302 usage_statement.ColumnInt(1), 0, 100, 10); | 304 usage_statement.ColumnInt(1), 0, 100, 10); |
303 } | 305 } |
304 } | 306 } |
307 | |
308 bool syncing_account_saved = false; | |
309 if (!sync_username.empty()) { | |
310 sql::Statement sync_statement(db_.GetCachedStatement( | |
311 SQL_FROM_HERE, | |
312 "SELECT username_value FROM logins " | |
313 "WHERE signon_realm == ?")); | |
314 sync_statement.BindString( | |
315 0, GaiaUrls::GetInstance()->gaia_url().GetOrigin().spec()); | |
316 | |
317 if (!sync_statement.is_valid()) | |
318 return; | |
319 | |
320 while (sync_statement.Step()) { | |
321 std::string username = sync_statement.ColumnString(0); | |
322 if (gaia::AreEmailsSame(sync_username, username)) { | |
323 syncing_account_saved = true; | |
324 break; | |
325 } | |
326 } | |
327 } | |
328 UMA_HISTOGRAM_ENUMERATION("PasswordManager.SyncingAccountState", | |
329 2 * sync_username.empty() + syncing_account_saved, | |
vabr (Chromium)
2014/07/01 08:52:00
This type of boolean mixing arithmetic looks almos
Garrett Casto
2014/07/04 07:27:49
Yeah, verified this with the standard before I use
| |
330 4); | |
305 } | 331 } |
306 | 332 |
307 PasswordStoreChangeList LoginDatabase::AddLogin(const PasswordForm& form) { | 333 PasswordStoreChangeList LoginDatabase::AddLogin(const PasswordForm& form) { |
308 PasswordStoreChangeList list; | 334 PasswordStoreChangeList list; |
309 std::string encrypted_password; | 335 std::string encrypted_password; |
310 if (EncryptedString(form.password_value, &encrypted_password) != | 336 if (EncryptedString(form.password_value, &encrypted_password) != |
311 ENCRYPTION_RESULT_SUCCESS) | 337 ENCRYPTION_RESULT_SUCCESS) |
312 return list; | 338 return list; |
313 | 339 |
314 // You *must* change LoginTableColumns if this query changes. | 340 // You *must* change LoginTableColumns if this query changes. |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
689 | 715 |
690 bool LoginDatabase::DeleteAndRecreateDatabaseFile() { | 716 bool LoginDatabase::DeleteAndRecreateDatabaseFile() { |
691 DCHECK(db_.is_open()); | 717 DCHECK(db_.is_open()); |
692 meta_table_.Reset(); | 718 meta_table_.Reset(); |
693 db_.Close(); | 719 db_.Close(); |
694 sql::Connection::Delete(db_path_); | 720 sql::Connection::Delete(db_path_); |
695 return Init(db_path_); | 721 return Init(db_path_); |
696 } | 722 } |
697 | 723 |
698 } // namespace password_manager | 724 } // namespace password_manager |
OLD | NEW |