| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/metrics/stats_counters.h" |
| 9 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| 10 #include "base/string_split.h" | 11 #include "base/string_split.h" |
| 11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/history/history_database.h" | 14 #include "chrome/browser/history/history_database.h" |
| 14 #include "chrome/browser/protector/histograms.h" | 15 #include "chrome/browser/protector/histograms.h" |
| 15 #include "chrome/browser/protector/protector.h" | 16 #include "chrome/browser/protector/protector.h" |
| 16 #include "chrome/browser/search_engines/template_url.h" | 17 #include "chrome/browser/search_engines/template_url.h" |
| 17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 18 #include "sql/statement.h" | 19 #include "sql/statement.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 73 } |
| 73 | 74 |
| 74 // Signs search provider id and returns its signature. | 75 // Signs search provider id and returns its signature. |
| 75 std::string GetSearchProviderIDSignature(int64 id) { | 76 std::string GetSearchProviderIDSignature(int64 id) { |
| 76 return protector::SignSetting(base::Int64ToString(id)); | 77 return protector::SignSetting(base::Int64ToString(id)); |
| 77 } | 78 } |
| 78 | 79 |
| 79 // Checks if signature for search provider id is correct and returns the | 80 // Checks if signature for search provider id is correct and returns the |
| 80 // result. | 81 // result. |
| 81 bool IsSearchProviderIDValid(int64 id, const std::string& signature) { | 82 bool IsSearchProviderIDValid(int64 id, const std::string& signature) { |
| 82 return signature == GetSearchProviderIDSignature(id); | 83 return protector::IsSettingValid(base::Int64ToString(id), signature); |
| 83 } | 84 } |
| 84 | 85 |
| 85 } // anonymous namespace | 86 } // anonymous namespace |
| 86 | 87 |
| 87 KeywordTable::~KeywordTable() {} | 88 KeywordTable::~KeywordTable() {} |
| 88 | 89 |
| 89 bool KeywordTable::Init() { | 90 bool KeywordTable::Init() { |
| 90 if (!db_->DoesTableExist("keywords")) { | 91 if (!db_->DoesTableExist("keywords")) { |
| 91 if (!db_->Execute("CREATE TABLE keywords (" | 92 if (!db_->Execute("CREATE TABLE keywords (" |
| 92 "id INTEGER PRIMARY KEY," | 93 "id INTEGER PRIMARY KEY," |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 int64 backup_value = 0; | 275 int64 backup_value = 0; |
| 275 meta_table_->GetValue(kDefaultSearchProviderBackupKey, &backup_value); | 276 meta_table_->GetValue(kDefaultSearchProviderBackupKey, &backup_value); |
| 276 std::string backup_signature; | 277 std::string backup_signature; |
| 277 meta_table_->GetValue( | 278 meta_table_->GetValue( |
| 278 kDefaultSearchProviderBackupSignatureKey, &backup_signature); | 279 kDefaultSearchProviderBackupSignatureKey, &backup_signature); |
| 279 if (!IsSearchProviderIDValid(backup_value, backup_signature)) { | 280 if (!IsSearchProviderIDValid(backup_value, backup_signature)) { |
| 280 UMA_HISTOGRAM_ENUMERATION( | 281 UMA_HISTOGRAM_ENUMERATION( |
| 281 protector::kProtectorHistogramDefaultSearchProvider, | 282 protector::kProtectorHistogramDefaultSearchProvider, |
| 282 protector::kProtectorErrorBackupInvalid, | 283 protector::kProtectorErrorBackupInvalid, |
| 283 protector::kProtectorErrorCount); | 284 protector::kProtectorErrorCount); |
| 285 SIMPLE_STATS_COUNTER(protector::kProtectorBackupInvalidCounter); |
| 284 return true; | 286 return true; |
| 285 } else if (backup_value != GetDefaultSearchProviderID()) { | 287 } else if (backup_value != GetDefaultSearchProviderID()) { |
| 286 UMA_HISTOGRAM_ENUMERATION( | 288 UMA_HISTOGRAM_ENUMERATION( |
| 287 protector::kProtectorHistogramDefaultSearchProvider, | 289 protector::kProtectorHistogramDefaultSearchProvider, |
| 288 protector::kProtectorErrorValueChanged, | 290 protector::kProtectorErrorValueChanged, |
| 289 protector::kProtectorErrorCount); | 291 protector::kProtectorErrorCount); |
| 292 SIMPLE_STATS_COUNTER(protector::kProtectorValueChangedCounter); |
| 290 return true; | 293 return true; |
| 291 } | 294 } |
| 295 UMA_HISTOGRAM_ENUMERATION( |
| 296 protector::kProtectorHistogramDefaultSearchProvider, |
| 297 protector::kProtectorErrorValueValid, |
| 298 protector::kProtectorErrorCount); |
| 299 SIMPLE_STATS_COUNTER(protector::kProtectorValueValidCounter); |
| 292 return false; | 300 return false; |
| 293 } | 301 } |
| 294 | 302 |
| 295 bool KeywordTable::SetBuiltinKeywordVersion(int version) { | 303 bool KeywordTable::SetBuiltinKeywordVersion(int version) { |
| 296 return meta_table_->SetValue(kBuiltinKeywordVersion, version); | 304 return meta_table_->SetValue(kBuiltinKeywordVersion, version); |
| 297 } | 305 } |
| 298 | 306 |
| 299 int KeywordTable::GetBuiltinKeywordVersion() { | 307 int KeywordTable::GetBuiltinKeywordVersion() { |
| 300 int version = 0; | 308 int version = 0; |
| 301 if (!meta_table_->GetValue(kBuiltinKeywordVersion, &version)) | 309 if (!meta_table_->GetValue(kBuiltinKeywordVersion, &version)) |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 return | 398 return |
| 391 meta_table_->SetValue(kDefaultSearchProviderBackupKey, id) && | 399 meta_table_->SetValue(kDefaultSearchProviderBackupKey, id) && |
| 392 SetDefaultSearchProviderBackupIDSignature(id); | 400 SetDefaultSearchProviderBackupIDSignature(id); |
| 393 } | 401 } |
| 394 | 402 |
| 395 bool KeywordTable::SetDefaultSearchProviderBackupIDSignature(int64 id) { | 403 bool KeywordTable::SetDefaultSearchProviderBackupIDSignature(int64 id) { |
| 396 return meta_table_->SetValue( | 404 return meta_table_->SetValue( |
| 397 kDefaultSearchProviderBackupSignatureKey, | 405 kDefaultSearchProviderBackupSignatureKey, |
| 398 GetSearchProviderIDSignature(id)); | 406 GetSearchProviderIDSignature(id)); |
| 399 } | 407 } |
| OLD | NEW |