| 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 // Defines the public interface of the disk cache. For more details see | 5 // Defines the public interface of the disk cache. For more details see |
| 6 // http://dev.chromium.org/developers/design-documents/network-stack/disk-cache | 6 // http://dev.chromium.org/developers/design-documents/network-stack/disk-cache |
| 7 | 7 |
| 8 #ifndef NET_DISK_CACHE_DISK_CACHE_H_ | 8 #ifndef NET_DISK_CACHE_DISK_CACHE_H_ |
| 9 #define NET_DISK_CACHE_DISK_CACHE_H_ | 9 #define NET_DISK_CACHE_DISK_CACHE_H_ |
| 10 | 10 |
| 11 #include <stdint.h> | 11 #include <stdint.h> |
| 12 | 12 |
| 13 #include <memory> |
| 13 #include <string> | 14 #include <string> |
| 14 #include <vector> | 15 #include <vector> |
| 15 | 16 |
| 16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/scoped_ptr.h" | |
| 18 #include "base/strings/string_split.h" | 18 #include "base/strings/string_split.h" |
| 19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #include "net/base/cache_type.h" | 20 #include "net/base/cache_type.h" |
| 21 #include "net/base/completion_callback.h" | 21 #include "net/base/completion_callback.h" |
| 22 #include "net/base/net_export.h" | 22 #include "net/base/net_export.h" |
| 23 | 23 |
| 24 namespace base { | 24 namespace base { |
| 25 class FilePath; | 25 class FilePath; |
| 26 class SingleThreadTaskRunner; | 26 class SingleThreadTaskRunner; |
| 27 } | 27 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 52 // The pointer to receive the |backend| must remain valid until the operation | 52 // The pointer to receive the |backend| must remain valid until the operation |
| 53 // completes (the callback is notified). | 53 // completes (the callback is notified). |
| 54 NET_EXPORT int CreateCacheBackend( | 54 NET_EXPORT int CreateCacheBackend( |
| 55 net::CacheType type, | 55 net::CacheType type, |
| 56 net::BackendType backend_type, | 56 net::BackendType backend_type, |
| 57 const base::FilePath& path, | 57 const base::FilePath& path, |
| 58 int max_bytes, | 58 int max_bytes, |
| 59 bool force, | 59 bool force, |
| 60 const scoped_refptr<base::SingleThreadTaskRunner>& thread, | 60 const scoped_refptr<base::SingleThreadTaskRunner>& thread, |
| 61 net::NetLog* net_log, | 61 net::NetLog* net_log, |
| 62 scoped_ptr<Backend>* backend, | 62 std::unique_ptr<Backend>* backend, |
| 63 const net::CompletionCallback& callback); | 63 const net::CompletionCallback& callback); |
| 64 | 64 |
| 65 // The root interface for a disk cache instance. | 65 // The root interface for a disk cache instance. |
| 66 class NET_EXPORT Backend { | 66 class NET_EXPORT Backend { |
| 67 public: | 67 public: |
| 68 typedef net::CompletionCallback CompletionCallback; | 68 typedef net::CompletionCallback CompletionCallback; |
| 69 | 69 |
| 70 class Iterator { | 70 class Iterator { |
| 71 public: | 71 public: |
| 72 virtual ~Iterator() {} | 72 virtual ~Iterator() {} |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 const CompletionCallback& callback) = 0; | 147 const CompletionCallback& callback) = 0; |
| 148 | 148 |
| 149 // Calculate the total size of the cache. The return value is the size in | 149 // Calculate the total size of the cache. The return value is the size in |
| 150 // bytes or a net error code. If this method returns ERR_IO_PENDING, | 150 // bytes or a net error code. If this method returns ERR_IO_PENDING, |
| 151 // the |callback| will be invoked when the operation completes. | 151 // the |callback| will be invoked when the operation completes. |
| 152 virtual int CalculateSizeOfAllEntries( | 152 virtual int CalculateSizeOfAllEntries( |
| 153 const CompletionCallback& callback) = 0; | 153 const CompletionCallback& callback) = 0; |
| 154 | 154 |
| 155 // Returns an iterator which will enumerate all entries of the cache in an | 155 // Returns an iterator which will enumerate all entries of the cache in an |
| 156 // undefined order. | 156 // undefined order. |
| 157 virtual scoped_ptr<Iterator> CreateIterator() = 0; | 157 virtual std::unique_ptr<Iterator> CreateIterator() = 0; |
| 158 | 158 |
| 159 // Return a list of cache statistics. | 159 // Return a list of cache statistics. |
| 160 virtual void GetStats(base::StringPairs* stats) = 0; | 160 virtual void GetStats(base::StringPairs* stats) = 0; |
| 161 | 161 |
| 162 // Called whenever an external cache in the system reuses the resource | 162 // Called whenever an external cache in the system reuses the resource |
| 163 // referred to by |key|. | 163 // referred to by |key|. |
| 164 virtual void OnExternalCacheHit(const std::string& key) = 0; | 164 virtual void OnExternalCacheHit(const std::string& key) = 0; |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 // This interface represents an entry in the disk cache. | 167 // This interface represents an entry in the disk cache. |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 }; | 326 }; |
| 327 | 327 |
| 328 struct EntryDeleter { | 328 struct EntryDeleter { |
| 329 void operator()(Entry* entry) { | 329 void operator()(Entry* entry) { |
| 330 // Note that |entry| is ref-counted. | 330 // Note that |entry| is ref-counted. |
| 331 entry->Close(); | 331 entry->Close(); |
| 332 } | 332 } |
| 333 }; | 333 }; |
| 334 | 334 |
| 335 // Automatically closes an entry when it goes out of scope. | 335 // Automatically closes an entry when it goes out of scope. |
| 336 typedef scoped_ptr<Entry, EntryDeleter> ScopedEntryPtr; | 336 typedef std::unique_ptr<Entry, EntryDeleter> ScopedEntryPtr; |
| 337 | 337 |
| 338 } // namespace disk_cache | 338 } // namespace disk_cache |
| 339 | 339 |
| 340 #endif // NET_DISK_CACHE_DISK_CACHE_H_ | 340 #endif // NET_DISK_CACHE_DISK_CACHE_H_ |
| OLD | NEW |