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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | |
14 #include "base/callback.h" | 15 #include "base/callback.h" |
15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
16 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
17 #include "base/containers/hash_tables.h" | 18 #include "base/containers/hash_tables.h" |
19 #include "base/location.h" | |
18 #include "base/logging.h" | 20 #include "base/logging.h" |
19 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
22 #include "base/memory/ref_counted.h" | |
20 #include "base/metrics/histogram_macros.h" | 23 #include "base/metrics/histogram_macros.h" |
21 #include "components/precache/core/precache_switches.h" | 24 #include "components/precache/core/precache_switches.h" |
22 #include "components/precache/core/proto/precache.pb.h" | 25 #include "components/precache/core/proto/precache.pb.h" |
26 #include "components/precache/core/proto/unfinished_work.pb.h" | |
23 #include "net/base/completion_callback.h" | 27 #include "net/base/completion_callback.h" |
24 #include "net/base/escape.h" | 28 #include "net/base/escape.h" |
25 #include "net/base/io_buffer.h" | 29 #include "net/base/io_buffer.h" |
26 #include "net/base/load_flags.h" | 30 #include "net/base/load_flags.h" |
27 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
28 #include "net/http/http_response_headers.h" | 32 #include "net/http/http_response_headers.h" |
29 #include "net/url_request/url_fetcher_response_writer.h" | 33 #include "net/url_request/url_fetcher_response_writer.h" |
30 #include "net/url_request/url_request_context_getter.h" | 34 #include "net/url_request/url_request_context_getter.h" |
31 #include "net/url_request/url_request_status.h" | 35 #include "net/url_request/url_request_status.h" |
32 | 36 |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 // - The request was for a config or manifest. | 254 // - The request was for a config or manifest. |
251 // - The resource was a cache hit without validators. | 255 // - The resource was a cache hit without validators. |
252 // - The response came from the network. | 256 // - The response came from the network. |
253 // Then Fetcher is done with this URL and can return control to the caller. | 257 // Then Fetcher is done with this URL and can return control to the caller. |
254 response_bytes_ = source->GetReceivedResponseContentLength(); | 258 response_bytes_ = source->GetReceivedResponseContentLength(); |
255 network_response_bytes_ = source->GetTotalReceivedBytes(); | 259 network_response_bytes_ = source->GetTotalReceivedBytes(); |
256 callback_.Run(*this); | 260 callback_.Run(*this); |
257 } | 261 } |
258 | 262 |
259 PrecacheFetcher::PrecacheFetcher( | 263 PrecacheFetcher::PrecacheFetcher( |
260 const std::vector<std::string>& starting_hosts, | |
261 net::URLRequestContextGetter* request_context, | 264 net::URLRequestContextGetter* request_context, |
262 const GURL& config_url, | 265 const GURL& config_url, |
263 const std::string& manifest_url_prefix, | 266 const std::string& manifest_url_prefix, |
267 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work, | |
264 PrecacheFetcher::PrecacheDelegate* precache_delegate) | 268 PrecacheFetcher::PrecacheDelegate* precache_delegate) |
265 : starting_hosts_(starting_hosts), | 269 : request_context_(request_context), |
266 request_context_(request_context), | |
267 config_url_(config_url), | 270 config_url_(config_url), |
268 manifest_url_prefix_(manifest_url_prefix), | 271 manifest_url_prefix_(manifest_url_prefix), |
269 precache_delegate_(precache_delegate), | 272 precache_delegate_(precache_delegate), |
270 config_(new PrecacheConfigurationSettings), | 273 config_(new PrecacheConfigurationSettings), |
271 total_response_bytes_(0), | 274 total_response_bytes_(0), |
272 network_response_bytes_(0), | 275 network_response_bytes_(0), |
273 num_manifest_urls_to_fetch_(0), | 276 num_manifest_urls_to_fetch_(0), |
274 pool_(kMaxParallelFetches) { | 277 pool_(kMaxParallelFetches) { |
275 DCHECK(request_context_.get()); // Request context must be non-NULL. | 278 DCHECK(request_context_.get()); // Request context must be non-NULL. |
276 DCHECK(precache_delegate_); // Precache delegate must be non-NULL. | 279 DCHECK(precache_delegate_); // Precache delegate must be non-NULL. |
277 | 280 |
278 DCHECK_NE(GURL(), GetDefaultConfigURL()) | 281 DCHECK_NE(GURL(), GetDefaultConfigURL()) |
279 << "Could not determine the precache config settings URL."; | 282 << "Could not determine the precache config settings URL."; |
280 DCHECK_NE(std::string(), GetDefaultManifestURLPrefix()) | 283 DCHECK_NE(std::string(), GetDefaultManifestURLPrefix()) |
281 << "Could not determine the default precache manifest URL prefix."; | 284 << "Could not determine the default precache manifest URL prefix."; |
285 DCHECK(unfinished_work); | |
286 | |
287 for (const auto& manifest : unfinished_work->manifest()) { | |
288 if (manifest.has_url()) | |
289 manifest_urls_to_fetch_.push_back(GURL(manifest.url())); | |
290 } | |
291 for (const auto& resource : unfinished_work->resource()) { | |
292 if (resource.has_url()) | |
293 resource_urls_to_fetch_.push_back(GURL(resource.url())); | |
294 } | |
295 if (unfinished_work->has_total_bytes()) | |
296 total_response_bytes_ = unfinished_work->total_bytes(); | |
297 if (unfinished_work->has_network_bytes()) | |
298 network_response_bytes_ = unfinished_work->network_bytes(); | |
299 if (unfinished_work->has_num_manifest_urls()) | |
300 num_manifest_urls_to_fetch_ = unfinished_work->num_manifest_urls(); | |
301 if (unfinished_work->has_start_time()) | |
302 start_time_ = base::Time::FromInternalValue(unfinished_work->start_time()); | |
303 | |
304 unfinished_work_ = std::move(unfinished_work); | |
305 | |
282 } | 306 } |
283 | 307 |
284 PrecacheFetcher::~PrecacheFetcher() { | 308 PrecacheFetcher::~PrecacheFetcher() { |
285 base::TimeDelta time_to_fetch = base::TimeTicks::Now() - start_time_; | 309 base::TimeDelta time_to_fetch = base::Time::Now() - start_time_; |
286 UMA_HISTOGRAM_CUSTOM_TIMES("Precache.Fetch.TimeToComplete", time_to_fetch, | 310 UMA_HISTOGRAM_CUSTOM_TIMES("Precache.Fetch.TimeToComplete", time_to_fetch, |
287 base::TimeDelta::FromSeconds(1), | 311 base::TimeDelta::FromSeconds(1), |
288 base::TimeDelta::FromHours(4), 50); | 312 base::TimeDelta::FromHours(4), 50); |
289 | 313 |
290 // Number of manifests for which we have downloaded all resources. | 314 // Number of manifests for which we have downloaded all resources. |
291 int manifests_completed = | 315 int manifests_completed = |
292 num_manifest_urls_to_fetch_ - manifest_urls_to_fetch_.size(); | 316 num_manifest_urls_to_fetch_ - manifest_urls_to_fetch_.size(); |
293 | 317 |
294 // If there are resource URLs left to fetch, the last manifest is not yet | 318 // If there are resource URLs left to fetch, the last manifest is not yet |
295 // completed. | 319 // completed. |
296 if (!resource_urls_to_fetch_.empty()) | 320 if (!resource_urls_to_fetch_.empty()) |
297 --manifests_completed; | 321 --manifests_completed; |
298 | 322 |
299 DCHECK_GE(manifests_completed, 0); | 323 DCHECK_GE(manifests_completed, 0); |
300 int percent_completed = num_manifest_urls_to_fetch_ == 0 | 324 int percent_completed = num_manifest_urls_to_fetch_ == 0 |
301 ? 0 | 325 ? 0 |
302 : (static_cast<double>(manifests_completed) / | 326 : (static_cast<double>(manifests_completed) / |
303 num_manifest_urls_to_fetch_ * 100); | 327 num_manifest_urls_to_fetch_ * 100); |
304 UMA_HISTOGRAM_PERCENTAGE("Precache.Fetch.PercentCompleted", | 328 UMA_HISTOGRAM_PERCENTAGE("Precache.Fetch.PercentCompleted", |
sclittle
2016/05/20 21:57:07
Can you clean up this UMA like we discussed offlin
bengr
2016/05/21 00:16:32
Done.
| |
305 percent_completed); | 329 percent_completed); |
306 UMA_HISTOGRAM_CUSTOM_COUNTS("Precache.Fetch.ResponseBytes.Total", | 330 UMA_HISTOGRAM_CUSTOM_COUNTS("Precache.Fetch.ResponseBytes.Total", |
307 total_response_bytes_, 1, kMaxResponseBytes, 100); | 331 total_response_bytes_, 1, kMaxResponseBytes, 100); |
308 UMA_HISTOGRAM_CUSTOM_COUNTS("Precache.Fetch.ResponseBytes.Network", | 332 UMA_HISTOGRAM_CUSTOM_COUNTS("Precache.Fetch.ResponseBytes.Network", |
309 network_response_bytes_, 1, kMaxResponseBytes, | 333 network_response_bytes_, 1, kMaxResponseBytes, |
310 100); | 334 100); |
311 } | 335 } |
312 | 336 |
337 std::unique_ptr<PrecacheUnfinishedWork> PrecacheFetcher::CancelPrecaching() { | |
338 for (const auto& manifest : manifest_urls_to_fetch_) | |
339 unfinished_work_->add_manifest()->set_url(manifest.spec()); | |
340 for (const auto& resource : resource_urls_to_fetch_) | |
341 unfinished_work_->add_resource()->set_url(resource.spec()); | |
342 unfinished_work_->set_total_bytes(total_response_bytes_); | |
343 unfinished_work_->set_network_bytes(network_response_bytes_); | |
344 unfinished_work_->set_num_manifest_urls(num_manifest_urls_to_fetch_); | |
345 unfinished_work_->set_start_time(start_time_.ToInternalValue()); | |
346 return std::move(unfinished_work_); | |
347 } | |
348 | |
313 void PrecacheFetcher::Start() { | 349 void PrecacheFetcher::Start() { |
350 if (unfinished_work_->has_config_settings()) { | |
351 DetermineManifests(); | |
352 return; | |
353 } | |
354 | |
314 GURL config_url = | 355 GURL config_url = |
315 config_url_.is_empty() ? GetDefaultConfigURL() : config_url_; | 356 config_url_.is_empty() ? GetDefaultConfigURL() : config_url_; |
316 | 357 |
317 DCHECK(config_url.is_valid()) << "Config URL not valid: " | 358 DCHECK(config_url.is_valid()) << "Config URL not valid: " |
318 << config_url.possibly_invalid_spec(); | 359 << config_url.possibly_invalid_spec(); |
319 | 360 |
320 start_time_ = base::TimeTicks::Now(); | 361 start_time_ = base::Time::Now(); |
321 | 362 |
322 // Fetch the precache configuration settings from the server. | 363 // Fetch the precache configuration settings from the server. |
323 DCHECK(pool_.IsEmpty()) << "All parallel requests should be available"; | 364 DCHECK(pool_.IsEmpty()) << "All parallel requests should be available"; |
324 VLOG(3) << "Fetching " << config_url; | 365 VLOG(3) << "Fetching " << config_url; |
325 pool_.Add(base::WrapUnique(new Fetcher( | 366 pool_.Add(base::WrapUnique(new Fetcher( |
326 request_context_.get(), config_url, | 367 request_context_.get(), config_url, |
327 base::Bind(&PrecacheFetcher::OnConfigFetchComplete, | 368 base::Bind(&PrecacheFetcher::OnConfigFetchComplete, |
328 base::Unretained(this)), | 369 base::Unretained(this)), |
329 false /* is_resource_request */, std::numeric_limits<int32_t>::max()))); | 370 false /* is_resource_request */, std::numeric_limits<int32_t>::max()))); |
330 } | 371 } |
331 | 372 |
332 void PrecacheFetcher::StartNextResourceFetch() { | 373 void PrecacheFetcher::StartNextResourceFetch() { |
374 DCHECK(unfinished_work_->has_config_settings()); | |
333 while (!resource_urls_to_fetch_.empty() && pool_.IsAvailable()) { | 375 while (!resource_urls_to_fetch_.empty() && pool_.IsAvailable()) { |
334 const size_t max_bytes = | 376 const size_t max_bytes = |
335 std::min(config_->max_bytes_per_resource(), | 377 std::min(unfinished_work_->config_settings().max_bytes_per_resource(), |
336 config_->max_bytes_total() - total_response_bytes_); | 378 unfinished_work_->config_settings().max_bytes_total() - |
379 total_response_bytes_); | |
337 VLOG(3) << "Fetching " << resource_urls_to_fetch_.front(); | 380 VLOG(3) << "Fetching " << resource_urls_to_fetch_.front(); |
338 pool_.Add(base::WrapUnique( | 381 pool_.Add(base::WrapUnique( |
339 new Fetcher(request_context_.get(), resource_urls_to_fetch_.front(), | 382 new Fetcher(request_context_.get(), resource_urls_to_fetch_.front(), |
340 base::Bind(&PrecacheFetcher::OnResourceFetchComplete, | 383 base::Bind(&PrecacheFetcher::OnResourceFetchComplete, |
341 base::Unretained(this)), | 384 base::Unretained(this)), |
342 true /* is_resource_request */, max_bytes))); | 385 true /* is_resource_request */, max_bytes))); |
343 | 386 |
344 resource_urls_to_fetch_.pop_front(); | 387 resource_urls_to_fetch_.pop_front(); |
sclittle
2016/05/20 21:57:07
If precaching is cancelled, what happens to any re
bengr
2016/05/21 00:16:32
Done.
| |
345 } | 388 } |
346 } | 389 } |
347 | 390 |
348 void PrecacheFetcher::StartNextManifestFetch() { | 391 void PrecacheFetcher::StartNextManifestFetch() { |
349 if (manifest_urls_to_fetch_.empty()) | 392 if (manifest_urls_to_fetch_.empty()) |
350 return; | 393 return; |
351 | 394 |
352 // We only fetch one manifest at a time to keep the size of | 395 // We only fetch one manifest at a time to keep the size of |
353 // resource_urls_to_fetch_ as small as possible. | 396 // resource_urls_to_fetch_ as small as possible. |
354 DCHECK(pool_.IsAvailable()) | 397 DCHECK(pool_.IsAvailable()) |
355 << "There are no available parallel requests to fetch the next manifest. " | 398 << "There are no available parallel requests to fetch the next manifest. " |
356 "Did you forget to call Delete?"; | 399 "Did you forget to call Delete?"; |
357 VLOG(3) << "Fetching " << manifest_urls_to_fetch_.front(); | 400 VLOG(3) << "Fetching " << manifest_urls_to_fetch_.front(); |
358 pool_.Add(base::WrapUnique(new Fetcher( | 401 pool_.Add(base::WrapUnique(new Fetcher( |
359 request_context_.get(), manifest_urls_to_fetch_.front(), | 402 request_context_.get(), manifest_urls_to_fetch_.front(), |
360 base::Bind(&PrecacheFetcher::OnManifestFetchComplete, | 403 base::Bind(&PrecacheFetcher::OnManifestFetchComplete, |
361 base::Unretained(this)), | 404 base::Unretained(this)), |
362 false /* is_resource_request */, std::numeric_limits<int32_t>::max()))); | 405 false /* is_resource_request */, std::numeric_limits<int32_t>::max()))); |
363 | 406 |
364 manifest_urls_to_fetch_.pop_front(); | 407 manifest_urls_to_fetch_.pop_front(); |
365 } | 408 } |
366 | 409 |
367 void PrecacheFetcher::StartNextFetch() { | 410 void PrecacheFetcher::StartNextFetch() { |
411 DCHECK(unfinished_work_->has_config_settings()); | |
368 // If over the precache total size cap, then stop prefetching. | 412 // If over the precache total size cap, then stop prefetching. |
369 if (total_response_bytes_ > config_->max_bytes_total()) { | 413 if (total_response_bytes_ > |
414 unfinished_work_->config_settings().max_bytes_total()) { | |
370 precache_delegate_->OnDone(); | 415 precache_delegate_->OnDone(); |
371 return; | 416 return; |
372 } | 417 } |
373 | 418 |
374 StartNextResourceFetch(); | 419 StartNextResourceFetch(); |
375 StartNextManifestFetch(); | 420 StartNextManifestFetch(); |
376 | |
377 if (pool_.IsEmpty()) { | 421 if (pool_.IsEmpty()) { |
378 // There are no more URLs to fetch, so end the precache cycle. | 422 // There are no more URLs to fetch, so end the precache cycle. |
379 precache_delegate_->OnDone(); | 423 precache_delegate_->OnDone(); |
380 // OnDone may have deleted this PrecacheFetcher, so don't do anything after | 424 // OnDone may have deleted this PrecacheFetcher, so don't do anything after |
381 // it is called. | 425 // it is called. |
382 } | 426 } |
383 } | 427 } |
384 | 428 |
385 void PrecacheFetcher::OnConfigFetchComplete(const Fetcher& source) { | 429 void PrecacheFetcher::OnConfigFetchComplete(const Fetcher& source) { |
386 UpdateStats(source.response_bytes(), source.network_response_bytes()); | 430 UpdateStats(source.response_bytes(), source.network_response_bytes()); |
387 if (source.network_url_fetcher() == nullptr) { | 431 if (source.network_url_fetcher() == nullptr) { |
388 pool_.DeleteAll(); // Cancel any other ongoing request. | 432 pool_.DeleteAll(); // Cancel any other ongoing request. |
389 } else { | 433 } else { |
390 // Attempt to parse the config proto. On failure, continue on with the | 434 // Attempt to parse the config proto. On failure, continue on with the |
391 // default configuration. | 435 // default configuration. |
392 ParseProtoFromFetchResponse(*source.network_url_fetcher(), config_.get()); | 436 ParseProtoFromFetchResponse( |
437 *source.network_url_fetcher(), | |
438 unfinished_work_->mutable_config_settings()); | |
439 pool_.Delete(source); | |
440 DetermineManifests(); | |
441 } | |
442 } | |
393 | 443 |
444 void PrecacheFetcher::DetermineManifests() { | |
445 DCHECK(unfinished_work_->has_config_settings()); | |
394 std::string prefix = manifest_url_prefix_.empty() | 446 std::string prefix = manifest_url_prefix_.empty() |
395 ? GetDefaultManifestURLPrefix() | 447 ? GetDefaultManifestURLPrefix() |
396 : manifest_url_prefix_; | 448 : manifest_url_prefix_; |
397 DCHECK_NE(std::string(), prefix) | 449 DCHECK_NE(std::string(), prefix) |
398 << "Could not determine the precache manifest URL prefix."; | 450 << "Could not determine the precache manifest URL prefix."; |
399 | 451 |
400 // Keep track of manifest URLs that are being fetched, in order to elide | 452 // Keep track of manifest URLs that are being fetched, in order to elide |
401 // duplicates. | 453 // duplicates. |
402 base::hash_set<std::string> seen_manifest_urls; | 454 base::hash_set<std::string> seen_manifest_urls; |
403 | 455 |
404 // Attempt to fetch manifests for starting hosts up to the maximum top sites | 456 // Attempt to fetch manifests for starting hosts up to the maximum top sites |
405 // count. If a manifest does not exist for a particular starting host, then | 457 // count. If a manifest does not exist for a particular starting host, then |
406 // the fetch will fail, and that starting host will be ignored. | 458 // the fetch will fail, and that starting host will be ignored. Starting |
407 int64_t rank = 0; | 459 // hosts are not added if this is a continuation from a previous precache |
408 for (const std::string& host : starting_hosts_) { | 460 // session. |
409 ++rank; | 461 if (manifest_urls_to_fetch_.empty() && |
410 if (rank > config_->top_sites_count()) | 462 resource_urls_to_fetch_.empty()) { |
411 break; | 463 int64_t rank = 0; |
412 AppendManifestURLIfNew(prefix, host, &seen_manifest_urls, | 464 for (const auto& host : unfinished_work_->top_host()) { |
413 &manifest_urls_to_fetch_); | 465 ++rank; |
466 if (rank > unfinished_work_->config_settings().top_sites_count()) | |
467 break; | |
468 AppendManifestURLIfNew(prefix, host.hostname(), &seen_manifest_urls, | |
469 &manifest_urls_to_fetch_); | |
470 } | |
471 | |
472 for (const std::string& host | |
473 : unfinished_work_->config_settings().forced_site()) { | |
474 AppendManifestURLIfNew(prefix, host, &seen_manifest_urls, | |
475 &manifest_urls_to_fetch_); | |
476 } | |
414 } | 477 } |
415 | |
416 for (const std::string& host : config_->forced_site()) | |
417 AppendManifestURLIfNew(prefix, host, &seen_manifest_urls, | |
418 &manifest_urls_to_fetch_); | |
419 | |
420 num_manifest_urls_to_fetch_ = manifest_urls_to_fetch_.size(); | 478 num_manifest_urls_to_fetch_ = manifest_urls_to_fetch_.size(); |
421 } | 479 StartNextFetch(); |
422 pool_.Delete(source); | |
423 | |
424 StartNextFetch(); | |
425 } | 480 } |
426 | 481 |
427 void PrecacheFetcher::OnManifestFetchComplete(const Fetcher& source) { | 482 void PrecacheFetcher::OnManifestFetchComplete(const Fetcher& source) { |
483 DCHECK(unfinished_work_->has_config_settings()); | |
428 UpdateStats(source.response_bytes(), source.network_response_bytes()); | 484 UpdateStats(source.response_bytes(), source.network_response_bytes()); |
429 if (source.network_url_fetcher() == nullptr) { | 485 if (source.network_url_fetcher() == nullptr) { |
430 pool_.DeleteAll(); // Cancel any other ongoing request. | 486 pool_.DeleteAll(); // Cancel any other ongoing request. |
431 } else { | 487 } else { |
432 PrecacheManifest manifest; | 488 PrecacheManifest manifest; |
433 | 489 |
434 if (ParseProtoFromFetchResponse(*source.network_url_fetcher(), &manifest)) { | 490 if (ParseProtoFromFetchResponse(*source.network_url_fetcher(), &manifest)) { |
435 const int32_t len = | 491 const int32_t len = |
436 std::min(manifest.resource_size(), config_->top_resources_count()); | 492 std::min(manifest.resource_size(), |
493 unfinished_work_->config_settings().top_resources_count()); | |
437 for (int i = 0; i < len; ++i) { | 494 for (int i = 0; i < len; ++i) { |
438 if (manifest.resource(i).has_url()) { | 495 if (manifest.resource(i).has_url()) |
439 resource_urls_to_fetch_.push_back(GURL(manifest.resource(i).url())); | 496 resource_urls_to_fetch_.push_back(GURL(manifest.resource(i).url())); |
440 } | |
441 } | 497 } |
442 } | 498 } |
443 } | 499 } |
444 | 500 |
445 pool_.Delete(source); | 501 pool_.Delete(source); |
446 StartNextFetch(); | 502 StartNextFetch(); |
447 } | 503 } |
448 | 504 |
449 void PrecacheFetcher::OnResourceFetchComplete(const Fetcher& source) { | 505 void PrecacheFetcher::OnResourceFetchComplete(const Fetcher& source) { |
450 UpdateStats(source.response_bytes(), source.network_response_bytes()); | 506 UpdateStats(source.response_bytes(), source.network_response_bytes()); |
451 pool_.Delete(source); | 507 pool_.Delete(source); |
452 // The resource has already been put in the cache during the fetch process, so | 508 // The resource has already been put in the cache during the fetch process, so |
453 // nothing more needs to be done for the resource. | 509 // nothing more needs to be done for the resource. |
454 StartNextFetch(); | 510 StartNextFetch(); |
455 } | 511 } |
456 | 512 |
457 void PrecacheFetcher::UpdateStats(int64_t response_bytes, | 513 void PrecacheFetcher::UpdateStats(int64_t response_bytes, |
458 int64_t network_response_bytes) { | 514 int64_t network_response_bytes) { |
459 total_response_bytes_ += response_bytes; | 515 total_response_bytes_ += response_bytes; |
460 network_response_bytes_ += network_response_bytes; | 516 network_response_bytes_ += network_response_bytes; |
461 } | 517 } |
462 | 518 |
519 void PrecacheFetcher::AssignWorkForTest(const std::list<GURL>& manifests, | |
520 const std::list<GURL>& resources, | |
521 size_t total_response_bytes, | |
522 size_t network_response_bytes, | |
523 size_t num_manifest_urls_to_fetch, | |
524 const base::Time& start_time) { | |
525 DCHECK(manifest_urls_to_fetch_.empty()); | |
526 DCHECK(resource_urls_to_fetch_.empty()); | |
527 manifest_urls_to_fetch_ = manifests; | |
528 resource_urls_to_fetch_ = resources; | |
529 total_response_bytes_ = total_response_bytes; | |
530 network_response_bytes_ = network_response_bytes; | |
531 num_manifest_urls_to_fetch_ = num_manifest_urls_to_fetch; | |
532 start_time_ = start_time; | |
533 } | |
534 | |
463 } // namespace precache | 535 } // namespace precache |
OLD | NEW |