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

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

Issue 10790116: Have the VariationsService attempt to fetch the seed when an update is ready. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Reset timer Created 8 years, 5 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
OLDNEW
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 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/metrics/field_trial.h" 13 #include "base/metrics/field_trial.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "base/timer.h" 15 #include "base/timer.h"
16 #include "chrome/browser/metrics/proto/study.pb.h" 16 #include "chrome/browser/metrics/proto/study.pb.h"
17 #include "chrome/browser/metrics/proto/trials_seed.pb.h" 17 #include "chrome/browser/metrics/proto/trials_seed.pb.h"
18 #include "chrome/common/chrome_version_info.h" 18 #include "chrome/common/chrome_version_info.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
19 #include "googleurl/src/gurl.h" 21 #include "googleurl/src/gurl.h"
20 #include "net/url_request/url_fetcher_delegate.h" 22 #include "net/url_request/url_fetcher_delegate.h"
21 23
22 class PrefService; 24 class PrefService;
23 25
24 namespace net { 26 namespace net {
25 class URLFetcher; 27 class URLFetcher;
26 } // namespace net 28 } // namespace net
27 29
28 namespace chrome_variations { 30 namespace chrome_variations {
29 31
30 // Used to setup field trials based on stored variations seed data, and fetch 32 // Used to setup field trials based on stored variations seed data, and fetch
31 // new seed data from the variations server. 33 // new seed data from the variations server.
32 class VariationsService : public net::URLFetcherDelegate { 34 class VariationsService : public net::URLFetcherDelegate,
35 public content::NotificationObserver {
33 public: 36 public:
34 VariationsService(); 37 VariationsService();
35 virtual ~VariationsService(); 38 virtual ~VariationsService();
36 39
37 // Creates field trials based on Variations Seed loaded from local prefs. If 40 // Creates field trials based on Variations Seed loaded from local prefs. If
38 // there is a problem loading the seed data, all trials specified by the seed 41 // there is a problem loading the seed data, all trials specified by the seed
39 // may not be created. 42 // may not be created.
40 bool CreateTrialsFromSeed(PrefService* local_prefs); 43 bool CreateTrialsFromSeed(PrefService* local_prefs);
41 44
42 // Calls FetchVariationsSeed once and repeats this periodically. See 45 // Calls FetchVariationsSeed once and repeats this periodically. See
43 // implementation for details on the period. 46 // implementation for details on the period.
44 void StartRepeatedVariationsSeedFetch(); 47 void StartRepeatedVariationsSeedFetch();
45 48
46 // Starts the fetching process once, where |OnURLFetchComplete| is called with 49 // Starts the fetching process once, where |OnURLFetchComplete| is called with
47 // the response. 50 // the response.
48 void FetchVariationsSeed(); 51 void FetchVariationsSeed();
Alexei Svitkine (slow) 2012/07/23 15:32:13 I think this should be private too. Sorry that I d
SteveT 2012/07/23 15:44:14 Done.
49 52
50 // net::URLFetcherDelegate implementation: 53 // net::URLFetcherDelegate implementation:
51 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 54 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
Alexei Svitkine (slow) 2012/07/23 15:32:13 This should be private too, I think.
SteveT 2012/07/23 15:44:14 Done.
52 55
53 // Register Variations related prefs in Local State. 56 // Register Variations related prefs in Local State.
54 static void RegisterPrefs(PrefService* prefs); 57 static void RegisterPrefs(PrefService* prefs);
55 58
59 // Overridden from content::NotificationObserver:
60 virtual void Observe(int type,
Alexei Svitkine (slow) 2012/07/23 14:42:43 Does this need to be public?
SteveT 2012/07/23 15:24:31 I guess we can make this private and friend it if
Alexei Svitkine (slow) 2012/07/23 15:32:13 I think that makes sense to do. The existing tests
SteveT 2012/07/23 15:44:14 SGTM. Will add the FRIEND stuff when I add the tes
61 const content::NotificationSource& source,
62 const content::NotificationDetails& details) OVERRIDE;
63
56 private: 64 private:
57 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyChannel); 65 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyChannel);
58 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyLocale); 66 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyLocale);
59 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyPlatform); 67 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyPlatform);
60 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyVersion); 68 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyVersion);
61 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyVersionWildcards); 69 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyVersionWildcards);
62 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyStartDate); 70 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, CheckStudyStartDate);
63 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, IsStudyExpired); 71 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, IsStudyExpired);
64 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, LoadSeed); 72 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, LoadSeed);
65 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, StoreSeed); 73 FRIEND_TEST_ALL_PREFIXES(VariationsServiceTest, StoreSeed);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // is pending, and will be reset by |OnURLFetchComplete|. 132 // is pending, and will be reset by |OnURLFetchComplete|.
125 scoped_ptr<net::URLFetcher> pending_seed_request_; 133 scoped_ptr<net::URLFetcher> pending_seed_request_;
126 134
127 // The URL to use for querying the variations server. 135 // The URL to use for querying the variations server.
128 GURL variations_server_url_; 136 GURL variations_server_url_;
129 137
130 // The timer used to repeatedly ping the server. Keep this as an instance 138 // The timer used to repeatedly ping the server. Keep this as an instance
131 // member so if VariationsService goes out of scope, the timer is 139 // member so if VariationsService goes out of scope, the timer is
132 // automatically cancelled. 140 // automatically cancelled.
133 base::RepeatingTimer<VariationsService> timer_; 141 base::RepeatingTimer<VariationsService> timer_;
142
143 content::NotificationRegistrar registrar_;
Alexei Svitkine (slow) 2012/07/23 14:42:43 Nit: Add a comment.
SteveT 2012/07/23 15:24:31 Done.
134 }; 144 };
135 145
136 } // namespace chrome_variations 146 } // namespace chrome_variations
137 147
138 #endif // CHROME_BROWSER_METRICS_VARIATIONS_SERVICE_H_ 148 #endif // CHROME_BROWSER_METRICS_VARIATIONS_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/metrics/variations_service.cc » ('j') | chrome/browser/metrics/variations_service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698