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 DCHECK(service); |
| 84 policy_pref_service_ = service; |
| 85 } |
| 86 |
73 protected: | 87 protected: |
74 // Starts the fetching process once, where |OnURLFetchComplete| is called with | 88 // Starts the fetching process once, where |OnURLFetchComplete| is called with |
75 // the response. | 89 // the response. |
76 virtual void DoActualFetch(); | 90 virtual void DoActualFetch(); |
77 | 91 |
78 // This constructor exists for injecting a mock notifier. It is meant for | 92 // This constructor exists for injecting a mock notifier. It is meant for |
79 // testing only. This instance will take ownership of |notifier|. | 93 // testing only. This instance will take ownership of |notifier|. |
80 VariationsService(ResourceRequestAllowedNotifier* notifier, | 94 VariationsService(ResourceRequestAllowedNotifier* notifier, |
81 PrefService* local_state); | 95 PrefService* local_state); |
82 | 96 |
(...skipping 20 matching lines...) Expand all Loading... |
103 | 117 |
104 // ResourceRequestAllowedNotifier::Observer implementation: | 118 // ResourceRequestAllowedNotifier::Observer implementation: |
105 virtual void OnResourceRequestsAllowed() OVERRIDE; | 119 virtual void OnResourceRequestsAllowed() OVERRIDE; |
106 | 120 |
107 // Record the time of the most recent successful fetch. | 121 // Record the time of the most recent successful fetch. |
108 void RecordLastFetchTime(); | 122 void RecordLastFetchTime(); |
109 | 123 |
110 // The pref service used to store persist the variations seed. | 124 // The pref service used to store persist the variations seed. |
111 PrefService* local_state_; | 125 PrefService* local_state_; |
112 | 126 |
| 127 // Used to obtain policy-related preferences. Depending on the platform, will |
| 128 // either be Local State or Profile prefs. |
| 129 PrefService* policy_pref_service_; |
| 130 |
113 VariationsSeedStore seed_store_; | 131 VariationsSeedStore seed_store_; |
114 | 132 |
115 // Contains the scheduler instance that handles timing for requests to the | 133 // Contains the scheduler instance that handles timing for requests to the |
116 // server. Initially NULL and instantiated when the initial fetch is | 134 // server. Initially NULL and instantiated when the initial fetch is |
117 // requested. | 135 // requested. |
118 scoped_ptr<VariationsRequestScheduler> request_scheduler_; | 136 scoped_ptr<VariationsRequestScheduler> request_scheduler_; |
119 | 137 |
120 // Contains the current seed request. Will only have a value while a request | 138 // Contains the current seed request. Will only have a value while a request |
121 // is pending, and will be reset by |OnURLFetchComplete|. | 139 // is pending, and will be reset by |OnURLFetchComplete|. |
122 scoped_ptr<net::URLFetcher> pending_seed_request_; | 140 scoped_ptr<net::URLFetcher> pending_seed_request_; |
(...skipping 20 matching lines...) Expand all Loading... |
143 // Helper that handles synchronizing Variations with the Registry. | 161 // Helper that handles synchronizing Variations with the Registry. |
144 VariationsRegistrySyncer registry_syncer_; | 162 VariationsRegistrySyncer registry_syncer_; |
145 #endif | 163 #endif |
146 | 164 |
147 DISALLOW_COPY_AND_ASSIGN(VariationsService); | 165 DISALLOW_COPY_AND_ASSIGN(VariationsService); |
148 }; | 166 }; |
149 | 167 |
150 } // namespace chrome_variations | 168 } // namespace chrome_variations |
151 | 169 |
152 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ | 170 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ |
OLD | NEW |