| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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://wiki/Main/ChromeDiskCacheBackend | 6 // http://wiki/Main/ChromeDiskCacheBackend |
| 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 <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 #include "net/base/completion_callback.h" | 16 #include "net/base/completion_callback.h" |
| 17 | 17 |
| 18 namespace net { |
| 19 class IOBuffer; |
| 20 } |
| 21 |
| 18 namespace disk_cache { | 22 namespace disk_cache { |
| 19 | 23 |
| 20 class Entry; | 24 class Entry; |
| 21 class Backend; | 25 class Backend; |
| 22 | 26 |
| 23 // Returns an instance of the Backend. path points to a folder where | 27 // Returns an instance of the Backend. path points to a folder where |
| 24 // the cached data will be stored. This cache instance must be the only object | 28 // the cached data will be stored. This cache instance must be the only object |
| 25 // that will be reading or writing files to that folder. The returned object | 29 // that will be reading or writing files to that folder. The returned object |
| 26 // should be deleted when not needed anymore. If force is true, and there is | 30 // should be deleted when not needed anymore. If force is true, and there is |
| 27 // a problem with the cache initialization, the files will be deleted and a | 31 // a problem with the cache initialization, the files will be deleted and a |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 virtual base::Time GetLastModified() const = 0; | 120 virtual base::Time GetLastModified() const = 0; |
| 117 | 121 |
| 118 // Returns the size of the cache data with the given index. | 122 // Returns the size of the cache data with the given index. |
| 119 virtual int32 GetDataSize(int index) const = 0; | 123 virtual int32 GetDataSize(int index) const = 0; |
| 120 | 124 |
| 121 // Copies cache data into the given buffer of length |buf_len|. If | 125 // Copies cache data into the given buffer of length |buf_len|. If |
| 122 // completion_callback is null, then this call blocks until the read | 126 // completion_callback is null, then this call blocks until the read |
| 123 // operation is complete. Otherwise, completion_callback will be | 127 // operation is complete. Otherwise, completion_callback will be |
| 124 // called on the current thread once the read completes. Returns the | 128 // called on the current thread once the read completes. Returns the |
| 125 // number of bytes read or a network error code. If a completion callback is | 129 // number of bytes read or a network error code. If a completion callback is |
| 126 // provided then it will be called if this function returns ERR_IO_PENDING. | 130 // provided then it will be called if this function returns ERR_IO_PENDING, |
| 131 // and a reference to |buf| will be retained until the callback is called. |
| 127 // Note that the callback will be invoked in any case, even after Close has | 132 // Note that the callback will be invoked in any case, even after Close has |
| 128 // been called; in other words, the caller may close this entry without | 133 // been called; in other words, the caller may close this entry without |
| 129 // having to wait for all the callbacks, and still rely on the cleanup | 134 // having to wait for all the callbacks, and still rely on the cleanup |
| 130 // performed from the callback code. | 135 // performed from the callback code. |
| 131 virtual int ReadData(int index, int offset, char* buf, int buf_len, | 136 virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, |
| 132 net::CompletionCallback* completion_callback) = 0; | 137 net::CompletionCallback* completion_callback) = 0; |
| 133 | 138 |
| 134 // Copies cache data from the given buffer of length |buf_len|. If | 139 // Copies cache data from the given buffer of length |buf_len|. If |
| 135 // completion_callback is null, then this call blocks until the write | 140 // completion_callback is null, then this call blocks until the write |
| 136 // operation is complete. Otherwise, completion_callback will be | 141 // operation is complete. Otherwise, completion_callback will be |
| 137 // called on the current thread once the write completes. Returns the | 142 // called on the current thread once the write completes. Returns the |
| 138 // number of bytes written or a network error code. If a completion callback | 143 // number of bytes written or a network error code. If a completion callback |
| 139 // is provided then it will be called if this function returns ERR_IO_PENDING. | 144 // is provided then it will be called if this function returns ERR_IO_PENDING, |
| 145 // and a reference to |buf| will be retained until the callback is called. |
| 140 // Note that the callback will be invoked in any case, even after Close has | 146 // Note that the callback will be invoked in any case, even after Close has |
| 141 // been called; in other words, the caller may close this entry without | 147 // been called; in other words, the caller may close this entry without |
| 142 // having to wait for all the callbacks, and still rely on the cleanup | 148 // having to wait for all the callbacks, and still rely on the cleanup |
| 143 // performed from the callback code. | 149 // performed from the callback code. |
| 144 // If truncate is true, this call will truncate the stored data at the end of | 150 // If truncate is true, this call will truncate the stored data at the end of |
| 145 // what we are writing here. | 151 // what we are writing here. |
| 146 virtual int WriteData(int index, int offset, const char* buf, int buf_len, | 152 virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, |
| 147 net::CompletionCallback* completion_callback, | 153 net::CompletionCallback* completion_callback, |
| 148 bool truncate) = 0; | 154 bool truncate) = 0; |
| 149 | 155 |
| 150 protected: | 156 protected: |
| 151 virtual ~Entry() {} | 157 virtual ~Entry() {} |
| 152 }; | 158 }; |
| 153 | 159 |
| 154 } // namespace disk_cache | 160 } // namespace disk_cache |
| 155 | 161 |
| 156 #endif // NET_DISK_CACHE_DISK_CACHE_H__ | 162 #endif // NET_DISK_CACHE_DISK_CACHE_H__ |
| 157 | 163 |
| OLD | NEW |