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/platform_file.h" |
15 #include "base/time.h" | 16 #include "base/time.h" |
16 #include "net/base/completion_callback.h" | 17 #include "net/base/completion_callback.h" |
17 | 18 |
18 namespace net { | 19 namespace net { |
19 class IOBuffer; | 20 class IOBuffer; |
20 } | 21 } |
21 | 22 |
22 namespace disk_cache { | 23 namespace disk_cache { |
23 | 24 |
24 class Entry; | 25 class Entry; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // Note that the callback will be invoked in any case, even after Close has | 147 // 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 | 148 // 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 | 149 // having to wait for all the callbacks, and still rely on the cleanup |
149 // performed from the callback code. | 150 // performed from the callback code. |
150 // If truncate is true, this call will truncate the stored data at the end of | 151 // If truncate is true, this call will truncate the stored data at the end of |
151 // what we are writing here. | 152 // what we are writing here. |
152 virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, | 153 virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, |
153 net::CompletionCallback* completion_callback, | 154 net::CompletionCallback* completion_callback, |
154 bool truncate) = 0; | 155 bool truncate) = 0; |
155 | 156 |
| 157 // Prepares a target stream as an external file, returns a corresponding |
| 158 // base::PlatformFile if successful, returns base::kInvalidPlatformFileValue |
| 159 // if fails. If this call returns a valid base::PlatformFile value (i.e. |
| 160 // not base::kInvalidPlatformFileValue), there is no guarantee that the file |
| 161 // is truncated. Implementor can always return base::kInvalidPlatformFileValue |
| 162 // if external file is not available in that particular implementation. |
| 163 // Caller should never close the file handle returned by this method, since |
| 164 // the handle should be managed by the implementor of this class. Caller |
| 165 // should never save the handle for future use. |
| 166 // With a stream prepared as an external file, the stream would always be |
| 167 // kept in an external file since creation, even if the stream has 0 bytes. |
| 168 // So we need to be cautious about using this option for preparing a stream or |
| 169 // we will end up having a lot of empty cache files. Calling this method also |
| 170 // means that all data written to the stream will always be written to file |
| 171 // directly *without* buffering. |
| 172 virtual base::PlatformFile UseExternalFile(int index) = 0; |
| 173 |
| 174 // Returns a read file handle for the cache stream referenced by |index|. |
| 175 // Caller should never close the handle returned by this method and should |
| 176 // not save it for future use. The lifetime of the base::PlatformFile handle |
| 177 // is managed by the implementor of this class. |
| 178 virtual base::PlatformFile GetPlatformFile(int index) = 0; |
| 179 |
156 protected: | 180 protected: |
157 virtual ~Entry() {} | 181 virtual ~Entry() {} |
158 }; | 182 }; |
159 | 183 |
160 } // namespace disk_cache | 184 } // namespace disk_cache |
161 | 185 |
162 #endif // NET_DISK_CACHE_DISK_CACHE_H__ | 186 #endif // NET_DISK_CACHE_DISK_CACHE_H__ |
163 | 187 |
OLD | NEW |