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/cache_storage/cache_storage_cache.h" | 5 #include "content/browser/cache_storage/cache_storage_cache.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 // If the header exists in one, it exists in both. Verify that the values | 140 // If the header exists in one, it exists in both. Verify that the values |
141 // are equal. | 141 // are equal. |
142 if (request_iter != request.end() && | 142 if (request_iter != request.end() && |
143 request_iter->second != cached_request_iter->second) | 143 request_iter->second != cached_request_iter->second) |
144 return false; | 144 return false; |
145 } | 145 } |
146 | 146 |
147 return true; | 147 return true; |
148 } | 148 } |
149 | 149 |
150 bool URLMatchWithoutQuery(const GURL& request_url, const GURL& key) { | |
nhiroki
2016/01/20 08:56:02
This function name sounds a bit strange to me.
Th
zino
2016/02/03 12:04:47
Done.
| |
151 url::Replacements<char> replacements; | |
152 replacements.ClearQuery(); | |
153 return request_url.ReplaceComponents(replacements) == | |
154 key.ReplaceComponents(replacements); | |
155 } | |
156 | |
150 void ReadMetadata(disk_cache::Entry* entry, const MetadataCallback& callback) { | 157 void ReadMetadata(disk_cache::Entry* entry, const MetadataCallback& callback) { |
151 DCHECK(entry); | 158 DCHECK(entry); |
152 | 159 |
153 scoped_refptr<net::IOBufferWithSize> buffer( | 160 scoped_refptr<net::IOBufferWithSize> buffer( |
154 new net::IOBufferWithSize(entry->GetDataSize(INDEX_HEADERS))); | 161 new net::IOBufferWithSize(entry->GetDataSize(INDEX_HEADERS))); |
155 | 162 |
156 net::CompletionCallback read_header_callback = | 163 net::CompletionCallback read_header_callback = |
157 base::Bind(ReadMetadataDidReadMetadata, entry, callback, buffer); | 164 base::Bind(ReadMetadataDidReadMetadata, entry, callback, buffer); |
158 | 165 |
159 int read_rv = entry->ReadData(INDEX_HEADERS, 0, buffer.get(), buffer->size(), | 166 int read_rv = entry->ReadData(INDEX_HEADERS, 0, buffer.get(), buffer->size(), |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 // Used for enumerating cache entries. | 210 // Used for enumerating cache entries. |
204 scoped_ptr<disk_cache::Backend::Iterator> backend_iterator; | 211 scoped_ptr<disk_cache::Backend::Iterator> backend_iterator; |
205 disk_cache::Entry* enumerated_entry; | 212 disk_cache::Entry* enumerated_entry; |
206 | 213 |
207 private: | 214 private: |
208 DISALLOW_COPY_AND_ASSIGN(OpenAllEntriesContext); | 215 DISALLOW_COPY_AND_ASSIGN(OpenAllEntriesContext); |
209 }; | 216 }; |
210 | 217 |
211 // The state needed to pass between CacheStorageCache::MatchAll callbacks. | 218 // The state needed to pass between CacheStorageCache::MatchAll callbacks. |
212 struct CacheStorageCache::MatchAllContext { | 219 struct CacheStorageCache::MatchAllContext { |
213 explicit MatchAllContext(const CacheStorageCache::ResponsesCallback& callback) | 220 MatchAllContext(scoped_ptr<ServiceWorkerFetchRequest> request, |
214 : original_callback(callback), | 221 const CacheStorageCacheQueryParams& match_params, |
222 const ResponsesCallback& callback) | |
223 : request(std::move(request)), | |
224 options(match_params), | |
225 original_callback(callback), | |
215 out_responses(new Responses), | 226 out_responses(new Responses), |
216 out_blob_data_handles(new BlobDataHandles) {} | 227 out_blob_data_handles(new BlobDataHandles) {} |
217 ~MatchAllContext() {} | 228 ~MatchAllContext() {} |
218 | 229 |
230 scoped_ptr<ServiceWorkerFetchRequest> request; | |
231 | |
232 CacheStorageCacheQueryParams options; | |
233 | |
219 // The callback passed to the MatchAll() function. | 234 // The callback passed to the MatchAll() function. |
220 ResponsesCallback original_callback; | 235 ResponsesCallback original_callback; |
221 | 236 |
222 // The outputs of the MatchAll function. | 237 // The outputs of the MatchAll function. |
223 scoped_ptr<Responses> out_responses; | 238 scoped_ptr<Responses> out_responses; |
224 scoped_ptr<BlobDataHandles> out_blob_data_handles; | 239 scoped_ptr<BlobDataHandles> out_blob_data_handles; |
225 | 240 |
226 // The context holding open entries. | 241 // The context holding open entries. |
227 scoped_ptr<OpenAllEntriesContext> entries_context; | 242 scoped_ptr<OpenAllEntriesContext> entries_context; |
228 | 243 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 } | 335 } |
321 | 336 |
322 ResponseCallback pending_callback = | 337 ResponseCallback pending_callback = |
323 base::Bind(&CacheStorageCache::PendingResponseCallback, | 338 base::Bind(&CacheStorageCache::PendingResponseCallback, |
324 weak_ptr_factory_.GetWeakPtr(), callback); | 339 weak_ptr_factory_.GetWeakPtr(), callback); |
325 scheduler_->ScheduleOperation( | 340 scheduler_->ScheduleOperation( |
326 base::Bind(&CacheStorageCache::MatchImpl, weak_ptr_factory_.GetWeakPtr(), | 341 base::Bind(&CacheStorageCache::MatchImpl, weak_ptr_factory_.GetWeakPtr(), |
327 base::Passed(std::move(request)), pending_callback)); | 342 base::Passed(std::move(request)), pending_callback)); |
328 } | 343 } |
329 | 344 |
330 void CacheStorageCache::MatchAll(const ResponsesCallback& callback) { | 345 void CacheStorageCache::MatchAll( |
346 scoped_ptr<ServiceWorkerFetchRequest> request, | |
347 const CacheStorageCacheQueryParams& match_params, | |
348 const ResponsesCallback& callback) { | |
331 if (!LazyInitialize()) { | 349 if (!LazyInitialize()) { |
332 callback.Run(CACHE_STORAGE_ERROR_STORAGE, scoped_ptr<Responses>(), | 350 callback.Run(CACHE_STORAGE_ERROR_STORAGE, scoped_ptr<Responses>(), |
333 scoped_ptr<BlobDataHandles>()); | 351 scoped_ptr<BlobDataHandles>()); |
334 return; | 352 return; |
335 } | 353 } |
336 | 354 |
337 ResponsesCallback pending_callback = | 355 ResponsesCallback pending_callback = |
338 base::Bind(&CacheStorageCache::PendingResponsesCallback, | 356 base::Bind(&CacheStorageCache::PendingResponsesCallback, |
339 weak_ptr_factory_.GetWeakPtr(), callback); | 357 weak_ptr_factory_.GetWeakPtr(), callback); |
358 | |
359 scoped_ptr<MatchAllContext> context( | |
360 new MatchAllContext(std::move(request), match_params, pending_callback)); | |
340 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::MatchAllImpl, | 361 scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::MatchAllImpl, |
341 weak_ptr_factory_.GetWeakPtr(), | 362 weak_ptr_factory_.GetWeakPtr(), |
342 pending_callback)); | 363 base::Passed(std::move(context)))); |
343 } | 364 } |
344 | 365 |
345 void CacheStorageCache::BatchOperation( | 366 void CacheStorageCache::BatchOperation( |
346 const std::vector<CacheStorageBatchOperation>& operations, | 367 const std::vector<CacheStorageBatchOperation>& operations, |
347 const ErrorCallback& callback) { | 368 const ErrorCallback& callback) { |
348 if (!LazyInitialize()) { | 369 if (!LazyInitialize()) { |
349 callback.Run(CACHE_STORAGE_ERROR_STORAGE); | 370 callback.Run(CACHE_STORAGE_ERROR_STORAGE); |
350 return; | 371 return; |
351 } | 372 } |
352 | 373 |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 scoped_ptr<storage::BlobDataHandle>()); | 652 scoped_ptr<storage::BlobDataHandle>()); |
632 return; | 653 return; |
633 } | 654 } |
634 | 655 |
635 scoped_ptr<storage::BlobDataHandle> blob_data_handle = | 656 scoped_ptr<storage::BlobDataHandle> blob_data_handle = |
636 PopulateResponseBody(std::move(entry), response.get()); | 657 PopulateResponseBody(std::move(entry), response.get()); |
637 callback.Run(CACHE_STORAGE_OK, std::move(response), | 658 callback.Run(CACHE_STORAGE_OK, std::move(response), |
638 std::move(blob_data_handle)); | 659 std::move(blob_data_handle)); |
639 } | 660 } |
640 | 661 |
641 void CacheStorageCache::MatchAllImpl(const ResponsesCallback& callback) { | 662 void CacheStorageCache::MatchAllImpl(scoped_ptr<MatchAllContext> context) { |
642 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); | 663 DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_); |
643 if (backend_state_ != BACKEND_OPEN) { | 664 if (backend_state_ != BACKEND_OPEN) { |
644 callback.Run(CACHE_STORAGE_ERROR_STORAGE, scoped_ptr<Responses>(), | 665 context->original_callback.Run(CACHE_STORAGE_ERROR_STORAGE, |
645 scoped_ptr<BlobDataHandles>()); | 666 std::move(context->out_responses), |
667 std::move(context->out_blob_data_handles)); | |
nhiroki
2016/01/20 08:56:02
Do you have any reason to change these parameters?
zino
2016/02/03 12:04:47
Done.
I thought that we need to avoid creating ob
| |
646 return; | 668 return; |
647 } | 669 } |
648 | 670 |
649 OpenAllEntries(base::Bind(&CacheStorageCache::MatchAllDidOpenAllEntries, | 671 OpenAllEntries(base::Bind(&CacheStorageCache::MatchAllDidOpenAllEntries, |
650 weak_ptr_factory_.GetWeakPtr(), callback)); | 672 weak_ptr_factory_.GetWeakPtr(), |
673 base::Passed(std::move(context)))); | |
651 } | 674 } |
652 | 675 |
653 void CacheStorageCache::MatchAllDidOpenAllEntries( | 676 void CacheStorageCache::MatchAllDidOpenAllEntries( |
654 const ResponsesCallback& callback, | 677 scoped_ptr<MatchAllContext> context, |
655 scoped_ptr<OpenAllEntriesContext> entries_context, | 678 scoped_ptr<OpenAllEntriesContext> entries_context, |
656 CacheStorageError error) { | 679 CacheStorageError error) { |
657 if (error != CACHE_STORAGE_OK) { | 680 if (error != CACHE_STORAGE_OK) { |
658 callback.Run(error, scoped_ptr<Responses>(), scoped_ptr<BlobDataHandles>()); | 681 context->original_callback.Run(error, std::move(context->out_responses), |
682 std::move(context->out_blob_data_handles)); | |
nhiroki
2016/01/20 08:56:02
ditto.
zino
2016/02/03 12:04:47
Done.
| |
659 return; | 683 return; |
660 } | 684 } |
661 | 685 |
662 scoped_ptr<MatchAllContext> context(new MatchAllContext(callback)); | |
663 context->entries_context.swap(entries_context); | 686 context->entries_context.swap(entries_context); |
664 Entries::iterator iter = context->entries_context->entries.begin(); | 687 Entries::iterator iter = context->entries_context->entries.begin(); |
665 MatchAllProcessNextEntry(std::move(context), iter); | 688 MatchAllProcessNextEntry(std::move(context), iter); |
666 } | 689 } |
667 | 690 |
668 void CacheStorageCache::MatchAllProcessNextEntry( | 691 void CacheStorageCache::MatchAllProcessNextEntry( |
669 scoped_ptr<MatchAllContext> context, | 692 scoped_ptr<MatchAllContext> context, |
670 const Entries::iterator& iter) { | 693 const Entries::iterator& iter) { |
671 if (iter == context->entries_context->entries.end()) { | 694 if (iter == context->entries_context->entries.end()) { |
672 // All done. Return all of the responses. | 695 // All done. Return all of the responses. |
673 context->original_callback.Run(CACHE_STORAGE_OK, | 696 context->original_callback.Run(CACHE_STORAGE_OK, |
674 std::move(context->out_responses), | 697 std::move(context->out_responses), |
675 std::move(context->out_blob_data_handles)); | 698 std::move(context->out_blob_data_handles)); |
676 return; | 699 return; |
677 } | 700 } |
678 | 701 |
702 disk_cache::Entry* entry(*iter); | |
nhiroki
2016/01/20 08:56:02
Can you move this to line 705?
zino
2016/02/03 12:04:47
Done.
| |
703 if (context->options.ignore_search) { | |
704 DCHECK(context->request); | |
705 if (!URLMatchWithoutQuery(context->request->url, GURL(entry->GetKey()))) { | |
706 // In this caase, we don't need to read data. | |
nhiroki
2016/01/20 08:56:02
s/casse/case
zino
2016/02/03 12:04:47
Done.
| |
707 MatchAllProcessNextEntry(std::move(context), iter + 1); | |
708 return; | |
709 } | |
710 } | |
711 | |
679 ReadMetadata(*iter, base::Bind(&CacheStorageCache::MatchAllDidReadMetadata, | 712 ReadMetadata(*iter, base::Bind(&CacheStorageCache::MatchAllDidReadMetadata, |
680 weak_ptr_factory_.GetWeakPtr(), | 713 weak_ptr_factory_.GetWeakPtr(), |
681 base::Passed(std::move(context)), iter)); | 714 base::Passed(std::move(context)), iter)); |
682 } | 715 } |
683 | 716 |
684 void CacheStorageCache::MatchAllDidReadMetadata( | 717 void CacheStorageCache::MatchAllDidReadMetadata( |
685 scoped_ptr<MatchAllContext> context, | 718 scoped_ptr<MatchAllContext> context, |
686 const Entries::iterator& iter, | 719 const Entries::iterator& iter, |
687 scoped_ptr<CacheMetadata> metadata) { | 720 scoped_ptr<CacheMetadata> metadata) { |
688 // Move ownership of the entry from the context. | 721 // Move ownership of the entry from the context. |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1256 storage::BlobDataBuilder blob_data(response->blob_uuid); | 1289 storage::BlobDataBuilder blob_data(response->blob_uuid); |
1257 | 1290 |
1258 disk_cache::Entry* temp_entry = entry.get(); | 1291 disk_cache::Entry* temp_entry = entry.get(); |
1259 blob_data.AppendDiskCacheEntry( | 1292 blob_data.AppendDiskCacheEntry( |
1260 new CacheStorageCacheDataHandle(this, std::move(entry)), temp_entry, | 1293 new CacheStorageCacheDataHandle(this, std::move(entry)), temp_entry, |
1261 INDEX_RESPONSE_BODY); | 1294 INDEX_RESPONSE_BODY); |
1262 return blob_storage_context_->AddFinishedBlob(&blob_data); | 1295 return blob_storage_context_->AddFinishedBlob(&blob_data); |
1263 } | 1296 } |
1264 | 1297 |
1265 } // namespace content | 1298 } // namespace content |
OLD | NEW |