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