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_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_METRICS_VARIATIONS_SERVICE_H_ |
6 #define CHROME_BROWSER_METRICS_VARIATIONS_SERVICE_H_ | 6 #define CHROME_BROWSER_METRICS_VARIATIONS_SERVICE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/time.h" | 14 #include "base/time.h" |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "chrome/browser/metrics/proto/study.pb.h" | 15 #include "chrome/browser/metrics/proto/study.pb.h" |
16 #include "chrome/browser/metrics/proto/trials_seed.pb.h" | 16 #include "chrome/browser/metrics/proto/trials_seed.pb.h" |
17 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
18 #include "content/public/common/url_fetcher_delegate.h" | 18 #include "net/url_request/url_fetcher_delegate.h" |
19 | 19 |
20 class PrefService; | 20 class PrefService; |
21 | 21 |
| 22 namespace net { |
| 23 class URLFetcher; |
| 24 } // namespace net |
| 25 |
22 // Used to setup field trials based on stored variations seed data, and fetch | 26 // Used to setup field trials based on stored variations seed data, and fetch |
23 // new seed data from the variations server. | 27 // new seed data from the variations server. |
24 class VariationsService : public content::URLFetcherDelegate { | 28 class VariationsService : public net::URLFetcherDelegate { |
25 public: | 29 public: |
26 VariationsService(); | 30 VariationsService(); |
27 virtual ~VariationsService(); | 31 virtual ~VariationsService(); |
28 | 32 |
29 // Creates field trials based on Variations Seed loaded from local prefs. If | 33 // Creates field trials based on Variations Seed loaded from local prefs. If |
30 // there is a problem loading the seed data, all trials specified by the seed | 34 // there is a problem loading the seed data, all trials specified by the seed |
31 // may not be created. | 35 // may not be created. |
32 bool CreateTrialsFromSeed(PrefService* local_prefs); | 36 bool CreateTrialsFromSeed(PrefService* local_prefs); |
33 | 37 |
34 // Starts the fetching process, where |OnURLFetchComplete| is called with the | 38 // Starts the fetching process, where |OnURLFetchComplete| is called with the |
35 // response. | 39 // response. |
36 void StartFetchingVariationsSeed(); | 40 void StartFetchingVariationsSeed(); |
37 | 41 |
38 // content::URLFetcherDelegate implementation: | 42 // net::URLFetcherDelegate implementation: |
39 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 43 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
40 | 44 |
41 // Register Variations related prefs in Local State. | 45 // Register Variations related prefs in Local State. |
42 static void RegisterPrefs(PrefService* prefs); | 46 static void RegisterPrefs(PrefService* prefs); |
43 | 47 |
44 private: | 48 private: |
45 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyChannel); | 49 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyChannel); |
46 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyVersion); | 50 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyVersion); |
47 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyVersionWildcards); | 51 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyVersionWildcards); |
48 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyDate); | 52 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyDate); |
(...skipping 24 matching lines...) Expand all Loading... |
73 // there is a problem with loading, the pref value is cleared and false is | 77 // there is a problem with loading, the pref value is cleared and false is |
74 // returned. If successful, |seed| will contain the loaded data and true is | 78 // returned. If successful, |seed| will contain the loaded data and true is |
75 // returned. | 79 // returned. |
76 bool LoadTrialsSeedFromPref(PrefService* local_prefs, | 80 bool LoadTrialsSeedFromPref(PrefService* local_prefs, |
77 chrome_variations::TrialsSeed* seed); | 81 chrome_variations::TrialsSeed* seed); |
78 | 82 |
79 void CreateTrialFromStudy(const chrome_variations::Study& study); | 83 void CreateTrialFromStudy(const chrome_variations::Study& study); |
80 | 84 |
81 // Contains the current seed request. Will only have a value while a request | 85 // Contains the current seed request. Will only have a value while a request |
82 // is pending, and will be reset by |OnURLFetchComplete|. | 86 // is pending, and will be reset by |OnURLFetchComplete|. |
83 scoped_ptr<content::URLFetcher> pending_seed_request_; | 87 scoped_ptr<net::URLFetcher> pending_seed_request_; |
84 | 88 |
85 // The variations seed data being used for this session. | 89 // The variations seed data being used for this session. |
86 // TODO(jwd): This should be removed. When the seed data is loaded, it will be | 90 // TODO(jwd): This should be removed. When the seed data is loaded, it will be |
87 // used immediately so it won't need to be stored. | 91 // used immediately so it won't need to be stored. |
88 chrome_variations::TrialsSeed variations_seed_; | 92 chrome_variations::TrialsSeed variations_seed_; |
89 }; | 93 }; |
90 | 94 |
91 #endif // CHROME_BROWSER_METRICS_VARIATIONS_SERVICE_H_ | 95 #endif // CHROME_BROWSER_METRICS_VARIATIONS_SERVICE_H_ |
OLD | NEW |