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.h" | 14 #include "base/time.h" |
15 #include "base/timer.h" | 15 #include "base/timer.h" |
16 #include "chrome/browser/metrics/proto/study.pb.h" | 16 #include "chrome/browser/metrics/proto/study.pb.h" |
17 #include "chrome/browser/metrics/proto/trials_seed.pb.h" | 17 #include "chrome/browser/metrics/proto/trials_seed.pb.h" |
18 #include "chrome/browser/metrics/variations/resource_request_allowed_notifier.h" | 18 #include "chrome/browser/metrics/variations/resource_request_allowed_notifier.h" |
19 #include "chrome/common/chrome_version_info.h" | 19 #include "chrome/common/chrome_version_info.h" |
20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
21 #include "net/url_request/url_fetcher_delegate.h" | 21 #include "net/url_request/url_fetcher_delegate.h" |
22 | 22 |
23 class PrefService; | 23 class PrefService; |
| 24 class PrefServiceSimple; |
24 | 25 |
25 namespace chrome_variations { | 26 namespace chrome_variations { |
26 | 27 |
27 // Used to setup field trials based on stored variations seed data, and fetch | 28 // Used to setup field trials based on stored variations seed data, and fetch |
28 // new seed data from the variations server. | 29 // new seed data from the variations server. |
29 class VariationsService | 30 class VariationsService |
30 : public net::URLFetcherDelegate, | 31 : public net::URLFetcherDelegate, |
31 public ResourceRequestAllowedNotifier::Observer { | 32 public ResourceRequestAllowedNotifier::Observer { |
32 public: | 33 public: |
33 VariationsService(); | 34 VariationsService(); |
34 | 35 |
35 // This constructor exists for injecting a mock notifier. It is meant for | 36 // This constructor exists for injecting a mock notifier. It is meant for |
36 // testing only. This instance will take ownership of |notifier|. | 37 // testing only. This instance will take ownership of |notifier|. |
37 explicit VariationsService(ResourceRequestAllowedNotifier* notifier); | 38 explicit VariationsService(ResourceRequestAllowedNotifier* notifier); |
38 | 39 |
39 virtual ~VariationsService(); | 40 virtual ~VariationsService(); |
40 | 41 |
41 // Creates field trials based on Variations Seed loaded from local prefs. If | 42 // Creates field trials based on Variations Seed loaded from local prefs. If |
42 // there is a problem loading the seed data, all trials specified by the seed | 43 // there is a problem loading the seed data, all trials specified by the seed |
43 // may not be created. | 44 // may not be created. |
44 bool CreateTrialsFromSeed(PrefService* local_prefs); | 45 bool CreateTrialsFromSeed(PrefService* local_prefs); |
45 | 46 |
46 // Calls FetchVariationsSeed once and repeats this periodically. See | 47 // Calls FetchVariationsSeed once and repeats this periodically. See |
47 // implementation for details on the period. Must be called after | 48 // implementation for details on the period. Must be called after |
48 // |CreateTrialsFromSeed|. | 49 // |CreateTrialsFromSeed|. |
49 void StartRepeatedVariationsSeedFetch(); | 50 void StartRepeatedVariationsSeedFetch(); |
50 | 51 |
51 // Register Variations related prefs in Local State. | 52 // Register Variations related prefs in Local State. |
52 static void RegisterPrefs(PrefService* prefs); | 53 static void RegisterPrefs(PrefServiceSimple* prefs); |
53 | 54 |
54 // Exposed for testing. | 55 // Exposed for testing. |
55 void SetCreateTrialsFromSeedCalledForTesting(bool called); | 56 void SetCreateTrialsFromSeedCalledForTesting(bool called); |
56 | 57 |
57 protected: | 58 protected: |
58 // Starts the fetching process once, where |OnURLFetchComplete| is called with | 59 // Starts the fetching process once, where |OnURLFetchComplete| is called with |
59 // the response. | 60 // the response. |
60 virtual void DoActualFetch(); | 61 virtual void DoActualFetch(); |
61 | 62 |
62 private: | 63 private: |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 scoped_ptr<ResourceRequestAllowedNotifier> resource_request_allowed_notifier_; | 164 scoped_ptr<ResourceRequestAllowedNotifier> resource_request_allowed_notifier_; |
164 | 165 |
165 // The start time of the last seed request. This is used to measure the | 166 // The start time of the last seed request. This is used to measure the |
166 // latency of seed requests. Initially zero. | 167 // latency of seed requests. Initially zero. |
167 base::TimeTicks last_request_started_time_; | 168 base::TimeTicks last_request_started_time_; |
168 }; | 169 }; |
169 | 170 |
170 } // namespace chrome_variations | 171 } // namespace chrome_variations |
171 | 172 |
172 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ | 173 #endif // CHROME_BROWSER_METRICS_VARIATIONS_VARIATIONS_SERVICE_H_ |
OLD | NEW |