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

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: asvit nit 2 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..1efae326a81aaec189d7bf9d9d57d111be278e43 100644
--- a/chrome/browser/metrics/variations/variations_service.h
+++ b/chrome/browser/metrics/variations/variations_service.h
@@ -15,20 +15,24 @@
#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();
virtual ~VariationsService();
@@ -43,17 +47,31 @@ 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();
+
+ // See ResourceRequestAllowedNotifier::RegisterForEulaAcceptedNotification.
+ void RegisterForEulaAcceptedNotification(chromeos::WizardController* source);
+
+ // 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. 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();
+ virtual void DoActualFetch();
- // Exposed for testing.
- void SetWasOfflineDuringLastRequestAttemptForTesting(bool offline);
+ // Allows tests to replace |resource_request_allowed_notifier_| with a mock.
+ void SetResourceRequestAllowedNotifierForTesting(
+ ResourceRequestAllowedNotifier* notifier);
- // Register Variations related prefs in Local State.
- static void RegisterPrefs(PrefService* prefs);
+ // 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.
+ bool create_trials_from_seed_called_;
Ilya Sherman 2012/09/14 20:55:43 nit: Member variables should always have private v
private:
FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyChannel);
@@ -66,16 +84,15 @@ class VariationsService
FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, DoNotFetchIfOnlineToOnline);
FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, FetchOnReconnect);
FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, IsStudyExpired);
- FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, LoadSeed);
- FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, StoreSeed);
+ FRIEND_TEST_ALL_PREFIXES(VariationsServiceCreatedTest, LoadSeed);
+ FRIEND_TEST_ALL_PREFIXES(VariationsServiceCreatedTest, StoreSeed);
FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, ValidateStudy);
// 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
@@ -142,18 +159,14 @@ class VariationsService
// Cached serial number from the most recently fetched Variations seed.
std::string variations_serial_number_;
- // Tracks whether |CreateTrialsFromSeed| has been called, to ensure that
- // 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