Commit 5cc0d2d6 authored by avayvod@chromium.org's avatar avayvod@chromium.org

Added histogram on successful check. Safe verification

R=ivankr@chromium.org
BUG=102480
TEST=Verify that new stats appear at chrome://histograms

Review URL: http://codereview.chromium.org/8430027

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108111 0039d316-1c4b-4281-b951-d872f2087c98
parent 5a3000bb
......@@ -9,4 +9,9 @@ namespace protector {
const char kProtectorHistogramDefaultSearchProvider[] =
"Protector.DefaultSearchProvider";
const char kProtectorBackupInvalidCounter[] =
"Protector.BackupInvalidCounter";
const char kProtectorValueChangedCounter[] = "Protector.ValueChangedCounter";
const char kProtectorValueValidCounter[] = "Protector.ValueValidCounter";
} // namespace protector
......@@ -12,10 +12,15 @@ namespace protector {
// provider.
extern const char kProtectorHistogramDefaultSearchProvider[];
extern const char kProtectorBackupInvalidCounter[];
extern const char kProtectorValueChangedCounter[];
extern const char kProtectorValueValidCounter[];
// Protector histogram values.
enum ProtectorError {
kProtectorErrorBackupInvalid,
kProtectorErrorValueChanged,
kProtectorErrorValueValid,
// This is for convenience only, must always be the last.
kProtectorErrorCount
......
......@@ -69,12 +69,27 @@ void Protector::OnChangesAction(SettingChangeAction action) {
std::string SignSetting(const std::string& value) {
crypto::HMAC hmac(crypto::HMAC::SHA256);
DCHECK(hmac.Init(kProtectorSigningKey));
if (!hmac.Init(kProtectorSigningKey)) {
LOG(WARNING) << "Failed to initialize HMAC algorithm for signing";
return std::string();
}
std::vector<unsigned char> digest(hmac.DigestLength());
DCHECK(hmac.Sign(value, &digest[0], digest.size()));
if (!hmac.Sign(value, &digest[0], digest.size())) {
LOG(WARNING) << "Failed to sign setting";
return std::string();
}
return std::string(&digest[0], &digest[0] + digest.size());
}
bool IsSettingValid(const std::string& value, const std::string& signature) {
crypto::HMAC hmac(crypto::HMAC::SHA256);
if (!hmac.Init(kProtectorSigningKey)) {
LOG(WARNING) << "Failed to initialize HMAC algorithm for verification.";
return false;
}
return hmac.Verify(value, signature);
}
} // namespace protector
......@@ -68,6 +68,9 @@ class Protector : public SettingsChangeGlobalErrorDelegate {
// Signs string value with protector's key.
std::string SignSetting(const std::string& value);
// Returns true if the signature is valid for the specified key.
bool IsSettingValid(const std::string& value, const std::string& signature);
} // namespace protector
#endif // CHROME_BROWSER_PROTECTOR_PROTECTOR_H_
......@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/metrics/stats_counters.h"
#include "base/string_number_conversions.h"
#include "base/string_split.h"
#include "base/string_util.h"
......@@ -79,7 +80,7 @@ std::string GetSearchProviderIDSignature(int64 id) {
// Checks if signature for search provider id is correct and returns the
// result.
bool IsSearchProviderIDValid(int64 id, const std::string& signature) {
return signature == GetSearchProviderIDSignature(id);
return protector::IsSettingValid(base::Int64ToString(id), signature);
}
} // anonymous namespace
......@@ -281,14 +282,21 @@ bool KeywordTable::DidDefaultSearchProviderChange() {
protector::kProtectorHistogramDefaultSearchProvider,
protector::kProtectorErrorBackupInvalid,
protector::kProtectorErrorCount);
SIMPLE_STATS_COUNTER(protector::kProtectorBackupInvalidCounter);
return true;
} else if (backup_value != GetDefaultSearchProviderID()) {
UMA_HISTOGRAM_ENUMERATION(
protector::kProtectorHistogramDefaultSearchProvider,
protector::kProtectorErrorValueChanged,
protector::kProtectorErrorCount);
SIMPLE_STATS_COUNTER(protector::kProtectorValueChangedCounter);
return true;
}
UMA_HISTOGRAM_ENUMERATION(
protector::kProtectorHistogramDefaultSearchProvider,
protector::kProtectorErrorValueValid,
protector::kProtectorErrorCount);
SIMPLE_STATS_COUNTER(protector::kProtectorValueValidCounter);
return false;
}
......
......@@ -168,7 +168,6 @@ TEST_F(KeywordTableTest, DefaultSearchProviderBackup) {
EXPECT_EQ(10, db.GetKeywordTable()->GetDefaultSearchProviderIDBackup());
EXPECT_FALSE(db.GetKeywordTable()->DidDefaultSearchProviderChange());
// Verify that backup doesn't affect the actual value for now.
ASSERT_TRUE(db.GetKeywordTable()->SetDefaultSearchProviderBackupID(11));
EXPECT_EQ(10, db.GetKeywordTable()->GetDefaultSearchProviderID());
EXPECT_EQ(11, db.GetKeywordTable()->GetDefaultSearchProviderIDBackup());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment