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 COMPONENTS_VARIATIONS_SERVICE_VARIATIONS_SERVICE_H_ | 5 #ifndef COMPONENTS_VARIATIONS_SERVICE_VARIATIONS_SERVICE_H_ |
6 #define COMPONENTS_VARIATIONS_SERVICE_VARIATIONS_SERVICE_H_ | 6 #define COMPONENTS_VARIATIONS_SERVICE_VARIATIONS_SERVICE_H_ |
7 | 7 |
| 8 #include <memory> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
11 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
16 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
19 #include "components/variations/service/ui_string_overrider.h" | 19 #include "components/variations/service/ui_string_overrider.h" |
20 #include "components/variations/service/variations_service_client.h" | 20 #include "components/variations/service/variations_service_client.h" |
21 #include "components/variations/variations_request_scheduler.h" | 21 #include "components/variations/variations_request_scheduler.h" |
22 #include "components/variations/variations_seed_simulator.h" | 22 #include "components/variations/variations_seed_simulator.h" |
23 #include "components/variations/variations_seed_store.h" | 23 #include "components/variations/variations_seed_store.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 133 |
134 // Register Variations related prefs in Local State. | 134 // Register Variations related prefs in Local State. |
135 static void RegisterPrefs(PrefRegistrySimple* registry); | 135 static void RegisterPrefs(PrefRegistrySimple* registry); |
136 | 136 |
137 // Register Variations related prefs in the Profile prefs. | 137 // Register Variations related prefs in the Profile prefs. |
138 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 138 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
139 | 139 |
140 // Factory method for creating a VariationsService. Does not take ownership of | 140 // Factory method for creating a VariationsService. Does not take ownership of |
141 // |state_manager|. Caller should ensure that |state_manager| is valid for the | 141 // |state_manager|. Caller should ensure that |state_manager| is valid for the |
142 // lifetime of this class. | 142 // lifetime of this class. |
143 static scoped_ptr<VariationsService> Create( | 143 static std::unique_ptr<VariationsService> Create( |
144 scoped_ptr<VariationsServiceClient> client, | 144 std::unique_ptr<VariationsServiceClient> client, |
145 PrefService* local_state, | 145 PrefService* local_state, |
146 metrics::MetricsStateManager* state_manager, | 146 metrics::MetricsStateManager* state_manager, |
147 const char* disable_network_switch, | 147 const char* disable_network_switch, |
148 const UIStringOverrider& ui_string_overrider); | 148 const UIStringOverrider& ui_string_overrider); |
149 | 149 |
150 // Factory method for creating a VariationsService in a testing context. | 150 // Factory method for creating a VariationsService in a testing context. |
151 static scoped_ptr<VariationsService> CreateForTesting( | 151 static std::unique_ptr<VariationsService> CreateForTesting( |
152 scoped_ptr<VariationsServiceClient> client, | 152 std::unique_ptr<VariationsServiceClient> client, |
153 PrefService* local_state); | 153 PrefService* local_state); |
154 | 154 |
155 // Set the PrefService responsible for getting policy-related preferences, | 155 // Set the PrefService responsible for getting policy-related preferences, |
156 // such as the restrict parameter. | 156 // such as the restrict parameter. |
157 void set_policy_pref_service(PrefService* service) { | 157 void set_policy_pref_service(PrefService* service) { |
158 DCHECK(service); | 158 DCHECK(service); |
159 policy_pref_service_ = service; | 159 policy_pref_service_ = service; |
160 } | 160 } |
161 | 161 |
162 // Returns the invalid variations seed signature in base64 format, or an empty | 162 // Returns the invalid variations seed signature in base64 format, or an empty |
(...skipping 13 matching lines...) Expand all Loading... |
176 const std::string& country_code, | 176 const std::string& country_code, |
177 const base::Time& date_fetched, | 177 const base::Time& date_fetched, |
178 bool is_delta_compressed, | 178 bool is_delta_compressed, |
179 bool is_gzip_compressed); | 179 bool is_gzip_compressed); |
180 | 180 |
181 // Creates the VariationsService with the given |local_state| prefs service | 181 // Creates the VariationsService with the given |local_state| prefs service |
182 // and |state_manager|. Does not take ownership of |state_manager|. Caller | 182 // and |state_manager|. Does not take ownership of |state_manager|. Caller |
183 // should ensure that |state_manager| is valid for the lifetime of this class. | 183 // should ensure that |state_manager| is valid for the lifetime of this class. |
184 // Use the |Create| factory method to create a VariationsService. | 184 // Use the |Create| factory method to create a VariationsService. |
185 VariationsService( | 185 VariationsService( |
186 scoped_ptr<VariationsServiceClient> client, | 186 std::unique_ptr<VariationsServiceClient> client, |
187 scoped_ptr<web_resource::ResourceRequestAllowedNotifier> notifier, | 187 std::unique_ptr<web_resource::ResourceRequestAllowedNotifier> notifier, |
188 PrefService* local_state, | 188 PrefService* local_state, |
189 metrics::MetricsStateManager* state_manager, | 189 metrics::MetricsStateManager* state_manager, |
190 const UIStringOverrider& ui_string_overrider); | 190 const UIStringOverrider& ui_string_overrider); |
191 | 191 |
192 // Sets the URL for querying the variations server. Used for testing. | 192 // Sets the URL for querying the variations server. Used for testing. |
193 void set_variations_server_url(const GURL& url) { | 193 void set_variations_server_url(const GURL& url) { |
194 variations_server_url_ = url; | 194 variations_server_url_ = url; |
195 } | 195 } |
196 | 196 |
197 private: | 197 private: |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 const variations::VariationsSeedSimulator::Result& result); | 239 const variations::VariationsSeedSimulator::Result& result); |
240 | 240 |
241 // net::URLFetcherDelegate implementation: | 241 // net::URLFetcherDelegate implementation: |
242 void OnURLFetchComplete(const net::URLFetcher* source) override; | 242 void OnURLFetchComplete(const net::URLFetcher* source) override; |
243 | 243 |
244 // ResourceRequestAllowedNotifier::Observer implementation: | 244 // ResourceRequestAllowedNotifier::Observer implementation: |
245 void OnResourceRequestsAllowed() override; | 245 void OnResourceRequestsAllowed() override; |
246 | 246 |
247 // Performs a variations seed simulation with the given |seed| and |version| | 247 // Performs a variations seed simulation with the given |seed| and |version| |
248 // and logs the simulation results as histograms. | 248 // and logs the simulation results as histograms. |
249 void PerformSimulationWithVersion(scoped_ptr<variations::VariationsSeed> seed, | 249 void PerformSimulationWithVersion( |
250 const base::Version& version); | 250 std::unique_ptr<variations::VariationsSeed> seed, |
| 251 const base::Version& version); |
251 | 252 |
252 // Record the time of the most recent successful fetch. | 253 // Record the time of the most recent successful fetch. |
253 void RecordLastFetchTime(); | 254 void RecordLastFetchTime(); |
254 | 255 |
255 // Loads the country code to use for filtering permanent consistency studies, | 256 // Loads the country code to use for filtering permanent consistency studies, |
256 // updating the stored country code if the stored value was for a different | 257 // updating the stored country code if the stored value was for a different |
257 // Chrome version. The country used for permanent consistency studies is kept | 258 // Chrome version. The country used for permanent consistency studies is kept |
258 // consistent between Chrome upgrades in order to avoid annoying the user due | 259 // consistent between Chrome upgrades in order to avoid annoying the user due |
259 // to experiment churn while traveling. | 260 // to experiment churn while traveling. |
260 std::string LoadPermanentConsistencyCountry( | 261 std::string LoadPermanentConsistencyCountry( |
261 const base::Version& version, | 262 const base::Version& version, |
262 const std::string& latest_country); | 263 const std::string& latest_country); |
263 | 264 |
264 scoped_ptr<VariationsServiceClient> client_; | 265 std::unique_ptr<VariationsServiceClient> client_; |
265 UIStringOverrider ui_string_overrider_; | 266 UIStringOverrider ui_string_overrider_; |
266 | 267 |
267 // The pref service used to store persist the variations seed. | 268 // The pref service used to store persist the variations seed. |
268 PrefService* local_state_; | 269 PrefService* local_state_; |
269 | 270 |
270 // Used for instantiating entropy providers for variations seed simulation. | 271 // Used for instantiating entropy providers for variations seed simulation. |
271 // Weak pointer. | 272 // Weak pointer. |
272 metrics::MetricsStateManager* state_manager_; | 273 metrics::MetricsStateManager* state_manager_; |
273 | 274 |
274 // Used to obtain policy-related preferences. Depending on the platform, will | 275 // Used to obtain policy-related preferences. Depending on the platform, will |
275 // either be Local State or Profile prefs. | 276 // either be Local State or Profile prefs. |
276 PrefService* policy_pref_service_; | 277 PrefService* policy_pref_service_; |
277 | 278 |
278 VariationsSeedStore seed_store_; | 279 VariationsSeedStore seed_store_; |
279 | 280 |
280 // Contains the scheduler instance that handles timing for requests to the | 281 // Contains the scheduler instance that handles timing for requests to the |
281 // server. Initially NULL and instantiated when the initial fetch is | 282 // server. Initially NULL and instantiated when the initial fetch is |
282 // requested. | 283 // requested. |
283 scoped_ptr<VariationsRequestScheduler> request_scheduler_; | 284 std::unique_ptr<VariationsRequestScheduler> request_scheduler_; |
284 | 285 |
285 // Contains the current seed request. Will only have a value while a request | 286 // Contains the current seed request. Will only have a value while a request |
286 // is pending, and will be reset by |OnURLFetchComplete|. | 287 // is pending, and will be reset by |OnURLFetchComplete|. |
287 scoped_ptr<net::URLFetcher> pending_seed_request_; | 288 std::unique_ptr<net::URLFetcher> pending_seed_request_; |
288 | 289 |
289 // The value of the "restrict" URL param to the variations server that has | 290 // The value of the "restrict" URL param to the variations server that has |
290 // been specified via |SetRestrictMode|. If empty, the URL param will be set | 291 // been specified via |SetRestrictMode|. If empty, the URL param will be set |
291 // based on policy prefs. | 292 // based on policy prefs. |
292 std::string restrict_mode_; | 293 std::string restrict_mode_; |
293 | 294 |
294 // The URL to use for querying the variations server. | 295 // The URL to use for querying the variations server. |
295 GURL variations_server_url_; | 296 GURL variations_server_url_; |
296 | 297 |
297 // Tracks whether |CreateTrialsFromSeed| has been called, to ensure that | 298 // Tracks whether |CreateTrialsFromSeed| has been called, to ensure that |
298 // it gets called prior to |StartRepeatedVariationsSeedFetch|. | 299 // it gets called prior to |StartRepeatedVariationsSeedFetch|. |
299 bool create_trials_from_seed_called_; | 300 bool create_trials_from_seed_called_; |
300 | 301 |
301 // Tracks whether the initial request to the variations server had completed. | 302 // Tracks whether the initial request to the variations server had completed. |
302 bool initial_request_completed_; | 303 bool initial_request_completed_; |
303 | 304 |
304 // Indicates that the next request to the variations service shouldn't specify | 305 // Indicates that the next request to the variations service shouldn't specify |
305 // that it supports delta compression. Set to true when a delta compressed | 306 // that it supports delta compression. Set to true when a delta compressed |
306 // response encountered an error. | 307 // response encountered an error. |
307 bool disable_deltas_for_next_request_; | 308 bool disable_deltas_for_next_request_; |
308 | 309 |
309 // Helper class used to tell this service if it's allowed to make network | 310 // Helper class used to tell this service if it's allowed to make network |
310 // resource requests. | 311 // resource requests. |
311 scoped_ptr<web_resource::ResourceRequestAllowedNotifier> | 312 std::unique_ptr<web_resource::ResourceRequestAllowedNotifier> |
312 resource_request_allowed_notifier_; | 313 resource_request_allowed_notifier_; |
313 | 314 |
314 // The start time of the last seed request. This is used to measure the | 315 // The start time of the last seed request. This is used to measure the |
315 // latency of seed requests. Initially zero. | 316 // latency of seed requests. Initially zero. |
316 base::TimeTicks last_request_started_time_; | 317 base::TimeTicks last_request_started_time_; |
317 | 318 |
318 // The number of requests to the variations server that have been performed. | 319 // The number of requests to the variations server that have been performed. |
319 int request_count_; | 320 int request_count_; |
320 | 321 |
321 // List of observers of the VariationsService. | 322 // List of observers of the VariationsService. |
322 base::ObserverList<Observer> observer_list_; | 323 base::ObserverList<Observer> observer_list_; |
323 | 324 |
324 base::ThreadChecker thread_checker_; | 325 base::ThreadChecker thread_checker_; |
325 | 326 |
326 base::WeakPtrFactory<VariationsService> weak_ptr_factory_; | 327 base::WeakPtrFactory<VariationsService> weak_ptr_factory_; |
327 | 328 |
328 DISALLOW_COPY_AND_ASSIGN(VariationsService); | 329 DISALLOW_COPY_AND_ASSIGN(VariationsService); |
329 }; | 330 }; |
330 | 331 |
331 } // namespace variations | 332 } // namespace variations |
332 | 333 |
333 #endif // COMPONENTS_VARIATIONS_SERVICE_VARIATIONS_SERVICE_H_ | 334 #endif // COMPONENTS_VARIATIONS_SERVICE_VARIATIONS_SERVICE_H_ |
OLD | NEW |