| 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" | |
| 15 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
| 16 #include "content/browser/bad_message.h" | 15 #include "content/browser/bad_message.h" |
| 17 #include "content/browser/cache_storage/cache_storage_cache.h" | 16 #include "content/browser/cache_storage/cache_storage_cache.h" |
| 18 #include "content/browser/cache_storage/cache_storage_context_impl.h" | 17 #include "content/browser/cache_storage/cache_storage_context_impl.h" |
| 19 #include "content/browser/cache_storage/cache_storage_manager.h" | 18 #include "content/browser/cache_storage/cache_storage_manager.h" |
| 20 #include "content/common/cache_storage/cache_storage_messages.h" | 19 #include "content/common/cache_storage/cache_storage_messages.h" |
| 21 #include "content/public/browser/content_browser_client.h" | 20 #include "content/public/browser/content_browser_client.h" |
| 22 #include "content/public/common/origin_util.h" | 21 #include "content/public/common/origin_util.h" |
| 23 #include "storage/browser/blob/blob_data_handle.h" | 22 #include "storage/browser/blob/blob_data_handle.h" |
| 24 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerCacheError.h" | 23 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerCacheError.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 int thread_id, | 114 int thread_id, |
| 116 int request_id, | 115 int request_id, |
| 117 const GURL& origin, | 116 const GURL& origin, |
| 118 const base::string16& cache_name) { | 117 const base::string16& cache_name) { |
| 119 TRACE_EVENT0("CacheStorage", "CacheStorageDispatcherHost::OnCacheStorageHas"); | 118 TRACE_EVENT0("CacheStorage", "CacheStorageDispatcherHost::OnCacheStorageHas"); |
| 120 if (!OriginCanAccessCacheStorage(origin)) { | 119 if (!OriginCanAccessCacheStorage(origin)) { |
| 121 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); | 120 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); |
| 122 return; | 121 return; |
| 123 } | 122 } |
| 124 context_->cache_manager()->HasCache( | 123 context_->cache_manager()->HasCache( |
| 125 origin, base::UTF16ToUTF8(cache_name), | 124 origin, cache_name, |
| 126 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageHasCallback, this, | 125 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageHasCallback, this, |
| 127 thread_id, request_id)); | 126 thread_id, request_id)); |
| 128 } | 127 } |
| 129 | 128 |
| 130 void CacheStorageDispatcherHost::OnCacheStorageOpen( | 129 void CacheStorageDispatcherHost::OnCacheStorageOpen( |
| 131 int thread_id, | 130 int thread_id, |
| 132 int request_id, | 131 int request_id, |
| 133 const GURL& origin, | 132 const GURL& origin, |
| 134 const base::string16& cache_name) { | 133 const base::string16& cache_name) { |
| 135 TRACE_EVENT0("CacheStorage", | 134 TRACE_EVENT0("CacheStorage", |
| 136 "CacheStorageDispatcherHost::OnCacheStorageOpen"); | 135 "CacheStorageDispatcherHost::OnCacheStorageOpen"); |
| 137 if (!OriginCanAccessCacheStorage(origin)) { | 136 if (!OriginCanAccessCacheStorage(origin)) { |
| 138 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); | 137 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); |
| 139 return; | 138 return; |
| 140 } | 139 } |
| 141 context_->cache_manager()->OpenCache( | 140 context_->cache_manager()->OpenCache( |
| 142 origin, base::UTF16ToUTF8(cache_name), | 141 origin, cache_name, |
| 143 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageOpenCallback, this, | 142 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageOpenCallback, this, |
| 144 thread_id, request_id)); | 143 thread_id, request_id)); |
| 145 } | 144 } |
| 146 | 145 |
| 147 void CacheStorageDispatcherHost::OnCacheStorageDelete( | 146 void CacheStorageDispatcherHost::OnCacheStorageDelete( |
| 148 int thread_id, | 147 int thread_id, |
| 149 int request_id, | 148 int request_id, |
| 150 const GURL& origin, | 149 const GURL& origin, |
| 151 const base::string16& cache_name) { | 150 const base::string16& cache_name) { |
| 152 TRACE_EVENT0("CacheStorage", | 151 TRACE_EVENT0("CacheStorage", |
| 153 "CacheStorageDispatcherHost::OnCacheStorageDelete"); | 152 "CacheStorageDispatcherHost::OnCacheStorageDelete"); |
| 154 if (!OriginCanAccessCacheStorage(origin)) { | 153 if (!OriginCanAccessCacheStorage(origin)) { |
| 155 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); | 154 bad_message::ReceivedBadMessage(this, bad_message::CSDH_INVALID_ORIGIN); |
| 156 return; | 155 return; |
| 157 } | 156 } |
| 158 context_->cache_manager()->DeleteCache( | 157 context_->cache_manager()->DeleteCache( |
| 159 origin, base::UTF16ToUTF8(cache_name), | 158 origin, cache_name, |
| 160 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageDeleteCallback, | 159 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageDeleteCallback, |
| 161 this, thread_id, request_id)); | 160 this, thread_id, request_id)); |
| 162 } | 161 } |
| 163 | 162 |
| 164 void CacheStorageDispatcherHost::OnCacheStorageKeys(int thread_id, | 163 void CacheStorageDispatcherHost::OnCacheStorageKeys(int thread_id, |
| 165 int request_id, | 164 int request_id, |
| 166 const GURL& origin) { | 165 const GURL& origin) { |
| 167 TRACE_EVENT0("CacheStorage", | 166 TRACE_EVENT0("CacheStorage", |
| 168 "CacheStorageDispatcherHost::OnCacheStorageKeys"); | 167 "CacheStorageDispatcherHost::OnCacheStorageKeys"); |
| 169 if (!OriginCanAccessCacheStorage(origin)) { | 168 if (!OriginCanAccessCacheStorage(origin)) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 194 request.is_reload)); | 193 request.is_reload)); |
| 195 | 194 |
| 196 if (match_params.cache_name.empty()) { | 195 if (match_params.cache_name.empty()) { |
| 197 context_->cache_manager()->MatchAllCaches( | 196 context_->cache_manager()->MatchAllCaches( |
| 198 origin, std::move(scoped_request), | 197 origin, std::move(scoped_request), |
| 199 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, | 198 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, |
| 200 this, thread_id, request_id)); | 199 this, thread_id, request_id)); |
| 201 return; | 200 return; |
| 202 } | 201 } |
| 203 context_->cache_manager()->MatchCache( | 202 context_->cache_manager()->MatchCache( |
| 204 origin, base::UTF16ToUTF8(match_params.cache_name), | 203 origin, match_params.cache_name, std::move(scoped_request), |
| 205 std::move(scoped_request), | |
| 206 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, this, | 204 base::Bind(&CacheStorageDispatcherHost::OnCacheStorageMatchCallback, this, |
| 207 thread_id, request_id)); | 205 thread_id, request_id)); |
| 208 } | 206 } |
| 209 | 207 |
| 210 void CacheStorageDispatcherHost::OnCacheMatch( | 208 void CacheStorageDispatcherHost::OnCacheMatch( |
| 211 int thread_id, | 209 int thread_id, |
| 212 int request_id, | 210 int request_id, |
| 213 int cache_id, | 211 int cache_id, |
| 214 const ServiceWorkerFetchRequest& request, | 212 const ServiceWorkerFetchRequest& request, |
| 215 const CacheStorageCacheQueryParams& match_params) { | 213 const CacheStorageCacheQueryParams& match_params) { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 Send(new CacheStorageMsg_CacheStorageDeleteError( | 353 Send(new CacheStorageMsg_CacheStorageDeleteError( |
| 356 thread_id, request_id, ToWebServiceWorkerCacheError(error))); | 354 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
| 357 return; | 355 return; |
| 358 } | 356 } |
| 359 Send(new CacheStorageMsg_CacheStorageDeleteSuccess(thread_id, request_id)); | 357 Send(new CacheStorageMsg_CacheStorageDeleteSuccess(thread_id, request_id)); |
| 360 } | 358 } |
| 361 | 359 |
| 362 void CacheStorageDispatcherHost::OnCacheStorageKeysCallback( | 360 void CacheStorageDispatcherHost::OnCacheStorageKeysCallback( |
| 363 int thread_id, | 361 int thread_id, |
| 364 int request_id, | 362 int request_id, |
| 365 const std::vector<std::string>& strings, | 363 const std::vector<base::string16>& cache_names, |
| 366 CacheStorageError error) { | 364 CacheStorageError error) { |
| 367 if (error != CACHE_STORAGE_OK) { | 365 if (error != CACHE_STORAGE_OK) { |
| 368 Send(new CacheStorageMsg_CacheStorageKeysError( | 366 Send(new CacheStorageMsg_CacheStorageKeysError( |
| 369 thread_id, request_id, ToWebServiceWorkerCacheError(error))); | 367 thread_id, request_id, ToWebServiceWorkerCacheError(error))); |
| 370 return; | 368 return; |
| 371 } | 369 } |
| 372 | 370 |
| 373 std::vector<base::string16> string16s; | |
| 374 for (size_t i = 0, max = strings.size(); i < max; ++i) { | |
| 375 string16s.push_back(base::UTF8ToUTF16(strings[i])); | |
| 376 } | |
| 377 Send(new CacheStorageMsg_CacheStorageKeysSuccess(thread_id, request_id, | 371 Send(new CacheStorageMsg_CacheStorageKeysSuccess(thread_id, request_id, |
| 378 string16s)); | 372 cache_names)); |
| 379 } | 373 } |
| 380 | 374 |
| 381 void CacheStorageDispatcherHost::OnCacheStorageMatchCallback( | 375 void CacheStorageDispatcherHost::OnCacheStorageMatchCallback( |
| 382 int thread_id, | 376 int thread_id, |
| 383 int request_id, | 377 int request_id, |
| 384 CacheStorageError error, | 378 CacheStorageError error, |
| 385 scoped_ptr<ServiceWorkerResponse> response, | 379 scoped_ptr<ServiceWorkerResponse> response, |
| 386 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { | 380 scoped_ptr<storage::BlobDataHandle> blob_data_handle) { |
| 387 if (error != CACHE_STORAGE_OK) { | 381 if (error != CACHE_STORAGE_OK) { |
| 388 Send(new CacheStorageMsg_CacheStorageMatchError( | 382 Send(new CacheStorageMsg_CacheStorageMatchError( |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); | 513 UUIDToBlobDataHandleList::iterator it = blob_handle_store_.find(uuid); |
| 520 if (it == blob_handle_store_.end()) | 514 if (it == blob_handle_store_.end()) |
| 521 return; | 515 return; |
| 522 DCHECK(!it->second.empty()); | 516 DCHECK(!it->second.empty()); |
| 523 it->second.pop_front(); | 517 it->second.pop_front(); |
| 524 if (it->second.empty()) | 518 if (it->second.empty()) |
| 525 blob_handle_store_.erase(it); | 519 blob_handle_store_.erase(it); |
| 526 } | 520 } |
| 527 | 521 |
| 528 } // namespace content | 522 } // namespace content |
| OLD | NEW |