| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/appcache/appcache_update_job.h" | 5 #include "webkit/appcache/appcache_update_job.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 if (!new_master_resource.is_empty()) { | 375 if (!new_master_resource.is_empty()) { |
| 376 AddMasterEntryToFetchList(host, new_master_resource, | 376 AddMasterEntryToFetchList(host, new_master_resource, |
| 377 is_new_pending_master_entry); | 377 is_new_pending_master_entry); |
| 378 } | 378 } |
| 379 | 379 |
| 380 FetchManifest(true); | 380 FetchManifest(true); |
| 381 } | 381 } |
| 382 | 382 |
| 383 AppCacheResponseWriter* AppCacheUpdateJob::CreateResponseWriter() { | 383 AppCacheResponseWriter* AppCacheUpdateJob::CreateResponseWriter() { |
| 384 AppCacheResponseWriter* writer = | 384 AppCacheResponseWriter* writer = |
| 385 service_->storage()->CreateResponseWriter(manifest_url_); | 385 service_->storage()->CreateResponseWriter(manifest_url_, |
| 386 group_->group_id()); |
| 386 stored_response_ids_.push_back(writer->response_id()); | 387 stored_response_ids_.push_back(writer->response_id()); |
| 387 return writer; | 388 return writer; |
| 388 } | 389 } |
| 389 | 390 |
| 390 void AppCacheUpdateJob::HandleCacheFailure(const std::string& error_message) { | 391 void AppCacheUpdateJob::HandleCacheFailure(const std::string& error_message) { |
| 391 // 6.9.4 cache failure steps 2-8. | 392 // 6.9.4 cache failure steps 2-8. |
| 392 DCHECK(internal_state_ != CACHE_FAILURE); | 393 DCHECK(internal_state_ != CACHE_FAILURE); |
| 393 DCHECK(!error_message.empty()); | 394 DCHECK(!error_message.empty()); |
| 394 internal_state_ = CACHE_FAILURE; | 395 internal_state_ = CACHE_FAILURE; |
| 395 CancelAllUrlFetches(); | 396 CancelAllUrlFetches(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 407 is_first_fetch ? URLFetcher::MANIFEST_FETCH : | 408 is_first_fetch ? URLFetcher::MANIFEST_FETCH : |
| 408 URLFetcher::MANIFEST_REFETCH, | 409 URLFetcher::MANIFEST_REFETCH, |
| 409 this); | 410 this); |
| 410 | 411 |
| 411 // Add any necessary Http headers before sending fetch request. | 412 // Add any necessary Http headers before sending fetch request. |
| 412 if (is_first_fetch) { | 413 if (is_first_fetch) { |
| 413 AppCacheEntry* entry = (update_type_ == UPGRADE_ATTEMPT) ? | 414 AppCacheEntry* entry = (update_type_ == UPGRADE_ATTEMPT) ? |
| 414 group_->newest_complete_cache()->GetEntry(manifest_url_) : NULL; | 415 group_->newest_complete_cache()->GetEntry(manifest_url_) : NULL; |
| 415 if (entry) { | 416 if (entry) { |
| 416 // Asynchronously load response info for manifest from newest cache. | 417 // Asynchronously load response info for manifest from newest cache. |
| 417 service_->storage()->LoadResponseInfo(manifest_url_, | 418 service_->storage()->LoadResponseInfo(manifest_url_, group_->group_id(), |
| 418 entry->response_id(), this); | 419 entry->response_id(), this); |
| 419 } else { | 420 } else { |
| 420 manifest_fetcher_->Start(); | 421 manifest_fetcher_->Start(); |
| 421 } | 422 } |
| 422 } else { | 423 } else { |
| 423 DCHECK(internal_state_ == REFETCH_MANIFEST); | 424 DCHECK(internal_state_ == REFETCH_MANIFEST); |
| 424 DCHECK(manifest_response_info_.get()); | 425 DCHECK(manifest_response_info_.get()); |
| 425 manifest_fetcher_->set_existing_response_headers( | 426 manifest_fetcher_->set_existing_response_headers( |
| 426 manifest_response_info_->headers); | 427 manifest_response_info_->headers); |
| 427 manifest_fetcher_->Start(); | 428 manifest_fetcher_->Start(); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 AppCacheEntry& entry = url_file_list_.find(url)->second; | 555 AppCacheEntry& entry = url_file_list_.find(url)->second; |
| 555 | 556 |
| 556 if (response_code / 100 == 2) { | 557 if (response_code / 100 == 2) { |
| 557 // Associate storage with the new entry. | 558 // Associate storage with the new entry. |
| 558 DCHECK(fetcher->response_writer()); | 559 DCHECK(fetcher->response_writer()); |
| 559 entry.set_response_id(fetcher->response_writer()->response_id()); | 560 entry.set_response_id(fetcher->response_writer()->response_id()); |
| 560 entry.set_response_size(fetcher->response_writer()->amount_written()); | 561 entry.set_response_size(fetcher->response_writer()->amount_written()); |
| 561 if (!inprogress_cache_->AddOrModifyEntry(url, entry)) | 562 if (!inprogress_cache_->AddOrModifyEntry(url, entry)) |
| 562 duplicate_response_ids_.push_back(entry.response_id()); | 563 duplicate_response_ids_.push_back(entry.response_id()); |
| 563 | 564 |
| 565 // TODO(michaeln): Check for <html manifest=xxx> |
| 566 // See http://code.google.com/p/chromium/issues/detail?id=97930 |
| 567 // if (entry.IsMaster() && !entry.IsExplicit()) |
| 568 // if (!manifestAttribute) skip it |
| 569 |
| 564 // Foreign entries will be detected during cache selection. | 570 // Foreign entries will be detected during cache selection. |
| 565 // Note: 6.9.4, step 17.9 possible optimization: if resource is HTML or XML | 571 // Note: 6.9.4, step 17.9 possible optimization: if resource is HTML or XML |
| 566 // file whose root element is an html element with a manifest attribute | 572 // file whose root element is an html element with a manifest attribute |
| 567 // whose value doesn't match the manifest url of the application cache | 573 // whose value doesn't match the manifest url of the application cache |
| 568 // being processed, mark the entry as being foreign. | 574 // being processed, mark the entry as being foreign. |
| 569 } else { | 575 } else { |
| 570 VLOG(1) << "Request status: " << request->status().status() | 576 VLOG(1) << "Request status: " << request->status().status() |
| 571 << " error: " << request->status().error() | 577 << " error: " << request->status().error() |
| 572 << " response code: " << response_code; | 578 << " response code: " << response_code; |
| 573 if (entry.IsExplicit() || entry.IsFallback()) { | 579 if (entry.IsExplicit() || entry.IsFallback()) { |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 | 847 |
| 842 void AppCacheUpdateJob::CheckIfManifestChanged() { | 848 void AppCacheUpdateJob::CheckIfManifestChanged() { |
| 843 DCHECK(update_type_ == UPGRADE_ATTEMPT); | 849 DCHECK(update_type_ == UPGRADE_ATTEMPT); |
| 844 AppCacheEntry* entry = | 850 AppCacheEntry* entry = |
| 845 group_->newest_complete_cache()->GetEntry(manifest_url_); | 851 group_->newest_complete_cache()->GetEntry(manifest_url_); |
| 846 DCHECK(entry); | 852 DCHECK(entry); |
| 847 | 853 |
| 848 // Load manifest data from storage to compare against fetched manifest. | 854 // Load manifest data from storage to compare against fetched manifest. |
| 849 manifest_response_reader_.reset( | 855 manifest_response_reader_.reset( |
| 850 service_->storage()->CreateResponseReader(manifest_url_, | 856 service_->storage()->CreateResponseReader(manifest_url_, |
| 857 group_->group_id(), |
| 851 entry->response_id())); | 858 entry->response_id())); |
| 852 read_manifest_buffer_ = new net::IOBuffer(kBufferSize); | 859 read_manifest_buffer_ = new net::IOBuffer(kBufferSize); |
| 853 manifest_response_reader_->ReadData(read_manifest_buffer_, kBufferSize, | 860 manifest_response_reader_->ReadData(read_manifest_buffer_, kBufferSize, |
| 854 &manifest_data_read_callback_); // async read | 861 &manifest_data_read_callback_); // async read |
| 855 } | 862 } |
| 856 | 863 |
| 857 void AppCacheUpdateJob::OnManifestDataReadComplete(int result) { | 864 void AppCacheUpdateJob::OnManifestDataReadComplete(int result) { |
| 858 if (result > 0) { | 865 if (result > 0) { |
| 859 loaded_manifest_data_.append(read_manifest_buffer_->data(), result); | 866 loaded_manifest_data_.append(read_manifest_buffer_->data(), result); |
| 860 manifest_response_reader_->ReadData(read_manifest_buffer_, kBufferSize, | 867 manifest_response_reader_->ReadData(read_manifest_buffer_, kBufferSize, |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 return false; | 1111 return false; |
| 1105 | 1112 |
| 1106 AppCache* newest = group_->newest_complete_cache(); | 1113 AppCache* newest = group_->newest_complete_cache(); |
| 1107 AppCacheEntry* copy_me = newest->GetEntry(url); | 1114 AppCacheEntry* copy_me = newest->GetEntry(url); |
| 1108 if (!copy_me || !copy_me->has_response_id()) | 1115 if (!copy_me || !copy_me->has_response_id()) |
| 1109 return false; | 1116 return false; |
| 1110 | 1117 |
| 1111 // Load HTTP headers for entry from newest cache. | 1118 // Load HTTP headers for entry from newest cache. |
| 1112 loading_responses_.insert( | 1119 loading_responses_.insert( |
| 1113 LoadingResponses::value_type(copy_me->response_id(), url)); | 1120 LoadingResponses::value_type(copy_me->response_id(), url)); |
| 1114 service_->storage()->LoadResponseInfo(manifest_url_, copy_me->response_id(), | 1121 service_->storage()->LoadResponseInfo(manifest_url_, group_->group_id(), |
| 1122 copy_me->response_id(), |
| 1115 this); | 1123 this); |
| 1116 // Async: wait for OnResponseInfoLoaded to complete. | 1124 // Async: wait for OnResponseInfoLoaded to complete. |
| 1117 return true; | 1125 return true; |
| 1118 } | 1126 } |
| 1119 | 1127 |
| 1120 void AppCacheUpdateJob::OnResponseInfoLoaded( | 1128 void AppCacheUpdateJob::OnResponseInfoLoaded( |
| 1121 AppCacheResponseInfo* response_info, int64 response_id) { | 1129 AppCacheResponseInfo* response_info, int64 response_id) { |
| 1122 const net::HttpResponseInfo* http_info = response_info ? | 1130 const net::HttpResponseInfo* http_info = response_info ? |
| 1123 response_info->http_response_info() : NULL; | 1131 response_info->http_response_info() : NULL; |
| 1124 | 1132 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 | 1322 |
| 1315 // Break the connection with the group so the group cannot call delete | 1323 // Break the connection with the group so the group cannot call delete |
| 1316 // on this object after we've posted a task to delete ourselves. | 1324 // on this object after we've posted a task to delete ourselves. |
| 1317 group_->SetUpdateStatus(AppCacheGroup::IDLE); | 1325 group_->SetUpdateStatus(AppCacheGroup::IDLE); |
| 1318 group_ = NULL; | 1326 group_ = NULL; |
| 1319 | 1327 |
| 1320 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 1328 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 1321 } | 1329 } |
| 1322 | 1330 |
| 1323 } // namespace appcache | 1331 } // namespace appcache |
| OLD | NEW |