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 "webkit/browser/appcache/appcache_update_job.h" | 5 #include "webkit/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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 AppCacheUpdateJob::AppCacheUpdateJob(AppCacheService* service, | 332 AppCacheUpdateJob::AppCacheUpdateJob(AppCacheService* service, |
333 AppCacheGroup* group) | 333 AppCacheGroup* group) |
334 : service_(service), | 334 : service_(service), |
335 manifest_url_(group->manifest_url()), | 335 manifest_url_(group->manifest_url()), |
336 group_(group), | 336 group_(group), |
337 update_type_(UNKNOWN_TYPE), | 337 update_type_(UNKNOWN_TYPE), |
338 internal_state_(FETCH_MANIFEST), | 338 internal_state_(FETCH_MANIFEST), |
339 master_entries_completed_(0), | 339 master_entries_completed_(0), |
340 url_fetches_completed_(0), | 340 url_fetches_completed_(0), |
341 manifest_fetcher_(NULL), | 341 manifest_fetcher_(NULL), |
342 manifest_has_valid_mime_type_(false), | |
342 stored_state_(UNSTORED), | 343 stored_state_(UNSTORED), |
343 storage_(service->storage()) { | 344 storage_(service->storage()) { |
344 service_->AddObserver(this); | 345 service_->AddObserver(this); |
345 } | 346 } |
346 | 347 |
347 AppCacheUpdateJob::~AppCacheUpdateJob() { | 348 AppCacheUpdateJob::~AppCacheUpdateJob() { |
348 if (service_) | 349 if (service_) |
349 service_->RemoveObserver(this); | 350 service_->RemoveObserver(this); |
350 if (internal_state_ != COMPLETED) | 351 if (internal_state_ != COMPLETED) |
351 Cancel(); | 352 Cancel(); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
482 DCHECK_EQ(internal_state_, FETCH_MANIFEST); | 483 DCHECK_EQ(internal_state_, FETCH_MANIFEST); |
483 DCHECK_EQ(manifest_fetcher_, fetcher); | 484 DCHECK_EQ(manifest_fetcher_, fetcher); |
484 manifest_fetcher_ = NULL; | 485 manifest_fetcher_ = NULL; |
485 | 486 |
486 net::URLRequest* request = fetcher->request(); | 487 net::URLRequest* request = fetcher->request(); |
487 int response_code = -1; | 488 int response_code = -1; |
488 bool is_valid_response_code = false; | 489 bool is_valid_response_code = false; |
489 if (request->status().is_success()) { | 490 if (request->status().is_success()) { |
490 response_code = request->GetResponseCode(); | 491 response_code = request->GetResponseCode(); |
491 is_valid_response_code = (response_code / 100 == 2); | 492 is_valid_response_code = (response_code / 100 == 2); |
493 | |
494 std::string mime_type; | |
495 request->GetMimeType(&mime_type); | |
496 const char kManifestMimeType[] = "text/cache-manifest"; | |
497 manifest_has_valid_mime_type_ = (mime_type == kManifestMimeType); | |
darin (slow to review)
2014/05/12 23:45:32
nit: I probably wouldn't have bothered with the na
| |
492 } | 498 } |
493 | 499 |
494 if (is_valid_response_code) { | 500 if (is_valid_response_code) { |
495 manifest_data_ = fetcher->manifest_data(); | 501 manifest_data_ = fetcher->manifest_data(); |
496 manifest_response_info_.reset( | 502 manifest_response_info_.reset( |
497 new net::HttpResponseInfo(request->response_info())); | 503 new net::HttpResponseInfo(request->response_info())); |
498 if (update_type_ == UPGRADE_ATTEMPT) | 504 if (update_type_ == UPGRADE_ATTEMPT) |
499 CheckIfManifestChanged(); // continues asynchronously | 505 CheckIfManifestChanged(); // continues asynchronously |
500 else | 506 else |
501 ContinueHandleManifestFetchCompleted(true); | 507 ContinueHandleManifestFetchCompleted(true); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
554 internal_state_ = NO_UPDATE; | 560 internal_state_ = NO_UPDATE; |
555 | 561 |
556 // Wait for pending master entries to download. | 562 // Wait for pending master entries to download. |
557 FetchMasterEntries(); | 563 FetchMasterEntries(); |
558 MaybeCompleteUpdate(); // if not done, run async 6.9.4 step 7 substeps | 564 MaybeCompleteUpdate(); // if not done, run async 6.9.4 step 7 substeps |
559 return; | 565 return; |
560 } | 566 } |
561 | 567 |
562 Manifest manifest; | 568 Manifest manifest; |
563 if (!ParseManifest(manifest_url_, manifest_data_.data(), | 569 if (!ParseManifest(manifest_url_, manifest_data_.data(), |
564 manifest_data_.length(), manifest)) { | 570 manifest_data_.length(), manifest_has_valid_mime_type_, |
571 manifest)) { | |
565 const char* kFormatString = "Failed to parse manifest %s"; | 572 const char* kFormatString = "Failed to parse manifest %s"; |
566 const std::string message = base::StringPrintf(kFormatString, | 573 const std::string message = base::StringPrintf(kFormatString, |
567 manifest_url_.spec().c_str()); | 574 manifest_url_.spec().c_str()); |
568 HandleCacheFailure( | 575 HandleCacheFailure( |
569 ErrorDetails( | 576 ErrorDetails( |
570 message, SIGNATURE_ERROR, GURL(), 0, false /*is_cross_origin*/), | 577 message, SIGNATURE_ERROR, GURL(), 0, false /*is_cross_origin*/), |
571 MANIFEST_ERROR, | 578 MANIFEST_ERROR, |
572 GURL()); | 579 GURL()); |
573 VLOG(1) << message; | 580 VLOG(1) << message; |
574 return; | 581 return; |
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1562 | 1569 |
1563 // Break the connection with the group so the group cannot call delete | 1570 // Break the connection with the group so the group cannot call delete |
1564 // on this object after we've posted a task to delete ourselves. | 1571 // on this object after we've posted a task to delete ourselves. |
1565 group_->SetUpdateStatus(AppCacheGroup::IDLE); | 1572 group_->SetUpdateStatus(AppCacheGroup::IDLE); |
1566 group_ = NULL; | 1573 group_ = NULL; |
1567 | 1574 |
1568 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 1575 base::MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
1569 } | 1576 } |
1570 | 1577 |
1571 } // namespace appcache | 1578 } // namespace appcache |
OLD | NEW |