OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ |
6 #define CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ | 6 #define CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 13 matching lines...) Expand all Loading... | |
24 class PrefServiceSimple; | 24 class PrefServiceSimple; |
25 | 25 |
26 namespace chrome_variations { | 26 namespace chrome_variations { |
27 | 27 |
28 // Used to setup field trials based on stored variations seed data, and fetch | 28 // Used to setup field trials based on stored variations seed data, and fetch |
29 // new seed data from the variations server. | 29 // new seed data from the variations server. |
30 class VariationsService | 30 class VariationsService |
31 : public net::URLFetcherDelegate, | 31 : public net::URLFetcherDelegate, |
32 public ResourceRequestAllowedNotifier::Observer { | 32 public ResourceRequestAllowedNotifier::Observer { |
33 public: | 33 public: |
34 VariationsService(); | |
35 | |
36 // This constructor exists for injecting a mock notifier. It is meant for | |
37 // testing only. This instance will take ownership of |notifier|. | |
38 explicit VariationsService(ResourceRequestAllowedNotifier* notifier); | |
39 | |
40 virtual ~VariationsService(); | 34 virtual ~VariationsService(); |
41 | 35 |
42 // Creates field trials based on Variations Seed loaded from local prefs. If | 36 // Creates field trials based on Variations Seed loaded from local prefs. If |
43 // there is a problem loading the seed data, all trials specified by the seed | 37 // there is a problem loading the seed data, all trials specified by the seed |
44 // may not be created. | 38 // may not be created. |
45 bool CreateTrialsFromSeed(PrefService* local_prefs); | 39 bool CreateTrialsFromSeed(PrefService* local_prefs); |
46 | 40 |
47 // Calls FetchVariationsSeed once and repeats this periodically. See | 41 // Calls FetchVariationsSeed once and repeats this periodically. See |
48 // implementation for details on the period. Must be called after | 42 // implementation for details on the period. Must be called after |
49 // |CreateTrialsFromSeed|. | 43 // |CreateTrialsFromSeed|. |
50 void StartRepeatedVariationsSeedFetch(); | 44 void StartRepeatedVariationsSeedFetch(); |
51 | 45 |
46 // Exposed for testing. | |
47 void SetCreateTrialsFromSeedCalledForTesting(bool called); | |
Alexei Svitkine (slow)
2013/01/03 20:14:06
Are you using this somewhere?
SteveT
2013/01/03 20:35:42
I believe this is used by the tests. It was just m
Alexei Svitkine (slow)
2013/01/03 20:40:42
Ah, I misread the diff before. SGTM.
| |
48 | |
52 // Register Variations related prefs in Local State. | 49 // Register Variations related prefs in Local State. |
53 static void RegisterPrefs(PrefServiceSimple* prefs); | 50 static void RegisterPrefs(PrefServiceSimple* prefs); |
54 | 51 |
55 // Exposed for testing. | 52 // Factory method for creating a VariationsService. |
56 void SetCreateTrialsFromSeedCalledForTesting(bool called); | 53 static VariationsService* Create(); |
57 | 54 |
58 protected: | 55 protected: |
59 // Starts the fetching process once, where |OnURLFetchComplete| is called with | 56 // Starts the fetching process once, where |OnURLFetchComplete| is called with |
60 // the response. | 57 // the response. |
61 virtual void DoActualFetch(); | 58 virtual void DoActualFetch(); |
62 | 59 |
60 // This constructor exists for injecting a mock notifier. It is meant for | |
61 // testing only. This instance will take ownership of |notifier|. | |
62 explicit VariationsService(ResourceRequestAllowedNotifier* notifier); | |
63 | |
63 private: | 64 private: |
64 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyChannel); | 65 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyChannel); |
65 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyLocale); | 66 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyLocale); |
66 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyPlatform); | 67 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyPlatform); |
67 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyVersion); | 68 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyVersion); |
68 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyVersionWildcards); | 69 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyVersionWildcards); |
69 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyStartDate); | 70 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyStartDate); |
70 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, DoNotFetchIfOffline); | 71 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, DoNotFetchIfOffline); |
71 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, DoNotFetchIfOnlineToOnline); | 72 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, DoNotFetchIfOnlineToOnline); |
72 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, FetchOnReconnect); | 73 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, FetchOnReconnect); |
73 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, IsStudyExpired); | 74 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, IsStudyExpired); |
74 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, LoadSeed); | 75 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, LoadSeed); |
75 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, StoreSeed); | 76 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, StoreSeed); |
76 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, ValidateStudy); | 77 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, ValidateStudy); |
77 | 78 |
79 // Default constructor is private. Use the |Create| factory method to create a | |
80 // VariationsService. | |
81 VariationsService(); | |
82 | |
78 // Checks if prerequisites for fetching the Variations seed are met, and if | 83 // Checks if prerequisites for fetching the Variations seed are met, and if |
79 // so, performs the actual fetch using |DoActualFetch|. | 84 // so, performs the actual fetch using |DoActualFetch|. |
80 void FetchVariationsSeed(); | 85 void FetchVariationsSeed(); |
81 | 86 |
82 // net::URLFetcherDelegate implementation: | 87 // net::URLFetcherDelegate implementation: |
83 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 88 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
84 | 89 |
85 // ResourceRequestAllowedNotifier::Observer implementation: | 90 // ResourceRequestAllowedNotifier::Observer implementation: |
86 virtual void OnResourceRequestsAllowed() OVERRIDE; | 91 virtual void OnResourceRequestsAllowed() OVERRIDE; |
87 | 92 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 scoped_ptr<ResourceRequestAllowedNotifier> resource_request_allowed_notifier_; | 169 scoped_ptr<ResourceRequestAllowedNotifier> resource_request_allowed_notifier_; |
165 | 170 |
166 // The start time of the last seed request. This is used to measure the | 171 // The start time of the last seed request. This is used to measure the |
167 // latency of seed requests. Initially zero. | 172 // latency of seed requests. Initially zero. |
168 base::TimeTicks last_request_started_time_; | 173 base::TimeTicks last_request_started_time_; |
169 }; | 174 }; |
170 | 175 |
171 } // namespace chrome_variations | 176 } // namespace chrome_variations |
172 | 177 |
173 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ | 178 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ |
OLD | NEW |