| Index: content/browser/cache_storage/cache_storage_cache.cc
|
| diff --git a/content/browser/cache_storage/cache_storage_cache.cc b/content/browser/cache_storage/cache_storage_cache.cc
|
| index 1e114d9d4166aacee49b8a9999c6e92f98398686..cf4c94d73f3ff4848198d3bf9b694a242ab89233 100644
|
| --- a/content/browser/cache_storage/cache_storage_cache.cc
|
| +++ b/content/browser/cache_storage/cache_storage_cache.cc
|
| @@ -211,35 +211,15 @@ struct CacheStorageCache::OpenAllEntriesContext {
|
| DISALLOW_COPY_AND_ASSIGN(OpenAllEntriesContext);
|
| };
|
|
|
| -// The state needed to pass between CacheStorageCache::MatchAll callbacks.
|
| -struct CacheStorageCache::MatchAllContext {
|
| - MatchAllContext(scoped_ptr<ServiceWorkerFetchRequest> request,
|
| - const CacheStorageCacheQueryParams& match_params,
|
| - const ResponsesCallback& callback)
|
| - : request(std::move(request)),
|
| - options(match_params),
|
| - original_callback(callback),
|
| - out_responses(new Responses),
|
| - out_blob_data_handles(new BlobDataHandles) {}
|
| - ~MatchAllContext() {}
|
| -
|
| - scoped_ptr<ServiceWorkerFetchRequest> request;
|
| -
|
| - CacheStorageCacheQueryParams options;
|
| -
|
| - // The callback passed to the MatchAll() function.
|
| - ResponsesCallback original_callback;
|
| -
|
| - // The outputs of the MatchAll function.
|
| - scoped_ptr<Responses> out_responses;
|
| - scoped_ptr<BlobDataHandles> out_blob_data_handles;
|
| -
|
| - // The context holding open entries.
|
| - scoped_ptr<OpenAllEntriesContext> entries_context;
|
| +CacheStorageCache::QueryCacheResults::QueryCacheResults(
|
| + scoped_ptr<ServiceWorkerFetchRequest> request,
|
| + const CacheStorageCacheQueryParams& match_params,
|
| + const QueryCacheResultsCallback& callback)
|
| + : request(std::move(request)),
|
| + match_params(match_params),
|
| + callback(callback) {}
|
|
|
| - private:
|
| - DISALLOW_COPY_AND_ASSIGN(MatchAllContext);
|
| -};
|
| +CacheStorageCache::QueryCacheResults::~QueryCacheResults() {}
|
|
|
| // The state needed to pass between CacheStorageCache::Keys callbacks.
|
| struct CacheStorageCache::KeysContext {
|
| @@ -332,22 +312,19 @@ void CacheStorageCache::Match(scoped_ptr<ServiceWorkerFetchRequest> request,
|
| void CacheStorageCache::MatchAll(
|
| scoped_ptr<ServiceWorkerFetchRequest> request,
|
| const CacheStorageCacheQueryParams& match_params,
|
| - const ResponsesCallback& callback) {
|
| + const QueryCacheResultsCallback& callback) {
|
| if (!LazyInitialize()) {
|
| - callback.Run(CACHE_STORAGE_ERROR_STORAGE, scoped_ptr<Responses>(),
|
| - scoped_ptr<BlobDataHandles>());
|
| + callback.Run(CACHE_STORAGE_ERROR_STORAGE, scoped_ptr<QueryCacheResults>());
|
| return;
|
| }
|
|
|
| - ResponsesCallback pending_callback =
|
| - base::Bind(&CacheStorageCache::PendingResponsesCallback,
|
| + QueryCacheResultsCallback pending_callback =
|
| + base::Bind(&CacheStorageCache::PendingQueryCacheResultsCallback,
|
| weak_ptr_factory_.GetWeakPtr(), callback);
|
|
|
| - scoped_ptr<MatchAllContext> context(
|
| - new MatchAllContext(std::move(request), match_params, pending_callback));
|
| - scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::MatchAllImpl,
|
| + scheduler_->ScheduleOperation(base::Bind(&CacheStorageCache::QueryCache,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| - base::Passed(std::move(context))));
|
| + base::Passed(std::move(request)), match_params, pending_callback));
|
| }
|
|
|
| void CacheStorageCache::BatchOperation(
|
| @@ -658,64 +635,76 @@ void CacheStorageCache::MatchDidReadMetadata(
|
| std::move(blob_data_handle));
|
| }
|
|
|
| -void CacheStorageCache::MatchAllImpl(scoped_ptr<MatchAllContext> context) {
|
| +void CacheStorageCache::QueryCache(
|
| + scoped_ptr<ServiceWorkerFetchRequest> request,
|
| + const CacheStorageCacheQueryParams& match_params,
|
| + const QueryCacheResultsCallback& callback) {
|
| DCHECK_NE(BACKEND_UNINITIALIZED, backend_state_);
|
| if (backend_state_ != BACKEND_OPEN) {
|
| - context->original_callback.Run(CACHE_STORAGE_ERROR_STORAGE,
|
| - scoped_ptr<Responses>(),
|
| - scoped_ptr<BlobDataHandles>());
|
| + callback.Run(CACHE_STORAGE_ERROR_STORAGE, scoped_ptr<QueryCacheResults>());
|
| return;
|
| }
|
|
|
| - OpenAllEntries(base::Bind(&CacheStorageCache::MatchAllDidOpenAllEntries,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - base::Passed(std::move(context))));
|
| + scoped_ptr<QueryCacheResults> results(
|
| + new QueryCacheResults(std::move(request), match_params, callback));
|
| +
|
| + //if (request->url.is_empty() || match_params.ignore_search) {
|
| + // system(">/tmp/whatareu");
|
| + OpenAllEntries(base::Bind(&CacheStorageCache::QueryCacheDidOpenAllEntries,
|
| + weak_ptr_factory_.GetWeakPtr(),
|
| + base::Passed(std::move(results))));
|
| + // return;
|
| + //}
|
| +
|
| + // TODO(zino): Do OpenEntry() taking request object.
|
| }
|
|
|
| -void CacheStorageCache::MatchAllDidOpenAllEntries(
|
| - scoped_ptr<MatchAllContext> context,
|
| +void CacheStorageCache::QueryCacheDidOpenAllEntries(
|
| + scoped_ptr<QueryCacheResults> results,
|
| scoped_ptr<OpenAllEntriesContext> entries_context,
|
| CacheStorageError error) {
|
| if (error != CACHE_STORAGE_OK) {
|
| - context->original_callback.Run(error, scoped_ptr<Responses>(),
|
| - scoped_ptr<BlobDataHandles>());
|
| + results->callback.Run(error, scoped_ptr<QueryCacheResults>());
|
| return;
|
| }
|
|
|
| - context->entries_context.swap(entries_context);
|
| - Entries::iterator iter = context->entries_context->entries.begin();
|
| - MatchAllProcessNextEntry(std::move(context), iter);
|
| + Entries::iterator iter = entries_context->entries.begin();
|
| + QueryCacheProcessNextEntry(std::move(results), std::move(entries_context),
|
| + iter);
|
| }
|
|
|
| -void CacheStorageCache::MatchAllProcessNextEntry(
|
| - scoped_ptr<MatchAllContext> context,
|
| +void CacheStorageCache::QueryCacheProcessNextEntry(
|
| + scoped_ptr<QueryCacheResults> results,
|
| + scoped_ptr<OpenAllEntriesContext> entries_context,
|
| const Entries::iterator& iter) {
|
| - if (iter == context->entries_context->entries.end()) {
|
| - // All done. Return all of the responses.
|
| - context->original_callback.Run(CACHE_STORAGE_OK,
|
| - std::move(context->out_responses),
|
| - std::move(context->out_blob_data_handles));
|
| + if (iter == entries_context->entries.end()) {
|
| + // All done. Return all of results.
|
| + results->callback.Run(CACHE_STORAGE_OK, std::move(results));
|
| return;
|
| }
|
|
|
| - if (context->options.ignore_search) {
|
| - DCHECK(context->request);
|
| + if (results->match_params.ignore_search) {
|
| + DCHECK(results->request);
|
| disk_cache::Entry* entry(*iter);
|
| - if (RemoveQueryParam(context->request->url) !=
|
| + if (RemoveQueryParam(results->request->url) !=
|
| RemoveQueryParam(GURL(entry->GetKey()))) {
|
| // In this case, we don't need to read data.
|
| - MatchAllProcessNextEntry(std::move(context), iter + 1);
|
| + QueryCacheProcessNextEntry(std::move(results), std::move(entries_context),
|
| + iter + 1);
|
| return;
|
| }
|
| }
|
|
|
| - ReadMetadata(*iter, base::Bind(&CacheStorageCache::MatchAllDidReadMetadata,
|
| - weak_ptr_factory_.GetWeakPtr(),
|
| - base::Passed(std::move(context)), iter));
|
| + ReadMetadata(*iter,
|
| + base::Bind(&CacheStorageCache::QueryCacheDidReadMetadata,
|
| + weak_ptr_factory_.GetWeakPtr(),
|
| + base::Passed(std::move(results)),
|
| + base::Passed(std::move(entries_context)), iter));
|
| }
|
|
|
| -void CacheStorageCache::MatchAllDidReadMetadata(
|
| - scoped_ptr<MatchAllContext> context,
|
| +void CacheStorageCache::QueryCacheDidReadMetadata(
|
| + scoped_ptr<QueryCacheResults> results,
|
| + scoped_ptr<OpenAllEntriesContext> entries_context,
|
| const Entries::iterator& iter,
|
| scoped_ptr<CacheMetadata> metadata) {
|
| // Move ownership of the entry from the context.
|
| @@ -724,32 +713,50 @@ void CacheStorageCache::MatchAllDidReadMetadata(
|
|
|
| if (!metadata) {
|
| entry->Doom();
|
| - MatchAllProcessNextEntry(std::move(context), iter + 1);
|
| + QueryCacheProcessNextEntry(std::move(results), std::move(entries_context),
|
| + iter + 1);
|
| return;
|
| }
|
|
|
| + // Read request
|
| + results->requests->push_back(ServiceWorkerFetchRequest(
|
| + GURL(entry->GetKey()), metadata->request().method(),
|
| + ServiceWorkerHeaderMap(), Referrer(), false));
|
| +
|
| + ServiceWorkerHeaderMap& req_headers = results->requests->back().headers;
|
| +
|
| + for (int i = 0; i < metadata->request().headers_size(); ++i) {
|
| + const CacheHeaderMap header = metadata->request().headers(i);
|
| + DCHECK_EQ(std::string::npos, header.name().find('\0'));
|
| + DCHECK_EQ(std::string::npos, header.value().find('\0'));
|
| + req_headers.insert(std::make_pair(header.name(), header.value()));
|
| + }
|
| +
|
| + // Read response
|
| ServiceWorkerResponse response;
|
| PopulateResponseMetadata(*metadata, &response);
|
|
|
| if (entry->GetDataSize(INDEX_RESPONSE_BODY) == 0) {
|
| - context->out_responses->push_back(response);
|
| - MatchAllProcessNextEntry(std::move(context), iter + 1);
|
| + results->responses->push_back(response);
|
| + QueryCacheProcessNextEntry(std::move(results), std::move(entries_context),
|
| + iter + 1);
|
| return;
|
| }
|
|
|
| if (!blob_storage_context_) {
|
| - context->original_callback.Run(CACHE_STORAGE_ERROR_STORAGE,
|
| - scoped_ptr<Responses>(),
|
| - scoped_ptr<BlobDataHandles>());
|
| + results->callback.Run(CACHE_STORAGE_ERROR_STORAGE,
|
| + scoped_ptr<QueryCacheResults>());
|
| return;
|
| }
|
|
|
| scoped_ptr<storage::BlobDataHandle> blob_data_handle =
|
| PopulateResponseBody(std::move(entry), &response);
|
|
|
| - context->out_responses->push_back(response);
|
| - context->out_blob_data_handles->push_back(*blob_data_handle);
|
| - MatchAllProcessNextEntry(std::move(context), iter + 1);
|
| + results->responses->push_back(response);
|
| + results->blob_data_handles->push_back(*blob_data_handle);
|
| +
|
| + QueryCacheProcessNextEntry(std::move(results), std::move(entries_context),
|
| + iter + 1);
|
| }
|
|
|
| void CacheStorageCache::Put(const CacheStorageBatchOperation& operation,
|
| @@ -1333,14 +1340,13 @@ void CacheStorageCache::PendingResponseCallback(
|
| scheduler_->CompleteOperationAndRunNext();
|
| }
|
|
|
| -void CacheStorageCache::PendingResponsesCallback(
|
| - const ResponsesCallback& callback,
|
| +void CacheStorageCache::PendingQueryCacheResultsCallback(
|
| + const QueryCacheResultsCallback& callback,
|
| CacheStorageError error,
|
| - scoped_ptr<Responses> responses,
|
| - scoped_ptr<BlobDataHandles> blob_data_handles) {
|
| + scoped_ptr<QueryCacheResults> results) {
|
| base::WeakPtr<CacheStorageCache> cache = weak_ptr_factory_.GetWeakPtr();
|
|
|
| - callback.Run(error, std::move(responses), std::move(blob_data_handles));
|
| + callback.Run(error, std::move(results));
|
| if (cache)
|
| scheduler_->CompleteOperationAndRunNext();
|
| }
|
|
|