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