| 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" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 void LogAccountStat(const std::string& name, int sample) { | 149 void LogAccountStat(const std::string& name, int sample) { |
| 150 LogDynamicUMAStat(name, sample, 0, 32, 6); | 150 LogDynamicUMAStat(name, sample, 0, 32, 6); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void LogTimesUsedStat(const std::string& name, int sample) { | 153 void LogTimesUsedStat(const std::string& name, int sample) { |
| 154 LogDynamicUMAStat(name, sample, 0, 100, 10); | 154 LogDynamicUMAStat(name, sample, 0, 100, 10); |
| 155 } | 155 } |
| 156 | 156 |
| 157 } // namespace | 157 } // namespace |
| 158 | 158 |
| 159 LoginDatabase::LoginDatabase() { | 159 LoginDatabase::LoginDatabase(const base::FilePath& db_path) |
| 160 : db_path_(db_path) { |
| 160 } | 161 } |
| 161 | 162 |
| 162 LoginDatabase::~LoginDatabase() { | 163 LoginDatabase::~LoginDatabase() { |
| 163 } | 164 } |
| 164 | 165 |
| 165 bool LoginDatabase::Init(const base::FilePath& db_path) { | 166 bool LoginDatabase::Init() { |
| 166 // Set pragmas for a small, private database (based on WebDatabase). | 167 // Set pragmas for a small, private database (based on WebDatabase). |
| 167 db_.set_page_size(2048); | 168 db_.set_page_size(2048); |
| 168 db_.set_cache_size(32); | 169 db_.set_cache_size(32); |
| 169 db_.set_exclusive_locking(); | 170 db_.set_exclusive_locking(); |
| 170 db_.set_restrict_to_user(); | 171 db_.set_restrict_to_user(); |
| 171 | 172 |
| 172 { | 173 { |
| 173 // TODO(vadimt): Remove ScopedTracker below once crbug.com/138903 is fixed. | 174 // TODO(vadimt): Remove ScopedTracker below once crbug.com/138903 is fixed. |
| 174 tracked_objects::ScopedTracker tracking_profile( | 175 tracked_objects::ScopedTracker tracking_profile( |
| 175 FROM_HERE_WITH_EXPLICIT_FUNCTION("138903 LoginDatabase::Init db init")); | 176 FROM_HERE_WITH_EXPLICIT_FUNCTION("138903 LoginDatabase::Init db init")); |
| 176 | 177 |
| 177 if (!db_.Open(db_path)) { | 178 if (!db_.Open(db_path_)) { |
| 178 LOG(WARNING) << "Unable to open the password store database."; | 179 LOG(WARNING) << "Unable to open the password store database."; |
| 179 return false; | 180 return false; |
| 180 } | 181 } |
| 181 } | 182 } |
| 182 | 183 |
| 183 sql::Transaction transaction(&db_); | 184 sql::Transaction transaction(&db_); |
| 184 transaction.Begin(); | 185 transaction.Begin(); |
| 185 | 186 |
| 186 // Check the database version. | 187 // Check the database version. |
| 187 if (!meta_table_.Init(&db_, kCurrentVersionNumber, | 188 if (!meta_table_.Init(&db_, kCurrentVersionNumber, |
| 188 kCompatibleVersionNumber)) { | 189 kCompatibleVersionNumber)) { |
| 189 db_.Close(); | 190 db_.Close(); |
| 190 return false; | 191 return false; |
| 191 } | 192 } |
| 192 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) { | 193 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) { |
| 193 LOG(WARNING) << "Password store database is too new."; | 194 LOG(WARNING) << "Password store database is too new."; |
| 194 db_.Close(); | 195 db_.Close(); |
| 195 return false; | 196 return false; |
| 196 } | 197 } |
| 197 | 198 |
| 198 // Initialize the tables. | 199 // Initialize the tables. |
| 199 if (!InitLoginsTable()) { | 200 if (!InitLoginsTable()) { |
| 200 LOG(WARNING) << "Unable to initialize the password store database."; | 201 LOG(WARNING) << "Unable to initialize the password store database."; |
| 201 db_.Close(); | 202 db_.Close(); |
| 202 return false; | 203 return false; |
| 203 } | 204 } |
| 204 | 205 |
| 205 // Save the path for DeleteDatabaseFile(). | |
| 206 db_path_ = db_path; | |
| 207 | |
| 208 // If the file on disk is an older database version, bring it up to date. | 206 // If the file on disk is an older database version, bring it up to date. |
| 209 if (!MigrateOldVersionsAsNeeded()) { | 207 if (!MigrateOldVersionsAsNeeded()) { |
| 210 LOG(WARNING) << "Unable to migrate database"; | 208 LOG(WARNING) << "Unable to migrate database"; |
| 211 db_.Close(); | 209 db_.Close(); |
| 212 return false; | 210 return false; |
| 213 } | 211 } |
| 214 | 212 |
| 215 if (!transaction.Commit()) { | 213 if (!transaction.Commit()) { |
| 216 db_.Close(); | 214 db_.Close(); |
| 217 return false; | 215 return false; |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 forms->push_back(new_form.release()); | 851 forms->push_back(new_form.release()); |
| 854 } | 852 } |
| 855 return s.Succeeded(); | 853 return s.Succeeded(); |
| 856 } | 854 } |
| 857 | 855 |
| 858 bool LoginDatabase::DeleteAndRecreateDatabaseFile() { | 856 bool LoginDatabase::DeleteAndRecreateDatabaseFile() { |
| 859 DCHECK(db_.is_open()); | 857 DCHECK(db_.is_open()); |
| 860 meta_table_.Reset(); | 858 meta_table_.Reset(); |
| 861 db_.Close(); | 859 db_.Close(); |
| 862 sql::Connection::Delete(db_path_); | 860 sql::Connection::Delete(db_path_); |
| 863 return Init(db_path_); | 861 return Init(); |
| 864 } | 862 } |
| 865 | 863 |
| 866 } // namespace password_manager | 864 } // namespace password_manager |
| OLD | NEW |