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 "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/metrics/proto/trials_seed.pb.h" |
| 12 #include "content/public/common/url_fetcher_delegate.h" |
| 13 |
| 14 template <typename T> struct DefaultSingletonTraits; |
| 15 class PrefService; |
| 16 |
| 17 // Used to setup field trials based on stored variations seed data, and fetch |
| 18 // new seed data from the variations server. |
| 19 class VariationsService : public content::URLFetcherDelegate { |
| 20 public: |
| 21 // Returns the singleton instance; |
| 22 static VariationsService* GetInstance(); |
| 23 |
| 24 // Loads the Variations seed data from the given local prefs. If there is a |
| 25 // problem with loading, the pref value is cleared. |
| 26 void LoadVariationsSeed(PrefService* local_prefs); |
| 27 |
| 28 // Starts the fetching process, where |OnURLFetchComplete| is called with the |
| 29 // response. |
| 30 void StartFetchingVariationsSeed(); |
| 31 |
| 32 // content::URLFetcherDelegate implementation: |
| 33 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; |
| 34 |
| 35 // Register Variations related prefs in Local State. |
| 36 static void RegisterPrefs(PrefService* prefs); |
| 37 |
| 38 private: |
| 39 friend struct DefaultSingletonTraits<VariationsService>; |
| 40 |
| 41 VariationsService(); |
| 42 virtual ~VariationsService(); |
| 43 |
| 44 // Store the given seed data to the given local prefs. Note that |seed_data| |
| 45 // is assumed to be the raw serialized protobuf data stored in a string. It |
| 46 // will be Base64Encoded for storage. If the string is invalid or the encoding |
| 47 // fails, the |local_prefs| is left as is. |
| 48 void StoreSeedData(const std::string& seed_data, PrefService* local_prefs); |
| 49 |
| 50 // Contains the current seed request. Will only have a value while a request |
| 51 // is pending, and will be reset by |OnURLFetchComplete|. |
| 52 scoped_ptr<content::URLFetcher> pending_seed_request_; |
| 53 |
| 54 // The variations seed data being used for this session. |
| 55 // TODO(jwd): This should be removed. When the seed data is loaded, it will be |
| 56 // used immediately so it won't need to be stored. |
| 57 chrome_variations::TrialsSeed variations_seed_; |
| 58 }; |
| 59 |
| 60 #endif // CHROME_BROWSER_METRICS_VARIATIONS_SERVICE_H_ |
OLD | NEW |