Chromium Code Reviews| Index: chrome/browser/metrics/variations/variations_service.h |
| diff --git a/chrome/browser/metrics/variations/variations_service.h b/chrome/browser/metrics/variations/variations_service.h |
| index 3f341212ecf699343c3fa375ef22928e77eae42e..d0855f17501fab65808f611a7bd78b6568f95dea 100644 |
| --- a/chrome/browser/metrics/variations/variations_service.h |
| +++ b/chrome/browser/metrics/variations/variations_service.h |
| @@ -15,22 +15,33 @@ |
| #include "base/timer.h" |
| #include "chrome/browser/metrics/proto/study.pb.h" |
| #include "chrome/browser/metrics/proto/trials_seed.pb.h" |
| +#include "chrome/browser/metrics/variations/resource_request_allowed_notifier.h" |
| #include "chrome/common/chrome_version_info.h" |
| #include "googleurl/src/gurl.h" |
| -#include "net/base/network_change_notifier.h" |
| #include "net/url_request/url_fetcher_delegate.h" |
| class PrefService; |
| +namespace chromeos { |
| +class WizardController; |
| +} |
| + |
| namespace chrome_variations { |
| // Used to setup field trials based on stored variations seed data, and fetch |
| // new seed data from the variations server. |
| class VariationsService |
| : public net::URLFetcherDelegate, |
| - public net::NetworkChangeNotifier::ConnectionTypeObserver{ |
| + public ResourceRequestAllowedNotifier::Observer { |
| public: |
| VariationsService(); |
| + |
| + // This constructor is created to injecting a mock notifier. It is meant for |
|
Alexei Svitkine (slow)
2012/09/20 21:39:03
Nit: wording. This constructor exists for injectin
SteveT
2012/09/21 15:16:17
Done.
|
| + // testing only. This instance will take ownership of |notifier|. Tests can |
| + // use GetResourceRequestAllowedNotifierForTesting to retrieve a weak pointer |
| + // to the mock to manipulate tests. |
| + VariationsService(ResourceRequestAllowedNotifier* notifier); |
| + |
| virtual ~VariationsService(); |
| // Creates field trials based on Variations Seed loaded from local prefs. If |
| @@ -43,17 +54,23 @@ class VariationsService |
| // |CreateTrialsFromSeed|. |
| void StartRepeatedVariationsSeedFetch(); |
| + // Checks if prerequisites for fetching the Variations seed are met, and if |
| + // so, performs the actual fetch using |DoActualFetch|. |
| + void FetchVariationsSeed(); |
|
Alexei Svitkine (slow)
2012/09/20 21:39:03
Why is this public?
SteveT
2012/09/21 15:16:17
This has been made private now.
|
| + |
| + // Register Variations related prefs in Local State. |
| + static void RegisterPrefs(PrefService* prefs); |
| + |
| + // Exposed for testing. |
| + ResourceRequestAllowedNotifier* GetResourceRequestAllowedNotifierForTesting(); |
|
Alexei Svitkine (slow)
2012/09/20 21:39:03
I think this won't be needed anymore, after you fo
SteveT
2012/09/21 15:16:17
Yes - removed.
|
| + void SetCreateTrialsFromSeedCalledForTesting(bool called); |
| + |
| + protected: |
| // Starts the fetching process once, where |OnURLFetchComplete| is called with |
| // the response. If the network is down at the time, sets a flag to retry when |
| // the network is back online. This is virtual so it can be overriden for |
| // testing. |
| - virtual void FetchVariationsSeed(); |
| - |
| - // Exposed for testing. |
| - void SetWasOfflineDuringLastRequestAttemptForTesting(bool offline); |
| - |
| - // Register Variations related prefs in Local State. |
| - static void RegisterPrefs(PrefService* prefs); |
| + virtual void DoActualFetch(); |
| private: |
| FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyChannel); |
| @@ -73,9 +90,8 @@ class VariationsService |
| // net::URLFetcherDelegate implementation: |
| virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| - // net::NetworkChangeNotifier::ConnectionTypeObserver implementation. |
| - virtual void OnConnectionTypeChanged( |
| - net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| + // ResourceRequestAllowedNotifier::Observer implementation: |
| + virtual void OnResourceRequestsAllowed() OVERRIDE; |
| // Store the given seed data to the given local prefs. Note that |seed_data| |
| // is assumed to be the raw serialized protobuf data stored in a string. It |
| @@ -144,16 +160,17 @@ class VariationsService |
| // Tracks whether |CreateTrialsFromSeed| has been called, to ensure that |
| // it gets called prior to |StartRepeatedVariationsSeedFetch|. |
| + // This field is protected so test classes can modify it. |
|
Alexei Svitkine (slow)
2012/09/20 21:39:03
Not protected anymore, remove this comment.
SteveT
2012/09/21 15:16:17
Done.
|
| bool create_trials_from_seed_called_; |
| - // Tracks whether or not the last seed request attempt failed due to being |
| - // offline. |
| - bool was_offline_during_last_request_attempt_; |
| - |
| // The timer used to repeatedly ping the server. Keep this as an instance |
| // member so if VariationsService goes out of scope, the timer is |
| // automatically canceled. |
| base::RepeatingTimer<VariationsService> timer_; |
| + |
| + // Helper class used to tell this service if it's allowed to make network |
| + // resource requests. |
| + scoped_ptr<ResourceRequestAllowedNotifier> resource_request_allowed_notifier_; |
| }; |
| } // namespace chrome_variations |