Chromium Code Reviews| 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 "content/browser/appcache/appcache_update_job.h" | 5 #include "content/browser/appcache/appcache_update_job.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 DCHECK_EQ(UPDATE_OK, result_); | 244 DCHECK_EQ(UPDATE_OK, result_); |
| 245 OnResponseCompleted(); | 245 OnResponseCompleted(); |
| 246 } | 246 } |
| 247 } | 247 } |
| 248 | 248 |
| 249 void AppCacheUpdateJob::URLFetcher::AddConditionalHeaders( | 249 void AppCacheUpdateJob::URLFetcher::AddConditionalHeaders( |
| 250 const net::HttpResponseHeaders* headers) { | 250 const net::HttpResponseHeaders* headers) { |
| 251 DCHECK(request_.get() && headers); | 251 DCHECK(request_.get() && headers); |
| 252 net::HttpRequestHeaders extra_headers; | 252 net::HttpRequestHeaders extra_headers; |
| 253 | 253 |
| 254 // TODO(michaeln): skip condition headers on manifest fetches if its been 24 h ours | |
| 255 // since the last update check | |
| 256 // TODO: store date of last update check even that busted the cache | |
| 257 // if (firstManifestFetch && | |
| 258 // now > newest_successful_unconditional_update_check_time + 24hours) | |
| 259 // performing_unconditional_update_check_ = true; | |
| 260 | |
| 254 // Add If-Modified-Since header if response info has Last-Modified header. | 261 // Add If-Modified-Since header if response info has Last-Modified header. |
| 255 const std::string last_modified = "Last-Modified"; | 262 const std::string last_modified = "Last-Modified"; |
| 256 std::string last_modified_value; | 263 std::string last_modified_value; |
| 257 headers->EnumerateHeader(NULL, last_modified, &last_modified_value); | 264 headers->EnumerateHeader(NULL, last_modified, &last_modified_value); |
| 258 if (!last_modified_value.empty()) { | 265 if (!last_modified_value.empty()) { |
| 259 extra_headers.SetHeader(net::HttpRequestHeaders::kIfModifiedSince, | 266 extra_headers.SetHeader(net::HttpRequestHeaders::kIfModifiedSince, |
| 260 last_modified_value); | 267 last_modified_value); |
| 261 } | 268 } |
| 262 | 269 |
| 263 // Add If-None-Match header if response info has ETag header. | 270 // Add If-None-Match header if response info has ETag header. |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 DCHECK(!error_details.message.empty()); | 478 DCHECK(!error_details.message.empty()); |
| 472 DCHECK(result != UPDATE_OK); | 479 DCHECK(result != UPDATE_OK); |
| 473 internal_state_ = CACHE_FAILURE; | 480 internal_state_ = CACHE_FAILURE; |
| 474 LogHistogramStats(result, failed_resource_url); | 481 LogHistogramStats(result, failed_resource_url); |
| 475 CancelAllUrlFetches(); | 482 CancelAllUrlFetches(); |
| 476 CancelAllMasterEntryFetches(error_details); | 483 CancelAllMasterEntryFetches(error_details); |
| 477 NotifyAllError(error_details); | 484 NotifyAllError(error_details); |
| 478 DiscardInprogressCache(); | 485 DiscardInprogressCache(); |
| 479 internal_state_ = COMPLETED; | 486 internal_state_ = COMPLETED; |
| 480 DeleteSoon(); // To unwind the stack prior to deletion. | 487 DeleteSoon(); // To unwind the stack prior to deletion. |
| 488 | |
| 489 // TODO(michaeln): Evict the cache under other cicrumstances too | |
| 490 // if we've been getting srvr errors for "too long" | |
| 491 // if we've been getting srvr redirects for "too long" | |
| 492 // if we've been getting an invalid manifest for "too long" | |
| 493 // maybe "too long" for http is less than it is for https? | |
|
palmer
2015/04/21 19:56:34
Good idea.
| |
| 494 // TODO: store date of first evictable error since last successfull update c heck | |
| 495 // if (is_an_evictable_error && | |
| 496 // now > first_evictable_error_since_successfull_check + kTooLong) | |
| 497 // evict(); | |
| 498 // else if (!first_evictable_error_since_successfull_check) set it to now | |
| 481 } | 499 } |
| 482 | 500 |
| 483 void AppCacheUpdateJob::FetchManifest(bool is_first_fetch) { | 501 void AppCacheUpdateJob::FetchManifest(bool is_first_fetch) { |
| 484 DCHECK(!manifest_fetcher_); | 502 DCHECK(!manifest_fetcher_); |
| 485 manifest_fetcher_ = new URLFetcher( | 503 manifest_fetcher_ = new URLFetcher( |
| 486 manifest_url_, | 504 manifest_url_, |
| 487 is_first_fetch ? URLFetcher::MANIFEST_FETCH : | 505 is_first_fetch ? URLFetcher::MANIFEST_FETCH : |
| 488 URLFetcher::MANIFEST_REFETCH, | 506 URLFetcher::MANIFEST_REFETCH, |
| 489 this); | 507 this); |
| 490 | 508 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 if (update_type_ == UPGRADE_ATTEMPT) | 552 if (update_type_ == UPGRADE_ATTEMPT) |
| 535 CheckIfManifestChanged(); // continues asynchronously | 553 CheckIfManifestChanged(); // continues asynchronously |
| 536 else | 554 else |
| 537 ContinueHandleManifestFetchCompleted(true); | 555 ContinueHandleManifestFetchCompleted(true); |
| 538 } else if (response_code == 304 && update_type_ == UPGRADE_ATTEMPT) { | 556 } else if (response_code == 304 && update_type_ == UPGRADE_ATTEMPT) { |
| 539 ContinueHandleManifestFetchCompleted(false); | 557 ContinueHandleManifestFetchCompleted(false); |
| 540 } else if ((response_code == 404 || response_code == 410) && | 558 } else if ((response_code == 404 || response_code == 410) && |
| 541 update_type_ == UPGRADE_ATTEMPT) { | 559 update_type_ == UPGRADE_ATTEMPT) { |
| 542 storage_->MakeGroupObsolete(group_, this, response_code); // async | 560 storage_->MakeGroupObsolete(group_, this, response_code); // async |
| 543 } else { | 561 } else { |
| 562 // TODO(michaeln): Evict the cache under other cicrumstances too. | |
| 563 // APPCACHE_MANIFEST_ERROR + networkresponsecde is an evictable error | |
| 544 const char* kFormatString = "Manifest fetch failed (%d) %s"; | 564 const char* kFormatString = "Manifest fetch failed (%d) %s"; |
| 545 std::string message = FormatUrlErrorMessage( | 565 std::string message = FormatUrlErrorMessage( |
| 546 kFormatString, manifest_url_, fetcher->result(), response_code); | 566 kFormatString, manifest_url_, fetcher->result(), response_code); |
| 547 HandleCacheFailure(AppCacheErrorDetails(message, | 567 HandleCacheFailure(AppCacheErrorDetails(message, |
| 548 APPCACHE_MANIFEST_ERROR, | 568 APPCACHE_MANIFEST_ERROR, |
| 549 manifest_url_, | 569 manifest_url_, |
| 550 response_code, | 570 response_code, |
| 551 false /*is_cross_origin*/), | 571 false /*is_cross_origin*/), |
| 552 fetcher->result(), | 572 fetcher->result(), |
| 553 GURL()); | 573 GURL()); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 580 false /*is_cross_origin*/), | 600 false /*is_cross_origin*/), |
| 581 DB_ERROR, | 601 DB_ERROR, |
| 582 GURL()); | 602 GURL()); |
| 583 } | 603 } |
| 584 } | 604 } |
| 585 | 605 |
| 586 void AppCacheUpdateJob::ContinueHandleManifestFetchCompleted(bool changed) { | 606 void AppCacheUpdateJob::ContinueHandleManifestFetchCompleted(bool changed) { |
| 587 DCHECK(internal_state_ == FETCH_MANIFEST); | 607 DCHECK(internal_state_ == FETCH_MANIFEST); |
| 588 | 608 |
| 589 if (!changed) { | 609 if (!changed) { |
| 610 // if unconditional_check, set time to now | |
| 590 DCHECK(update_type_ == UPGRADE_ATTEMPT); | 611 DCHECK(update_type_ == UPGRADE_ATTEMPT); |
| 591 internal_state_ = NO_UPDATE; | 612 internal_state_ = NO_UPDATE; |
| 592 | 613 |
| 593 // Wait for pending master entries to download. | 614 // Wait for pending master entries to download. |
| 594 FetchMasterEntries(); | 615 FetchMasterEntries(); |
| 595 MaybeCompleteUpdate(); // if not done, run async 6.9.4 step 7 substeps | 616 MaybeCompleteUpdate(); // if not done, run async 6.9.4 step 7 substeps |
| 596 return; | 617 return; |
| 597 } | 618 } |
| 598 | 619 |
| 599 AppCacheManifest manifest; | 620 AppCacheManifest manifest; |
| 600 if (!ParseManifest(manifest_url_, manifest_data_.data(), | 621 if (!ParseManifest(manifest_url_, manifest_data_.data(), |
| 601 manifest_data_.length(), | 622 manifest_data_.length(), |
| 602 manifest_has_valid_mime_type_ ? | 623 manifest_has_valid_mime_type_ ? |
| 603 PARSE_MANIFEST_ALLOWING_INTERCEPTS : | 624 PARSE_MANIFEST_ALLOWING_INTERCEPTS : |
| 604 PARSE_MANIFEST_PER_STANDARD, | 625 PARSE_MANIFEST_PER_STANDARD, |
| 605 manifest)) { | 626 manifest)) { |
| 627 // TODO(michaeln): Evict the cache under other cicrumstances too. | |
| 628 // APPCACHE_SIGNATURE_ERROR is an evictable error | |
| 606 const char* kFormatString = "Failed to parse manifest %s"; | 629 const char* kFormatString = "Failed to parse manifest %s"; |
| 607 const std::string message = base::StringPrintf(kFormatString, | 630 const std::string message = base::StringPrintf(kFormatString, |
| 608 manifest_url_.spec().c_str()); | 631 manifest_url_.spec().c_str()); |
| 609 HandleCacheFailure( | 632 HandleCacheFailure( |
| 610 AppCacheErrorDetails( | 633 AppCacheErrorDetails( |
| 611 message, APPCACHE_SIGNATURE_ERROR, GURL(), 0, | 634 message, APPCACHE_SIGNATURE_ERROR, GURL(), 0, |
| 612 false /*is_cross_origin*/), | 635 false /*is_cross_origin*/), |
| 613 MANIFEST_ERROR, | 636 MANIFEST_ERROR, |
| 614 GURL()); | 637 GURL()); |
| 615 VLOG(1) << message; | 638 VLOG(1) << message; |
| (...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1621 | 1644 |
| 1622 // Break the connection with the group so the group cannot call delete | 1645 // Break the connection with the group so the group cannot call delete |
| 1623 // on this object after we've posted a task to delete ourselves. | 1646 // on this object after we've posted a task to delete ourselves. |
| 1624 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE); | 1647 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE); |
| 1625 group_ = NULL; | 1648 group_ = NULL; |
| 1626 | 1649 |
| 1627 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 1650 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 1628 } | 1651 } |
| 1629 | 1652 |
| 1630 } // namespace content | 1653 } // namespace content |
| OLD | NEW |