Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 WEBKIT_APPCACHE_APPCACHE_RESPONSE_H_ | 5 #ifndef WEBKIT_APPCACHE_APPCACHE_RESPONSE_H_ |
| 6 #define WEBKIT_APPCACHE_APPCACHE_RESPONSE_H_ | 6 #define WEBKIT_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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 int response_data_size; | 60 int response_data_size; |
| 61 | 61 |
| 62 HttpResponseInfoIOBuffer(); | 62 HttpResponseInfoIOBuffer(); |
| 63 explicit HttpResponseInfoIOBuffer(net::HttpResponseInfo* info); | 63 explicit HttpResponseInfoIOBuffer(net::HttpResponseInfo* info); |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 friend class base::RefCountedThreadSafe<HttpResponseInfoIOBuffer>; | 66 friend class base::RefCountedThreadSafe<HttpResponseInfoIOBuffer>; |
| 67 virtual ~HttpResponseInfoIOBuffer(); | 67 virtual ~HttpResponseInfoIOBuffer(); |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 // Low level storage api used by the response reader and writer. | 70 // Low level storage API used by the response reader and writer. |
| 71 class APPCACHE_EXPORT AppCacheDiskCacheInterface { | 71 class APPCACHE_EXPORT AppCacheDiskCacheInterface { |
| 72 public: | 72 public: |
| 73 class Entry { | 73 class Entry { |
| 74 public: | 74 public: |
| 75 virtual int Read(int index, int64 offset, net::IOBuffer* buf, int buf_len, | 75 virtual int Read(int index, int64 offset, net::IOBuffer* buf, int buf_len, |
| 76 const net::CompletionCallback& callback) = 0; | 76 const net::CompletionCallback& callback) = 0; |
| 77 virtual int Write(int index, int64 offset, net::IOBuffer* buf, int buf_len, | 77 virtual int Write(int index, int64 offset, net::IOBuffer* buf, int buf_len, |
| 78 const net::CompletionCallback& callback) = 0; | 78 const net::CompletionCallback& callback) = 0; |
| 79 virtual int64 GetSize(int index) = 0; | 79 virtual int64 GetSize(int index) = 0; |
| 80 virtual void Close() = 0; | 80 virtual void Close() = 0; |
| 81 protected: | 81 protected: |
| 82 virtual ~Entry() {} | 82 virtual ~Entry() {} |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 virtual int CreateEntry(int64 key, Entry** entry, | 85 virtual int CreateEntry(int64 key, Entry** entry, |
| 86 net::OldCompletionCallback* callback) = 0; | 86 const net::CompletionCallback& callback) = 0; |
| 87 virtual int OpenEntry(int64 key, Entry** entry, | 87 virtual int OpenEntry(int64 key, Entry** entry, |
| 88 net::OldCompletionCallback* callback) = 0; | 88 const net::CompletionCallback& callback) = 0; |
| 89 virtual int DoomEntry(int64 key, net::OldCompletionCallback* callback) = 0; | 89 virtual int DoomEntry(int64 key, const net::CompletionCallback& callback) = 0; |
| 90 | 90 |
| 91 protected: | 91 protected: |
| 92 friend class base::RefCounted<AppCacheDiskCacheInterface>; | 92 friend class base::RefCounted<AppCacheDiskCacheInterface>; |
| 93 virtual ~AppCacheDiskCacheInterface() {} | 93 virtual ~AppCacheDiskCacheInterface() {} |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 // Common base class for response reader and writer. | 96 // Common base class for response reader and writer. |
| 97 class APPCACHE_EXPORT AppCacheResponseIO { | 97 class APPCACHE_EXPORT AppCacheResponseIO { |
| 98 public: | 98 public: |
| 99 virtual ~AppCacheResponseIO(); | 99 virtual ~AppCacheResponseIO(); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 114 entry_ptr_->Close(); | 114 entry_ptr_->Close(); |
| 115 } | 115 } |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 AppCacheResponseIO(int64 response_id, | 118 AppCacheResponseIO(int64 response_id, |
| 119 int64 group_id, | 119 int64 group_id, |
| 120 AppCacheDiskCacheInterface* disk_cache); | 120 AppCacheDiskCacheInterface* disk_cache); |
| 121 | 121 |
| 122 virtual void OnIOComplete(int result) = 0; | 122 virtual void OnIOComplete(int result) = 0; |
| 123 | 123 |
| 124 bool IsIOPending() { return user_callback_ ? true : false; } | 124 bool IsIOPending() { return callback_.is_null() ? false : true; } |
|
awong
2011/12/20 23:51:47
"!callback_.is_null()"?
James Hawkins
2011/12/21 00:43:08
Haha, done.
| |
| 125 void ScheduleIOOldCompletionCallback(int result); | 125 void ScheduleIOOldCompletionCallback(int result); |
| 126 void InvokeUserOldCompletionCallback(int result); | 126 void InvokeUserOldCompletionCallback(int result); |
| 127 void ReadRaw(int index, int offset, net::IOBuffer* buf, int buf_len); | 127 void ReadRaw(int index, int offset, net::IOBuffer* buf, int buf_len); |
| 128 void WriteRaw(int index, int offset, net::IOBuffer* buf, int buf_len); | 128 void WriteRaw(int index, int offset, net::IOBuffer* buf, int buf_len); |
| 129 | 129 |
| 130 const int64 response_id_; | 130 const int64 response_id_; |
| 131 const int64 group_id_; | 131 const int64 group_id_; |
| 132 AppCacheDiskCacheInterface* disk_cache_; | 132 AppCacheDiskCacheInterface* disk_cache_; |
| 133 AppCacheDiskCacheInterface::Entry* entry_; | 133 AppCacheDiskCacheInterface::Entry* entry_; |
| 134 scoped_refptr<HttpResponseInfoIOBuffer> info_buffer_; | 134 scoped_refptr<HttpResponseInfoIOBuffer> info_buffer_; |
| 135 scoped_refptr<net::IOBuffer> buffer_; | 135 scoped_refptr<net::IOBuffer> buffer_; |
| 136 int buffer_len_; | 136 int buffer_len_; |
| 137 net::OldCompletionCallback* user_callback_; | 137 net::CompletionCallback callback_; |
| 138 base::WeakPtrFactory<AppCacheResponseIO> weak_factory_; | 138 base::WeakPtrFactory<AppCacheResponseIO> weak_factory_; |
| 139 | 139 |
| 140 private: | 140 private: |
| 141 void OnRawIOComplete(int result); | 141 void OnRawIOComplete(int result); |
| 142 }; | 142 }; |
| 143 | 143 |
| 144 // Reads existing response data from storage. If the object is deleted | 144 // Reads existing response data from storage. If the object is deleted |
| 145 // and there is a read in progress, the implementation will return | 145 // and there is a read in progress, the implementation will return |
| 146 // immediately but will take care of any side effect of cancelling the | 146 // immediately but will take care of any side effect of cancelling the |
| 147 // operation. In other words, instances are safe to delete at will. | 147 // operation. In other words, instances are safe to delete at will. |
| 148 class APPCACHE_EXPORT AppCacheResponseReader : public AppCacheResponseIO { | 148 class APPCACHE_EXPORT AppCacheResponseReader : public AppCacheResponseIO { |
| 149 public: | 149 public: |
| 150 virtual ~AppCacheResponseReader(); | 150 virtual ~AppCacheResponseReader(); |
| 151 | 151 |
| 152 // Reads http info from storage. Always returns the result of the read | 152 // Reads http info from storage. Always returns the result of the read |
| 153 // asynchronously through the 'callback'. Returns the number of bytes read | 153 // asynchronously through the 'callback'. Returns the number of bytes read |
| 154 // or a net:: error code. Guaranteed to not perform partial reads of | 154 // or a net:: error code. Guaranteed to not perform partial reads of |
| 155 // the info data. The reader acquires a reference to the 'info_buf' until | 155 // the info data. The reader acquires a reference to the 'info_buf' until |
| 156 // completion at which time the callback is invoked with either a negative | 156 // completion at which time the callback is invoked with either a negative |
| 157 // error code or the number of bytes read. The 'info_buf' argument should | 157 // error code or the number of bytes read. The 'info_buf' argument should |
| 158 // contain a NULL http_info when ReadInfo is called. The 'callback' is a | 158 // contain a NULL http_info when ReadInfo is called. The 'callback' is a |
| 159 // required parameter. | 159 // required parameter. |
| 160 // Should only be called where there is no Read operation in progress. | 160 // Should only be called where there is no Read operation in progress. |
| 161 // (virtual for testing) | 161 // (virtual for testing) |
| 162 virtual void ReadInfo(HttpResponseInfoIOBuffer* info_buf, | 162 virtual void ReadInfo(HttpResponseInfoIOBuffer* info_buf, |
| 163 net::OldCompletionCallback* callback); | 163 const net::CompletionCallback& callback); |
| 164 | 164 |
| 165 // Reads data from storage. Always returns the result of the read | 165 // Reads data from storage. Always returns the result of the read |
| 166 // asynchronously through the 'callback'. Returns the number of bytes read | 166 // asynchronously through the 'callback'. Returns the number of bytes read |
| 167 // or a net:: error code. EOF is indicated with a return value of zero. | 167 // or a net:: error code. EOF is indicated with a return value of zero. |
| 168 // The reader acquires a reference to the provided 'buf' until completion | 168 // The reader acquires a reference to the provided 'buf' until completion |
| 169 // at which time the callback is invoked with either a negative error code | 169 // at which time the callback is invoked with either a negative error code |
| 170 // or the number of bytes read. The 'callback' is a required parameter. | 170 // or the number of bytes read. The 'callback' is a required parameter. |
| 171 // Should only be called where there is no Read operation in progress. | 171 // Should only be called where there is no Read operation in progress. |
| 172 // (virtual for testing) | 172 // (virtual for testing) |
| 173 virtual void ReadData(net::IOBuffer* buf, int buf_len, | 173 virtual void ReadData(net::IOBuffer* buf, int buf_len, |
| 174 net::OldCompletionCallback* callback); | 174 const net::CompletionCallback& callback); |
| 175 | 175 |
| 176 // Returns true if there is a read operation, for data or info, pending. | 176 // Returns true if there is a read operation, for data or info, pending. |
| 177 bool IsReadPending() { return IsIOPending(); } | 177 bool IsReadPending() { return IsIOPending(); } |
| 178 | 178 |
| 179 // Used to support range requests. If not called, the reader will | 179 // Used to support range requests. If not called, the reader will |
| 180 // read the entire response body. If called, this must be called prior | 180 // read the entire response body. If called, this must be called prior |
| 181 // to the first call to the ReadData method. | 181 // to the first call to the ReadData method. |
| 182 void SetReadRange(int offset, int length); | 182 void SetReadRange(int offset, int length); |
| 183 | 183 |
| 184 protected: | 184 protected: |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 211 virtual ~AppCacheResponseWriter(); | 211 virtual ~AppCacheResponseWriter(); |
| 212 | 212 |
| 213 // Writes the http info to storage. Always returns the result of the write | 213 // Writes the http info to storage. Always returns the result of the write |
| 214 // asynchronously through the 'callback'. Returns the number of bytes written | 214 // asynchronously through the 'callback'. Returns the number of bytes written |
| 215 // or a net:: error code. The writer acquires a reference to the 'info_buf' | 215 // or a net:: error code. The writer acquires a reference to the 'info_buf' |
| 216 // until completion at which time the callback is invoked with either a | 216 // until completion at which time the callback is invoked with either a |
| 217 // negative error code or the number of bytes written. The 'callback' is a | 217 // negative error code or the number of bytes written. The 'callback' is a |
| 218 // required parameter. The contents of 'info_buf' are not modified. | 218 // required parameter. The contents of 'info_buf' are not modified. |
| 219 // Should only be called where there is no Write operation in progress. | 219 // Should only be called where there is no Write operation in progress. |
| 220 void WriteInfo(HttpResponseInfoIOBuffer* info_buf, | 220 void WriteInfo(HttpResponseInfoIOBuffer* info_buf, |
| 221 net::OldCompletionCallback* callback); | 221 const net::CompletionCallback& callback); |
| 222 | 222 |
| 223 // Writes data to storage. Always returns the result of the write | 223 // Writes data to storage. Always returns the result of the write |
| 224 // asynchronously through the 'callback'. Returns the number of bytes written | 224 // asynchronously through the 'callback'. Returns the number of bytes written |
| 225 // or a net:: error code. Guaranteed to not perform partial writes. | 225 // or a net:: error code. Guaranteed to not perform partial writes. |
| 226 // The writer acquires a reference to the provided 'buf' until completion at | 226 // The writer acquires a reference to the provided 'buf' until completion at |
| 227 // which time the callback is invoked with either a negative error code or | 227 // which time the callback is invoked with either a negative error code or |
| 228 // the number of bytes written. The 'callback' is a required parameter. | 228 // the number of bytes written. The 'callback' is a required parameter. |
| 229 // The contents of 'buf' are not modified. | 229 // The contents of 'buf' are not modified. |
| 230 // Should only be called where there is no Write operation in progress. | 230 // Should only be called where there is no Write operation in progress. |
| 231 void WriteData(net::IOBuffer* buf, int buf_len, | 231 void WriteData(net::IOBuffer* buf, int buf_len, |
| 232 net::OldCompletionCallback* callback); | 232 const net::CompletionCallback& callback); |
| 233 | 233 |
| 234 // Returns true if there is a write pending. | 234 // Returns true if there is a write pending. |
| 235 bool IsWritePending() { return IsIOPending(); } | 235 bool IsWritePending() { return IsIOPending(); } |
| 236 | 236 |
| 237 // Returns the amount written, info and data. | 237 // Returns the amount written, info and data. |
| 238 int64 amount_written() { return info_size_ + write_position_; } | 238 int64 amount_written() { return info_size_ + write_position_; } |
| 239 | 239 |
| 240 private: | 240 private: |
| 241 friend class AppCacheStorageImpl; | 241 friend class AppCacheStorageImpl; |
| 242 friend class MockAppCacheStorage; | 242 friend class MockAppCacheStorage; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 263 int write_position_; | 263 int write_position_; |
| 264 int write_amount_; | 264 int write_amount_; |
| 265 CreationPhase creation_phase_; | 265 CreationPhase creation_phase_; |
| 266 scoped_refptr<EntryCallback<AppCacheResponseWriter> > create_callback_; | 266 scoped_refptr<EntryCallback<AppCacheResponseWriter> > create_callback_; |
| 267 }; | 267 }; |
| 268 | 268 |
| 269 } // namespace appcache | 269 } // namespace appcache |
| 270 | 270 |
| 271 #endif // WEBKIT_APPCACHE_APPCACHE_RESPONSE_H_ | 271 #endif // WEBKIT_APPCACHE_APPCACHE_RESPONSE_H_ |
| 272 | 272 |
| OLD | NEW |