| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/cache_storage/cache_storage_dispatcher_host.h" | 5 #include "content/browser/cache_storage/cache_storage_dispatcher_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "base/time/time.h" |
| 15 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
| 16 #include "content/browser/bad_message.h" | 18 #include "content/browser/bad_message.h" |
| 17 #include "content/browser/cache_storage/cache_storage_cache.h" | 19 #include "content/browser/cache_storage/cache_storage_cache.h" |
| 18 #include "content/browser/cache_storage/cache_storage_cache_handle.h" | 20 #include "content/browser/cache_storage/cache_storage_cache_handle.h" |
| 19 #include "content/browser/cache_storage/cache_storage_context_impl.h" | 21 #include "content/browser/cache_storage/cache_storage_context_impl.h" |
| 20 #include "content/browser/cache_storage/cache_storage_manager.h" | 22 #include "content/browser/cache_storage/cache_storage_manager.h" |
| 21 #include "content/common/cache_storage/cache_storage_messages.h" | 23 #include "content/common/cache_storage/cache_storage_messages.h" |
| 22 #include "content/public/browser/content_browser_client.h" | 24 #include "content/public/browser/content_browser_client.h" |
| 23 #include "content/public/common/origin_util.h" | 25 #include "content/public/common/origin_util.h" |
| 24 #include "storage/browser/blob/blob_data_handle.h" | 26 #include "storage/browser/blob/blob_data_handle.h" |
| 25 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerCacheError.h" | 27 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerCacheError.h" |
| 26 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 27 #include "url/origin.h" | 29 #include "url/origin.h" |
| 28 | 30 |
| 29 namespace content { | 31 namespace content { |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| 32 | 34 |
| 33 const uint32_t kFilteredMessageClasses[] = {CacheStorageMsgStart}; | 35 const uint32_t kFilteredMessageClasses[] = {CacheStorageMsgStart}; |
| 36 const int32_t kCachePreservationSeconds = 5; |
| 34 | 37 |
| 35 blink::WebServiceWorkerCacheError ToWebServiceWorkerCacheError( | 38 blink::WebServiceWorkerCacheError ToWebServiceWorkerCacheError( |
| 36 CacheStorageError err) { | 39 CacheStorageError err) { |
| 37 switch (err) { | 40 switch (err) { |
| 38 case CACHE_STORAGE_OK: | 41 case CACHE_STORAGE_OK: |
| 39 NOTREACHED(); | 42 NOTREACHED(); |
| 40 return blink::WebServiceWorkerCacheErrorNotImplemented; | 43 return blink::WebServiceWorkerCacheErrorNotImplemented; |
| 41 case CACHE_STORAGE_ERROR_EXISTS: | 44 case CACHE_STORAGE_ERROR_EXISTS: |
| 42 return blink::WebServiceWorkerCacheErrorExists; | 45 return blink::WebServiceWorkerCacheErrorExists; |
| 43 case CACHE_STORAGE_ERROR_STORAGE: | 46 case CACHE_STORAGE_ERROR_STORAGE: |
| 44 // TODO(nhiroki): Add WebServiceWorkerCacheError equivalent to | 47 // TODO(nhiroki): Add WebServiceWorkerCacheError equivalent to |
| 45 // CACHE_STORAGE_ERROR_STORAGE. | 48 // CACHE_STORAGE_ERROR_STORAGE. |
| 46 return blink::WebServiceWorkerCacheErrorNotFound; | 49 return blink::WebServiceWorkerCacheErrorNotFound; |
| 47 case CACHE_STORAGE_ERROR_NOT_FOUND: | 50 case CACHE_STORAGE_ERROR_NOT_FOUND: |
| 48 return blink::WebServiceWorkerCacheErrorNotFound; | 51 return blink::WebServiceWorkerCacheErrorNotFound; |
| 49 case CACHE_STORAGE_ERROR_QUOTA_EXCEEDED: | 52 case CACHE_STORAGE_ERROR_QUOTA_EXCEEDED: |
| 50 return blink::WebServiceWorkerCacheErrorQuotaExceeded; | 53 return blink::WebServiceWorkerCacheErrorQuotaExceeded; |
| 51 case CACHE_STORAGE_ERROR_CACHE_NAME_NOT_FOUND: | 54 case CACHE_STORAGE_ERROR_CACHE_NAME_NOT_FOUND: |
| 52 return blink::WebServiceWorkerCacheErrorCacheNameNotFound; | 55 return blink::WebServiceWorkerCacheErrorCacheNameNotFound; |
| 53 } | 56 } |
| 54 NOTREACHED(); | 57 NOTREACHED(); |
| 55 return blink::WebServiceWorkerCacheErrorNotImplemented; | 58 return blink::WebServiceWorkerCacheErrorNotImplemented; |
| 56 } | 59 } |
| 57 | 60 |
| 58 bool OriginCanAccessCacheStorage(const url::Origin& origin) { | 61 bool OriginCanAccessCacheStorage(const url::Origin& origin) { |
| 59 return !origin.unique() && IsOriginSecure(GURL(origin.Serialize())); | 62 return !origin.unique() && IsOriginSecure(GURL(origin.Serialize())); |
| 60 } | 63 } |
| 61 | 64 |
| 65 void StopPreservingCache( |
| 66 std::unique_ptr<CacheStorageCacheHandle> cache_handle) {} |
| 67 |
| 62 } // namespace | 68 } // namespace |
| 63 | 69 |
| 64 CacheStorageDispatcherHost::CacheStorageDispatcherHost() | 70 CacheStorageDispatcherHost::CacheStorageDispatcherHost() |
| 65 : BrowserMessageFilter(kFilteredMessageClasses, | 71 : BrowserMessageFilter(kFilteredMessageClasses, |
| 66 arraysize(kFilteredMessageClasses)) { | 72 arraysize(kFilteredMessageClasses)) {} |
| 67 } | |
| 68 | 73 |
| 69 CacheStorageDispatcherHost::~CacheStorageDispatcherHost() { | 74 CacheStorageDispatcherHost::~CacheStorageDispatcherHost() { |
| 70 } | 75 } |
| 71 | 76 |
| 72 void CacheStorageDispatcherHost::Init(CacheStorageContextImpl* context) { | 77 void CacheStorageDispatcherHost::Init(CacheStorageContextImpl* context) { |
| 73 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 78 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 74 BrowserThread::PostTask( | 79 BrowserThread::PostTask( |
| 75 BrowserThread::IO, FROM_HERE, | 80 BrowserThread::IO, FROM_HERE, |
| 76 base::Bind(&CacheStorageDispatcherHost::CreateCacheListener, this, | 81 base::Bind(&CacheStorageDispatcherHost::CreateCacheListener, this, |
| 77 base::RetainedRef(context))); | 82 base::RetainedRef(context))); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 void CacheStorageDispatcherHost::OnCacheStorageOpenCallback( | 352 void CacheStorageDispatcherHost::OnCacheStorageOpenCallback( |
| 348 int thread_id, | 353 int thread_id, |
| 349 int request_id, | 354 int request_id, |
| 350 std::unique_ptr<CacheStorageCacheHandle> cache_handle, | 355 std::unique_ptr<CacheStorageCacheHandle> cache_handle, |
| 351 CacheStorageError error) { | 356 CacheStorageError error) { |
| 352 if (error != CACHE_STORAGE_OK) { | 357 if (error != CACHE_STORAGE_OK) { |
| 353 Send(new CacheStorageMsg_CacheStorageOpenError( | 358 Send(new CacheStorageMsg_CacheStorageOpenError( |
| 354 thread_id, request_id, ToWebServiceWorkerCacheError(error))); | 359 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
| 355 return; | 360 return; |
| 356 } | 361 } |
| 362 |
| 363 // Hang on to the cache for a few seconds. This way if the user quickly closes |
| 364 // and reopens it the cache backend won't have to be reinitialized. |
| 365 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 366 FROM_HERE, |
| 367 base::Bind(&StopPreservingCache, base::Passed(cache_handle->Clone())), |
| 368 base::TimeDelta::FromSeconds(kCachePreservationSeconds)); |
| 369 |
| 357 CacheID cache_id = StoreCacheReference(std::move(cache_handle)); | 370 CacheID cache_id = StoreCacheReference(std::move(cache_handle)); |
| 358 Send(new CacheStorageMsg_CacheStorageOpenSuccess(thread_id, request_id, | 371 Send(new CacheStorageMsg_CacheStorageOpenSuccess(thread_id, request_id, |
| 359 cache_id)); | 372 cache_id)); |
| 360 } | 373 } |
| 361 | 374 |
| 362 void CacheStorageDispatcherHost::OnCacheStorageDeleteCallback( | 375 void CacheStorageDispatcherHost::OnCacheStorageDeleteCallback( |
| 363 int thread_id, | 376 int thread_id, |
| 364 int request_id, | 377 int request_id, |
| 365 bool deleted, | 378 bool deleted, |
| 366 CacheStorageError error) { | 379 CacheStorageError error) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); | 545 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); |
| 533 if (it == blob_handle_store_.end()) | 546 if (it == blob_handle_store_.end()) |
| 534 return; | 547 return; |
| 535 DCHECK(!it->second.empty()); | 548 DCHECK(!it->second.empty()); |
| 536 it->second.pop_front(); | 549 it->second.pop_front(); |
| 537 if (it->second.empty()) | 550 if (it->second.empty()) |
| 538 blob_handle_store_.erase(it); | 551 blob_handle_store_.erase(it); |
| 539 } | 552 } |
| 540 | 553 |
| 541 } // namespace content | 554 } // namespace content |
| OLD | NEW |