Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: chrome/browser/metrics/variations_service.h

Issue 10392007: Restoring the chrome variatioons client, with a fix for browser_test failures caused by it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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
SteveT 2012/05/14 21:08:57 Nit: Remove superfluous break.
jwd 2012/05/15 14:58:36 Done.
50
51 // Store the given seed data to the given local prefs. Note that |seed_data|
52 // is assumed to be the raw serialized protobuf data stored in a string. It
53 // will be Base64Encoded for storage. If the string is invalid or the encoding
54 // fails, the |local_prefs| is left as is.
55 void StoreSeedData(const std::string& seed_data, PrefService* local_prefs);
56
57 // Returns whether |study| should be added to the local field trials list
58 // according to its restriction parameters.
59 static bool ShouldAddStudy(const chrome_variations::Study& study);
60
61 // Checks whether |study| is applicable for the given |channel|.
62 static bool CheckStudyChannel(const chrome_variations::Study& study,
63 chrome::VersionInfo::Channel channel);
64
65 // Checks whether |study| is applicable for the given version string.
66 static bool CheckStudyVersion(const chrome_variations::Study& study,
67 const std::string& version_string);
68
69 // Checks whether |study| is applicable for the given date/time.
70 static bool CheckStudyDate(const chrome_variations::Study& study,
71 const base::Time& date_time);
72
73 // Loads the Variations seed data from the given local prefs into |seed|. If
74 // there is a problem with loading, the pref value is cleared and false is
75 // returned. If successful, |seed| will contain the loaded data and true is
76 // returned.
77 bool LoadTrialsSeedFromPref(PrefService* local_prefs,
78 chrome_variations::TrialsSeed* seed);
79
80 void CreateTrialFromStudy(const chrome_variations::Study& study);
81
82 // Contains the current seed request. Will only have a value while a request
83 // is pending, and will be reset by |OnURLFetchComplete|.
84 scoped_ptr<content::URLFetcher> pending_seed_request_;
85
86 // The variations seed data being used for this session.
87 // TODO(jwd): This should be removed. When the seed data is loaded, it will be
88 // used immediately so it won't need to be stored.
89 chrome_variations::TrialsSeed variations_seed_;
90 };
91
92 #endif // CHROME_BROWSER_METRICS_VARIATIONS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698