| 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/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 } | 491 } |
| 492 | 492 |
| 493 BrowserThread::PostAfterStartupTask( | 493 BrowserThread::PostAfterStartupTask( |
| 494 FROM_HERE, base::ThreadTaskRunnerHandle::Get(), | 494 FROM_HERE, base::ThreadTaskRunnerHandle::Get(), |
| 495 base::Bind(&AppCacheUpdateJob::FetchManifest, weak_factory_.GetWeakPtr(), | 495 base::Bind(&AppCacheUpdateJob::FetchManifest, weak_factory_.GetWeakPtr(), |
| 496 true)); | 496 true)); |
| 497 } | 497 } |
| 498 | 498 |
| 499 AppCacheResponseWriter* AppCacheUpdateJob::CreateResponseWriter() { | 499 AppCacheResponseWriter* AppCacheUpdateJob::CreateResponseWriter() { |
| 500 AppCacheResponseWriter* writer = | 500 AppCacheResponseWriter* writer = |
| 501 storage_->CreateResponseWriter(manifest_url_, | 501 storage_->CreateResponseWriter(manifest_url_); |
| 502 group_->group_id()); | |
| 503 stored_response_ids_.push_back(writer->response_id()); | 502 stored_response_ids_.push_back(writer->response_id()); |
| 504 return writer; | 503 return writer; |
| 505 } | 504 } |
| 506 | 505 |
| 507 void AppCacheUpdateJob::HandleCacheFailure( | 506 void AppCacheUpdateJob::HandleCacheFailure( |
| 508 const AppCacheErrorDetails& error_details, | 507 const AppCacheErrorDetails& error_details, |
| 509 ResultType result, | 508 ResultType result, |
| 510 const GURL& failed_resource_url) { | 509 const GURL& failed_resource_url) { |
| 511 // 6.9.4 cache failure steps 2-8. | 510 // 6.9.4 cache failure steps 2-8. |
| 512 DCHECK(internal_state_ != CACHE_FAILURE); | 511 DCHECK(internal_state_ != CACHE_FAILURE); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 is_first_fetch ? URLFetcher::MANIFEST_FETCH : | 556 is_first_fetch ? URLFetcher::MANIFEST_FETCH : |
| 558 URLFetcher::MANIFEST_REFETCH, | 557 URLFetcher::MANIFEST_REFETCH, |
| 559 this); | 558 this); |
| 560 | 559 |
| 561 if (is_first_fetch) { | 560 if (is_first_fetch) { |
| 562 // Maybe load the cached headers to make a condiditional request. | 561 // Maybe load the cached headers to make a condiditional request. |
| 563 AppCacheEntry* entry = (update_type_ == UPGRADE_ATTEMPT) ? | 562 AppCacheEntry* entry = (update_type_ == UPGRADE_ATTEMPT) ? |
| 564 group_->newest_complete_cache()->GetEntry(manifest_url_) : NULL; | 563 group_->newest_complete_cache()->GetEntry(manifest_url_) : NULL; |
| 565 if (entry && !doing_full_update_check_) { | 564 if (entry && !doing_full_update_check_) { |
| 566 // Asynchronously load response info for manifest from newest cache. | 565 // Asynchronously load response info for manifest from newest cache. |
| 567 storage_->LoadResponseInfo(manifest_url_, group_->group_id(), | 566 storage_->LoadResponseInfo(manifest_url_, entry->response_id(), this); |
| 568 entry->response_id(), this); | |
| 569 return; | 567 return; |
| 570 } | 568 } |
| 571 manifest_fetcher_->Start(); | 569 manifest_fetcher_->Start(); |
| 572 return; | 570 return; |
| 573 } | 571 } |
| 574 | 572 |
| 575 DCHECK(internal_state_ == REFETCH_MANIFEST); | 573 DCHECK(internal_state_ == REFETCH_MANIFEST); |
| 576 DCHECK(manifest_response_info_.get()); | 574 DCHECK(manifest_response_info_.get()); |
| 577 manifest_fetcher_->set_existing_response_headers( | 575 manifest_fetcher_->set_existing_response_headers( |
| 578 manifest_response_info_->headers.get()); | 576 manifest_response_info_->headers.get()); |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1153 GURL()); | 1151 GURL()); |
| 1154 AppCacheHistograms::AddMissingManifestEntrySample(); | 1152 AppCacheHistograms::AddMissingManifestEntrySample(); |
| 1155 service->DeleteAppCacheGroup(manifest_url_, net::CompletionCallback()); | 1153 service->DeleteAppCacheGroup(manifest_url_, net::CompletionCallback()); |
| 1156 } | 1154 } |
| 1157 return; | 1155 return; |
| 1158 } | 1156 } |
| 1159 | 1157 |
| 1160 // Load manifest data from storage to compare against fetched manifest. | 1158 // Load manifest data from storage to compare against fetched manifest. |
| 1161 manifest_response_reader_.reset( | 1159 manifest_response_reader_.reset( |
| 1162 storage_->CreateResponseReader(manifest_url_, | 1160 storage_->CreateResponseReader(manifest_url_, |
| 1163 group_->group_id(), | |
| 1164 entry->response_id())); | 1161 entry->response_id())); |
| 1165 read_manifest_buffer_ = new net::IOBuffer(kBufferSize); | 1162 read_manifest_buffer_ = new net::IOBuffer(kBufferSize); |
| 1166 manifest_response_reader_->ReadData( | 1163 manifest_response_reader_->ReadData( |
| 1167 read_manifest_buffer_.get(), | 1164 read_manifest_buffer_.get(), |
| 1168 kBufferSize, | 1165 kBufferSize, |
| 1169 base::Bind(&AppCacheUpdateJob::OnManifestDataReadComplete, | 1166 base::Bind(&AppCacheUpdateJob::OnManifestDataReadComplete, |
| 1170 base::Unretained(this))); // async read | 1167 base::Unretained(this))); // async read |
| 1171 } | 1168 } |
| 1172 | 1169 |
| 1173 void AppCacheUpdateJob::OnManifestDataReadComplete(int result) { | 1170 void AppCacheUpdateJob::OnManifestDataReadComplete(int result) { |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1436 return false; | 1433 return false; |
| 1437 | 1434 |
| 1438 AppCache* newest = group_->newest_complete_cache(); | 1435 AppCache* newest = group_->newest_complete_cache(); |
| 1439 AppCacheEntry* copy_me = newest->GetEntry(url); | 1436 AppCacheEntry* copy_me = newest->GetEntry(url); |
| 1440 if (!copy_me || !copy_me->has_response_id()) | 1437 if (!copy_me || !copy_me->has_response_id()) |
| 1441 return false; | 1438 return false; |
| 1442 | 1439 |
| 1443 // Load HTTP headers for entry from newest cache. | 1440 // Load HTTP headers for entry from newest cache. |
| 1444 loading_responses_.insert( | 1441 loading_responses_.insert( |
| 1445 LoadingResponses::value_type(copy_me->response_id(), url)); | 1442 LoadingResponses::value_type(copy_me->response_id(), url)); |
| 1446 storage_->LoadResponseInfo(manifest_url_, group_->group_id(), | 1443 storage_->LoadResponseInfo(manifest_url_, copy_me->response_id(), this); |
| 1447 copy_me->response_id(), | |
| 1448 this); | |
| 1449 // Async: wait for OnResponseInfoLoaded to complete. | 1444 // Async: wait for OnResponseInfoLoaded to complete. |
| 1450 return true; | 1445 return true; |
| 1451 } | 1446 } |
| 1452 | 1447 |
| 1453 void AppCacheUpdateJob::OnResponseInfoLoaded( | 1448 void AppCacheUpdateJob::OnResponseInfoLoaded( |
| 1454 AppCacheResponseInfo* response_info, | 1449 AppCacheResponseInfo* response_info, |
| 1455 int64_t response_id) { | 1450 int64_t response_id) { |
| 1456 const net::HttpResponseInfo* http_info = response_info ? | 1451 const net::HttpResponseInfo* http_info = response_info ? |
| 1457 response_info->http_response_info() : NULL; | 1452 response_info->http_response_info() : NULL; |
| 1458 | 1453 |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1711 // on this object after we've posted a task to delete ourselves. | 1706 // on this object after we've posted a task to delete ourselves. |
| 1712 if (group_) { | 1707 if (group_) { |
| 1713 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE); | 1708 group_->SetUpdateAppCacheStatus(AppCacheGroup::IDLE); |
| 1714 group_ = NULL; | 1709 group_ = NULL; |
| 1715 } | 1710 } |
| 1716 | 1711 |
| 1717 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 1712 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 1718 } | 1713 } |
| 1719 | 1714 |
| 1720 } // namespace content | 1715 } // namespace content |
| OLD | NEW |