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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 GURL GetVariationsServerURL() { | 89 GURL GetVariationsServerURL() { |
| 90 std::string server_url(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 90 std::string server_url(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 91 switches::kVariationsServerURL)); | 91 switches::kVariationsServerURL)); |
| 92 if (server_url.empty()) | 92 if (server_url.empty()) |
| 93 server_url = kDefaultVariationsServerURL; | 93 server_url = kDefaultVariationsServerURL; |
| 94 GURL url_as_gurl = GURL(server_url); | 94 GURL url_as_gurl = GURL(server_url); |
| 95 DCHECK(url_as_gurl.is_valid()); | 95 DCHECK(url_as_gurl.is_valid()); |
| 96 return url_as_gurl; | 96 return url_as_gurl; |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Logs |latency| in the time histogram named |name|. | |
| 100 void LogRequestLatency(const char* name, base::TimeDelta latency) { | |
| 101 UMA_HISTOGRAM_CUSTOM_TIMES(name, | |
|
Ilya Sherman
2012/10/02 21:09:33
This won't work. The name passed to any of the UM
Ilya Sherman
2012/10/02 21:09:33
nit: Why do we need custom times for this histogra
SteveT
2012/10/03 19:51:34
Darn, okay. It was odd that my testing seemed to w
SteveT
2012/10/03 19:51:34
I was following what how some Net code was measuri
| |
| 102 latency, | |
| 103 base::TimeDelta::FromMilliseconds(1), | |
| 104 base::TimeDelta::FromMinutes(10), | |
| 105 100); | |
| 106 } | |
| 107 | |
| 99 } // namespace | 108 } // namespace |
| 100 | 109 |
| 101 VariationsService::VariationsService() | 110 VariationsService::VariationsService() |
| 102 : variations_server_url_(GetVariationsServerURL()), | 111 : variations_server_url_(GetVariationsServerURL()), |
| 103 create_trials_from_seed_called_(false), | 112 create_trials_from_seed_called_(false), |
| 104 resource_request_allowed_notifier_( | 113 resource_request_allowed_notifier_( |
| 105 new ResourceRequestAllowedNotifier) { | 114 new ResourceRequestAllowedNotifier) { |
| 106 resource_request_allowed_notifier_->Init(this); | 115 resource_request_allowed_notifier_->Init(this); |
| 107 } | 116 } |
| 108 | 117 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 pending_seed_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 185 pending_seed_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 177 net::LOAD_DO_NOT_SAVE_COOKIES); | 186 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 178 pending_seed_request_->SetRequestContext( | 187 pending_seed_request_->SetRequestContext( |
| 179 g_browser_process->system_request_context()); | 188 g_browser_process->system_request_context()); |
| 180 pending_seed_request_->SetMaxRetries(kMaxRetrySeedFetch); | 189 pending_seed_request_->SetMaxRetries(kMaxRetrySeedFetch); |
| 181 if (!variations_serial_number_.empty()) { | 190 if (!variations_serial_number_.empty()) { |
| 182 pending_seed_request_->AddExtraRequestHeader("If-Match:" + | 191 pending_seed_request_->AddExtraRequestHeader("If-Match:" + |
| 183 variations_serial_number_); | 192 variations_serial_number_); |
| 184 } | 193 } |
| 185 pending_seed_request_->Start(); | 194 pending_seed_request_->Start(); |
| 195 | |
| 196 last_request_started_time_ = base::TimeTicks::Now(); | |
| 186 } | 197 } |
| 187 | 198 |
| 188 void VariationsService::FetchVariationsSeed() { | 199 void VariationsService::FetchVariationsSeed() { |
| 189 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 200 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 190 | 201 |
| 191 if (!resource_request_allowed_notifier_->ResourceRequestsAllowed()) { | 202 if (!resource_request_allowed_notifier_->ResourceRequestsAllowed()) { |
| 192 DVLOG(1) << "Resource requests were not allowed. Waiting for notification."; | 203 DVLOG(1) << "Resource requests were not allowed. Waiting for notification."; |
| 193 return; | 204 return; |
| 194 } | 205 } |
| 195 | 206 |
| 196 DoActualFetch(); | 207 DoActualFetch(); |
| 197 } | 208 } |
| 198 | 209 |
| 199 void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) { | 210 void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) { |
| 200 DCHECK_EQ(pending_seed_request_.get(), source); | 211 DCHECK_EQ(pending_seed_request_.get(), source); |
| 201 // The fetcher will be deleted when the request is handled. | 212 // The fetcher will be deleted when the request is handled. |
| 202 scoped_ptr<const net::URLFetcher> request( | 213 scoped_ptr<const net::URLFetcher> request( |
| 203 pending_seed_request_.release()); | 214 pending_seed_request_.release()); |
| 204 if (request->GetStatus().status() != net::URLRequestStatus::SUCCESS) { | 215 if (request->GetStatus().status() != net::URLRequestStatus::SUCCESS) { |
| 205 DVLOG(1) << "Variations server request failed."; | 216 DVLOG(1) << "Variations server request failed."; |
| 206 return; | 217 return; |
| 207 } | 218 } |
| 208 | 219 |
| 209 // Log the response code. | 220 // Log the response code. |
| 210 UMA_HISTOGRAM_CUSTOM_ENUMERATION("Variations.SeedFetchResponseCode", | 221 UMA_HISTOGRAM_CUSTOM_ENUMERATION("Variations.SeedFetchResponseCode", |
| 211 net::HttpUtil::MapStatusCodeForHistogram(request->GetResponseCode()), | 222 net::HttpUtil::MapStatusCodeForHistogram(request->GetResponseCode()), |
| 212 net::HttpUtil::GetStatusCodesForHistogram()); | 223 net::HttpUtil::GetStatusCodesForHistogram()); |
| 213 | 224 |
| 225 const base::TimeDelta latency = | |
| 226 base::TimeTicks::Now() - last_request_started_time_; | |
| 227 | |
| 214 if (request->GetResponseCode() != 200) { | 228 if (request->GetResponseCode() != 200) { |
| 215 DVLOG(1) << "Variations server request returned non-200 response code: " | 229 DVLOG(1) << "Variations server request returned non-200 response code: " |
| 216 << request->GetResponseCode(); | 230 << request->GetResponseCode(); |
| 231 if (request->GetResponseCode() == 304) | |
| 232 LogRequestLatency("Variations.FetchNotModifiedLatency", latency); | |
| 233 else | |
| 234 LogRequestLatency("Variations.FetchOtherLatency", latency); | |
| 217 return; | 235 return; |
| 218 } | 236 } |
| 237 LogRequestLatency("Variations.FetchSuccessLatency", latency); | |
| 219 | 238 |
| 220 std::string seed_data; | 239 std::string seed_data; |
| 221 bool success = request->GetResponseAsString(&seed_data); | 240 bool success = request->GetResponseAsString(&seed_data); |
| 222 DCHECK(success); | 241 DCHECK(success); |
| 223 | 242 |
| 224 base::Time response_date; | 243 base::Time response_date; |
| 225 success = request->GetResponseHeaders()->GetDateValue(&response_date); | 244 success = request->GetResponseHeaders()->GetDateValue(&response_date); |
| 226 DCHECK(success || response_date.is_null()); | 245 DCHECK(success || response_date.is_null()); |
| 227 | 246 |
| 228 StoreSeedData(seed_data, response_date, g_browser_process->local_state()); | 247 StoreSeedData(seed_data, response_date, g_browser_process->local_state()); |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 variation_id); | 519 variation_id); |
| 501 } | 520 } |
| 502 } | 521 } |
| 503 | 522 |
| 504 trial->SetForced(); | 523 trial->SetForced(); |
| 505 if (IsStudyExpired(study, reference_date)) | 524 if (IsStudyExpired(study, reference_date)) |
| 506 trial->Disable(); | 525 trial->Disable(); |
| 507 } | 526 } |
| 508 | 527 |
| 509 } // namespace chrome_variations | 528 } // namespace chrome_variations |
| OLD | NEW |