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 #include "chrome/browser/metrics/variations_service.h" | 5 #include "chrome/browser/metrics/variations_service.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/build_time.h" | 10 #include "base/build_time.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.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/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/version.h" | 15 #include "base/version.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/metrics/proto/trials_seed.pb.h" | 17 #include "chrome/browser/metrics/proto/trials_seed.pb.h" |
18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/common/chrome_notification_types.h" | |
19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/metrics/experiments_helper.h" | 21 #include "chrome/common/metrics/experiments_helper.h" |
21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/notification_service.h" | |
23 #include "content/public/common/url_fetcher.h" | 25 #include "content/public/common/url_fetcher.h" |
24 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
25 #include "net/base/load_flags.h" | 27 #include "net/base/load_flags.h" |
26 #include "net/base/network_change_notifier.h" | 28 #include "net/base/network_change_notifier.h" |
27 #include "net/http/http_response_headers.h" | 29 #include "net/http/http_response_headers.h" |
28 #include "net/url_request/url_fetcher.h" | 30 #include "net/url_request/url_fetcher.h" |
29 #include "net/url_request/url_request_status.h" | 31 #include "net/url_request/url_request_status.h" |
30 | 32 |
31 namespace chrome_variations { | 33 namespace chrome_variations { |
32 | 34 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 server_url = kDefaultVariationsServerURL; | 94 server_url = kDefaultVariationsServerURL; |
93 GURL url_as_gurl = GURL(server_url); | 95 GURL url_as_gurl = GURL(server_url); |
94 DCHECK(url_as_gurl.is_valid()); | 96 DCHECK(url_as_gurl.is_valid()); |
95 return url_as_gurl; | 97 return url_as_gurl; |
96 } | 98 } |
97 | 99 |
98 } // namespace | 100 } // namespace |
99 | 101 |
100 VariationsService::VariationsService() | 102 VariationsService::VariationsService() |
101 : variations_server_url_(GetVariationsServerURL()) { | 103 : variations_server_url_(GetVariationsServerURL()) { |
104 registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | |
105 content::NotificationService::AllSources()); | |
102 } | 106 } |
103 | 107 |
104 VariationsService::~VariationsService() {} | 108 VariationsService::~VariationsService() {} |
105 | 109 |
106 bool VariationsService::CreateTrialsFromSeed(PrefService* local_prefs) { | 110 bool VariationsService::CreateTrialsFromSeed(PrefService* local_prefs) { |
107 TrialsSeed seed; | 111 TrialsSeed seed; |
108 if (!LoadTrialsSeedFromPref(local_prefs, &seed)) | 112 if (!LoadTrialsSeedFromPref(local_prefs, &seed)) |
109 return false; | 113 return false; |
110 | 114 |
111 const int64 date_value = local_prefs->GetInt64(prefs::kVariationsSeedDate); | 115 const int64 date_value = local_prefs->GetInt64(prefs::kVariationsSeedDate); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 StoreSeedData(seed_data, response_date, g_browser_process->local_state()); | 190 StoreSeedData(seed_data, response_date, g_browser_process->local_state()); |
187 } | 191 } |
188 | 192 |
189 // static | 193 // static |
190 void VariationsService::RegisterPrefs(PrefService* prefs) { | 194 void VariationsService::RegisterPrefs(PrefService* prefs) { |
191 prefs->RegisterStringPref(prefs::kVariationsSeed, std::string()); | 195 prefs->RegisterStringPref(prefs::kVariationsSeed, std::string()); |
192 prefs->RegisterInt64Pref(prefs::kVariationsSeedDate, | 196 prefs->RegisterInt64Pref(prefs::kVariationsSeedDate, |
193 base::Time().ToInternalValue()); | 197 base::Time().ToInternalValue()); |
194 } | 198 } |
195 | 199 |
200 void VariationsService::Observe(int type, | |
Alexei Svitkine (slow)
2012/07/23 14:42:43
Please define this in the same order as functions
SteveT
2012/07/23 15:24:31
Uh... this is already in the correct place?
Alexei Svitkine (slow)
2012/07/23 15:32:13
Oops, you're right - I must have misread the order
| |
201 const content::NotificationSource& source, | |
202 const content::NotificationDetails& details) { | |
Alexei Svitkine (slow)
2012/07/23 14:42:43
Is this guaranteed to be called on the UI thread?
SteveT
2012/07/23 15:24:31
I believe it is, though I'll have to check to make
| |
203 DCHECK(type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED); | |
204 // An upgrade is ready, so attempt to fetch the Variations seed in case there | |
205 // were updates. | |
206 FetchVariationsSeed(); | |
207 timer_.Reset(); | |
Alexei Svitkine (slow)
2012/07/23 14:42:43
Nit: Add a comment explaining timer resetting.
SteveT
2012/07/23 15:24:31
Done.
| |
208 } | |
209 | |
196 bool VariationsService::StoreSeedData(const std::string& seed_data, | 210 bool VariationsService::StoreSeedData(const std::string& seed_data, |
197 const base::Time& seed_date, | 211 const base::Time& seed_date, |
198 PrefService* local_prefs) { | 212 PrefService* local_prefs) { |
199 // Only store the seed data if it parses correctly. | 213 // Only store the seed data if it parses correctly. |
200 TrialsSeed seed; | 214 TrialsSeed seed; |
201 if (!seed.ParseFromString(seed_data)) { | 215 if (!seed.ParseFromString(seed_data)) { |
202 VLOG(1) << "Variations Seed data from server is not in valid proto format, " | 216 VLOG(1) << "Variations Seed data from server is not in valid proto format, " |
203 << "rejecting the seed."; | 217 << "rejecting the seed."; |
204 return false; | 218 return false; |
205 } | 219 } |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
450 variation_id); | 464 variation_id); |
451 } | 465 } |
452 } | 466 } |
453 | 467 |
454 trial->SetForced(); | 468 trial->SetForced(); |
455 if (IsStudyExpired(study, reference_date)) | 469 if (IsStudyExpired(study, reference_date)) |
456 trial->Disable(); | 470 trial->Disable(); |
457 } | 471 } |
458 | 472 |
459 } // namespace chrome_variations | 473 } // namespace chrome_variations |
OLD | NEW |