OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This file declares a HttpTransactionFactory implementation that can be | 5 // This file declares a HttpTransactionFactory implementation that can be |
6 // layered on top of another HttpTransactionFactory to add HTTP caching. The | 6 // layered on top of another HttpTransactionFactory to add HTTP caching. The |
7 // caching logic follows RFC 2616 (any exceptions are called out in the code). | 7 // caching logic follows RFC 2616 (any exceptions are called out in the code). |
8 // | 8 // |
9 // The HttpCache takes a disk_cache::Backend as a parameter, and uses that for | 9 // The HttpCache takes a disk_cache::Backend as a parameter, and uses that for |
10 // the cache storage. | 10 // the cache storage. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 150 |
151 virtual ~HttpCache(); | 151 virtual ~HttpCache(); |
152 | 152 |
153 HttpTransactionFactory* network_layer() { return network_layer_.get(); } | 153 HttpTransactionFactory* network_layer() { return network_layer_.get(); } |
154 | 154 |
155 // Retrieves the cache backend for this HttpCache instance. If the backend | 155 // Retrieves the cache backend for this HttpCache instance. If the backend |
156 // is not initialized yet, this method will initialize it. The return value is | 156 // is not initialized yet, this method will initialize it. The return value is |
157 // a network error code, and it could be ERR_IO_PENDING, in which case the | 157 // a network error code, and it could be ERR_IO_PENDING, in which case the |
158 // |callback| will be notified when the operation completes. The pointer that | 158 // |callback| will be notified when the operation completes. The pointer that |
159 // receives the |backend| must remain valid until the operation completes. | 159 // receives the |backend| must remain valid until the operation completes. |
160 int GetBackend(disk_cache::Backend** backend, | 160 int GetBackend(disk_cache::Backend** backend, OldCompletionCallback* callback)
; |
161 const CompletionCallback& callback); | |
162 | 161 |
163 // Returns the current backend (can be NULL). | 162 // Returns the current backend (can be NULL). |
164 disk_cache::Backend* GetCurrentBackend() const; | 163 disk_cache::Backend* GetCurrentBackend() const; |
165 | 164 |
166 // Given a header data blob, convert it to a response info object. | 165 // Given a header data blob, convert it to a response info object. |
167 static bool ParseResponseInfo(const char* data, int len, | 166 static bool ParseResponseInfo(const char* data, int len, |
168 HttpResponseInfo* response_info, | 167 HttpResponseInfo* response_info, |
169 bool* response_truncated); | 168 bool* response_truncated); |
170 | 169 |
171 // Writes |buf_len| bytes of metadata stored in |buf| to the cache entry | 170 // Writes |buf_len| bytes of metadata stored in |buf| to the cache entry |
(...skipping 12 matching lines...) Expand all Loading... |
184 // immediately, but they will not be reusable. This is for debugging. | 183 // immediately, but they will not be reusable. This is for debugging. |
185 void CloseAllConnections(); | 184 void CloseAllConnections(); |
186 | 185 |
187 // Close all idle connections. Will close all sockets not in active use. | 186 // Close all idle connections. Will close all sockets not in active use. |
188 void CloseIdleConnections(); | 187 void CloseIdleConnections(); |
189 | 188 |
190 // Called whenever an external cache in the system reuses the resource | 189 // Called whenever an external cache in the system reuses the resource |
191 // referred to by |url| and |http_method|. | 190 // referred to by |url| and |http_method|. |
192 void OnExternalCacheHit(const GURL& url, const std::string& http_method); | 191 void OnExternalCacheHit(const GURL& url, const std::string& http_method); |
193 | 192 |
194 // HttpTransactionFactory implementation. | 193 // HttpTransactionFactory implementation: |
195 virtual int CreateTransaction(scoped_ptr<HttpTransaction>* trans) OVERRIDE; | 194 virtual int CreateTransaction(scoped_ptr<HttpTransaction>* trans) OVERRIDE; |
196 virtual HttpCache* GetCache() OVERRIDE; | 195 virtual HttpCache* GetCache() OVERRIDE; |
197 virtual HttpNetworkSession* GetSession() OVERRIDE; | 196 virtual HttpNetworkSession* GetSession() OVERRIDE; |
198 | 197 |
199 protected: | 198 protected: |
200 // Disk cache entry data indices. | 199 // Disk cache entry data indices. |
201 enum { | 200 enum { |
202 kResponseInfoIndex = 0, | 201 kResponseInfoIndex = 0, |
203 kResponseContentIndex, | 202 kResponseContentIndex, |
204 kMetadataIndex, | 203 kMetadataIndex, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 typedef base::hash_map<std::string, ActiveEntry*> ActiveEntriesMap; | 236 typedef base::hash_map<std::string, ActiveEntry*> ActiveEntriesMap; |
238 typedef base::hash_map<std::string, PendingOp*> PendingOpsMap; | 237 typedef base::hash_map<std::string, PendingOp*> PendingOpsMap; |
239 typedef std::set<ActiveEntry*> ActiveEntriesSet; | 238 typedef std::set<ActiveEntry*> ActiveEntriesSet; |
240 typedef base::hash_map<std::string, int> PlaybackCacheMap; | 239 typedef base::hash_map<std::string, int> PlaybackCacheMap; |
241 | 240 |
242 // Methods ------------------------------------------------------------------ | 241 // Methods ------------------------------------------------------------------ |
243 | 242 |
244 // Creates the |backend| object and notifies the |callback| when the operation | 243 // Creates the |backend| object and notifies the |callback| when the operation |
245 // completes. Returns an error code. | 244 // completes. Returns an error code. |
246 int CreateBackend(disk_cache::Backend** backend, | 245 int CreateBackend(disk_cache::Backend** backend, |
247 const CompletionCallback& callback); | 246 OldCompletionCallback* callback); |
248 | 247 |
249 // Makes sure that the backend creation is complete before allowing the | 248 // Makes sure that the backend creation is complete before allowing the |
250 // provided transaction to use the object. Returns an error code. |trans| | 249 // provided transaction to use the object. Returns an error code. |trans| |
251 // will be notified via its IO callback if this method returns ERR_IO_PENDING. | 250 // will be notified via its IO callback if this method returns ERR_IO_PENDING. |
252 // The transaction is free to use the backend directly at any time after | 251 // The transaction is free to use the backend directly at any time after |
253 // receiving the notification. | 252 // receiving the notification. |
254 int GetBackendForTransaction(Transaction* trans); | 253 int GetBackendForTransaction(Transaction* trans); |
255 | 254 |
256 // Generates the cache key for this request. | 255 // Generates the cache key for this request. |
257 std::string GenerateCacheKey(const HttpRequestInfo*); | 256 std::string GenerateCacheKey(const HttpRequestInfo*); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 PendingOpsMap pending_ops_; | 381 PendingOpsMap pending_ops_; |
383 | 382 |
384 scoped_ptr<PlaybackCacheMap> playback_cache_map_; | 383 scoped_ptr<PlaybackCacheMap> playback_cache_map_; |
385 | 384 |
386 DISALLOW_COPY_AND_ASSIGN(HttpCache); | 385 DISALLOW_COPY_AND_ASSIGN(HttpCache); |
387 }; | 386 }; |
388 | 387 |
389 } // namespace net | 388 } // namespace net |
390 | 389 |
391 #endif // NET_HTTP_HTTP_CACHE_H_ | 390 #endif // NET_HTTP_HTTP_CACHE_H_ |
OLD | NEW |