Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2612)

Unified Diff: chrome/browser/metrics/variations/variations_service.h

Issue 10917120: Activate the VariationsService for ChromeOS and ensure that it does not ping the server until the E… (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: one more asvit nit Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..4f55d4a012574d7f517b4c09feb7882fc49d7722 100644
--- a/chrome/browser/metrics/variations/variations_service.h
+++ b/chrome/browser/metrics/variations/variations_service.h
@@ -15,9 +15,9 @@
#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;
@@ -28,9 +28,14 @@ namespace chrome_variations {
// new seed data from the variations server.
class VariationsService
: public net::URLFetcherDelegate,
- public net::NetworkChangeNotifier::ConnectionTypeObserver{
+ 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
@@ -43,17 +48,16 @@ class VariationsService
// |CreateTrialsFromSeed|.
void StartRepeatedVariationsSeedFetch();
- // 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();
+ // Register Variations related prefs in Local State.
+ static void RegisterPrefs(PrefService* prefs);
// Exposed for testing.
- void SetWasOfflineDuringLastRequestAttemptForTesting(bool offline);
+ void SetCreateTrialsFromSeedCalledForTesting(bool called);
- // Register Variations related prefs in Local State.
- static void RegisterPrefs(PrefService* prefs);
+ protected:
+ // Starts the fetching process once, where |OnURLFetchComplete| is called with
+ // the response.
+ virtual void DoActualFetch();
private:
FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyChannel);
@@ -70,12 +74,15 @@ class VariationsService
FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, StoreSeed);
FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, ValidateStudy);
+ // Checks if prerequisites for fetching the Variations seed are met, and if
+ // so, performs the actual fetch using |DoActualFetch|.
+ void FetchVariationsSeed();
+
// 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
@@ -146,14 +153,14 @@ class VariationsService
// it gets called prior to |StartRepeatedVariationsSeedFetch|.
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

Powered by Google App Engine
This is Rietveld 408576698