| 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" |
| 11 #include "base/task.h" | 11 #include "base/task.h" |
| 12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 13 #include "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
| 14 #include "net/http/http_response_info.h" | 14 #include "net/http/http_response_info.h" |
| 15 #include "webkit/appcache/appcache_interfaces.h" | 15 #include "webkit/appcache/appcache_interfaces.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 class IOBuffer; | 18 class IOBuffer; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace appcache { | 21 namespace appcache { |
| 22 | 22 |
| 23 class AppCacheService; | 23 class AppCacheService; |
| 24 | 24 |
| 25 static const int kUnkownResponseDataSize = -1; | 25 static const int kUnkownResponseDataSize = -1; |
| 26 | 26 |
| 27 // Response info for a particular response id. Instances are tracked in | 27 // Response info for a particular response id. Instances are tracked in |
| 28 // the working set. | 28 // the working set. |
| 29 class AppCacheResponseInfo | 29 class APPCACHE_EXPORT AppCacheResponseInfo |
| 30 : public base::RefCounted<AppCacheResponseInfo> { | 30 : public base::RefCounted<AppCacheResponseInfo> { |
| 31 public: | 31 public: |
| 32 // AppCacheResponseInfo takes ownership of the http_info. | 32 // AppCacheResponseInfo takes ownership of the http_info. |
| 33 AppCacheResponseInfo(AppCacheService* service, const GURL& manifest_url, | 33 AppCacheResponseInfo(AppCacheService* service, const GURL& manifest_url, |
| 34 int64 response_id, net::HttpResponseInfo* http_info, | 34 int64 response_id, net::HttpResponseInfo* http_info, |
| 35 int64 response_data_size); | 35 int64 response_data_size); |
| 36 | 36 |
| 37 const GURL& manifest_url() const { return manifest_url_; } | 37 const GURL& manifest_url() const { return manifest_url_; } |
| 38 int64 response_id() const { return response_id_; } | 38 int64 response_id() const { return response_id_; } |
| 39 const net::HttpResponseInfo* http_response_info() const { | 39 const net::HttpResponseInfo* http_response_info() const { |
| 40 return http_response_info_.get(); | 40 return http_response_info_.get(); |
| 41 } | 41 } |
| 42 int64 response_data_size() const { return response_data_size_; } | 42 int64 response_data_size() const { return response_data_size_; } |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 friend class base::RefCounted<AppCacheResponseInfo>; | 45 friend class base::RefCounted<AppCacheResponseInfo>; |
| 46 virtual ~AppCacheResponseInfo(); | 46 virtual ~AppCacheResponseInfo(); |
| 47 | 47 |
| 48 const GURL manifest_url_; | 48 const GURL manifest_url_; |
| 49 const int64 response_id_; | 49 const int64 response_id_; |
| 50 const scoped_ptr<net::HttpResponseInfo> http_response_info_; | 50 const scoped_ptr<net::HttpResponseInfo> http_response_info_; |
| 51 const int64 response_data_size_; | 51 const int64 response_data_size_; |
| 52 const AppCacheService* service_; | 52 const AppCacheService* service_; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 // A refcounted wrapper for HttpResponseInfo so we can apply the | 55 // A refcounted wrapper for HttpResponseInfo so we can apply the |
| 56 // refcounting semantics used with IOBuffer with these structures too. | 56 // refcounting semantics used with IOBuffer with these structures too. |
| 57 struct HttpResponseInfoIOBuffer | 57 struct APPCACHE_EXPORT HttpResponseInfoIOBuffer |
| 58 : public base::RefCountedThreadSafe<HttpResponseInfoIOBuffer> { | 58 : public base::RefCountedThreadSafe<HttpResponseInfoIOBuffer> { |
| 59 scoped_ptr<net::HttpResponseInfo> http_info; | 59 scoped_ptr<net::HttpResponseInfo> http_info; |
| 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 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 net::CompletionCallback* completion_callback) = 0; | 76 net::CompletionCallback* completion_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 net::CompletionCallback* completion_callback) = 0; | 78 net::CompletionCallback* completion_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::CompletionCallback* callback) = 0; | 86 net::CompletionCallback* callback) = 0; |
| 87 virtual int OpenEntry(int64 key, Entry** entry, | 87 virtual int OpenEntry(int64 key, Entry** entry, |
| 88 net::CompletionCallback* callback) = 0; | 88 net::CompletionCallback* callback) = 0; |
| 89 virtual int DoomEntry(int64 key, net::CompletionCallback* callback) = 0; | 89 virtual int DoomEntry(int64 key, 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 AppCacheResponseIO { | 97 class APPCACHE_EXPORT AppCacheResponseIO { |
| 98 public: | 98 public: |
| 99 virtual ~AppCacheResponseIO(); | 99 virtual ~AppCacheResponseIO(); |
| 100 int64 response_id() const { return response_id_; } | 100 int64 response_id() const { return response_id_; } |
| 101 | 101 |
| 102 protected: | 102 protected: |
| 103 friend class ScopedRunnableMethodFactory<AppCacheResponseIO>; | 103 friend class ScopedRunnableMethodFactory<AppCacheResponseIO>; |
| 104 | 104 |
| 105 template <class T> | 105 template <class T> |
| 106 class EntryCallback : public net::CancelableCompletionCallback<T> { | 106 class EntryCallback : public net::CancelableCompletionCallback<T> { |
| 107 public: | 107 public: |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 void OnRawIOComplete(int result); | 141 void OnRawIOComplete(int result); |
| 142 | 142 |
| 143 scoped_refptr<net::CancelableCompletionCallback<AppCacheResponseIO> > | 143 scoped_refptr<net::CancelableCompletionCallback<AppCacheResponseIO> > |
| 144 raw_callback_; | 144 raw_callback_; |
| 145 }; | 145 }; |
| 146 | 146 |
| 147 // Reads existing response data from storage. If the object is deleted | 147 // Reads existing response data from storage. If the object is deleted |
| 148 // and there is a read in progress, the implementation will return | 148 // and there is a read in progress, the implementation will return |
| 149 // immediately but will take care of any side effect of cancelling the | 149 // immediately but will take care of any side effect of cancelling the |
| 150 // operation. In other words, instances are safe to delete at will. | 150 // operation. In other words, instances are safe to delete at will. |
| 151 class AppCacheResponseReader : public AppCacheResponseIO { | 151 class APPCACHE_EXPORT AppCacheResponseReader : public AppCacheResponseIO { |
| 152 public: | 152 public: |
| 153 virtual ~AppCacheResponseReader(); | 153 virtual ~AppCacheResponseReader(); |
| 154 | 154 |
| 155 // Reads http info from storage. Always returns the result of the read | 155 // Reads http info from storage. Always returns the result of the read |
| 156 // asynchronously through the 'callback'. Returns the number of bytes read | 156 // asynchronously through the 'callback'. Returns the number of bytes read |
| 157 // or a net:: error code. Guaranteed to not perform partial reads of | 157 // or a net:: error code. Guaranteed to not perform partial reads of |
| 158 // the info data. The reader acquires a reference to the 'info_buf' until | 158 // the info data. The reader acquires a reference to the 'info_buf' until |
| 159 // completion at which time the callback is invoked with either a negative | 159 // completion at which time the callback is invoked with either a negative |
| 160 // error code or the number of bytes read. The 'info_buf' argument should | 160 // error code or the number of bytes read. The 'info_buf' argument should |
| 161 // contain a NULL http_info when ReadInfo is called. The 'callback' is a | 161 // contain a NULL http_info when ReadInfo is called. The 'callback' is a |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 int range_offset_; | 201 int range_offset_; |
| 202 int range_length_; | 202 int range_length_; |
| 203 int read_position_; | 203 int read_position_; |
| 204 scoped_refptr<EntryCallback<AppCacheResponseReader> > open_callback_; | 204 scoped_refptr<EntryCallback<AppCacheResponseReader> > open_callback_; |
| 205 }; | 205 }; |
| 206 | 206 |
| 207 // Writes new response data to storage. If the object is deleted | 207 // Writes new response data to storage. If the object is deleted |
| 208 // and there is a write in progress, the implementation will return | 208 // and there is a write in progress, the implementation will return |
| 209 // immediately but will take care of any side effect of cancelling the | 209 // immediately but will take care of any side effect of cancelling the |
| 210 // operation. In other words, instances are safe to delete at will. | 210 // operation. In other words, instances are safe to delete at will. |
| 211 class AppCacheResponseWriter : public AppCacheResponseIO { | 211 class APPCACHE_EXPORT AppCacheResponseWriter : public AppCacheResponseIO { |
| 212 public: | 212 public: |
| 213 virtual ~AppCacheResponseWriter(); | 213 virtual ~AppCacheResponseWriter(); |
| 214 | 214 |
| 215 // Writes the http info to storage. Always returns the result of the write | 215 // Writes the http info to storage. Always returns the result of the write |
| 216 // asynchronously through the 'callback'. Returns the number of bytes written | 216 // asynchronously through the 'callback'. Returns the number of bytes written |
| 217 // or a net:: error code. The writer acquires a reference to the 'info_buf' | 217 // or a net:: error code. The writer acquires a reference to the 'info_buf' |
| 218 // until completion at which time the callback is invoked with either a | 218 // until completion at which time the callback is invoked with either a |
| 219 // negative error code or the number of bytes written. The 'callback' is a | 219 // negative error code or the number of bytes written. The 'callback' is a |
| 220 // required parameter. The contents of 'info_buf' are not modified. | 220 // required parameter. The contents of 'info_buf' are not modified. |
| 221 // Should only be called where there is no Write operation in progress. | 221 // Should only be called where there is no Write operation in progress. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 int write_position_; | 264 int write_position_; |
| 265 int write_amount_; | 265 int write_amount_; |
| 266 CreationPhase creation_phase_; | 266 CreationPhase creation_phase_; |
| 267 scoped_refptr<EntryCallback<AppCacheResponseWriter> > create_callback_; | 267 scoped_refptr<EntryCallback<AppCacheResponseWriter> > create_callback_; |
| 268 }; | 268 }; |
| 269 | 269 |
| 270 } // namespace appcache | 270 } // namespace appcache |
| 271 | 271 |
| 272 #endif // WEBKIT_APPCACHE_APPCACHE_RESPONSE_H_ | 272 #endif // WEBKIT_APPCACHE_APPCACHE_RESPONSE_H_ |
| 273 | 273 |
| OLD | NEW |