Commit d2b0ae0d authored by stevet@chromium.org's avatar stevet@chromium.org

Enable the VariationsService on official builds when --variations-service-url is provided.

We do this by wrapping the default ctor in a factory Create method, which handles the build-type logic.

Also, group static methods in variations_service.*.
Also, move the testing constructor to protected where it's better... protected.

BUG=162417
TEST=With an unofficial build: Ensure that running Chromium without a command line argument does not result in a request to the Variations server (https://clients4.google.com/chrome-variations/seed). Ensure that providing the --variations-server-url flag with a URL results in a request to that URL.

Review URL: https://chromiumcodereview.appspot.com/11753014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175352 0039d316-1c4b-4281-b951-d872f2087c98
parent 17e7e426
......@@ -416,10 +416,8 @@ net::URLRequestContextGetter* BrowserProcessImpl::system_request_context() {
chrome_variations::VariationsService* BrowserProcessImpl::variations_service() {
DCHECK(CalledOnValidThread());
#if defined(GOOGLE_CHROME_BUILD) && !defined(OS_ANDROID)
if (!variations_service_.get())
variations_service_.reset(new chrome_variations::VariationsService());
#endif
variations_service_.reset(chrome_variations::VariationsService::Create());
return variations_service_.get();
}
......
......@@ -159,6 +159,10 @@ void VariationsService::StartRepeatedVariationsSeedFetch() {
this, &VariationsService::FetchVariationsSeed);
}
void VariationsService::SetCreateTrialsFromSeedCalledForTesting(bool called) {
create_trials_from_seed_called_ = called;
}
// static
void VariationsService::RegisterPrefs(PrefServiceSimple* prefs) {
prefs->RegisterStringPref(prefs::kVariationsSeed, std::string());
......@@ -166,8 +170,17 @@ void VariationsService::RegisterPrefs(PrefServiceSimple* prefs) {
base::Time().ToInternalValue());
}
void VariationsService::SetCreateTrialsFromSeedCalledForTesting(bool called) {
create_trials_from_seed_called_ = called;
// static
VariationsService* VariationsService::Create() {
// This is temporarily disabled for Android. See http://crbug.com/168224
#if !defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID)
// Unless the URL was provided, unsupported builds should return NULL to
// indicate that the service should not be used.
if (!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kVariationsServerURL))
return NULL;
#endif
return new VariationsService;
}
void VariationsService::DoActualFetch() {
......
......@@ -31,12 +31,6 @@ class VariationsService
: public net::URLFetcherDelegate,
public ResourceRequestAllowedNotifier::Observer {
public:
VariationsService();
// This constructor exists for injecting a mock notifier. It is meant for
// testing only. This instance will take ownership of |notifier|.
explicit VariationsService(ResourceRequestAllowedNotifier* notifier);
virtual ~VariationsService();
// Creates field trials based on Variations Seed loaded from local prefs. If
......@@ -49,17 +43,24 @@ class VariationsService
// |CreateTrialsFromSeed|.
void StartRepeatedVariationsSeedFetch();
// Exposed for testing.
void SetCreateTrialsFromSeedCalledForTesting(bool called);
// Register Variations related prefs in Local State.
static void RegisterPrefs(PrefServiceSimple* prefs);
// Exposed for testing.
void SetCreateTrialsFromSeedCalledForTesting(bool called);
// Factory method for creating a VariationsService.
static VariationsService* Create();
protected:
// Starts the fetching process once, where |OnURLFetchComplete| is called with
// the response.
virtual void DoActualFetch();
// This constructor exists for injecting a mock notifier. It is meant for
// testing only. This instance will take ownership of |notifier|.
explicit VariationsService(ResourceRequestAllowedNotifier* notifier);
private:
FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyChannel);
FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyLocale);
......@@ -75,6 +76,10 @@ class VariationsService
FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, StoreSeed);
FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, ValidateStudy);
// Default constructor is private. Use the |Create| factory method to create a
// VariationsService.
VariationsService();
// Checks if prerequisites for fetching the Variations seed are met, and if
// so, performs the actual fetch using |DoActualFetch|.
void FetchVariationsSeed();
......
......@@ -1334,7 +1334,8 @@ const char kUserDataDir[] = "user-data-dir";
const char kUseWebBasedSigninFlow[] = "use-web-based-signin-flow";
// Specifies a custom URL for the server which reports variation data to the
// client. See variations_service.cc.
// client. Specifying this switch enables the Variations service on
// unofficial builds. See variations_service.cc.
const char kVariationsServerURL[] = "variations-server-url";
// Prints version information and quits.
......
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