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" |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "chrome/browser/metrics/variations/variations_request_scheduler.h" | 18 #include "chrome/browser/metrics/variations/variations_request_scheduler.h" |
19 #include "chrome/browser/metrics/variations/variations_seed_store.h" | 19 #include "chrome/browser/metrics/variations/variations_seed_store.h" |
20 #include "components/variations/variations_seed_simulator.h" | 20 #include "components/variations/variations_seed_simulator.h" |
| 21 #include "components/variations/variations_service_client.h" |
21 #include "components/web_resource/resource_request_allowed_notifier.h" | 22 #include "components/web_resource/resource_request_allowed_notifier.h" |
22 #include "net/url_request/url_fetcher_delegate.h" | 23 #include "net/url_request/url_fetcher_delegate.h" |
23 #include "url/gurl.h" | 24 #include "url/gurl.h" |
24 | 25 |
25 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
26 #include "chrome/browser/metrics/variations/variations_registry_syncer_win.h" | 27 #include "chrome/browser/metrics/variations/variations_registry_syncer_win.h" |
27 #endif | 28 #endif |
28 | 29 |
29 class PrefService; | 30 class PrefService; |
30 class PrefRegistrySimple; | 31 class PrefRegistrySimple; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // Register Variations related prefs in Local State. | 124 // Register Variations related prefs in Local State. |
124 static void RegisterPrefs(PrefRegistrySimple* registry); | 125 static void RegisterPrefs(PrefRegistrySimple* registry); |
125 | 126 |
126 // Register Variations related prefs in the Profile prefs. | 127 // Register Variations related prefs in the Profile prefs. |
127 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 128 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
128 | 129 |
129 // Factory method for creating a VariationsService. Does not take ownership of | 130 // Factory method for creating a VariationsService. Does not take ownership of |
130 // |state_manager|. Caller should ensure that |state_manager| is valid for the | 131 // |state_manager|. Caller should ensure that |state_manager| is valid for the |
131 // lifetime of this class. | 132 // lifetime of this class. |
132 static scoped_ptr<VariationsService> Create( | 133 static scoped_ptr<VariationsService> Create( |
| 134 scoped_ptr<VariationsServiceClient> client, |
133 PrefService* local_state, | 135 PrefService* local_state, |
134 metrics::MetricsStateManager* state_manager); | 136 metrics::MetricsStateManager* state_manager); |
135 | 137 |
136 // Set the PrefService responsible for getting policy-related preferences, | 138 // Set the PrefService responsible for getting policy-related preferences, |
137 // such as the restrict parameter. | 139 // such as the restrict parameter. |
138 void set_policy_pref_service(PrefService* service) { | 140 void set_policy_pref_service(PrefService* service) { |
139 DCHECK(service); | 141 DCHECK(service); |
140 policy_pref_service_ = service; | 142 policy_pref_service_ = service; |
141 } | 143 } |
142 | 144 |
(...skipping 13 matching lines...) Expand all Loading... |
156 const std::string& seed_signature, | 158 const std::string& seed_signature, |
157 const std::string& country_code, | 159 const std::string& country_code, |
158 const base::Time& date_fetched, | 160 const base::Time& date_fetched, |
159 bool is_delta_compressed); | 161 bool is_delta_compressed); |
160 | 162 |
161 // Creates the VariationsService with the given |local_state| prefs service | 163 // Creates the VariationsService with the given |local_state| prefs service |
162 // and |state_manager|. This instance will take ownership of |notifier|. | 164 // and |state_manager|. This instance will take ownership of |notifier|. |
163 // Does not take ownership of |state_manager|. Caller should ensure that | 165 // Does not take ownership of |state_manager|. Caller should ensure that |
164 // |state_manager| is valid for the lifetime of this class. Use the |Create| | 166 // |state_manager| is valid for the lifetime of this class. Use the |Create| |
165 // factory method to create a VariationsService. | 167 // factory method to create a VariationsService. |
166 VariationsService(web_resource::ResourceRequestAllowedNotifier* notifier, | 168 VariationsService(scoped_ptr<VariationsServiceClient> client, |
| 169 web_resource::ResourceRequestAllowedNotifier* notifier, |
167 PrefService* local_state, | 170 PrefService* local_state, |
168 metrics::MetricsStateManager* state_manager); | 171 metrics::MetricsStateManager* state_manager); |
169 | 172 |
170 private: | 173 private: |
171 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, Observer); | 174 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, Observer); |
172 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, SeedStoredWhenOKStatus); | 175 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, SeedStoredWhenOKStatus); |
173 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, SeedNotStoredWhenNonOKStatus); | 176 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, SeedNotStoredWhenNonOKStatus); |
174 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, SeedDateUpdatedOn304Status); | 177 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, SeedDateUpdatedOn304Status); |
175 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, | 178 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, |
176 LoadPermanentConsistencyCountry); | 179 LoadPermanentConsistencyCountry); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 220 |
218 // Loads the country code to use for filtering permanent consistency studies, | 221 // Loads the country code to use for filtering permanent consistency studies, |
219 // updating the stored country code if the stored value was for a different | 222 // updating the stored country code if the stored value was for a different |
220 // Chrome version. The country used for permanent consistency studies is kept | 223 // Chrome version. The country used for permanent consistency studies is kept |
221 // consistent between Chrome upgrades in order to avoid annoying the user due | 224 // consistent between Chrome upgrades in order to avoid annoying the user due |
222 // to experiment churn while traveling. | 225 // to experiment churn while traveling. |
223 std::string LoadPermanentConsistencyCountry( | 226 std::string LoadPermanentConsistencyCountry( |
224 const base::Version& version, | 227 const base::Version& version, |
225 const std::string& latest_country); | 228 const std::string& latest_country); |
226 | 229 |
| 230 scoped_ptr<VariationsServiceClient> client_; |
| 231 |
227 // The pref service used to store persist the variations seed. | 232 // The pref service used to store persist the variations seed. |
228 PrefService* local_state_; | 233 PrefService* local_state_; |
229 | 234 |
230 // Used for instantiating entropy providers for variations seed simulation. | 235 // Used for instantiating entropy providers for variations seed simulation. |
231 // Weak pointer. | 236 // Weak pointer. |
232 metrics::MetricsStateManager* state_manager_; | 237 metrics::MetricsStateManager* state_manager_; |
233 | 238 |
234 // Used to obtain policy-related preferences. Depending on the platform, will | 239 // Used to obtain policy-related preferences. Depending on the platform, will |
235 // either be Local State or Profile prefs. | 240 // either be Local State or Profile prefs. |
236 PrefService* policy_pref_service_; | 241 PrefService* policy_pref_service_; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 base::ThreadChecker thread_checker_; | 294 base::ThreadChecker thread_checker_; |
290 | 295 |
291 base::WeakPtrFactory<VariationsService> weak_ptr_factory_; | 296 base::WeakPtrFactory<VariationsService> weak_ptr_factory_; |
292 | 297 |
293 DISALLOW_COPY_AND_ASSIGN(VariationsService); | 298 DISALLOW_COPY_AND_ASSIGN(VariationsService); |
294 }; | 299 }; |
295 | 300 |
296 } // namespace chrome_variations | 301 } // namespace chrome_variations |
297 | 302 |
298 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ | 303 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ |
OLD | NEW |