Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: net/url_request/test_url_fetcher_factory.cc

Issue 1212773002: Add prefetch UMA metrics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix for CloudExternalDataManagerBaseTest.CacheCorruption. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/url_request/test_url_fetcher_factory.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "net/url_request/test_url_fetcher_factory.h" 5 #include "net/url_request/test_url_fetcher_factory.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 case URLRequestStatus::CANCELED: 349 case URLRequestStatus::CANCELED:
350 error = ERR_ABORTED; 350 error = ERR_ABORTED;
351 break; 351 break;
352 case URLRequestStatus::FAILED: 352 case URLRequestStatus::FAILED:
353 error = ERR_FAILED; 353 error = ERR_FAILED;
354 break; 354 break;
355 } 355 }
356 set_status(URLRequestStatus(status, error)); 356 set_status(URLRequestStatus(status, error));
357 set_response_code(response_code); 357 set_response_code(response_code);
358 SetResponseString(response_data); 358 SetResponseString(response_data);
359 response_bytes_ = response_data.size();
359 } 360 }
360 361
361 FakeURLFetcher::~FakeURLFetcher() {} 362 FakeURLFetcher::~FakeURLFetcher() {}
362 363
363 void FakeURLFetcher::Start() { 364 void FakeURLFetcher::Start() {
364 base::ThreadTaskRunnerHandle::Get()->PostTask( 365 base::ThreadTaskRunnerHandle::Get()->PostTask(
365 FROM_HERE, 366 FROM_HERE,
366 base::Bind(&FakeURLFetcher::RunDelegate, weak_factory_.GetWeakPtr())); 367 base::Bind(&FakeURLFetcher::RunDelegate, weak_factory_.GetWeakPtr()));
367 } 368 }
368 369
369 void FakeURLFetcher::RunDelegate() { 370 void FakeURLFetcher::RunDelegate() {
370 delegate()->OnURLFetchComplete(this); 371 // OnURLFetchDownloadProgress may delete this URLFetcher. We keep track of
372 // this with a weak pointer, and only call OnURLFetchComplete if this still
373 // exists.
374 auto weak_this = weak_factory_.GetWeakPtr();
375 delegate()->OnURLFetchDownloadProgress(this, response_bytes_,
376 response_bytes_);
377 if (weak_this.get())
378 delegate()->OnURLFetchComplete(this);
371 } 379 }
372 380
373 const GURL& FakeURLFetcher::GetURL() const { 381 const GURL& FakeURLFetcher::GetURL() const {
374 return TestURLFetcher::GetOriginalURL(); 382 return TestURLFetcher::GetOriginalURL();
375 } 383 }
376 384
377 FakeURLFetcherFactory::FakeURLFetcherFactory( 385 FakeURLFetcherFactory::FakeURLFetcherFactory(
378 URLFetcherFactory* default_factory) 386 URLFetcherFactory* default_factory)
379 : ScopedURLFetcherFactory(this), 387 : ScopedURLFetcherFactory(this),
380 creator_(base::Bind(&DefaultFakeURLFetcherCreator)), 388 creator_(base::Bind(&DefaultFakeURLFetcherCreator)),
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 454
447 scoped_ptr<URLFetcher> URLFetcherImplFactory::CreateURLFetcher( 455 scoped_ptr<URLFetcher> URLFetcherImplFactory::CreateURLFetcher(
448 int id, 456 int id,
449 const GURL& url, 457 const GURL& url,
450 URLFetcher::RequestType request_type, 458 URLFetcher::RequestType request_type,
451 URLFetcherDelegate* d) { 459 URLFetcherDelegate* d) {
452 return scoped_ptr<URLFetcher>(new URLFetcherImpl(url, request_type, d)); 460 return scoped_ptr<URLFetcher>(new URLFetcherImpl(url, request_type, d));
453 } 461 }
454 462
455 } // namespace net 463 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/test_url_fetcher_factory.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698