| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_service_impl.h" | 5 #include "content/browser/appcache/appcache_service_impl.h" |
| 6 | 6 |
| 7 #include <functional> | 7 #include <functional> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 void AppCacheServiceImpl::AsyncHelper::Cancel() { | 77 void AppCacheServiceImpl::AsyncHelper::Cancel() { |
| 78 if (!callback_.is_null()) { | 78 if (!callback_.is_null()) { |
| 79 callback_.Run(net::ERR_ABORTED); | 79 callback_.Run(net::ERR_ABORTED); |
| 80 callback_.Reset(); | 80 callback_.Reset(); |
| 81 } | 81 } |
| 82 service_->storage()->CancelDelegateCallbacks(this); | 82 service_->storage()->CancelDelegateCallbacks(this); |
| 83 service_ = NULL; | 83 service_ = NULL; |
| 84 } | 84 } |
| 85 | 85 |
| 86 // CanHandleOfflineHelper ------- | |
| 87 | |
| 88 class AppCacheServiceImpl::CanHandleOfflineHelper : AsyncHelper { | |
| 89 public: | |
| 90 CanHandleOfflineHelper( | |
| 91 AppCacheServiceImpl* service, const GURL& url, | |
| 92 const GURL& first_party, const net::CompletionCallback& callback) | |
| 93 : AsyncHelper(service, callback), | |
| 94 url_(url), | |
| 95 first_party_(first_party) { | |
| 96 } | |
| 97 | |
| 98 void Start() override { | |
| 99 AppCachePolicy* policy = service_->appcache_policy(); | |
| 100 if (policy && !policy->CanLoadAppCache(url_, first_party_)) { | |
| 101 CallCallback(net::ERR_FAILED); | |
| 102 delete this; | |
| 103 return; | |
| 104 } | |
| 105 | |
| 106 service_->storage()->FindResponseForMainRequest(url_, GURL(), this); | |
| 107 } | |
| 108 | |
| 109 private: | |
| 110 // AppCacheStorage::Delegate implementation. | |
| 111 void OnMainResponseFound(const GURL& url, | |
| 112 const AppCacheEntry& entry, | |
| 113 const GURL& fallback_url, | |
| 114 const AppCacheEntry& fallback_entry, | |
| 115 int64 cache_id, | |
| 116 int64 group_id, | |
| 117 const GURL& mainfest_url) override; | |
| 118 | |
| 119 GURL url_; | |
| 120 GURL first_party_; | |
| 121 | |
| 122 DISALLOW_COPY_AND_ASSIGN(CanHandleOfflineHelper); | |
| 123 }; | |
| 124 | |
| 125 void AppCacheServiceImpl::CanHandleOfflineHelper::OnMainResponseFound( | |
| 126 const GURL& url, const AppCacheEntry& entry, | |
| 127 const GURL& fallback_url, const AppCacheEntry& fallback_entry, | |
| 128 int64 cache_id, int64 group_id, const GURL& manifest_url) { | |
| 129 bool can = (entry.has_response_id() || fallback_entry.has_response_id()); | |
| 130 CallCallback(can ? net::OK : net::ERR_FAILED); | |
| 131 delete this; | |
| 132 } | |
| 133 | |
| 134 // DeleteHelper ------- | 86 // DeleteHelper ------- |
| 135 | 87 |
| 136 class AppCacheServiceImpl::DeleteHelper : public AsyncHelper { | 88 class AppCacheServiceImpl::DeleteHelper : public AsyncHelper { |
| 137 public: | 89 public: |
| 138 DeleteHelper( | 90 DeleteHelper( |
| 139 AppCacheServiceImpl* service, const GURL& manifest_url, | 91 AppCacheServiceImpl* service, const GURL& manifest_url, |
| 140 const net::CompletionCallback& callback) | 92 const net::CompletionCallback& callback) |
| 141 : AsyncHelper(service, callback), manifest_url_(manifest_url) { | 93 : AsyncHelper(service, callback), manifest_url_(manifest_url) { |
| 142 } | 94 } |
| 143 | 95 |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 // Inform observers of about this and give them a chance to | 469 // Inform observers of about this and give them a chance to |
| 518 // defer deletion of the old storage object. | 470 // defer deletion of the old storage object. |
| 519 scoped_refptr<AppCacheStorageReference> | 471 scoped_refptr<AppCacheStorageReference> |
| 520 old_storage_ref(new AppCacheStorageReference(storage_.Pass())); | 472 old_storage_ref(new AppCacheStorageReference(storage_.Pass())); |
| 521 FOR_EACH_OBSERVER(Observer, observers_, | 473 FOR_EACH_OBSERVER(Observer, observers_, |
| 522 OnServiceReinitialized(old_storage_ref.get())); | 474 OnServiceReinitialized(old_storage_ref.get())); |
| 523 | 475 |
| 524 Initialize(cache_directory_, db_thread_, cache_thread_); | 476 Initialize(cache_directory_, db_thread_, cache_thread_); |
| 525 } | 477 } |
| 526 | 478 |
| 527 void AppCacheServiceImpl::CanHandleMainResourceOffline( | |
| 528 const GURL& url, | |
| 529 const GURL& first_party, | |
| 530 const net::CompletionCallback& callback) { | |
| 531 CanHandleOfflineHelper* helper = | |
| 532 new CanHandleOfflineHelper(this, url, first_party, callback); | |
| 533 helper->Start(); | |
| 534 } | |
| 535 | |
| 536 void AppCacheServiceImpl::GetAllAppCacheInfo( | 479 void AppCacheServiceImpl::GetAllAppCacheInfo( |
| 537 AppCacheInfoCollection* collection, | 480 AppCacheInfoCollection* collection, |
| 538 const net::CompletionCallback& callback) { | 481 const net::CompletionCallback& callback) { |
| 539 DCHECK(collection); | 482 DCHECK(collection); |
| 540 GetInfoHelper* helper = new GetInfoHelper(this, collection, callback); | 483 GetInfoHelper* helper = new GetInfoHelper(this, collection, callback); |
| 541 helper->Start(); | 484 helper->Start(); |
| 542 } | 485 } |
| 543 | 486 |
| 544 void AppCacheServiceImpl::DeleteAppCacheGroup( | 487 void AppCacheServiceImpl::DeleteAppCacheGroup( |
| 545 const GURL& manifest_url, | 488 const GURL& manifest_url, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 573 backends_.insert( | 516 backends_.insert( |
| 574 BackendMap::value_type(backend_impl->process_id(), backend_impl)); | 517 BackendMap::value_type(backend_impl->process_id(), backend_impl)); |
| 575 } | 518 } |
| 576 | 519 |
| 577 void AppCacheServiceImpl::UnregisterBackend( | 520 void AppCacheServiceImpl::UnregisterBackend( |
| 578 AppCacheBackendImpl* backend_impl) { | 521 AppCacheBackendImpl* backend_impl) { |
| 579 backends_.erase(backend_impl->process_id()); | 522 backends_.erase(backend_impl->process_id()); |
| 580 } | 523 } |
| 581 | 524 |
| 582 } // namespace content | 525 } // namespace content |
| OLD | NEW |