| 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/keyword_table.h" | 5 #include "chrome/browser/webdata/keyword_table.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Checks if signature for search provider id is correct and returns the | 109 // Checks if signature for search provider id is correct and returns the |
| 110 // result. | 110 // result. |
| 111 bool IsSearchProviderIDValid(int64 id, const std::string& signature) { | 111 bool IsSearchProviderIDValid(int64 id, const std::string& signature) { |
| 112 return protector::IsSettingValid(base::Int64ToString(id), signature); | 112 return protector::IsSettingValid(base::Int64ToString(id), signature); |
| 113 } | 113 } |
| 114 | 114 |
| 115 } // anonymous namespace | 115 } // anonymous namespace |
| 116 | 116 |
| 117 KeywordTable::KeywordTable(sql::Connection* db, sql::MetaTable* meta_table) |
| 118 : WebDatabaseTable(db, meta_table), |
| 119 backup_overwritten_(false) { |
| 120 } |
| 121 |
| 117 KeywordTable::~KeywordTable() {} | 122 KeywordTable::~KeywordTable() {} |
| 118 | 123 |
| 119 bool KeywordTable::Init() { | 124 bool KeywordTable::Init() { |
| 120 return db_->DoesTableExist("keywords") || | 125 return db_->DoesTableExist("keywords") || |
| 121 (db_->Execute("CREATE TABLE keywords (" | 126 (db_->Execute("CREATE TABLE keywords (" |
| 122 "id INTEGER PRIMARY KEY," | 127 "id INTEGER PRIMARY KEY," |
| 123 "short_name VARCHAR NOT NULL," | 128 "short_name VARCHAR NOT NULL," |
| 124 "keyword VARCHAR NOT NULL," | 129 "keyword VARCHAR NOT NULL," |
| 125 "favicon_url VARCHAR NOT NULL," | 130 "favicon_url VARCHAR NOT NULL," |
| 126 "url VARCHAR NOT NULL," | 131 "url VARCHAR NOT NULL," |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 255 |
| 251 int64 backup_id = kInvalidTemplateURLID; | 256 int64 backup_id = kInvalidTemplateURLID; |
| 252 meta_table_->GetValue(kDefaultSearchIDBackupKey, &backup_id); | 257 meta_table_->GetValue(kDefaultSearchIDBackupKey, &backup_id); |
| 253 int64 current_id = GetDefaultSearchProviderID(); | 258 int64 current_id = GetDefaultSearchProviderID(); |
| 254 if (backup_id == current_id) { | 259 if (backup_id == current_id) { |
| 255 // Either this is a new profile and both IDs are kInvalidTemplateURLID or | 260 // Either this is a new profile and both IDs are kInvalidTemplateURLID or |
| 256 // the search engines with the ids are equal. | 261 // the search engines with the ids are equal. |
| 257 if (backup_id == kInvalidTemplateURLID) { | 262 if (backup_id == kInvalidTemplateURLID) { |
| 258 UMA_HISTOGRAM_ENUMERATION( | 263 UMA_HISTOGRAM_ENUMERATION( |
| 259 protector::kProtectorHistogramDefaultSearchProvider, | 264 protector::kProtectorHistogramDefaultSearchProvider, |
| 260 protector::kProtectorErrorValueValidZero, | 265 backup_overwritten_ ? |
| 266 protector::kProtectorErrorOverwrittenByMigration : |
| 267 protector::kProtectorErrorValueValidZero, |
| 261 protector::kProtectorErrorCount); | 268 protector::kProtectorErrorCount); |
| 262 return false; | 269 return false; |
| 263 } | 270 } |
| 264 std::string backup_url; | 271 std::string backup_url; |
| 265 std::string current_url; | 272 std::string current_url; |
| 266 if (GetKeywordAsString(backup_id, "keywords_backup", &backup_url) && | 273 if (GetKeywordAsString(backup_id, "keywords_backup", &backup_url) && |
| 267 GetKeywordAsString(current_id, "keywords", ¤t_url) && | 274 GetKeywordAsString(current_id, "keywords", ¤t_url) && |
| 268 current_url == backup_url) { | 275 current_url == backup_url) { |
| 269 UMA_HISTOGRAM_ENUMERATION( | 276 UMA_HISTOGRAM_ENUMERATION( |
| 270 protector::kProtectorHistogramDefaultSearchProvider, | 277 protector::kProtectorHistogramDefaultSearchProvider, |
| 271 protector::kProtectorErrorValueValid, | 278 backup_overwritten_ ? |
| 279 protector::kProtectorErrorOverwrittenByMigration : |
| 280 protector::kProtectorErrorValueValid, |
| 272 protector::kProtectorErrorCount); | 281 protector::kProtectorErrorCount); |
| 273 return false; | 282 return false; |
| 274 } | 283 } |
| 275 } | 284 } |
| 276 | 285 |
| 277 UMA_HISTOGRAM_ENUMERATION( | 286 UMA_HISTOGRAM_ENUMERATION( |
| 278 protector::kProtectorHistogramDefaultSearchProvider, | 287 protector::kProtectorHistogramDefaultSearchProvider, |
| 279 protector::kProtectorErrorValueChanged, | 288 protector::kProtectorErrorValueChanged, |
| 280 protector::kProtectorErrorCount); | 289 protector::kProtectorErrorCount); |
| 281 LOG(WARNING) << "Default Search Provider has changed."; | 290 LOG(WARNING) << "Default Search Provider has changed."; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 bool KeywordTable::MigrateToVersion38AddLastModifiedColumn() { | 356 bool KeywordTable::MigrateToVersion38AddLastModifiedColumn() { |
| 348 return db_->Execute( | 357 return db_->Execute( |
| 349 "ALTER TABLE keywords ADD COLUMN last_modified INTEGER DEFAULT 0"); | 358 "ALTER TABLE keywords ADD COLUMN last_modified INTEGER DEFAULT 0"); |
| 350 } | 359 } |
| 351 | 360 |
| 352 bool KeywordTable::MigrateToVersion39AddSyncGUIDColumn() { | 361 bool KeywordTable::MigrateToVersion39AddSyncGUIDColumn() { |
| 353 return db_->Execute("ALTER TABLE keywords ADD COLUMN sync_guid VARCHAR"); | 362 return db_->Execute("ALTER TABLE keywords ADD COLUMN sync_guid VARCHAR"); |
| 354 } | 363 } |
| 355 | 364 |
| 356 bool KeywordTable::MigrateToVersion44AddDefaultSearchProviderBackup() { | 365 bool KeywordTable::MigrateToVersion44AddDefaultSearchProviderBackup() { |
| 357 return IsBackupSignatureValid(44) || UpdateBackupSignature(44); | 366 if (IsBackupSignatureValid(44)) |
| 367 return true; |
| 368 backup_overwritten_ = true; |
| 369 return UpdateBackupSignature(44); |
| 358 } | 370 } |
| 359 | 371 |
| 360 bool KeywordTable::MigrateToVersion45RemoveLogoIDAndAutogenerateColumns() { | 372 bool KeywordTable::MigrateToVersion45RemoveLogoIDAndAutogenerateColumns() { |
| 361 sql::Transaction transaction(db_); | 373 sql::Transaction transaction(db_); |
| 362 if (!transaction.Begin()) | 374 if (!transaction.Begin()) |
| 363 return false; | 375 return false; |
| 364 | 376 |
| 365 // The version 43 migration should have been written to do this, but since it | 377 // The version 43 migration should have been written to do this, but since it |
| 366 // wasn't, we'll do it now. Unfortunately a previous change deleted this for | 378 // wasn't, we'll do it now. Unfortunately a previous change deleted this for |
| 367 // some users, so we can't be sure this will succeed (so don't bail on error). | 379 // some users, so we can't be sure this will succeed (so don't bail on error). |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 } | 630 } |
| 619 } | 631 } |
| 620 | 632 |
| 621 // Replace the old table with the new one. | 633 // Replace the old table with the new one. |
| 622 sql = "DROP TABLE " + name; | 634 sql = "DROP TABLE " + name; |
| 623 if (!db_->Execute(sql.c_str())) | 635 if (!db_->Execute(sql.c_str())) |
| 624 return false; | 636 return false; |
| 625 sql = "ALTER TABLE keywords_temp RENAME TO " + name; | 637 sql = "ALTER TABLE keywords_temp RENAME TO " + name; |
| 626 return db_->Execute(sql.c_str()); | 638 return db_->Execute(sql.c_str()); |
| 627 } | 639 } |
| OLD | NEW |