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/variations_service.h" | 5 #include "chrome/browser/metrics/variations/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" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 return false; | 170 return false; |
171 | 171 |
172 chrome::VersionInfo::Channel channel = GetChannelForVariations(); | 172 chrome::VersionInfo::Channel channel = GetChannelForVariations(); |
173 for (int i = 0; i < seed.study_size(); ++i) { | 173 for (int i = 0; i < seed.study_size(); ++i) { |
174 if (ShouldAddStudy(seed.study(i), current_version_info, reference_date, | 174 if (ShouldAddStudy(seed.study(i), current_version_info, reference_date, |
175 channel)) { | 175 channel)) { |
176 CreateTrialFromStudy(seed.study(i), reference_date); | 176 CreateTrialFromStudy(seed.study(i), reference_date); |
177 } | 177 } |
178 } | 178 } |
179 | 179 |
| 180 // Log the "freshness" of the seed that was just used. The freshness is the |
| 181 // time between the last successful seed download and now. |
| 182 const int64 last_fetch_time_internal = |
| 183 local_state_->GetInt64(prefs::kVariationsLastFetchTime); |
| 184 if (last_fetch_time_internal) { |
| 185 const base::Time now = base::Time::Now(); |
| 186 const base::TimeDelta delta = |
| 187 now - base::Time::FromInternalValue(last_fetch_time_internal); |
| 188 // Log the value in number of minutes. |
| 189 UMA_HISTOGRAM_CUSTOM_COUNTS("Variations.SeedFreshness", delta.InMinutes(), |
| 190 1, base::TimeDelta::FromDays(30).InMinutes(), 50); |
| 191 } |
| 192 |
180 return true; | 193 return true; |
181 } | 194 } |
182 | 195 |
183 void VariationsService::StartRepeatedVariationsSeedFetch() { | 196 void VariationsService::StartRepeatedVariationsSeedFetch() { |
184 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 197 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
185 | 198 |
186 // Check that |CreateTrialsFromSeed| was called, which is necessary to | 199 // Check that |CreateTrialsFromSeed| was called, which is necessary to |
187 // retrieve the serial number that will be sent to the server. | 200 // retrieve the serial number that will be sent to the server. |
188 DCHECK(create_trials_from_seed_called_); | 201 DCHECK(create_trials_from_seed_called_); |
189 | 202 |
(...skipping 18 matching lines...) Expand all Loading... |
208 | 221 |
209 void VariationsService::SetCreateTrialsFromSeedCalledForTesting(bool called) { | 222 void VariationsService::SetCreateTrialsFromSeedCalledForTesting(bool called) { |
210 create_trials_from_seed_called_ = called; | 223 create_trials_from_seed_called_ = called; |
211 } | 224 } |
212 | 225 |
213 // static | 226 // static |
214 void VariationsService::RegisterPrefs(PrefRegistrySimple* registry) { | 227 void VariationsService::RegisterPrefs(PrefRegistrySimple* registry) { |
215 registry->RegisterStringPref(prefs::kVariationsSeed, std::string()); | 228 registry->RegisterStringPref(prefs::kVariationsSeed, std::string()); |
216 registry->RegisterInt64Pref(prefs::kVariationsSeedDate, | 229 registry->RegisterInt64Pref(prefs::kVariationsSeedDate, |
217 base::Time().ToInternalValue()); | 230 base::Time().ToInternalValue()); |
| 231 registry->RegisterInt64Pref(prefs::kVariationsLastFetchTime, 0); |
218 } | 232 } |
219 | 233 |
220 // static | 234 // static |
221 VariationsService* VariationsService::Create(PrefService* local_state) { | 235 VariationsService* VariationsService::Create(PrefService* local_state) { |
222 // This is temporarily disabled for Android. See http://crbug.com/168224 | 236 // This is temporarily disabled for Android. See http://crbug.com/168224 |
223 #if !defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID) | 237 #if !defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID) |
224 // Unless the URL was provided, unsupported builds should return NULL to | 238 // Unless the URL was provided, unsupported builds should return NULL to |
225 // indicate that the service should not be used. | 239 // indicate that the service should not be used. |
226 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 240 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
227 switches::kVariationsServerURL)) | 241 switches::kVariationsServerURL)) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 network_time_tracker_.UpdateNetworkTime( | 300 network_time_tracker_.UpdateNetworkTime( |
287 response_date, | 301 response_date, |
288 base::TimeDelta::FromMilliseconds(kServerTimeResolutionMs), | 302 base::TimeDelta::FromMilliseconds(kServerTimeResolutionMs), |
289 latency); | 303 latency); |
290 } | 304 } |
291 } | 305 } |
292 | 306 |
293 if (response_code != net::HTTP_OK) { | 307 if (response_code != net::HTTP_OK) { |
294 DVLOG(1) << "Variations server request returned non-HTTP_OK response code: " | 308 DVLOG(1) << "Variations server request returned non-HTTP_OK response code: " |
295 << response_code; | 309 << response_code; |
296 if (response_code == net::HTTP_NOT_MODIFIED) | 310 if (response_code == net::HTTP_NOT_MODIFIED) { |
297 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchNotModifiedLatency", latency); | 311 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchNotModifiedLatency", latency); |
298 else | 312 RecordLastFetchTime(); |
| 313 } else { |
299 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchOtherLatency", latency); | 314 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchOtherLatency", latency); |
| 315 } |
300 return; | 316 return; |
301 } | 317 } |
302 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchSuccessLatency", latency); | 318 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchSuccessLatency", latency); |
303 | 319 |
304 std::string seed_data; | 320 std::string seed_data; |
305 bool success = request->GetResponseAsString(&seed_data); | 321 bool success = request->GetResponseAsString(&seed_data); |
306 DCHECK(success); | 322 DCHECK(success); |
307 | 323 |
308 StoreSeedData(seed_data, response_date, local_state_); | 324 StoreSeedData(seed_data, response_date, local_state_); |
309 } | 325 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 if (!base::Base64Encode(seed_data, &base64_seed_data)) { | 357 if (!base::Base64Encode(seed_data, &base64_seed_data)) { |
342 VLOG(1) << "Variations Seed data from server fails Base64Encode, rejecting " | 358 VLOG(1) << "Variations Seed data from server fails Base64Encode, rejecting " |
343 << "the seed."; | 359 << "the seed."; |
344 return false; | 360 return false; |
345 } | 361 } |
346 | 362 |
347 local_prefs->SetString(prefs::kVariationsSeed, base64_seed_data); | 363 local_prefs->SetString(prefs::kVariationsSeed, base64_seed_data); |
348 local_prefs->SetInt64(prefs::kVariationsSeedDate, | 364 local_prefs->SetInt64(prefs::kVariationsSeedDate, |
349 seed_date.ToInternalValue()); | 365 seed_date.ToInternalValue()); |
350 variations_serial_number_ = seed.serial_number(); | 366 variations_serial_number_ = seed.serial_number(); |
| 367 |
| 368 RecordLastFetchTime(); |
| 369 |
351 return true; | 370 return true; |
352 } | 371 } |
353 | 372 |
354 // static | 373 // static |
355 bool VariationsService::ShouldAddStudy( | 374 bool VariationsService::ShouldAddStudy( |
356 const Study& study, | 375 const Study& study, |
357 const chrome::VersionInfo& version_info, | 376 const chrome::VersionInfo& version_info, |
358 const base::Time& reference_date, | 377 const base::Time& reference_date, |
359 const chrome::VersionInfo::Channel channel) { | 378 const chrome::VersionInfo::Channel channel) { |
360 if (study.has_filter()) { | 379 if (study.has_filter()) { |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 experiment.name(), | 613 experiment.name(), |
595 variation_id); | 614 variation_id); |
596 } | 615 } |
597 } | 616 } |
598 | 617 |
599 trial->SetForced(); | 618 trial->SetForced(); |
600 if (IsStudyExpired(study, reference_date)) | 619 if (IsStudyExpired(study, reference_date)) |
601 trial->Disable(); | 620 trial->Disable(); |
602 } | 621 } |
603 | 622 |
| 623 void VariationsService::RecordLastFetchTime() { |
| 624 // local_state_ is NULL in tests, so check it first. |
| 625 if (local_state_) { |
| 626 local_state_->SetInt64(prefs::kVariationsLastFetchTime, |
| 627 base::Time::Now().ToInternalValue()); |
| 628 } |
| 629 } |
| 630 |
604 } // namespace chrome_variations | 631 } // namespace chrome_variations |
OLD | NEW |