Chromium Code Reviews| 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/time.h" | 13 #include "base/time.h" |
| 14 #include "base/memory/scoped_ptr.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 "content/public/common/url_fetcher_delegate.h" |
| 19 | 19 |
| 20 template <typename T> struct DefaultSingletonTraits; | 20 template <typename T> struct DefaultSingletonTraits; |
| 21 class PrefService; | 21 class PrefService; |
| 22 | 22 |
| 23 // Used to setup field trials based on stored variations seed data, and fetch | 23 // Used to setup field trials based on stored variations seed data, and fetch |
| 24 // new seed data from the variations server. | 24 // new seed data from the variations server. |
| 25 class VariationsService : public content::URLFetcherDelegate { | 25 class VariationsService : public content::URLFetcherDelegate { |
| 26 public: | 26 public: |
| 27 // Returns the singleton instance; | 27 // Returns the singleton instance; |
| 28 static VariationsService* GetInstance(); | 28 static VariationsService* GetInstance(); |
| 29 | 29 |
| 30 // Loads the Variations seed data from the given local prefs. If there is a | 30 // Creates field trials based on Variations Seed loaded from local prefs. If |
| 31 // problem with loading, the pref value is cleared. | 31 // there is a problem loading the seed data, all trials specified by the seed |
| 32 void LoadVariationsSeed(PrefService* local_prefs); | 32 // may not be created. |
| 33 bool CreateTrialsFromSeed(PrefService* local_prefs); | |
| 33 | 34 |
| 34 // Starts the fetching process, where |OnURLFetchComplete| is called with the | 35 // Starts the fetching process, where |OnURLFetchComplete| is called with the |
| 35 // response. | 36 // response. |
| 36 void StartFetchingVariationsSeed(); | 37 void StartFetchingVariationsSeed(); |
| 37 | 38 |
| 38 // content::URLFetcherDelegate implementation: | 39 // content::URLFetcherDelegate implementation: |
| 39 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; | 40 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; |
| 40 | 41 |
| 41 // Register Variations related prefs in Local State. | 42 // Register Variations related prefs in Local State. |
| 42 static void RegisterPrefs(PrefService* prefs); | 43 static void RegisterPrefs(PrefService* prefs); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 67 chrome::VersionInfo::Channel channel); | 68 chrome::VersionInfo::Channel channel); |
| 68 | 69 |
| 69 // Checks whether |study| is applicable for the given version string. | 70 // Checks whether |study| is applicable for the given version string. |
| 70 static bool CheckStudyVersion(const chrome_variations::Study& study, | 71 static bool CheckStudyVersion(const chrome_variations::Study& study, |
| 71 const std::string& version_string); | 72 const std::string& version_string); |
| 72 | 73 |
| 73 // Checks whether |study| is applicable for the given date/time. | 74 // Checks whether |study| is applicable for the given date/time. |
| 74 static bool CheckStudyDate(const chrome_variations::Study& study, | 75 static bool CheckStudyDate(const chrome_variations::Study& study, |
| 75 const base::Time& date_time); | 76 const base::Time& date_time); |
| 76 | 77 |
| 78 // Loads the Variations seed data from the given local prefs into |seed|. If | |
| 79 // there is a problem with loading, the pref value is cleared and false is | |
| 80 // returned. If successful, |seed| will contain the loaded data and true is | |
| 81 // returned. | |
| 82 bool LoadVariationsSeed(PrefService* local_prefs, | |
|
Alexei Svitkine (slow)
2012/05/08 03:41:34
Also, see my previous comment: rename this to Load
jwd
2012/05/08 03:53:37
Done.
| |
| 83 chrome_variations::TrialsSeed* seed); | |
| 84 | |
| 85 void CreateTrialFromStudy(const chrome_variations::Study& study); | |
| 86 | |
| 77 // Contains the current seed request. Will only have a value while a request | 87 // Contains the current seed request. Will only have a value while a request |
| 78 // is pending, and will be reset by |OnURLFetchComplete|. | 88 // is pending, and will be reset by |OnURLFetchComplete|. |
| 79 scoped_ptr<content::URLFetcher> pending_seed_request_; | 89 scoped_ptr<content::URLFetcher> pending_seed_request_; |
| 80 | 90 |
| 81 // The variations seed data being used for this session. | 91 // The variations seed data being used for this session. |
| 82 // TODO(jwd): This should be removed. When the seed data is loaded, it will be | 92 // TODO(jwd): This should be removed. When the seed data is loaded, it will be |
| 83 // used immediately so it won't need to be stored. | 93 // used immediately so it won't need to be stored. |
| 84 chrome_variations::TrialsSeed variations_seed_; | 94 chrome_variations::TrialsSeed variations_seed_; |
| 85 }; | 95 }; |
| 86 | 96 |
| 87 #endif // CHROME_BROWSER_METRICS_VARIATIONS_SERVICE_H_ | 97 #endif // CHROME_BROWSER_METRICS_VARIATIONS_SERVICE_H_ |
| OLD | NEW |