| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/metrics/stats_counters.h" | 10 #include "base/metrics/stats_counters.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 "Default Search Provider ID Backup Signature"; | 46 "Default Search Provider ID Backup Signature"; |
| 47 | 47 |
| 48 const char kKeywordColumnsConcatenated[] = | 48 const char kKeywordColumnsConcatenated[] = |
| 49 "id || short_name || keyword || favicon_url || url || " | 49 "id || short_name || keyword || favicon_url || url || " |
| 50 "safe_for_autoreplace || originating_url || date_created || " | 50 "safe_for_autoreplace || originating_url || date_created || " |
| 51 "usage_count || input_encodings || show_in_default_list || " | 51 "usage_count || input_encodings || show_in_default_list || " |
| 52 "suggest_url || prepopulate_id || autogenerate_keyword || logo_id || " | 52 "suggest_url || prepopulate_id || autogenerate_keyword || logo_id || " |
| 53 "created_by_policy || instant_url || last_modified || sync_guid"; | 53 "created_by_policy || instant_url || last_modified || sync_guid"; |
| 54 | 54 |
| 55 void BindURLToStatement(const TemplateURL& url, sql::Statement* s) { | 55 void BindURLToStatement(const TemplateURL& url, sql::Statement* s) { |
| 56 s->BindString(0, UTF16ToUTF8(url.short_name())); | 56 s->BindString16(0, url.short_name()); |
| 57 s->BindString(1, UTF16ToUTF8(url.keyword())); | 57 s->BindString16(1, url.keyword()); |
| 58 GURL favicon_url = url.GetFaviconURL(); | 58 GURL favicon_url = url.GetFaviconURL(); |
| 59 if (!favicon_url.is_valid()) { | 59 if (!favicon_url.is_valid()) { |
| 60 s->BindString(2, std::string()); | 60 s->BindString(2, std::string()); |
| 61 } else { | 61 } else { |
| 62 s->BindString(2, history::HistoryDatabase::GURLToDatabaseURL( | 62 s->BindString(2, history::HistoryDatabase::GURLToDatabaseURL( |
| 63 url.GetFaviconURL())); | 63 url.GetFaviconURL())); |
| 64 } | 64 } |
| 65 s->BindString(3, url.url() ? url.url()->url() : std::string()); | 65 s->BindString(3, url.url() ? url.url()->url() : std::string()); |
| 66 s->BindInt(4, url.safe_for_autoreplace() ? 1 : 0); | 66 s->BindInt(4, url.safe_for_autoreplace() ? 1 : 0); |
| 67 if (!url.originating_url().is_valid()) { | 67 if (!url.originating_url().is_valid()) { |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 | 406 |
| 407 std::string keywords; | 407 std::string keywords; |
| 408 if (!GetTableContents("keywords", &keywords)) | 408 if (!GetTableContents("keywords", &keywords)) |
| 409 return false; | 409 return false; |
| 410 | 410 |
| 411 std::string data_to_sign = base::Int64ToString(id) + | 411 std::string data_to_sign = base::Int64ToString(id) + |
| 412 keyword_backup + | 412 keyword_backup + |
| 413 keywords; | 413 keywords; |
| 414 std::string signature = protector::SignSetting(data_to_sign); | 414 std::string signature = protector::SignSetting(data_to_sign); |
| 415 if (signature.empty()) | 415 if (signature.empty()) |
| 416 NOTREACHED() << "Signature is empty"; | 416 return false; |
| 417 if (!meta_table_->SetValue(kBackupSignatureKey, signature)) | 417 if (!meta_table_->SetValue(kBackupSignatureKey, signature)) |
| 418 NOTREACHED() << "Failed to write signature."; | 418 return false; |
| 419 | 419 |
| 420 return transaction.Commit(); | 420 return transaction.Commit(); |
| 421 } | 421 } |
| 422 | 422 |
| 423 bool KeywordTable::MigrateToVersion43AddKeywordsBackupTable() { | 423 bool KeywordTable::MigrateToVersion43AddKeywordsBackupTable() { |
| 424 return meta_table_->SetValue(kDefaultSearchBackupKey, std::string()) && | 424 return meta_table_->SetValue(kDefaultSearchBackupKey, std::string()) && |
| 425 UpdateBackupSignature(); | 425 UpdateBackupSignature(); |
| 426 } | 426 } |
| 427 | 427 |
| 428 bool KeywordTable::MigrateToVersion44UpdateKeywordsBackup() { | 428 bool KeywordTable::MigrateToVersion44UpdateKeywordsBackup() { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 void KeywordTable::GetURLFromStatement( | 524 void KeywordTable::GetURLFromStatement( |
| 525 const sql::Statement& s, | 525 const sql::Statement& s, |
| 526 TemplateURL* url) { | 526 TemplateURL* url) { |
| 527 url->set_id(s.ColumnInt64(0)); | 527 url->set_id(s.ColumnInt64(0)); |
| 528 | 528 |
| 529 std::string tmp; | 529 std::string tmp; |
| 530 tmp = s.ColumnString(1); | 530 tmp = s.ColumnString(1); |
| 531 DCHECK(!tmp.empty()); | 531 DCHECK(!tmp.empty()); |
| 532 url->set_short_name(UTF8ToUTF16(tmp)); | 532 url->set_short_name(UTF8ToUTF16(tmp)); |
| 533 | 533 |
| 534 url->set_keyword(UTF8ToUTF16(s.ColumnString(2))); | 534 url->set_keyword(s.ColumnString16(2)); |
| 535 | 535 |
| 536 tmp = s.ColumnString(3); | 536 tmp = s.ColumnString(3); |
| 537 if (!tmp.empty()) | 537 if (!tmp.empty()) |
| 538 url->SetFaviconURL(GURL(tmp)); | 538 url->SetFaviconURL(GURL(tmp)); |
| 539 | 539 |
| 540 url->SetURL(s.ColumnString(4), 0, 0); | 540 url->SetURL(s.ColumnString(4), 0, 0); |
| 541 | 541 |
| 542 url->set_safe_for_autoreplace(s.ColumnInt(5) == 1); | 542 url->set_safe_for_autoreplace(s.ColumnInt(5) == 1); |
| 543 | 543 |
| 544 tmp = s.ColumnString(6); | 544 tmp = s.ColumnString(6); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 return false; | 614 return false; |
| 615 } | 615 } |
| 616 if (!meta_table_->SetValue(kDefaultSearchBackupKey, backup_url)) { | 616 if (!meta_table_->SetValue(kDefaultSearchBackupKey, backup_url)) { |
| 617 LOG(WARNING) << "Failed to update the keyword backup"; | 617 LOG(WARNING) << "Failed to update the keyword backup"; |
| 618 return false; | 618 return false; |
| 619 } | 619 } |
| 620 | 620 |
| 621 *backup = backup_url; | 621 *backup = backup_url; |
| 622 return true; | 622 return true; |
| 623 } | 623 } |
| OLD | NEW |