Chromium Code Reviews| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 response_code == net::HTTP_NOT_MODIFIED) { | 295 response_code == net::HTTP_NOT_MODIFIED) { |
| 282 bool success = request->GetResponseHeaders()->GetDateValue(&response_date); | 296 bool success = request->GetResponseHeaders()->GetDateValue(&response_date); |
| 283 DCHECK(success || response_date.is_null()); | 297 DCHECK(success || response_date.is_null()); |
| 284 | 298 |
| 285 if (!response_date.is_null()) { | 299 if (!response_date.is_null()) { |
| 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 } |
| 305 | |
| 306 // Record the time of the most recent successful fetch. | |
| 307 local_state_->SetInt64(prefs::kVariationsLastFetchTime, | |
|
Alexei Svitkine (slow)
2013/02/22 18:46:51
Hmm, one little issue with doing this here is that
SteveT
2013/02/22 20:15:36
What do you think of this latest change? Another o
| |
| 308 base::Time::Now().ToInternalValue()); | |
| 291 } | 309 } |
| 292 | 310 |
| 293 if (response_code != net::HTTP_OK) { | 311 if (response_code != net::HTTP_OK) { |
| 294 DVLOG(1) << "Variations server request returned non-HTTP_OK response code: " | 312 DVLOG(1) << "Variations server request returned non-HTTP_OK response code: " |
| 295 << response_code; | 313 << response_code; |
| 296 if (response_code == net::HTTP_NOT_MODIFIED) | 314 if (response_code == net::HTTP_NOT_MODIFIED) |
| 297 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchNotModifiedLatency", latency); | 315 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchNotModifiedLatency", latency); |
| 298 else | 316 else |
| 299 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchOtherLatency", latency); | 317 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchOtherLatency", latency); |
| 300 return; | 318 return; |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 variation_id); | 613 variation_id); |
| 596 } | 614 } |
| 597 } | 615 } |
| 598 | 616 |
| 599 trial->SetForced(); | 617 trial->SetForced(); |
| 600 if (IsStudyExpired(study, reference_date)) | 618 if (IsStudyExpired(study, reference_date)) |
| 601 trial->Disable(); | 619 trial->Disable(); |
| 602 } | 620 } |
| 603 | 621 |
| 604 } // namespace chrome_variations | 622 } // namespace chrome_variations |
| OLD | NEW |