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