OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 128 |
129 // Initialize the cache from its component parts, which is useful for | 129 // Initialize the cache from its component parts, which is useful for |
130 // testing. The lifetime of the network_layer and backend_factory are managed | 130 // testing. The lifetime of the network_layer and backend_factory are managed |
131 // by the HttpCache and will be destroyed using |delete| when the HttpCache is | 131 // by the HttpCache and will be destroyed using |delete| when the HttpCache is |
132 // destroyed. | 132 // destroyed. |
133 HttpCache(HttpTransactionFactory* network_layer, | 133 HttpCache(HttpTransactionFactory* network_layer, |
134 BackendFactory* backend_factory); | 134 BackendFactory* backend_factory); |
135 | 135 |
136 HttpTransactionFactory* network_layer() { return network_layer_.get(); } | 136 HttpTransactionFactory* network_layer() { return network_layer_.get(); } |
137 | 137 |
138 // Returns the cache backend for this HttpCache instance. If the backend | |
139 // is not initialized yet, this method will initialize it. If the return | |
140 // value is NULL then the backend cannot be initialized. | |
141 // This method is deprecated. | |
142 disk_cache::Backend* GetBackend(); | |
143 | |
144 // Retrieves the cache backend for this HttpCache instance. If the backend | 138 // Retrieves the cache backend for this HttpCache instance. If the backend |
145 // is not initialized yet, this method will initialize it. The return value is | 139 // is not initialized yet, this method will initialize it. The return value is |
146 // a network error code, and it could be ERR_IO_PENDING, in which case the | 140 // a network error code, and it could be ERR_IO_PENDING, in which case the |
147 // |callback| will be notified when the operation completes. The pointer that | 141 // |callback| will be notified when the operation completes. The pointer that |
148 // receives the |backend| must remain valid until the operation completes. | 142 // receives the |backend| must remain valid until the operation completes. |
149 int GetBackend(disk_cache::Backend** backend, CompletionCallback* callback); | 143 int GetBackend(disk_cache::Backend** backend, CompletionCallback* callback); |
150 | 144 |
151 // Returns the current backend (can be NULL). | 145 // Returns the current backend (can be NULL). |
152 disk_cache::Backend* GetCurrentBackend(); | 146 disk_cache::Backend* GetCurrentBackend(); |
153 | 147 |
154 // HttpTransactionFactory implementation: | 148 // HttpTransactionFactory implementation: |
155 virtual int CreateTransaction(scoped_ptr<HttpTransaction>* trans); | 149 virtual int CreateTransaction(scoped_ptr<HttpTransaction>* trans); |
156 virtual HttpCache* GetCache(); | 150 virtual HttpCache* GetCache(); |
157 virtual HttpNetworkSession* GetSession(); | 151 virtual HttpNetworkSession* GetSession(); |
158 virtual void Suspend(bool suspend); | 152 virtual void Suspend(bool suspend); |
159 | 153 |
160 // Helper function for reading response info from the disk cache. If the | |
161 // cache doesn't have the whole resource *|request_truncated| is set to true. | |
162 // NOTE: This method is deprecated. | |
163 static bool ReadResponseInfo(disk_cache::Entry* disk_entry, | |
164 HttpResponseInfo* response_info, | |
165 bool* response_truncated); | |
166 | |
167 // Helper function for writing response info into the disk cache. If the | |
168 // cache doesn't have the whole resource |request_truncated| should be true. | |
169 // NOTE: This method is deprecated. | |
170 static bool WriteResponseInfo(disk_cache::Entry* disk_entry, | |
171 const HttpResponseInfo* response_info, | |
172 bool skip_transient_headers, | |
173 bool response_truncated); | |
174 | |
175 // Given a header data blob, convert it to a response info object. | 154 // Given a header data blob, convert it to a response info object. |
176 static bool ParseResponseInfo(const char* data, int len, | 155 static bool ParseResponseInfo(const char* data, int len, |
177 HttpResponseInfo* response_info, | 156 HttpResponseInfo* response_info, |
178 bool* response_truncated); | 157 bool* response_truncated); |
179 | 158 |
180 // Writes |buf_len| bytes of metadata stored in |buf| to the cache entry | 159 // Writes |buf_len| bytes of metadata stored in |buf| to the cache entry |
181 // referenced by |url|, as long as the entry's |expected_response_time| has | 160 // referenced by |url|, as long as the entry's |expected_response_time| has |
182 // not changed. This method returns without blocking, and the operation will | 161 // not changed. This method returns without blocking, and the operation will |
183 // be performed asynchronously without any completion notification. | 162 // be performed asynchronously without any completion notification. |
184 void WriteMetadata(const GURL& url, base::Time expected_response_time, | 163 void WriteMetadata(const GURL& url, base::Time expected_response_time, |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 | 362 |
384 typedef base::hash_map<std::string, int> PlaybackCacheMap; | 363 typedef base::hash_map<std::string, int> PlaybackCacheMap; |
385 scoped_ptr<PlaybackCacheMap> playback_cache_map_; | 364 scoped_ptr<PlaybackCacheMap> playback_cache_map_; |
386 | 365 |
387 DISALLOW_COPY_AND_ASSIGN(HttpCache); | 366 DISALLOW_COPY_AND_ASSIGN(HttpCache); |
388 }; | 367 }; |
389 | 368 |
390 } // namespace net | 369 } // namespace net |
391 | 370 |
392 #endif // NET_HTTP_HTTP_CACHE_H_ | 371 #endif // NET_HTTP_HTTP_CACHE_H_ |
OLD | NEW |