OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_METRICS_VARIATIONS_SERVICE_H_ |
| 6 #define CHROME_BROWSER_METRICS_VARIATIONS_SERVICE_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 |
| 11 #include "base/compiler_specific.h" |
| 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/time.h" |
| 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "chrome/browser/metrics/proto/study.pb.h" |
| 16 #include "chrome/browser/metrics/proto/trials_seed.pb.h" |
| 17 #include "chrome/common/chrome_version_info.h" |
| 18 #include "content/public/common/url_fetcher_delegate.h" |
| 19 |
| 20 class PrefService; |
| 21 |
| 22 // Used to setup field trials based on stored variations seed data, and fetch |
| 23 // new seed data from the variations server. |
| 24 class VariationsService : public content::URLFetcherDelegate { |
| 25 public: |
| 26 VariationsService(); |
| 27 virtual ~VariationsService(); |
| 28 |
| 29 // 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 |
| 31 // may not be created. |
| 32 bool CreateTrialsFromSeed(PrefService* local_prefs); |
| 33 |
| 34 // Starts the fetching process, where |OnURLFetchComplete| is called with the |
| 35 // response. |
| 36 void StartFetchingVariationsSeed(); |
| 37 |
| 38 // content::URLFetcherDelegate implementation: |
| 39 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 40 |
| 41 // Register Variations related prefs in Local State. |
| 42 static void RegisterPrefs(PrefService* prefs); |
| 43 |
| 44 private: |
| 45 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyChannel); |
| 46 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyVersion); |
| 47 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyVersionWildcards); |
| 48 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyDate); |
| 49 |
| 50 // Store the given seed data to the given local prefs. Note that |seed_data| |
| 51 // is assumed to be the raw serialized protobuf data stored in a string. It |
| 52 // will be Base64Encoded for storage. If the string is invalid or the encoding |
| 53 // fails, the |local_prefs| is left as is. |
| 54 void StoreSeedData(const std::string& seed_data, PrefService* local_prefs); |
| 55 |
| 56 // Returns whether |study| should be added to the local field trials list |
| 57 // according to its restriction parameters. |
| 58 static bool ShouldAddStudy(const chrome_variations::Study& study); |
| 59 |
| 60 // Checks whether |study| is applicable for the given |channel|. |
| 61 static bool CheckStudyChannel(const chrome_variations::Study& study, |
| 62 chrome::VersionInfo::Channel channel); |
| 63 |
| 64 // Checks whether |study| is applicable for the given version string. |
| 65 static bool CheckStudyVersion(const chrome_variations::Study& study, |
| 66 const std::string& version_string); |
| 67 |
| 68 // Checks whether |study| is applicable for the given date/time. |
| 69 static bool CheckStudyDate(const chrome_variations::Study& study, |
| 70 const base::Time& date_time); |
| 71 |
| 72 // Loads the Variations seed data from the given local prefs into |seed|. If |
| 73 // 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 |
| 75 // returned. |
| 76 bool LoadTrialsSeedFromPref(PrefService* local_prefs, |
| 77 chrome_variations::TrialsSeed* seed); |
| 78 |
| 79 void CreateTrialFromStudy(const chrome_variations::Study& study); |
| 80 |
| 81 // Contains the current seed request. Will only have a value while a request |
| 82 // is pending, and will be reset by |OnURLFetchComplete|. |
| 83 scoped_ptr<content::URLFetcher> pending_seed_request_; |
| 84 |
| 85 // 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 |
| 87 // used immediately so it won't need to be stored. |
| 88 chrome_variations::TrialsSeed variations_seed_; |
| 89 }; |
| 90 |
| 91 #endif // CHROME_BROWSER_METRICS_VARIATIONS_SERVICE_H_ |
OLD | NEW |