| 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/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "chrome/browser/metrics/variations/variations_request_scheduler.h" | 15 #include "chrome/browser/metrics/variations/variations_request_scheduler.h" |
| 16 #include "chrome/browser/metrics/variations/variations_seed_store.h" | 16 #include "chrome/browser/metrics/variations/variations_seed_store.h" |
| 17 #include "chrome/browser/web_resource/resource_request_allowed_notifier.h" | 17 #include "chrome/browser/web_resource/resource_request_allowed_notifier.h" |
| 18 #include "chrome/common/chrome_version_info.h" | 18 #include "chrome/common/chrome_version_info.h" |
| 19 #include "net/url_request/url_fetcher_delegate.h" | 19 #include "net/url_request/url_fetcher_delegate.h" |
| 20 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 21 | 21 |
| 22 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
| 23 #include "chrome/browser/metrics/variations/variations_registry_syncer_win.h" | 23 #include "chrome/browser/metrics/variations/variations_registry_syncer_win.h" |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 class PrefService; | 26 class PrefService; |
| 27 class PrefRegistrySimple; | 27 class PrefRegistrySimple; |
| 28 | 28 |
| 29 namespace user_prefs { |
| 30 class PrefRegistrySyncable; |
| 31 } |
| 32 |
| 29 namespace chrome_variations { | 33 namespace chrome_variations { |
| 30 | 34 |
| 31 class VariationsSeed; | 35 class VariationsSeed; |
| 32 | 36 |
| 33 // Used to setup field trials based on stored variations seed data, and fetch | 37 // Used to setup field trials based on stored variations seed data, and fetch |
| 34 // new seed data from the variations server. | 38 // new seed data from the variations server. |
| 35 class VariationsService | 39 class VariationsService |
| 36 : public net::URLFetcherDelegate, | 40 : public net::URLFetcherDelegate, |
| 37 public ResourceRequestAllowedNotifier::Observer { | 41 public ResourceRequestAllowedNotifier::Observer { |
| 38 public: | 42 public: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 60 | 64 |
| 61 // Exposed for testing. | 65 // Exposed for testing. |
| 62 void SetCreateTrialsFromSeedCalledForTesting(bool called); | 66 void SetCreateTrialsFromSeedCalledForTesting(bool called); |
| 63 | 67 |
| 64 // Exposed for testing. | 68 // Exposed for testing. |
| 65 static std::string GetDefaultVariationsServerURLForTesting(); | 69 static std::string GetDefaultVariationsServerURLForTesting(); |
| 66 | 70 |
| 67 // Register Variations related prefs in Local State. | 71 // Register Variations related prefs in Local State. |
| 68 static void RegisterPrefs(PrefRegistrySimple* registry); | 72 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 69 | 73 |
| 74 // Register Variations related prefs in the Profile prefs. |
| 75 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 76 |
| 70 // Factory method for creating a VariationsService. | 77 // Factory method for creating a VariationsService. |
| 71 static VariationsService* Create(PrefService* local_state); | 78 static VariationsService* Create(PrefService* local_state); |
| 72 | 79 |
| 80 // Set the PrefService responsible for getting policy-related preferences, |
| 81 // such as the restrict parameter. |
| 82 void set_policy_pref_service(PrefService* service) { |
| 83 policy_pref_service_ = service; |
| 84 } |
| 85 |
| 73 protected: | 86 protected: |
| 74 // Starts the fetching process once, where |OnURLFetchComplete| is called with | 87 // Starts the fetching process once, where |OnURLFetchComplete| is called with |
| 75 // the response. | 88 // the response. |
| 76 virtual void DoActualFetch(); | 89 virtual void DoActualFetch(); |
| 77 | 90 |
| 78 // This constructor exists for injecting a mock notifier. It is meant for | 91 // This constructor exists for injecting a mock notifier. It is meant for |
| 79 // testing only. This instance will take ownership of |notifier|. | 92 // testing only. This instance will take ownership of |notifier|. |
| 80 VariationsService(ResourceRequestAllowedNotifier* notifier, | 93 VariationsService(ResourceRequestAllowedNotifier* notifier, |
| 81 PrefService* local_state); | 94 PrefService* local_state); |
| 82 | 95 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 103 | 116 |
| 104 // ResourceRequestAllowedNotifier::Observer implementation: | 117 // ResourceRequestAllowedNotifier::Observer implementation: |
| 105 virtual void OnResourceRequestsAllowed() OVERRIDE; | 118 virtual void OnResourceRequestsAllowed() OVERRIDE; |
| 106 | 119 |
| 107 // Record the time of the most recent successful fetch. | 120 // Record the time of the most recent successful fetch. |
| 108 void RecordLastFetchTime(); | 121 void RecordLastFetchTime(); |
| 109 | 122 |
| 110 // The pref service used to store persist the variations seed. | 123 // The pref service used to store persist the variations seed. |
| 111 PrefService* local_state_; | 124 PrefService* local_state_; |
| 112 | 125 |
| 126 // Used to obtain policy-related preferences. Depending on the platform, will |
| 127 // either be Local State or Profile prefs. |
| 128 PrefService* policy_pref_service_; |
| 129 |
| 113 VariationsSeedStore seed_store_; | 130 VariationsSeedStore seed_store_; |
| 114 | 131 |
| 115 // Contains the scheduler instance that handles timing for requests to the | 132 // Contains the scheduler instance that handles timing for requests to the |
| 116 // server. Initially NULL and instantiated when the initial fetch is | 133 // server. Initially NULL and instantiated when the initial fetch is |
| 117 // requested. | 134 // requested. |
| 118 scoped_ptr<VariationsRequestScheduler> request_scheduler_; | 135 scoped_ptr<VariationsRequestScheduler> request_scheduler_; |
| 119 | 136 |
| 120 // Contains the current seed request. Will only have a value while a request | 137 // Contains the current seed request. Will only have a value while a request |
| 121 // is pending, and will be reset by |OnURLFetchComplete|. | 138 // is pending, and will be reset by |OnURLFetchComplete|. |
| 122 scoped_ptr<net::URLFetcher> pending_seed_request_; | 139 scoped_ptr<net::URLFetcher> pending_seed_request_; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 143 // Helper that handles synchronizing Variations with the Registry. | 160 // Helper that handles synchronizing Variations with the Registry. |
| 144 VariationsRegistrySyncer registry_syncer_; | 161 VariationsRegistrySyncer registry_syncer_; |
| 145 #endif | 162 #endif |
| 146 | 163 |
| 147 DISALLOW_COPY_AND_ASSIGN(VariationsService); | 164 DISALLOW_COPY_AND_ASSIGN(VariationsService); |
| 148 }; | 165 }; |
| 149 | 166 |
| 150 } // namespace chrome_variations | 167 } // namespace chrome_variations |
| 151 | 168 |
| 152 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ | 169 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ |
| OLD | NEW |