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() { ...@@ -416,10 +416,8 @@ net::URLRequestContextGetter* BrowserProcessImpl::system_request_context() {
chrome_variations::VariationsService* BrowserProcessImpl::variations_service() { chrome_variations::VariationsService* BrowserProcessImpl::variations_service() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
#if defined(GOOGLE_CHROME_BUILD) && !defined(OS_ANDROID)
if (!variations_service_.get()) if (!variations_service_.get())
variations_service_.reset(new chrome_variations::VariationsService()); variations_service_.reset(chrome_variations::VariationsService::Create());
#endif
return variations_service_.get(); return variations_service_.get();
} }
......
...@@ -159,6 +159,10 @@ void VariationsService::StartRepeatedVariationsSeedFetch() { ...@@ -159,6 +159,10 @@ void VariationsService::StartRepeatedVariationsSeedFetch() {
this, &VariationsService::FetchVariationsSeed); this, &VariationsService::FetchVariationsSeed);
} }
void VariationsService::SetCreateTrialsFromSeedCalledForTesting(bool called) {
create_trials_from_seed_called_ = called;
}
// static // static
void VariationsService::RegisterPrefs(PrefServiceSimple* prefs) { void VariationsService::RegisterPrefs(PrefServiceSimple* prefs) {
prefs->RegisterStringPref(prefs::kVariationsSeed, std::string()); prefs->RegisterStringPref(prefs::kVariationsSeed, std::string());
...@@ -166,8 +170,17 @@ void VariationsService::RegisterPrefs(PrefServiceSimple* prefs) { ...@@ -166,8 +170,17 @@ void VariationsService::RegisterPrefs(PrefServiceSimple* prefs) {
base::Time().ToInternalValue()); base::Time().ToInternalValue());
} }
void VariationsService::SetCreateTrialsFromSeedCalledForTesting(bool called) { // static
create_trials_from_seed_called_ = called; 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() { void VariationsService::DoActualFetch() {
......
...@@ -31,12 +31,6 @@ class VariationsService ...@@ -31,12 +31,6 @@ class VariationsService
: public net::URLFetcherDelegate, : public net::URLFetcherDelegate,
public ResourceRequestAllowedNotifier::Observer { public ResourceRequestAllowedNotifier::Observer {
public: 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(); virtual ~VariationsService();
// Creates field trials based on Variations Seed loaded from local prefs. If // Creates field trials based on Variations Seed loaded from local prefs. If
...@@ -49,17 +43,24 @@ class VariationsService ...@@ -49,17 +43,24 @@ class VariationsService
// |CreateTrialsFromSeed|. // |CreateTrialsFromSeed|.
void StartRepeatedVariationsSeedFetch(); void StartRepeatedVariationsSeedFetch();
// Exposed for testing.
void SetCreateTrialsFromSeedCalledForTesting(bool called);
// Register Variations related prefs in Local State. // Register Variations related prefs in Local State.
static void RegisterPrefs(PrefServiceSimple* prefs); static void RegisterPrefs(PrefServiceSimple* prefs);
// Exposed for testing. // Factory method for creating a VariationsService.
void SetCreateTrialsFromSeedCalledForTesting(bool called); static VariationsService* Create();
protected: protected:
// Starts the fetching process once, where |OnURLFetchComplete| is called with // Starts the fetching process once, where |OnURLFetchComplete| is called with
// the response. // the response.
virtual void DoActualFetch(); 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: private:
FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyChannel); FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyChannel);
FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyLocale); FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyLocale);
...@@ -75,6 +76,10 @@ class VariationsService ...@@ -75,6 +76,10 @@ class VariationsService
FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, StoreSeed); FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, StoreSeed);
FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, ValidateStudy); 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 // Checks if prerequisites for fetching the Variations seed are met, and if
// so, performs the actual fetch using |DoActualFetch|. // so, performs the actual fetch using |DoActualFetch|.
void FetchVariationsSeed(); void FetchVariationsSeed();
......
...@@ -1334,7 +1334,8 @@ const char kUserDataDir[] = "user-data-dir"; ...@@ -1334,7 +1334,8 @@ const char kUserDataDir[] = "user-data-dir";
const char kUseWebBasedSigninFlow[] = "use-web-based-signin-flow"; const char kUseWebBasedSigninFlow[] = "use-web-based-signin-flow";
// Specifies a custom URL for the server which reports variation data to the // 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"; const char kVariationsServerURL[] = "variations-server-url";
// Prints version information and quits. // 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