| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 public: | 82 public: |
| 83 virtual ~BackendFactory() {} | 83 virtual ~BackendFactory() {} |
| 84 | 84 |
| 85 // The actual method to build the backend. Returns a net error code. If | 85 // The actual method to build the backend. Returns a net error code. If |
| 86 // ERR_IO_PENDING is returned, the |callback| will be notified when the | 86 // ERR_IO_PENDING is returned, the |callback| will be notified when the |
| 87 // operation completes, and |backend| must remain valid until the | 87 // operation completes, and |backend| must remain valid until the |
| 88 // notification arrives. | 88 // notification arrives. |
| 89 // The implementation must not access the factory object after invoking the | 89 // The implementation must not access the factory object after invoking the |
| 90 // |callback| because the object can be deleted from within the callback. | 90 // |callback| because the object can be deleted from within the callback. |
| 91 virtual int CreateBackend(NetLog* net_log, | 91 virtual int CreateBackend(NetLog* net_log, |
| 92 disk_cache::Backend** backend, | 92 scoped_ptr<disk_cache::Backend>* backend, |
| 93 const CompletionCallback& callback) = 0; | 93 const CompletionCallback& callback) = 0; |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 // A default backend factory for the common use cases. | 96 // A default backend factory for the common use cases. |
| 97 class NET_EXPORT DefaultBackend : public BackendFactory { | 97 class NET_EXPORT DefaultBackend : public BackendFactory { |
| 98 public: | 98 public: |
| 99 // |path| is the destination for any files used by the backend, and | 99 // |path| is the destination for any files used by the backend, and |
| 100 // |cache_thread| is the thread where disk operations should take place. If | 100 // |cache_thread| is the thread where disk operations should take place. If |
| 101 // |max_bytes| is zero, a default value will be calculated automatically. | 101 // |max_bytes| is zero, a default value will be calculated automatically. |
| 102 DefaultBackend(CacheType type, BackendType backend_type, | 102 DefaultBackend(CacheType type, BackendType backend_type, |
| 103 const base::FilePath& path, int max_bytes, | 103 const base::FilePath& path, int max_bytes, |
| 104 base::MessageLoopProxy* thread); | 104 base::MessageLoopProxy* thread); |
| 105 virtual ~DefaultBackend(); | 105 virtual ~DefaultBackend(); |
| 106 | 106 |
| 107 // Returns a factory for an in-memory cache. | 107 // Returns a factory for an in-memory cache. |
| 108 static BackendFactory* InMemory(int max_bytes); | 108 static BackendFactory* InMemory(int max_bytes); |
| 109 | 109 |
| 110 // BackendFactory implementation. | 110 // BackendFactory implementation. |
| 111 virtual int CreateBackend(NetLog* net_log, | 111 virtual int CreateBackend(NetLog* net_log, |
| 112 disk_cache::Backend** backend, | 112 scoped_ptr<disk_cache::Backend>* backend, |
| 113 const CompletionCallback& callback) OVERRIDE; | 113 const CompletionCallback& callback) OVERRIDE; |
| 114 | 114 |
| 115 private: | 115 private: |
| 116 CacheType type_; | 116 CacheType type_; |
| 117 BackendType backend_type_; | 117 BackendType backend_type_; |
| 118 const base::FilePath path_; | 118 const base::FilePath path_; |
| 119 int max_bytes_; | 119 int max_bytes_; |
| 120 scoped_refptr<base::MessageLoopProxy> thread_; | 120 scoped_refptr<base::MessageLoopProxy> thread_; |
| 121 }; | 121 }; |
| 122 | 122 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 PendingOpsMap pending_ops_; | 395 PendingOpsMap pending_ops_; |
| 396 | 396 |
| 397 scoped_ptr<PlaybackCacheMap> playback_cache_map_; | 397 scoped_ptr<PlaybackCacheMap> playback_cache_map_; |
| 398 | 398 |
| 399 DISALLOW_COPY_AND_ASSIGN(HttpCache); | 399 DISALLOW_COPY_AND_ASSIGN(HttpCache); |
| 400 }; | 400 }; |
| 401 | 401 |
| 402 } // namespace net | 402 } // namespace net |
| 403 | 403 |
| 404 #endif // NET_HTTP_HTTP_CACHE_H_ | 404 #endif // NET_HTTP_HTTP_CACHE_H_ |
| OLD | NEW |