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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 | 208 |
209 void VariationsService::SetCreateTrialsFromSeedCalledForTesting(bool called) { | 209 void VariationsService::SetCreateTrialsFromSeedCalledForTesting(bool called) { |
210 create_trials_from_seed_called_ = called; | 210 create_trials_from_seed_called_ = called; |
211 } | 211 } |
212 | 212 |
213 // static | 213 // static |
214 void VariationsService::RegisterPrefs(PrefRegistrySimple* registry) { | 214 void VariationsService::RegisterPrefs(PrefRegistrySimple* registry) { |
215 registry->RegisterStringPref(prefs::kVariationsSeed, std::string()); | 215 registry->RegisterStringPref(prefs::kVariationsSeed, std::string()); |
216 registry->RegisterInt64Pref(prefs::kVariationsSeedDate, | 216 registry->RegisterInt64Pref(prefs::kVariationsSeedDate, |
217 base::Time().ToInternalValue()); | 217 base::Time().ToInternalValue()); |
218 registry->RegisterInt64Pref(prefs::kVariationsLastFetchTime, 0); | |
218 } | 219 } |
219 | 220 |
220 // static | 221 // static |
221 VariationsService* VariationsService::Create(PrefService* local_state) { | 222 VariationsService* VariationsService::Create(PrefService* local_state) { |
222 // This is temporarily disabled for Android. See http://crbug.com/168224 | 223 // This is temporarily disabled for Android. See http://crbug.com/168224 |
223 #if !defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID) | 224 #if !defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID) |
224 // Unless the URL was provided, unsupported builds should return NULL to | 225 // Unless the URL was provided, unsupported builds should return NULL to |
225 // indicate that the service should not be used. | 226 // indicate that the service should not be used. |
226 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 227 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
227 switches::kVariationsServerURL)) | 228 switches::kVariationsServerURL)) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 response_code == net::HTTP_NOT_MODIFIED) { | 282 response_code == net::HTTP_NOT_MODIFIED) { |
282 bool success = request->GetResponseHeaders()->GetDateValue(&response_date); | 283 bool success = request->GetResponseHeaders()->GetDateValue(&response_date); |
283 DCHECK(success || response_date.is_null()); | 284 DCHECK(success || response_date.is_null()); |
284 | 285 |
285 if (!response_date.is_null()) { | 286 if (!response_date.is_null()) { |
286 network_time_tracker_.UpdateNetworkTime( | 287 network_time_tracker_.UpdateNetworkTime( |
287 response_date, | 288 response_date, |
288 base::TimeDelta::FromMilliseconds(kServerTimeResolutionMs), | 289 base::TimeDelta::FromMilliseconds(kServerTimeResolutionMs), |
289 latency); | 290 latency); |
290 } | 291 } |
292 | |
293 // If this is not the first successful fetch, record the delta between now | |
294 // and the last successful fetch. | |
295 int64 internal_now = base::Time::Now().ToInternalValue(); | |
Ilya Sherman
2013/02/22 02:05:05
nit: I'd recommend writing this as
base::Time now
SteveT
2013/02/22 16:14:36
Done.
| |
296 int64 last_fetch_time = | |
297 local_state_->GetInt64(prefs::kVariationsLastFetchTime); | |
298 if (last_fetch_time) { | |
299 int64 internal_delta = internal_now - last_fetch_time; | |
300 DCHECK_GE(internal_delta, 0); | |
301 base::TimeDelta delta = | |
302 base::TimeDelta::FromInternalValue(internal_delta); | |
Ilya Sherman
2013/02/22 02:05:05
nit: I'd write this as
base::TimeDelta delta =
SteveT
2013/02/22 16:14:36
Done.
| |
303 // Log the value in number of minutes. | |
304 UMA_HISTOGRAM_CUSTOM_COUNTS("Variations.SeedFreshness", delta.InMinutes(), | |
Alexei Svitkine (slow)
2013/02/22 14:13:10
Doing this here will not give us as much info as d
SteveT
2013/02/22 15:17:55
I see, so what we're measuring here is "how recent
| |
305 1, base::TimeDelta::FromDays(7).InMinutes(), 50); | |
306 } | |
307 | |
308 // Record the time of the most recent successful fetch. | |
309 local_state_->SetInt64(prefs::kVariationsLastFetchTime, | |
310 internal_now); | |
291 } | 311 } |
292 | 312 |
293 if (response_code != net::HTTP_OK) { | 313 if (response_code != net::HTTP_OK) { |
294 DVLOG(1) << "Variations server request returned non-HTTP_OK response code: " | 314 DVLOG(1) << "Variations server request returned non-HTTP_OK response code: " |
295 << response_code; | 315 << response_code; |
296 if (response_code == net::HTTP_NOT_MODIFIED) | 316 if (response_code == net::HTTP_NOT_MODIFIED) |
297 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchNotModifiedLatency", latency); | 317 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchNotModifiedLatency", latency); |
298 else | 318 else |
299 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchOtherLatency", latency); | 319 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchOtherLatency", latency); |
300 return; | 320 return; |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
595 variation_id); | 615 variation_id); |
596 } | 616 } |
597 } | 617 } |
598 | 618 |
599 trial->SetForced(); | 619 trial->SetForced(); |
600 if (IsStudyExpired(study, reference_date)) | 620 if (IsStudyExpired(study, reference_date)) |
601 trial->Disable(); | 621 trial->Disable(); |
602 } | 622 } |
603 | 623 |
604 } // namespace chrome_variations | 624 } // namespace chrome_variations |
OLD | NEW |