| 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 "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 public: | 99 public: |
| 100 virtual ~AppCacheResponseIO(); | 100 virtual ~AppCacheResponseIO(); |
| 101 int64 response_id() const { return response_id_; } | 101 int64 response_id() const { return response_id_; } |
| 102 | 102 |
| 103 protected: | 103 protected: |
| 104 AppCacheResponseIO(int64 response_id, | 104 AppCacheResponseIO(int64 response_id, |
| 105 int64 group_id, | 105 int64 group_id, |
| 106 AppCacheDiskCacheInterface* disk_cache); | 106 AppCacheDiskCacheInterface* disk_cache); |
| 107 | 107 |
| 108 virtual void OnIOComplete(int result) = 0; | 108 virtual void OnIOComplete(int result) = 0; |
| 109 virtual void OnOpenEntryComplete() {} |
| 109 | 110 |
| 110 bool IsIOPending() { return !callback_.is_null(); } | 111 bool IsIOPending() { return !callback_.is_null(); } |
| 111 void ScheduleIOCompletionCallback(int result); | 112 void ScheduleIOCompletionCallback(int result); |
| 112 void InvokeUserCompletionCallback(int result); | 113 void InvokeUserCompletionCallback(int result); |
| 113 void ReadRaw(int index, int offset, net::IOBuffer* buf, int buf_len); | 114 void ReadRaw(int index, int offset, net::IOBuffer* buf, int buf_len); |
| 114 void WriteRaw(int index, int offset, net::IOBuffer* buf, int buf_len); | 115 void WriteRaw(int index, int offset, net::IOBuffer* buf, int buf_len); |
| 116 void OpenEntryIfNeeded(); |
| 115 | 117 |
| 116 const int64 response_id_; | 118 const int64 response_id_; |
| 117 const int64 group_id_; | 119 const int64 group_id_; |
| 118 AppCacheDiskCacheInterface* disk_cache_; | 120 AppCacheDiskCacheInterface* disk_cache_; |
| 119 AppCacheDiskCacheInterface::Entry* entry_; | 121 AppCacheDiskCacheInterface::Entry* entry_; |
| 120 scoped_refptr<HttpResponseInfoIOBuffer> info_buffer_; | 122 scoped_refptr<HttpResponseInfoIOBuffer> info_buffer_; |
| 121 scoped_refptr<net::IOBuffer> buffer_; | 123 scoped_refptr<net::IOBuffer> buffer_; |
| 122 int buffer_len_; | 124 int buffer_len_; |
| 123 net::CompletionCallback callback_; | 125 net::CompletionCallback callback_; |
| 126 net::CompletionCallback open_callback_; |
| 124 base::WeakPtrFactory<AppCacheResponseIO> weak_factory_; | 127 base::WeakPtrFactory<AppCacheResponseIO> weak_factory_; |
| 125 | 128 |
| 126 private: | 129 private: |
| 127 void OnRawIOComplete(int result); | 130 void OnRawIOComplete(int result); |
| 131 void OpenEntryCallback(AppCacheDiskCacheInterface::Entry** entry, int rv); |
| 128 }; | 132 }; |
| 129 | 133 |
| 130 // Reads existing response data from storage. If the object is deleted | 134 // Reads existing response data from storage. If the object is deleted |
| 131 // and there is a read in progress, the implementation will return | 135 // and there is a read in progress, the implementation will return |
| 132 // immediately but will take care of any side effect of cancelling the | 136 // immediately but will take care of any side effect of cancelling the |
| 133 // operation. In other words, instances are safe to delete at will. | 137 // operation. In other words, instances are safe to delete at will. |
| 134 class CONTENT_EXPORT AppCacheResponseReader | 138 class CONTENT_EXPORT AppCacheResponseReader |
| 135 : public AppCacheResponseIO { | 139 : public AppCacheResponseIO { |
| 136 public: | 140 public: |
| 137 ~AppCacheResponseReader() override; | 141 ~AppCacheResponseReader() override; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 protected: | 175 protected: |
| 172 friend class AppCacheStorageImpl; | 176 friend class AppCacheStorageImpl; |
| 173 friend class content::MockAppCacheStorage; | 177 friend class content::MockAppCacheStorage; |
| 174 | 178 |
| 175 // Should only be constructed by the storage class and derivatives. | 179 // Should only be constructed by the storage class and derivatives. |
| 176 AppCacheResponseReader(int64 response_id, | 180 AppCacheResponseReader(int64 response_id, |
| 177 int64 group_id, | 181 int64 group_id, |
| 178 AppCacheDiskCacheInterface* disk_cache); | 182 AppCacheDiskCacheInterface* disk_cache); |
| 179 | 183 |
| 180 void OnIOComplete(int result) override; | 184 void OnIOComplete(int result) override; |
| 185 void OnOpenEntryComplete() override; |
| 181 void ContinueReadInfo(); | 186 void ContinueReadInfo(); |
| 182 void ContinueReadData(); | 187 void ContinueReadData(); |
| 183 void OpenEntryIfNeededAndContinue(); | |
| 184 void OnOpenEntryComplete(AppCacheDiskCacheInterface::Entry** entry, int rv); | |
| 185 | 188 |
| 186 int range_offset_; | 189 int range_offset_; |
| 187 int range_length_; | 190 int range_length_; |
| 188 int read_position_; | 191 int read_position_; |
| 189 net::CompletionCallback open_callback_; | 192 int reading_metadata_size_; |
| 190 base::WeakPtrFactory<AppCacheResponseReader> weak_factory_; | 193 base::WeakPtrFactory<AppCacheResponseReader> weak_factory_; |
| 191 }; | 194 }; |
| 192 | 195 |
| 193 // Writes new response data to storage. If the object is deleted | 196 // Writes new response data to storage. If the object is deleted |
| 194 // and there is a write in progress, the implementation will return | 197 // and there is a write in progress, the implementation will return |
| 195 // immediately but will take care of any side effect of cancelling the | 198 // immediately but will take care of any side effect of cancelling the |
| 196 // operation. In other words, instances are safe to delete at will. | 199 // operation. In other words, instances are safe to delete at will. |
| 197 class CONTENT_EXPORT AppCacheResponseWriter | 200 class CONTENT_EXPORT AppCacheResponseWriter |
| 198 : public AppCacheResponseIO { | 201 : public AppCacheResponseIO { |
| 199 public: | 202 public: |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 void OnCreateEntryComplete(AppCacheDiskCacheInterface::Entry** entry, int rv); | 253 void OnCreateEntryComplete(AppCacheDiskCacheInterface::Entry** entry, int rv); |
| 251 | 254 |
| 252 int info_size_; | 255 int info_size_; |
| 253 int write_position_; | 256 int write_position_; |
| 254 int write_amount_; | 257 int write_amount_; |
| 255 CreationPhase creation_phase_; | 258 CreationPhase creation_phase_; |
| 256 net::CompletionCallback create_callback_; | 259 net::CompletionCallback create_callback_; |
| 257 base::WeakPtrFactory<AppCacheResponseWriter> weak_factory_; | 260 base::WeakPtrFactory<AppCacheResponseWriter> weak_factory_; |
| 258 }; | 261 }; |
| 259 | 262 |
| 263 // Writes metadata of the existing response to storage. If the object is deleted |
| 264 // and there is a write in progress, the implementation will return |
| 265 // immediately but will take care of any side effect of cancelling the |
| 266 // operation. In other words, instances are safe to delete at will. |
| 267 class CONTENT_EXPORT AppCacheResponseMetadataWriter |
| 268 : public AppCacheResponseIO { |
| 269 public: |
| 270 ~AppCacheResponseMetadataWriter() override; |
| 271 |
| 272 // Writes metadata to storage. Always returns the result of the write |
| 273 // asynchronously through the 'callback'. Returns the number of bytes written |
| 274 // or a net:: error code. Guaranteed to not perform partial writes. |
| 275 // The writer acquires a reference to the provided 'buf' until completion at |
| 276 // which time the callback is invoked with either a negative error code or |
| 277 // the number of bytes written. The 'callback' is a required parameter. |
| 278 // The contents of 'buf' are not modified. |
| 279 // Should only be called where there is no WriteMetadata operation in |
| 280 // progress. |
| 281 void WriteMetadata(net::IOBuffer* buf, |
| 282 int buf_len, |
| 283 const net::CompletionCallback& callback); |
| 284 |
| 285 // Returns true if there is a write pending. |
| 286 bool IsWritePending() { return IsIOPending(); } |
| 287 |
| 288 protected: |
| 289 friend class AppCacheStorageImpl; |
| 290 friend class content::MockAppCacheStorage; |
| 291 // Should only be constructed by the storage class and derivatives. |
| 292 AppCacheResponseMetadataWriter(int64 response_id, |
| 293 int64 group_id, |
| 294 AppCacheDiskCacheInterface* disk_cache); |
| 295 |
| 296 private: |
| 297 void OnIOComplete(int result) override; |
| 298 void OnOpenEntryComplete() override; |
| 299 |
| 300 int write_amount_; |
| 301 base::WeakPtrFactory<AppCacheResponseMetadataWriter> weak_factory_; |
| 302 }; |
| 303 |
| 260 } // namespace content | 304 } // namespace content |
| 261 | 305 |
| 262 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_RESPONSE_H_ | 306 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_RESPONSE_H_ |
| OLD | NEW |