Chromium Code Reviews| Index: net/http/http_cache_lookup_manager.h |
| diff --git a/net/http/http_cache_lookup_manager.h b/net/http/http_cache_lookup_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..81d7891c908097511dd0548cfbeeee15148e13c3 |
| --- /dev/null |
| +++ b/net/http/http_cache_lookup_manager.h |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef NET_HTTP_CACHE_LOOKUP_MANAGER_H_ |
| +#define NET_HTTP_CACHE_LOOKUP_MANAGER_H_ |
| + |
| +#include "net/base/net_export.h" |
| +#include "net/http/http_cache.h" |
| +#include "net/http/http_cache_transaction.h" |
| +#include "net/spdy/server_push_delegate.h" |
| + |
| +namespace net { |
| + |
| +// An implementation of ServerPushDelegate that issues an HttpCache::Transaction |
| +// to lookup whether the response to the pushed URL is cached and cancel the |
| +// push in that case. |
| +class NET_EXPORT_PRIVATE HttpCacheLookupManager : public ServerPushDelegate { |
| + public: |
| + // |http_cache| MUST outlive the HttpCacheLookupManager. |
| + HttpCacheLookupManager(HttpCache* http_cache, |
| + const NetLogWithSource& net_log); |
| + ~HttpCacheLookupManager() override; |
| + |
| + void OnPush(std::unique_ptr<ServerPushHelper> push_helper) override; |
| + |
| + // Invoked when the HttpCache::Transaction for |url| finishes to cancel the |
| + // server push if the response to the server push is found cached. |
| + void OnLookupComplete(const GURL& url, int rv); |
| + |
| + private: |
| + // A class that takes the ownership of ServerPushHelper, issues and owns an |
| + // HttpCache::Transaction which lookups the response in cache for the server |
| + // push. |
| + class LookupTransaction { |
| + public: |
| + LookupTransaction(std::unique_ptr<ServerPushHelper> push_helper); |
| + ~LookupTransaction(); |
| + |
| + // Issues an HttpCache::Transaction to lookup whether the response is cached |
| + // without header validation. |
| + int StartLookup(HttpCache* cache, |
| + const CompletionCallback& callback, |
| + const NetLogWithSource& net_log); |
| + |
| + void CancelPush(); |
| + |
| + private: |
| + std::unique_ptr<ServerPushHelper> push_helper; |
|
jkarlin
2016/11/21 14:40:41
push_helper_
Zhongyi Shi
2016/11/22 00:09:29
Ah, thanks for catching this! LookupTransaction us
|
| + std::unique_ptr<HttpRequestInfo> request; |
|
jkarlin
2016/11/21 14:40:41
request_
Zhongyi Shi
2016/11/22 00:09:29
Done.
|
| + std::unique_ptr<HttpTransaction> transaction; |
|
jkarlin
2016/11/21 14:40:41
transaction_
Zhongyi Shi
2016/11/22 00:09:29
Done.
|
| + }; |
| + |
| + NetLogWithSource net_log_; |
| + // HttpCache must outlive the HttpCacheLookupManager. |
| + HttpCache* http_cache_; |
| + std::map<GURL, std::unique_ptr<LookupTransaction>> lookup_transactions_; |
| + base::WeakPtrFactory<HttpCacheLookupManager> weak_factory_; |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_HTTP_CACHE_LOOKUP_MANAGER_H_ |