| 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 pending_seed_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 176 pending_seed_request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 177 net::LOAD_DO_NOT_SAVE_COOKIES); | 177 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 178 pending_seed_request_->SetRequestContext( | 178 pending_seed_request_->SetRequestContext( |
| 179 g_browser_process->system_request_context()); | 179 g_browser_process->system_request_context()); |
| 180 pending_seed_request_->SetMaxRetries(kMaxRetrySeedFetch); | 180 pending_seed_request_->SetMaxRetries(kMaxRetrySeedFetch); |
| 181 if (!variations_serial_number_.empty()) { | 181 if (!variations_serial_number_.empty()) { |
| 182 pending_seed_request_->AddExtraRequestHeader("If-Match:" + | 182 pending_seed_request_->AddExtraRequestHeader("If-Match:" + |
| 183 variations_serial_number_); | 183 variations_serial_number_); |
| 184 } | 184 } |
| 185 pending_seed_request_->Start(); | 185 pending_seed_request_->Start(); |
| 186 |
| 187 last_request_started_time_ = base::TimeTicks::Now(); |
| 186 } | 188 } |
| 187 | 189 |
| 188 void VariationsService::FetchVariationsSeed() { | 190 void VariationsService::FetchVariationsSeed() { |
| 189 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 191 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 190 | 192 |
| 191 if (!resource_request_allowed_notifier_->ResourceRequestsAllowed()) { | 193 if (!resource_request_allowed_notifier_->ResourceRequestsAllowed()) { |
| 192 DVLOG(1) << "Resource requests were not allowed. Waiting for notification."; | 194 DVLOG(1) << "Resource requests were not allowed. Waiting for notification."; |
| 193 return; | 195 return; |
| 194 } | 196 } |
| 195 | 197 |
| 196 DoActualFetch(); | 198 DoActualFetch(); |
| 197 } | 199 } |
| 198 | 200 |
| 199 void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) { | 201 void VariationsService::OnURLFetchComplete(const net::URLFetcher* source) { |
| 200 DCHECK_EQ(pending_seed_request_.get(), source); | 202 DCHECK_EQ(pending_seed_request_.get(), source); |
| 201 // The fetcher will be deleted when the request is handled. | 203 // The fetcher will be deleted when the request is handled. |
| 202 scoped_ptr<const net::URLFetcher> request( | 204 scoped_ptr<const net::URLFetcher> request( |
| 203 pending_seed_request_.release()); | 205 pending_seed_request_.release()); |
| 204 if (request->GetStatus().status() != net::URLRequestStatus::SUCCESS) { | 206 if (request->GetStatus().status() != net::URLRequestStatus::SUCCESS) { |
| 205 DVLOG(1) << "Variations server request failed."; | 207 DVLOG(1) << "Variations server request failed."; |
| 206 return; | 208 return; |
| 207 } | 209 } |
| 208 | 210 |
| 209 // Log the response code. | 211 // Log the response code. |
| 210 UMA_HISTOGRAM_CUSTOM_ENUMERATION("Variations.SeedFetchResponseCode", | 212 UMA_HISTOGRAM_CUSTOM_ENUMERATION("Variations.SeedFetchResponseCode", |
| 211 net::HttpUtil::MapStatusCodeForHistogram(request->GetResponseCode()), | 213 net::HttpUtil::MapStatusCodeForHistogram(request->GetResponseCode()), |
| 212 net::HttpUtil::GetStatusCodesForHistogram()); | 214 net::HttpUtil::GetStatusCodesForHistogram()); |
| 213 | 215 |
| 216 const base::TimeDelta latency = |
| 217 base::TimeTicks::Now() - last_request_started_time_; |
| 218 |
| 214 if (request->GetResponseCode() != 200) { | 219 if (request->GetResponseCode() != 200) { |
| 215 DVLOG(1) << "Variations server request returned non-200 response code: " | 220 DVLOG(1) << "Variations server request returned non-200 response code: " |
| 216 << request->GetResponseCode(); | 221 << request->GetResponseCode(); |
| 222 if (request->GetResponseCode() == 304) |
| 223 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchNotModifiedLatency", latency); |
| 224 else |
| 225 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchOtherLatency", latency); |
| 217 return; | 226 return; |
| 218 } | 227 } |
| 228 UMA_HISTOGRAM_MEDIUM_TIMES("Variations.FetchSuccessLatency", latency); |
| 219 | 229 |
| 220 std::string seed_data; | 230 std::string seed_data; |
| 221 bool success = request->GetResponseAsString(&seed_data); | 231 bool success = request->GetResponseAsString(&seed_data); |
| 222 DCHECK(success); | 232 DCHECK(success); |
| 223 | 233 |
| 224 base::Time response_date; | 234 base::Time response_date; |
| 225 success = request->GetResponseHeaders()->GetDateValue(&response_date); | 235 success = request->GetResponseHeaders()->GetDateValue(&response_date); |
| 226 DCHECK(success || response_date.is_null()); | 236 DCHECK(success || response_date.is_null()); |
| 227 | 237 |
| 228 StoreSeedData(seed_data, response_date, g_browser_process->local_state()); | 238 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); | 510 variation_id); |
| 501 } | 511 } |
| 502 } | 512 } |
| 503 | 513 |
| 504 trial->SetForced(); | 514 trial->SetForced(); |
| 505 if (IsStudyExpired(study, reference_date)) | 515 if (IsStudyExpired(study, reference_date)) |
| 506 trial->Disable(); | 516 trial->Disable(); |
| 507 } | 517 } |
| 508 | 518 |
| 509 } // namespace chrome_variations | 519 } // namespace chrome_variations |
| OLD | NEW |