| 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_seed_store.h" | 18 #include "chrome/browser/metrics/variations/variations_seed_store.h" |
| 19 #include "components/variations/variations_request_scheduler.h" | 19 #include "components/variations/variations_request_scheduler.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/variations/variations_service_client.h" |
| 22 #include "components/web_resource/resource_request_allowed_notifier.h" | 22 #include "components/web_resource/resource_request_allowed_notifier.h" |
| 23 #include "net/url_request/url_fetcher_delegate.h" | 23 #include "net/url_request/url_fetcher_delegate.h" |
| 24 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 25 | 25 |
| 26 #if defined(OS_WIN) | |
| 27 #include "chrome/browser/metrics/variations/variations_registry_syncer_win.h" | |
| 28 #endif | |
| 29 | |
| 30 class PrefService; | 26 class PrefService; |
| 31 class PrefRegistrySimple; | 27 class PrefRegistrySimple; |
| 32 | 28 |
| 33 namespace base { | 29 namespace base { |
| 34 class Version; | 30 class Version; |
| 35 } | 31 } |
| 36 | 32 |
| 37 namespace metrics { | 33 namespace metrics { |
| 38 class MetricsStateManager; | 34 class MetricsStateManager; |
| 39 } | 35 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 virtual ~Observer() {} | 69 virtual ~Observer() {} |
| 74 }; | 70 }; |
| 75 | 71 |
| 76 ~VariationsService() override; | 72 ~VariationsService() override; |
| 77 | 73 |
| 78 // Creates field trials based on Variations Seed loaded from local prefs. If | 74 // Creates field trials based on Variations Seed loaded from local prefs. If |
| 79 // there is a problem loading the seed data, all trials specified by the seed | 75 // there is a problem loading the seed data, all trials specified by the seed |
| 80 // may not be created. | 76 // may not be created. |
| 81 bool CreateTrialsFromSeed(); | 77 bool CreateTrialsFromSeed(); |
| 82 | 78 |
| 79 // Should be called before startup of the main message loop. |
| 80 void PerformPreMainMessageLoopStartup(); |
| 81 |
| 83 // Calls FetchVariationsSeed once and repeats this periodically. See | 82 // Calls FetchVariationsSeed once and repeats this periodically. See |
| 84 // implementation for details on the period. Must be called after | 83 // implementation for details on the period. Must be called after |
| 85 // |CreateTrialsFromSeed|. | 84 // |CreateTrialsFromSeed|. |
| 86 void StartRepeatedVariationsSeedFetch(); | 85 void StartRepeatedVariationsSeedFetch(); |
| 87 | 86 |
| 88 // Adds an observer to listen for detected experiment changes. | 87 // Adds an observer to listen for detected experiment changes. |
| 89 void AddObserver(Observer* observer); | 88 void AddObserver(Observer* observer); |
| 90 | 89 |
| 91 // Removes a previously-added observer. | 90 // Removes a previously-added observer. |
| 92 void RemoveObserver(Observer* observer); | 91 void RemoveObserver(Observer* observer); |
| 93 | 92 |
| 94 // Called when the application enters foreground. This may trigger a | 93 // Called when the application enters foreground. This may trigger a |
| 95 // FetchVariationsSeed call. | 94 // FetchVariationsSeed call. |
| 96 // TODO(rkaplow): Handle this and the similar event in metrics_service by | 95 // TODO(rkaplow): Handle this and the similar event in metrics_service by |
| 97 // observing an 'OnAppEnterForeground' event instead of requiring the frontend | 96 // observing an 'OnAppEnterForeground' event instead of requiring the frontend |
| 98 // code to notify each service individually. | 97 // code to notify each service individually. |
| 99 void OnAppEnterForeground(); | 98 void OnAppEnterForeground(); |
| 100 | 99 |
| 101 #if defined(OS_WIN) | |
| 102 // Starts syncing Google Update Variation IDs with the registry. | |
| 103 void StartGoogleUpdateRegistrySync(); | |
| 104 #endif | |
| 105 | |
| 106 // Sets the value of the "restrict" URL param to the variations service that | 100 // Sets the value of the "restrict" URL param to the variations service that |
| 107 // should be used for variation seed requests. This takes precedence over any | 101 // should be used for variation seed requests. This takes precedence over any |
| 108 // value coming from policy prefs. This should be called prior to any calls | 102 // value coming from policy prefs. This should be called prior to any calls |
| 109 // to |StartRepeatedVariationsSeedFetch|. | 103 // to |StartRepeatedVariationsSeedFetch|. |
| 110 void SetRestrictMode(const std::string& restrict_mode); | 104 void SetRestrictMode(const std::string& restrict_mode); |
| 111 | 105 |
| 112 // Exposed for testing. | 106 // Exposed for testing. |
| 113 void SetCreateTrialsFromSeedCalledForTesting(bool called); | 107 void SetCreateTrialsFromSeedCalledForTesting(bool called); |
| 114 | 108 |
| 115 // Returns the variations server URL, which can vary if a command-line flag is | 109 // Returns the variations server URL, which can vary if a command-line flag is |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 // The start time of the last seed request. This is used to measure the | 273 // The start time of the last seed request. This is used to measure the |
| 280 // latency of seed requests. Initially zero. | 274 // latency of seed requests. Initially zero. |
| 281 base::TimeTicks last_request_started_time_; | 275 base::TimeTicks last_request_started_time_; |
| 282 | 276 |
| 283 // The number of requests to the variations server that have been performed. | 277 // The number of requests to the variations server that have been performed. |
| 284 int request_count_; | 278 int request_count_; |
| 285 | 279 |
| 286 // List of observers of the VariationsService. | 280 // List of observers of the VariationsService. |
| 287 base::ObserverList<Observer> observer_list_; | 281 base::ObserverList<Observer> observer_list_; |
| 288 | 282 |
| 289 #if defined(OS_WIN) | |
| 290 // Helper that handles synchronizing Variations with the Registry. | |
| 291 VariationsRegistrySyncer registry_syncer_; | |
| 292 #endif | |
| 293 | |
| 294 base::ThreadChecker thread_checker_; | 283 base::ThreadChecker thread_checker_; |
| 295 | 284 |
| 296 base::WeakPtrFactory<VariationsService> weak_ptr_factory_; | 285 base::WeakPtrFactory<VariationsService> weak_ptr_factory_; |
| 297 | 286 |
| 298 DISALLOW_COPY_AND_ASSIGN(VariationsService); | 287 DISALLOW_COPY_AND_ASSIGN(VariationsService); |
| 299 }; | 288 }; |
| 300 | 289 |
| 301 } // namespace chrome_variations | 290 } // namespace chrome_variations |
| 302 | 291 |
| 303 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ | 292 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ |
| OLD | NEW |