Chromium Code Reviews| Index: chrome/browser/webdata/keyword_table.cc |
| diff --git a/chrome/browser/webdata/keyword_table.cc b/chrome/browser/webdata/keyword_table.cc |
| index 62a8a2ba2e4122c1c8aee3b953477a6a9add1ebf..c4c4a0f23e8225f69b8a91763f3dfe1f85cf60f2 100644 |
| --- a/chrome/browser/webdata/keyword_table.cc |
| +++ b/chrome/browser/webdata/keyword_table.cc |
| @@ -10,8 +10,9 @@ |
| #include "base/string_util.h" |
| #include "base/utf_string_conversions.h" |
| #include "chrome/browser/history/history_database.h" |
| +#include "chrome/browser/protector/protector.h" |
| +#include "chrome/browser/protector/keys.h" |
|
Ivan Korotkov
2011/10/19 20:24:37
Sort please.
whywhat
2011/10/20 20:50:10
Done.
|
| #include "chrome/browser/search_engines/template_url.h" |
| -#include "crypto/hmac.h" |
| #include "googleurl/src/gurl.h" |
| #include "sql/statement.h" |
| @@ -26,11 +27,6 @@ const int kUrlIdPosition = 18; |
| const char kDefaultSearchProviderKey[] = "Default Search Provider ID"; |
| const char kBuiltinKeywordVersion[] = "Builtin Keyword Version"; |
| -// Key for signing the default search provider backup. |
| -// TOOD(avayvod): Add key for Google Chrome to internal repository. |
| -const char kDefaultSearchProviderBackupSigningKey[] = |
| - "Please, don't change default search engine!"; |
| - |
| // Meta table key to store backup value for the default search provider. |
| const char kDefaultSearchProviderBackupKey[] = |
| "Default Search Provider ID Backup"; |
| @@ -76,14 +72,7 @@ void BindURLToStatement(const TemplateURL& url, sql::Statement* s) { |
| // Signs search provider id and returns its signature. |
| std::string GetSearchProviderIDSignature(int64 id) { |
| - crypto::HMAC hmac(crypto::HMAC::SHA256); |
| - DCHECK(hmac.Init(kDefaultSearchProviderBackupSigningKey)); |
| - |
| - std::string id_to_sign(base::Int64ToString(id)); |
| - std::vector<unsigned char> digest(hmac.DigestLength()); |
| - DCHECK(hmac.Sign(id_to_sign, &digest[0], digest.size())); |
| - |
| - return std::string(&digest[0], &digest[0] + digest.size()); |
| + return protector::Sign(base::Int64ToString(id)); |
| } |
| // Checks if signature for search provider id is correct and returns the |
| @@ -258,6 +247,23 @@ bool KeywordTable::UpdateKeyword(const TemplateURL& url) { |
| return s.Run(); |
| } |
| +string16 KeywordTable::GetKeywordShortName(int64 id) { |
| + sql::Statement s(db_->GetUniqueStatement( |
| + "SELECT short_name FROM keywords WHERE id=?")); |
| + if (!s) { |
| + NOTREACHED() << "Statement prepare failed"; |
| + return string16(); |
| + } |
| + s.BindInt64(0, id); |
| + if (s.Step()) { |
| + std::string short_name(s.ColumnString(0)); |
| + DCHECK(!short_name.empty()); |
| + return UTF8ToUTF16(short_name); |
| + } |
| + LOG(WARNING) << "Keyword with id " << id << " is not found."; |
| + return string16(); |
| +} |
| + |
| bool KeywordTable::SetDefaultSearchProviderID(int64 id) { |
| return meta_table_->SetValue(kDefaultSearchProviderKey, id) && |
| SetDefaultSearchProviderBackupID(id); |
| @@ -272,12 +278,17 @@ int64 KeywordTable::GetDefaultSearchProviderID() { |
| meta_table_->GetValue( |
| kDefaultSearchProviderBackupSignatureKey, &backup_signature); |
| if (!IsSearchProviderIDValid(backup_value, backup_signature)) { |
| - // TODO(avayvod): Notify UI about the setting having been hijacked and |
| - // the backup value lost. |
| - return value; |
| + scoped_refptr<protector::DefaultSearchProviderChange> change( |
| + new protector::DefaultSearchProviderChange(this, 0, value)); |
| + protector::NotifyUserOfChange(change); |
| + SetDefaultSearchProviderID(0); |
| + return 0; |
| } |
| if (value != backup_value) { |
| - // TODO(avayvod): Notify UI about the setting having been hijacked. |
| + scoped_refptr<protector::DefaultSearchProviderChange> change( |
| + new protector::DefaultSearchProviderChange(this, backup_value, value)); |
| + protector::NotifyUserOfChange(change); |
| + SetDefaultSearchProviderID(backup_value); |
| return backup_value; |
| } |
| return value; |