| Index: chrome/browser/webdata/keyword_table.cc
|
| diff --git a/chrome/browser/webdata/keyword_table.cc b/chrome/browser/webdata/keyword_table.cc
|
| index e6cf033cb81f01baedb7b5ac05fc21a098a9b59a..d4d6c206f62327d9b7901923495f9a830a9ebfab 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/setting_change.h"
|
| #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::SignSetting(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,18 @@ 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;
|
| + protector::SettingChange* change =
|
| + protector::CreateDefaultSearchProviderChange(this, 0, value);
|
| + protector::NotifyUserOfChange(change);
|
| + SetDefaultSearchProviderID(0);
|
| + return 0;
|
| }
|
| if (value != backup_value) {
|
| - // TODO(avayvod): Notify UI about the setting having been hijacked.
|
| + protector::SettingChange* change =
|
| + protector::CreateDefaultSearchProviderChange(
|
| + this, backup_value, value);
|
| + protector::NotifyUserOfChange(change);
|
| + SetDefaultSearchProviderID(backup_value);
|
| return backup_value;
|
| }
|
| return value;
|
|
|