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 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_RESPONSE_H_ | 5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_RESPONSE_H_ |
6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_RESPONSE_H_ | 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_RESPONSE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 115 |
116 // Common base class for response reader and writer. | 116 // Common base class for response reader and writer. |
117 class CONTENT_EXPORT AppCacheResponseIO { | 117 class CONTENT_EXPORT AppCacheResponseIO { |
118 public: | 118 public: |
119 virtual ~AppCacheResponseIO(); | 119 virtual ~AppCacheResponseIO(); |
120 int64_t response_id() const { return response_id_; } | 120 int64_t response_id() const { return response_id_; } |
121 | 121 |
122 protected: | 122 protected: |
123 AppCacheResponseIO( | 123 AppCacheResponseIO( |
124 int64_t response_id, | 124 int64_t response_id, |
125 int64_t group_id, | |
126 const base::WeakPtr<AppCacheDiskCacheInterface>& disk_cache); | 125 const base::WeakPtr<AppCacheDiskCacheInterface>& disk_cache); |
127 | 126 |
128 virtual void OnIOComplete(int result) = 0; | 127 virtual void OnIOComplete(int result) = 0; |
129 virtual void OnOpenEntryComplete() {} | 128 virtual void OnOpenEntryComplete() {} |
130 | 129 |
131 bool IsIOPending() { return !callback_.is_null(); } | 130 bool IsIOPending() { return !callback_.is_null(); } |
132 void ScheduleIOCompletionCallback(int result); | 131 void ScheduleIOCompletionCallback(int result); |
133 void InvokeUserCompletionCallback(int result); | 132 void InvokeUserCompletionCallback(int result); |
134 void ReadRaw(int index, int offset, net::IOBuffer* buf, int buf_len); | 133 void ReadRaw(int index, int offset, net::IOBuffer* buf, int buf_len); |
135 void WriteRaw(int index, int offset, net::IOBuffer* buf, int buf_len); | 134 void WriteRaw(int index, int offset, net::IOBuffer* buf, int buf_len); |
136 void OpenEntryIfNeeded(); | 135 void OpenEntryIfNeeded(); |
137 | 136 |
138 const int64_t response_id_; | 137 const int64_t response_id_; |
139 const int64_t group_id_; | |
140 base::WeakPtr<AppCacheDiskCacheInterface> disk_cache_; | 138 base::WeakPtr<AppCacheDiskCacheInterface> disk_cache_; |
141 AppCacheDiskCacheInterface::Entry* entry_; | 139 AppCacheDiskCacheInterface::Entry* entry_; |
142 scoped_refptr<HttpResponseInfoIOBuffer> info_buffer_; | 140 scoped_refptr<HttpResponseInfoIOBuffer> info_buffer_; |
143 scoped_refptr<net::IOBuffer> buffer_; | 141 scoped_refptr<net::IOBuffer> buffer_; |
144 int buffer_len_; | 142 int buffer_len_; |
145 net::CompletionCallback callback_; | 143 net::CompletionCallback callback_; |
146 net::CompletionCallback open_callback_; | 144 net::CompletionCallback open_callback_; |
147 base::WeakPtrFactory<AppCacheResponseIO> weak_factory_; | 145 base::WeakPtrFactory<AppCacheResponseIO> weak_factory_; |
148 | 146 |
149 private: | 147 private: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 // to the first call to the ReadData method. | 190 // to the first call to the ReadData method. |
193 void SetReadRange(int offset, int length); | 191 void SetReadRange(int offset, int length); |
194 | 192 |
195 protected: | 193 protected: |
196 friend class AppCacheStorageImpl; | 194 friend class AppCacheStorageImpl; |
197 friend class content::MockAppCacheStorage; | 195 friend class content::MockAppCacheStorage; |
198 | 196 |
199 // Should only be constructed by the storage class and derivatives. | 197 // Should only be constructed by the storage class and derivatives. |
200 AppCacheResponseReader( | 198 AppCacheResponseReader( |
201 int64_t response_id, | 199 int64_t response_id, |
202 int64_t group_id, | |
203 const base::WeakPtr<AppCacheDiskCacheInterface>& disk_cache); | 200 const base::WeakPtr<AppCacheDiskCacheInterface>& disk_cache); |
204 | 201 |
205 void OnIOComplete(int result) override; | 202 void OnIOComplete(int result) override; |
206 void OnOpenEntryComplete() override; | 203 void OnOpenEntryComplete() override; |
207 void ContinueReadInfo(); | 204 void ContinueReadInfo(); |
208 void ContinueReadData(); | 205 void ContinueReadData(); |
209 | 206 |
210 int range_offset_; | 207 int range_offset_; |
211 int range_length_; | 208 int range_length_; |
212 int read_position_; | 209 int read_position_; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 // Returns true if there is a write pending. | 247 // Returns true if there is a write pending. |
251 bool IsWritePending() { return IsIOPending(); } | 248 bool IsWritePending() { return IsIOPending(); } |
252 | 249 |
253 // Returns the amount written, info and data. | 250 // Returns the amount written, info and data. |
254 int64_t amount_written() { return info_size_ + write_position_; } | 251 int64_t amount_written() { return info_size_ + write_position_; } |
255 | 252 |
256 protected: | 253 protected: |
257 // Should only be constructed by the storage class and derivatives. | 254 // Should only be constructed by the storage class and derivatives. |
258 AppCacheResponseWriter( | 255 AppCacheResponseWriter( |
259 int64_t response_id, | 256 int64_t response_id, |
260 int64_t group_id, | |
261 const base::WeakPtr<AppCacheDiskCacheInterface>& disk_cache); | 257 const base::WeakPtr<AppCacheDiskCacheInterface>& disk_cache); |
262 | 258 |
263 private: | 259 private: |
264 friend class AppCacheStorageImpl; | 260 friend class AppCacheStorageImpl; |
265 friend class content::MockAppCacheStorage; | 261 friend class content::MockAppCacheStorage; |
266 | 262 |
267 enum CreationPhase { | 263 enum CreationPhase { |
268 NO_ATTEMPT, | 264 NO_ATTEMPT, |
269 INITIAL_ATTEMPT, | 265 INITIAL_ATTEMPT, |
270 DOOM_EXISTING, | 266 DOOM_EXISTING, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 // Returns true if there is a write pending. | 306 // Returns true if there is a write pending. |
311 bool IsWritePending() { return IsIOPending(); } | 307 bool IsWritePending() { return IsIOPending(); } |
312 | 308 |
313 protected: | 309 protected: |
314 friend class AppCacheStorageImpl; | 310 friend class AppCacheStorageImpl; |
315 friend class content::MockAppCacheStorage; | 311 friend class content::MockAppCacheStorage; |
316 | 312 |
317 // Should only be constructed by the storage class and derivatives. | 313 // Should only be constructed by the storage class and derivatives. |
318 AppCacheResponseMetadataWriter( | 314 AppCacheResponseMetadataWriter( |
319 int64_t response_id, | 315 int64_t response_id, |
320 int64_t group_id, | |
321 const base::WeakPtr<AppCacheDiskCacheInterface>& disk_cache); | 316 const base::WeakPtr<AppCacheDiskCacheInterface>& disk_cache); |
322 | 317 |
323 private: | 318 private: |
324 void OnIOComplete(int result) override; | 319 void OnIOComplete(int result) override; |
325 void OnOpenEntryComplete() override; | 320 void OnOpenEntryComplete() override; |
326 | 321 |
327 int write_amount_; | 322 int write_amount_; |
328 base::WeakPtrFactory<AppCacheResponseMetadataWriter> weak_factory_; | 323 base::WeakPtrFactory<AppCacheResponseMetadataWriter> weak_factory_; |
329 }; | 324 }; |
330 | 325 |
331 } // namespace content | 326 } // namespace content |
332 | 327 |
333 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_RESPONSE_H_ | 328 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_RESPONSE_H_ |
OLD | NEW |