| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/precache/core/precache_fetcher.h" | 5 #include "components/precache/core/precache_fetcher.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 if (resource.has_url()) | 352 if (resource.has_url()) |
| 353 resource_urls_to_fetch_.push_back(GURL(resource.url())); | 353 resource_urls_to_fetch_.push_back(GURL(resource.url())); |
| 354 } | 354 } |
| 355 unfinished_work_ = std::move(unfinished_work); | 355 unfinished_work_ = std::move(unfinished_work); |
| 356 } | 356 } |
| 357 | 357 |
| 358 PrecacheFetcher::~PrecacheFetcher() { | 358 PrecacheFetcher::~PrecacheFetcher() { |
| 359 } | 359 } |
| 360 | 360 |
| 361 std::unique_ptr<PrecacheUnfinishedWork> PrecacheFetcher::CancelPrecaching() { | 361 std::unique_ptr<PrecacheUnfinishedWork> PrecacheFetcher::CancelPrecaching() { |
| 362 // This could get called multiple times, and it should be handled gracefully. |
| 363 if (!unfinished_work_) |
| 364 return nullptr; |
| 365 |
| 362 unfinished_work_->clear_manifest(); | 366 unfinished_work_->clear_manifest(); |
| 363 unfinished_work_->clear_resource(); | 367 unfinished_work_->clear_resource(); |
| 364 for (const auto& manifest : manifest_urls_to_fetch_) | 368 for (const auto& manifest : manifest_urls_to_fetch_) |
| 365 unfinished_work_->add_manifest()->set_url(manifest.spec()); | 369 unfinished_work_->add_manifest()->set_url(manifest.spec()); |
| 366 for (const auto& resource : resource_urls_to_fetch_) | 370 for (const auto& resource : resource_urls_to_fetch_) |
| 367 unfinished_work_->add_resource()->set_url(resource.spec()); | 371 unfinished_work_->add_resource()->set_url(resource.spec()); |
| 368 for (const auto& it : pool_.elements()) { | 372 for (const auto& it : pool_.elements()) { |
| 369 const Fetcher* fetcher = it.first; | 373 const Fetcher* fetcher = it.first; |
| 370 if (fetcher->is_resource_request()) | 374 if (fetcher->is_resource_request()) |
| 371 unfinished_work_->add_resource()->set_url(fetcher->url().spec()); | 375 unfinished_work_->add_resource()->set_url(fetcher->url().spec()); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 | 571 |
| 568 void PrecacheFetcher::UpdateStats(int64_t response_bytes, | 572 void PrecacheFetcher::UpdateStats(int64_t response_bytes, |
| 569 int64_t network_response_bytes) { | 573 int64_t network_response_bytes) { |
| 570 unfinished_work_->set_total_bytes( | 574 unfinished_work_->set_total_bytes( |
| 571 unfinished_work_->total_bytes() + response_bytes); | 575 unfinished_work_->total_bytes() + response_bytes); |
| 572 unfinished_work_->set_network_bytes( | 576 unfinished_work_->set_network_bytes( |
| 573 unfinished_work_->network_bytes() + network_response_bytes); | 577 unfinished_work_->network_bytes() + network_response_bytes); |
| 574 } | 578 } |
| 575 | 579 |
| 576 } // namespace precache | 580 } // namespace precache |
| OLD | NEW |