Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: components/webdata/common/web_database.cc

Issue 382703002: Remove unused SQLLite tables from WebData (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments and cleanup Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "components/webdata/common/web_database.h" 5 #include "components/webdata/common/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 "sql/statement.h" 10 #include "sql/statement.h"
11 #include "sql/transaction.h" 11 #include "sql/transaction.h"
12 12
13 // Current version number. Note: when changing the current version number, 13 // Current version number. Note: when changing the current version number,
14 // corresponding changes must happen in the unit tests, and new migration test 14 // corresponding changes must happen in the unit tests, and new migration test
15 // added. See |WebDatabaseMigrationTest::kCurrentTestedVersionNumber|. 15 // added. See |WebDatabaseMigrationTest::kCurrentTestedVersionNumber|.
16 // static 16 // static
17 const int WebDatabase::kCurrentVersionNumber = 57; 17 const int WebDatabase::kCurrentVersionNumber = 58;
18 18
19 namespace { 19 namespace {
20 20
21 const int kCompatibleVersionNumber = 57; 21 const int kCompatibleVersionNumber = 58;
22 22
23 // Change the version number and possibly the compatibility version of 23 // Change the version number and possibly the compatibility version of
24 // |meta_table_|. 24 // |meta_table_|.
25 void ChangeVersion(sql::MetaTable* meta_table, 25 void ChangeVersion(sql::MetaTable* meta_table,
26 int version_num, 26 int version_num,
27 bool update_compatible_version_num) { 27 bool update_compatible_version_num) {
28 meta_table->SetVersionNumber(version_num); 28 meta_table->SetVersionNumber(version_num);
29 if (update_compatible_version_num) { 29 if (update_compatible_version_num) {
30 meta_table->SetCompatibleVersionNumber( 30 meta_table->SetCompatibleVersionNumber(
31 std::min(version_num, kCompatibleVersionNumber)); 31 std::min(version_num, kCompatibleVersionNumber));
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // erase all their prefs and start over, etc.). 148 // erase all their prefs and start over, etc.).
149 LOG(WARNING) << "Web database version " << current_version 149 LOG(WARNING) << "Web database version " << current_version
150 << " is too old to handle."; 150 << " is too old to handle.";
151 NOTREACHED(); 151 NOTREACHED();
152 return sql::INIT_FAILURE; 152 return sql::INIT_FAILURE;
153 } 153 }
154 154
155 for (int next_version = current_version + 1; 155 for (int next_version = current_version + 1;
156 next_version <= kCurrentVersionNumber; 156 next_version <= kCurrentVersionNumber;
157 ++next_version) { 157 ++next_version) {
158
159 // Do any database-wide migrations.
160 bool update_compatible_version = false;
161 if (!MigrateToVersion(next_version, &update_compatible_version))
162 return FailedMigrationTo(next_version);
163
164 ChangeVersion(&meta_table_, next_version, update_compatible_version);
165
158 // Give each table a chance to migrate to this version. 166 // Give each table a chance to migrate to this version.
159 for (TableMap::iterator it = tables_.begin(); it != tables_.end(); ++it) { 167 for (TableMap::iterator it = tables_.begin(); it != tables_.end(); ++it) {
160 // Any of the tables may set this to true, but by default it is false. 168 // Any of the tables may set this to true, but by default it is false.
161 bool update_compatible_version = false; 169 update_compatible_version = false;
162 if (!it->second->MigrateToVersion(next_version, 170 if (!it->second->MigrateToVersion(next_version,
163 &update_compatible_version)) { 171 &update_compatible_version)) {
164 return FailedMigrationTo(next_version); 172 return FailedMigrationTo(next_version);
165 } 173 }
166 174
167 ChangeVersion(&meta_table_, next_version, update_compatible_version); 175 ChangeVersion(&meta_table_, next_version, update_compatible_version);
168 } 176 }
169 } 177 }
170 return sql::INIT_OK; 178 return sql::INIT_OK;
171 } 179 }
180
181 bool WebDatabase::MigrateToVersion(int version,
182 bool* update_compatible_version) {
183 // Migrate if necessary.
184 switch (version) {
185 case 58:
186 *update_compatible_version = true;
187 return MigrateToVersion58DropWebAppsAndIntents();
188 }
189
190 return true;
191 }
192
193 bool WebDatabase::MigrateToVersion58DropWebAppsAndIntents() {
194 sql::Transaction transaction(&db_);
195 return transaction.Begin() &&
196 (db_.Execute("DROP TABLE IF EXISTS web_apps")) &&
197 (db_.Execute("DROP TABLE IF EXISTS web_app_icons")) &&
198 (db_.Execute("DROP TABLE IF EXISTS web_intents")) &&
199 (db_.Execute("DROP TABLE IF EXISTS web_intents_defaults")) &&
Scott Hess - ex-Googler 2014/07/14 23:27:53 Now that you aren't distinguishing the || from the
Cait (Slow) 2014/07/15 16:58:38 Done.
200 transaction.Commit();
201 }
OLDNEW
« no previous file with comments | « components/webdata/common/web_database.h ('k') | components/webdata/common/web_database_migration_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698