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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 } |
291 } | 305 } |
292 | 306 |
307 if (response_code == net::HTTP_NOT_MODIFIED) { | |
308 RecordLastFetchTime(); | |
309 } | |
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); |
Alexei Svitkine (slow)
2013/02/22 20:18:01
Might as well put it here.
SteveT
2013/02/22 21:03:19
Ah yes, done.
| |
298 else | 316 else |
299 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchOtherLatency", latency); | 317 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchOtherLatency", latency); |
300 return; | 318 return; |
301 } | 319 } |
302 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchSuccessLatency", latency); | 320 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchSuccessLatency", latency); |
303 | 321 |
304 std::string seed_data; | 322 std::string seed_data; |
305 bool success = request->GetResponseAsString(&seed_data); | 323 bool success = request->GetResponseAsString(&seed_data); |
306 DCHECK(success); | 324 DCHECK(success); |
307 | 325 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 if (!base::Base64Encode(seed_data, &base64_seed_data)) { | 359 if (!base::Base64Encode(seed_data, &base64_seed_data)) { |
342 VLOG(1) << "Variations Seed data from server fails Base64Encode, rejecting " | 360 VLOG(1) << "Variations Seed data from server fails Base64Encode, rejecting " |
343 << "the seed."; | 361 << "the seed."; |
344 return false; | 362 return false; |
345 } | 363 } |
346 | 364 |
347 local_prefs->SetString(prefs::kVariationsSeed, base64_seed_data); | 365 local_prefs->SetString(prefs::kVariationsSeed, base64_seed_data); |
348 local_prefs->SetInt64(prefs::kVariationsSeedDate, | 366 local_prefs->SetInt64(prefs::kVariationsSeedDate, |
349 seed_date.ToInternalValue()); | 367 seed_date.ToInternalValue()); |
350 variations_serial_number_ = seed.serial_number(); | 368 variations_serial_number_ = seed.serial_number(); |
369 | |
370 RecordLastFetchTime(); | |
371 | |
351 return true; | 372 return true; |
352 } | 373 } |
353 | 374 |
354 // static | 375 // static |
355 bool VariationsService::ShouldAddStudy( | 376 bool VariationsService::ShouldAddStudy( |
356 const Study& study, | 377 const Study& study, |
357 const chrome::VersionInfo& version_info, | 378 const chrome::VersionInfo& version_info, |
358 const base::Time& reference_date, | 379 const base::Time& reference_date, |
359 const chrome::VersionInfo::Channel channel) { | 380 const chrome::VersionInfo::Channel channel) { |
360 if (study.has_filter()) { | 381 if (study.has_filter()) { |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
594 experiment.name(), | 615 experiment.name(), |
595 variation_id); | 616 variation_id); |
596 } | 617 } |
597 } | 618 } |
598 | 619 |
599 trial->SetForced(); | 620 trial->SetForced(); |
600 if (IsStudyExpired(study, reference_date)) | 621 if (IsStudyExpired(study, reference_date)) |
601 trial->Disable(); | 622 trial->Disable(); |
602 } | 623 } |
603 | 624 |
625 void VariationsService::RecordLastFetchTime() { | |
626 local_state_->SetInt64(prefs::kVariationsLastFetchTime, | |
627 base::Time::Now().ToInternalValue()); | |
628 } | |
629 | |
604 } // namespace chrome_variations | 630 } // namespace chrome_variations |
OLD | NEW |