OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/webdata/web_database.h" | 5 #include "chrome/browser/webdata/web_database.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } | 62 } |
63 | 63 |
64 void WebDatabase::CommitTransaction() { | 64 void WebDatabase::CommitTransaction() { |
65 db_.CommitTransaction(); | 65 db_.CommitTransaction(); |
66 } | 66 } |
67 | 67 |
68 sql::Connection* WebDatabase::GetSQLConnection() { | 68 sql::Connection* WebDatabase::GetSQLConnection() { |
69 return &db_; | 69 return &db_; |
70 } | 70 } |
71 | 71 |
72 sql::InitStatus WebDatabase::Init(const base::FilePath& db_name, | 72 sql::InitStatus WebDatabase::Init(const base::FilePath& db_name) { |
73 const std::string& app_locale) { | |
74 // When running in unit tests, there is already a NotificationService object. | 73 // When running in unit tests, there is already a NotificationService object. |
75 // Since only one can exist at a time per thread, check first. | 74 // Since only one can exist at a time per thread, check first. |
76 if (!content::NotificationService::current()) | 75 if (!content::NotificationService::current()) |
77 notification_service_.reset(content::NotificationService::Create()); | 76 notification_service_.reset(content::NotificationService::Create()); |
78 | 77 |
79 db_.set_error_histogram_name("Sqlite.Web.Error"); | 78 db_.set_error_histogram_name("Sqlite.Web.Error"); |
80 | 79 |
81 // We don't store that much data in the tables so use a small page size. | 80 // We don't store that much data in the tables so use a small page size. |
82 // This provides a large benefit for empty tables (which is very likely with | 81 // This provides a large benefit for empty tables (which is very likely with |
83 // the tables we create). | 82 // the tables we create). |
(...skipping 29 matching lines...) Expand all Loading... |
113 ++it) { | 112 ++it) { |
114 if (!it->second->Init(&db_, &meta_table_)) { | 113 if (!it->second->Init(&db_, &meta_table_)) { |
115 LOG(WARNING) << "Unable to initialize the web database."; | 114 LOG(WARNING) << "Unable to initialize the web database."; |
116 return sql::INIT_FAILURE; | 115 return sql::INIT_FAILURE; |
117 } | 116 } |
118 } | 117 } |
119 | 118 |
120 // If the file on disk is an older database version, bring it up to date. | 119 // If the file on disk is an older database version, bring it up to date. |
121 // If the migration fails we return an error to caller and do not commit | 120 // If the migration fails we return an error to caller and do not commit |
122 // the migration. | 121 // the migration. |
123 sql::InitStatus migration_status = MigrateOldVersionsAsNeeded(app_locale); | 122 sql::InitStatus migration_status = MigrateOldVersionsAsNeeded(); |
124 if (migration_status != sql::INIT_OK) | 123 if (migration_status != sql::INIT_OK) |
125 return migration_status; | 124 return migration_status; |
126 | 125 |
127 return transaction.Commit() ? sql::INIT_OK : sql::INIT_FAILURE; | 126 return transaction.Commit() ? sql::INIT_OK : sql::INIT_FAILURE; |
128 } | 127 } |
129 | 128 |
130 sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded( | 129 sql::InitStatus WebDatabase::MigrateOldVersionsAsNeeded() { |
131 const std::string& app_locale) { | |
132 // Some malware used to lower the version number, causing migration to | 130 // Some malware used to lower the version number, causing migration to |
133 // fail. Ensure the version number is at least as high as the compatible | 131 // fail. Ensure the version number is at least as high as the compatible |
134 // version number. | 132 // version number. |
135 int current_version = std::max(meta_table_.GetVersionNumber(), | 133 int current_version = std::max(meta_table_.GetVersionNumber(), |
136 meta_table_.GetCompatibleVersionNumber()); | 134 meta_table_.GetCompatibleVersionNumber()); |
137 if (current_version > meta_table_.GetVersionNumber()) | 135 if (current_version > meta_table_.GetVersionNumber()) |
138 ChangeVersion(&meta_table_, current_version, false); | 136 ChangeVersion(&meta_table_, current_version, false); |
139 | 137 |
140 if (current_version < 20) { | 138 if (current_version < 20) { |
141 // Versions 1 - 19 are unhandled. Version numbers greater than | 139 // Versions 1 - 19 are unhandled. Version numbers greater than |
(...skipping 15 matching lines...) Expand all Loading... |
157 for (int next_version = current_version + 1; | 155 for (int next_version = current_version + 1; |
158 next_version <= kCurrentVersionNumber; | 156 next_version <= kCurrentVersionNumber; |
159 ++next_version) { | 157 ++next_version) { |
160 // Give each table a chance to migrate to this version. | 158 // Give each table a chance to migrate to this version. |
161 for (TableMap::iterator it = tables_.begin(); | 159 for (TableMap::iterator it = tables_.begin(); |
162 it != tables_.end(); | 160 it != tables_.end(); |
163 ++it) { | 161 ++it) { |
164 // Any of the tables may set this to true, but by default it is false. | 162 // Any of the tables may set this to true, but by default it is false. |
165 bool update_compatible_version = false; | 163 bool update_compatible_version = false; |
166 if (!it->second->MigrateToVersion(next_version, | 164 if (!it->second->MigrateToVersion(next_version, |
167 app_locale, | 165 &update_compatible_version)) { |
168 &update_compatible_version)) { | |
169 return FailedMigrationTo(next_version); | 166 return FailedMigrationTo(next_version); |
170 } | 167 } |
171 | 168 |
172 ChangeVersion(&meta_table_, next_version, update_compatible_version); | 169 ChangeVersion(&meta_table_, next_version, update_compatible_version); |
173 } | 170 } |
174 } | 171 } |
175 return sql::INIT_OK; | 172 return sql::INIT_OK; |
176 } | 173 } |
OLD | NEW |