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 base::Time now = base::Time::Now(); | |
Alexei Svitkine (slow)
2013/02/22 16:26:25
Move this into the if statement. Make it const.
SteveT
2013/02/22 18:12:03
Done.
| |
183 int64 last_fetch_time_internal = | |
Alexei Svitkine (slow)
2013/02/22 16:26:25
Nit: const.
SteveT
2013/02/22 18:12:03
Done.
| |
184 local_state_->GetInt64(prefs::kVariationsLastFetchTime); | |
185 if (last_fetch_time_internal) { | |
186 DCHECK_GE(now.ToInternalValue(), last_fetch_time_internal); | |
Alexei Svitkine (slow)
2013/02/22 16:26:25
This may happen if the user changed his system tim
SteveT
2013/02/22 18:12:03
Removed the DCHECK.
I think the histogram might j
Ilya Sherman
2013/02/22 23:26:16
Yes, negative values end up in the lowest bucket,
| |
187 base::TimeDelta delta = | |
Alexei Svitkine (slow)
2013/02/22 16:26:25
Nit: const.
SteveT
2013/02/22 18:12:03
Done.
| |
188 now - base::Time::FromInternalValue(last_fetch_time_internal); | |
189 // Log the value in number of minutes. | |
190 UMA_HISTOGRAM_CUSTOM_COUNTS("Variations.SeedFreshness", delta.InMinutes(), | |
191 1, base::TimeDelta::FromDays(7).InMinutes(), 50); | |
Alexei Svitkine (slow)
2013/02/22 16:26:25
I would say let's use 30 days, just to get a more
SteveT
2013/02/22 18:12:03
Done.
| |
192 } | |
193 | |
180 return true; | 194 return true; |
181 } | 195 } |
182 | 196 |
183 void VariationsService::StartRepeatedVariationsSeedFetch() { | 197 void VariationsService::StartRepeatedVariationsSeedFetch() { |
184 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 198 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
185 | 199 |
186 // Check that |CreateTrialsFromSeed| was called, which is necessary to | 200 // Check that |CreateTrialsFromSeed| was called, which is necessary to |
187 // retrieve the serial number that will be sent to the server. | 201 // retrieve the serial number that will be sent to the server. |
188 DCHECK(create_trials_from_seed_called_); | 202 DCHECK(create_trials_from_seed_called_); |
189 | 203 |
(...skipping 18 matching lines...) Expand all Loading... | |
208 | 222 |
209 void VariationsService::SetCreateTrialsFromSeedCalledForTesting(bool called) { | 223 void VariationsService::SetCreateTrialsFromSeedCalledForTesting(bool called) { |
210 create_trials_from_seed_called_ = called; | 224 create_trials_from_seed_called_ = called; |
211 } | 225 } |
212 | 226 |
213 // static | 227 // static |
214 void VariationsService::RegisterPrefs(PrefRegistrySimple* registry) { | 228 void VariationsService::RegisterPrefs(PrefRegistrySimple* registry) { |
215 registry->RegisterStringPref(prefs::kVariationsSeed, std::string()); | 229 registry->RegisterStringPref(prefs::kVariationsSeed, std::string()); |
216 registry->RegisterInt64Pref(prefs::kVariationsSeedDate, | 230 registry->RegisterInt64Pref(prefs::kVariationsSeedDate, |
217 base::Time().ToInternalValue()); | 231 base::Time().ToInternalValue()); |
232 registry->RegisterInt64Pref(prefs::kVariationsLastFetchTime, 0); | |
218 } | 233 } |
219 | 234 |
220 // static | 235 // static |
221 VariationsService* VariationsService::Create(PrefService* local_state) { | 236 VariationsService* VariationsService::Create(PrefService* local_state) { |
222 // This is temporarily disabled for Android. See http://crbug.com/168224 | 237 // This is temporarily disabled for Android. See http://crbug.com/168224 |
223 #if !defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID) | 238 #if !defined(GOOGLE_CHROME_BUILD) || defined(OS_ANDROID) |
224 // Unless the URL was provided, unsupported builds should return NULL to | 239 // Unless the URL was provided, unsupported builds should return NULL to |
225 // indicate that the service should not be used. | 240 // indicate that the service should not be used. |
226 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 241 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
227 switches::kVariationsServerURL)) | 242 switches::kVariationsServerURL)) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 response_code == net::HTTP_NOT_MODIFIED) { | 296 response_code == net::HTTP_NOT_MODIFIED) { |
282 bool success = request->GetResponseHeaders()->GetDateValue(&response_date); | 297 bool success = request->GetResponseHeaders()->GetDateValue(&response_date); |
283 DCHECK(success || response_date.is_null()); | 298 DCHECK(success || response_date.is_null()); |
284 | 299 |
285 if (!response_date.is_null()) { | 300 if (!response_date.is_null()) { |
286 network_time_tracker_.UpdateNetworkTime( | 301 network_time_tracker_.UpdateNetworkTime( |
287 response_date, | 302 response_date, |
288 base::TimeDelta::FromMilliseconds(kServerTimeResolutionMs), | 303 base::TimeDelta::FromMilliseconds(kServerTimeResolutionMs), |
289 latency); | 304 latency); |
290 } | 305 } |
306 | |
307 // Record the time of the most recent successful fetch. | |
308 local_state_->SetInt64(prefs::kVariationsLastFetchTime, | |
309 base::Time::Now().ToInternalValue()); | |
291 } | 310 } |
292 | 311 |
293 if (response_code != net::HTTP_OK) { | 312 if (response_code != net::HTTP_OK) { |
294 DVLOG(1) << "Variations server request returned non-HTTP_OK response code: " | 313 DVLOG(1) << "Variations server request returned non-HTTP_OK response code: " |
295 << response_code; | 314 << response_code; |
296 if (response_code == net::HTTP_NOT_MODIFIED) | 315 if (response_code == net::HTTP_NOT_MODIFIED) |
297 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchNotModifiedLatency", latency); | 316 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchNotModifiedLatency", latency); |
298 else | 317 else |
299 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchOtherLatency", latency); | 318 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchOtherLatency", latency); |
300 return; | 319 return; |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
604 } // namespace chrome_variations | 623 } // namespace chrome_variations |
OLD | NEW |