Commit 88a7831f authored by isherman@chromium.org's avatar isherman@chromium.org

[Metrics] Move CachingPermutedEntropyProvider into the variations component.

BUG=374298
TEST=compiles
R=asvitkine@chromium.org, blundell@chromium.org

Review URL: https://codereview.chromium.org/293623003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271393 0039d316-1c4b-4281-b951-d872f2087c98
parent 72f9371d
......@@ -16,8 +16,8 @@
#include "chrome/browser/metrics/cloned_install_detector.h"
#include "chrome/browser/metrics/machine_id_provider.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/metrics/caching_permuted_entropy_provider.h"
#include "chrome/common/pref_names.h"
#include "components/variations/caching_permuted_entropy_provider.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/settings/cros_settings.h"
......
......@@ -10,8 +10,9 @@
#include "base/command_line.h"
#include "base/prefs/testing_pref_service.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/metrics/caching_permuted_entropy_provider.h"
#include "chrome/common/pref_names.h"
#include "components/variations/caching_permuted_entropy_provider.h"
#include "components/variations/pref_names.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace metrics {
......@@ -83,8 +84,8 @@ TEST_F(MetricsStateManagerTest, LowEntropySource0NotReset) {
TEST_F(MetricsStateManagerTest,
PermutedEntropyCacheClearedWhenLowEntropyReset) {
const PrefService::Preference* low_entropy_pref =
prefs_.FindPreference(prefs::kMetricsLowEntropySource);
const char* kCachePrefName = prefs::kMetricsPermutedEntropyCache;
prefs_.FindPreference(::prefs::kMetricsLowEntropySource);
const char* kCachePrefName = prefs::kVariationsPermutedEntropyCache;
int low_entropy_value = -1;
// First, generate an initial low entropy source value.
......@@ -109,7 +110,7 @@ TEST_F(MetricsStateManagerTest,
EXPECT_EQ("test", prefs_.GetString(kCachePrefName));
EXPECT_EQ(low_entropy_value,
prefs_.GetInteger(prefs::kMetricsLowEntropySource));
prefs_.GetInteger(::prefs::kMetricsLowEntropySource));
}
// Verify that the cache does get reset if --reset-variations-state is passed.
......@@ -131,7 +132,7 @@ TEST_F(MetricsStateManagerTest, ResetMetricsIDs) {
// Set an initial client id in prefs. It should not be possible for the
// metrics state manager to generate this id randomly.
const std::string kInitialClientId = "initial client id";
prefs_.SetString(prefs::kMetricsClientID, kInitialClientId);
prefs_.SetString(::prefs::kMetricsClientID, kInitialClientId);
// Make sure the initial client id isn't reset by the metrics state manager.
{
......@@ -141,7 +142,7 @@ TEST_F(MetricsStateManagerTest, ResetMetricsIDs) {
}
// Set the reset pref to cause the IDs to be reset.
prefs_.SetBoolean(prefs::kMetricsResetIds, true);
prefs_.SetBoolean(::prefs::kMetricsResetIds, true);
// Cause the actual reset to happen.
{
......@@ -151,10 +152,10 @@ TEST_F(MetricsStateManagerTest, ResetMetricsIDs) {
state_manager->GetLowEntropySource();
EXPECT_FALSE(prefs_.GetBoolean(prefs::kMetricsResetIds));
EXPECT_FALSE(prefs_.GetBoolean(::prefs::kMetricsResetIds));
}
EXPECT_NE(kInitialClientId, prefs_.GetString(prefs::kMetricsClientID));
EXPECT_NE(kInitialClientId, prefs_.GetString(::prefs::kMetricsClientID));
}
} // namespace metrics
......@@ -253,8 +253,6 @@
'common/media/webrtc_logging_message_data.cc',
'common/media/webrtc_logging_message_data.h',
'common/media_galleries/metadata_types.h',
'common/metrics/caching_permuted_entropy_provider.cc',
'common/metrics/caching_permuted_entropy_provider.h',
'common/metrics/metrics_service_base.cc',
'common/metrics/metrics_service_base.h',
'common/metrics/variations/experiment_labels.cc',
......@@ -684,7 +682,6 @@
'type': 'static_library',
'sources': [
'common/metrics/proto/chrome_experiments.proto',
'common/metrics/proto/permuted_entropy_cache.proto',
],
'variables': {
'proto_in_dir': 'common/metrics/proto',
......
......@@ -1864,7 +1864,6 @@
'common/mac/mock_launchd.h',
'common/mac/objc_method_swizzle_unittest.mm',
'common/mac/objc_zombie_unittest.mm',
'common/metrics/caching_permuted_entropy_provider_unittest.cc',
'common/metrics/variations/experiment_labels_unittest.cc',
'common/metrics/variations/variations_util_unittest.cc',
'common/multi_process_lock_unittest.cc',
......
......@@ -1349,8 +1349,6 @@ const char kMetricsClientID[] = "user_experience_metrics.client_id2";
const char kMetricsSessionID[] = "user_experience_metrics.session_id";
const char kMetricsLowEntropySource[] =
"user_experience_metrics.low_entropy_source2";
const char kMetricsPermutedEntropyCache[] =
"user_experience_metrics.permuted_entropy_cache";
// Old client id and low entropy source values, cleared the first time this
// version is launched.
......
......@@ -428,7 +428,6 @@ extern const char kEulaAccepted[];
extern const char kMetricsClientID[];
extern const char kMetricsSessionID[];
extern const char kMetricsLowEntropySource[];
extern const char kMetricsPermutedEntropyCache[];
extern const char kMetricsOldClientID[];
extern const char kMetricsOldLowEntropySource[];
extern const char kMetricsReportingEnabled[];
......
......@@ -169,6 +169,7 @@
'url_matcher/substring_set_matcher_unittest.cc',
'url_matcher/url_matcher_factory_unittest.cc',
'url_matcher/url_matcher_unittest.cc',
'variations/caching_permuted_entropy_provider_unittest.cc',
'variations/entropy_provider_unittest.cc',
'variations/metrics_util_unittest.cc',
'variations/study_filtering_unittest.cc',
......
......@@ -15,14 +15,19 @@
'../third_party/mt19937ar/mt19937ar.gyp:mt19937ar',
],
'sources': [
'variations/caching_permuted_entropy_provider.cc',
'variations/caching_permuted_entropy_provider.h',
'variations/entropy_provider.cc',
'variations/entropy_provider.h',
'variations/metrics_util.cc',
'variations/metrics_util.h',
'variations/pref_names.cc',
'variations/pref_names.h',
'variations/processed_study.cc',
'variations/processed_study.h',
'variations/proto/variations_seed.proto',
'variations/proto/permuted_entropy_cache.proto',
'variations/proto/study.proto',
'variations/proto/variations_seed.proto',
'variations/study_filtering.cc',
'variations/study_filtering.h',
'variations/variations_associated_data.cc',
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/common/metrics/caching_permuted_entropy_provider.h"
#include "components/variations/caching_permuted_entropy_provider.h"
#include <string>
......@@ -10,7 +10,7 @@
#include "base/logging.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
#include "chrome/common/pref_names.h"
#include "components/variations/pref_names.h"
namespace metrics {
......@@ -29,13 +29,13 @@ CachingPermutedEntropyProvider::~CachingPermutedEntropyProvider() {
// static
void CachingPermutedEntropyProvider::RegisterPrefs(
PrefRegistrySimple* registry) {
registry->RegisterStringPref(prefs::kMetricsPermutedEntropyCache,
registry->RegisterStringPref(prefs::kVariationsPermutedEntropyCache,
std::string());
}
// static
void CachingPermutedEntropyProvider::ClearCache(PrefService* local_state) {
local_state->ClearPref(prefs::kMetricsPermutedEntropyCache);
local_state->ClearPref(prefs::kVariationsPermutedEntropyCache);
}
uint16 CachingPermutedEntropyProvider::GetPermutedValue(
......@@ -52,11 +52,11 @@ uint16 CachingPermutedEntropyProvider::GetPermutedValue(
void CachingPermutedEntropyProvider::ReadFromLocalState() const {
const std::string base64_cache_data =
local_state_->GetString(prefs::kMetricsPermutedEntropyCache);
local_state_->GetString(prefs::kVariationsPermutedEntropyCache);
std::string cache_data;
if (!base::Base64Decode(base64_cache_data, &cache_data) ||
!cache_.ParseFromString(cache_data)) {
local_state_->ClearPref(prefs::kMetricsPermutedEntropyCache);
local_state_->ClearPref(prefs::kVariationsPermutedEntropyCache);
NOTREACHED();
}
}
......@@ -67,7 +67,8 @@ void CachingPermutedEntropyProvider::UpdateLocalState() const {
std::string base64_encoded;
base::Base64Encode(serialized, &base64_encoded);
local_state_->SetString(prefs::kMetricsPermutedEntropyCache, base64_encoded);
local_state_->SetString(prefs::kVariationsPermutedEntropyCache,
base64_encoded);
}
void CachingPermutedEntropyProvider::AddToCache(uint32 randomization_seed,
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_COMMON_METRICS_CACHING_PERMUTED_ENTROPY_PROVIDER_H_
#define CHROME_COMMON_METRICS_CACHING_PERMUTED_ENTROPY_PROVIDER_H_
#ifndef COMPONENTS_VARIATIONS_CACHING_PERMUTED_ENTROPY_PROVIDER_H_
#define COMPONENTS_VARIATIONS_CACHING_PERMUTED_ENTROPY_PROVIDER_H_
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/threading/thread_checker.h"
#include "chrome/common/metrics/proto/permuted_entropy_cache.pb.h"
#include "components/variations/entropy_provider.h"
#include "components/variations/proto/permuted_entropy_cache.pb.h"
class PrefService;
class PrefRegistrySimple;
......@@ -62,4 +62,4 @@ class CachingPermutedEntropyProvider : public PermutedEntropyProvider {
} // namespace metrics
#endif // CHROME_COMMON_METRICS_CACHING_PERMUTED_ENTROPY_PROVIDER_H_
#endif // COMPONENTS_VARIATIONS_CACHING_PERMUTED_ENTROPY_PROVIDER_H_
// Copyright 2013 The Chromium Authors. All rights reserved.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/common/metrics/caching_permuted_entropy_provider.h"
#include "components/variations/caching_permuted_entropy_provider.h"
#include <string>
......@@ -17,8 +17,8 @@ namespace metrics {
const size_t kMaxLowEntropySize = 8000;
// Field trial names used in unit tests.
const char* const kTestTrialNames[] = { "TestTrial", "AnotherTestTrial",
"NewTabButton" };
const char* const kTestTrialNames[] = {"TestTrial", "AnotherTestTrial",
"NewTabButton"};
TEST(CachingPermutedEntropyProviderTest, HasConsistentResults) {
TestingPrefServiceSimple prefs;
......@@ -30,8 +30,8 @@ TEST(CachingPermutedEntropyProviderTest, HasConsistentResults) {
// expected results.
PermutedEntropyProvider provider(kEntropyValue, kMaxLowEntropySize);
for (size_t i = 0; i < 2 * arraysize(kTestTrialNames); ++i) {
CachingPermutedEntropyProvider cached_provider(&prefs, kEntropyValue,
kMaxLowEntropySize);
CachingPermutedEntropyProvider cached_provider(
&prefs, kEntropyValue, kMaxLowEntropySize);
const std::string trial_name =
kTestTrialNames[i % arraysize(kTestTrialNames)];
EXPECT_DOUBLE_EQ(provider.GetEntropyForTrial(trial_name, 0),
......@@ -39,8 +39,8 @@ TEST(CachingPermutedEntropyProviderTest, HasConsistentResults) {
}
// Now, do the same test re-using the same caching provider.
CachingPermutedEntropyProvider cached_provider(&prefs, kEntropyValue,
kMaxLowEntropySize);
CachingPermutedEntropyProvider cached_provider(
&prefs, kEntropyValue, kMaxLowEntropySize);
for (size_t i = 0; i < 2 * arraysize(kTestTrialNames); ++i) {
const std::string trial_name =
kTestTrialNames[i % arraysize(kTestTrialNames)];
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/variations/pref_names.h"
namespace metrics {
namespace prefs {
// A serialized PermutedEntropyCache protobuf, used as a cache to avoid
// recomputing permutations.
const char kVariationsPermutedEntropyCache[] =
"user_experience_metrics.permuted_entropy_cache";
} // namespace prefs
} // namespace metrics
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_VARIATIONS_PREF_NAMES_H_
#define COMPONENTS_VARIATIONS_PREF_NAMES_H_
namespace metrics {
namespace prefs {
// Alphabetical list of preference names specific to the variations component.
// Keep alphabetized, and document each in the .cc file.
extern const char kVariationsPermutedEntropyCache[];
} // namespace prefs
} // namespace metrics
#endif // COMPONENTS_VARIATIONS_PREF_NAMES_H_
// Copyright 2013 The Chromium Authors. All rights reserved.
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......
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