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 "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 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 base::ThreadTaskRunnerHandle::Get()->PostTask( | 391 base::ThreadTaskRunnerHandle::Get()->PostTask( |
392 FROM_HERE, | 392 FROM_HERE, |
393 base::Bind(&FakeURLFetcher::RunDelegate, weak_factory_.GetWeakPtr())); | 393 base::Bind(&FakeURLFetcher::RunDelegate, weak_factory_.GetWeakPtr())); |
394 } | 394 } |
395 | 395 |
396 void FakeURLFetcher::RunDelegate() { | 396 void FakeURLFetcher::RunDelegate() { |
397 // OnURLFetchDownloadProgress may delete this URLFetcher. We keep track of | 397 // OnURLFetchDownloadProgress may delete this URLFetcher. We keep track of |
398 // this with a weak pointer, and only call OnURLFetchComplete if this still | 398 // this with a weak pointer, and only call OnURLFetchComplete if this still |
399 // exists. | 399 // exists. |
400 auto weak_this = weak_factory_.GetWeakPtr(); | 400 auto weak_this = weak_factory_.GetWeakPtr(); |
401 delegate()->OnURLFetchDownloadProgress(this, response_bytes_, | 401 delegate()->OnURLFetchDownloadProgress(this, response_bytes_, response_bytes_, |
402 response_bytes_); | 402 response_bytes_); |
403 if (weak_this.get()) | 403 if (weak_this.get()) |
404 delegate()->OnURLFetchComplete(this); | 404 delegate()->OnURLFetchComplete(this); |
405 } | 405 } |
406 | 406 |
407 const GURL& FakeURLFetcher::GetURL() const { | 407 const GURL& FakeURLFetcher::GetURL() const { |
408 return TestURLFetcher::GetOriginalURL(); | 408 return TestURLFetcher::GetOriginalURL(); |
409 } | 409 } |
410 | 410 |
411 FakeURLFetcherFactory::FakeURLFetcherFactory( | 411 FakeURLFetcherFactory::FakeURLFetcherFactory( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 | 481 |
482 std::unique_ptr<URLFetcher> URLFetcherImplFactory::CreateURLFetcher( | 482 std::unique_ptr<URLFetcher> URLFetcherImplFactory::CreateURLFetcher( |
483 int id, | 483 int id, |
484 const GURL& url, | 484 const GURL& url, |
485 URLFetcher::RequestType request_type, | 485 URLFetcher::RequestType request_type, |
486 URLFetcherDelegate* d) { | 486 URLFetcherDelegate* d) { |
487 return std::unique_ptr<URLFetcher>(new URLFetcherImpl(url, request_type, d)); | 487 return std::unique_ptr<URLFetcher>(new URLFetcherImpl(url, request_type, d)); |
488 } | 488 } |
489 | 489 |
490 } // namespace net | 490 } // namespace net |
OLD | NEW |