| 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 WEBKIT_BROWSER_APPCACHE_APPCACHE_RESPONSE_H_ | 5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_RESPONSE_H_ |
| 6 #define WEBKIT_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" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "content/common/appcache_interfaces.h" |
| 13 #include "content/common/content_export.h" |
| 12 #include "net/base/completion_callback.h" | 14 #include "net/base/completion_callback.h" |
| 13 #include "net/http/http_response_info.h" | 15 #include "net/http/http_response_info.h" |
| 14 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 15 #include "webkit/browser/webkit_storage_browser_export.h" | |
| 16 #include "webkit/common/appcache/appcache_interfaces.h" | |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 class IOBuffer; | 19 class IOBuffer; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 class MockAppCacheStorage; | 23 class MockAppCacheStorage; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace appcache { | 26 namespace content { |
| 27 | 27 |
| 28 class AppCacheStorage; | 28 class AppCacheStorage; |
| 29 | 29 |
| 30 static const int kUnkownResponseDataSize = -1; | 30 static const int kUnkownResponseDataSize = -1; |
| 31 | 31 |
| 32 // Response info for a particular response id. Instances are tracked in | 32 // Response info for a particular response id. Instances are tracked in |
| 33 // the working set. | 33 // the working set. |
| 34 class WEBKIT_STORAGE_BROWSER_EXPORT AppCacheResponseInfo | 34 class CONTENT_EXPORT AppCacheResponseInfo |
| 35 : public base::RefCounted<AppCacheResponseInfo> { | 35 : public base::RefCounted<AppCacheResponseInfo> { |
| 36 public: | 36 public: |
| 37 // AppCacheResponseInfo takes ownership of the http_info. | 37 // AppCacheResponseInfo takes ownership of the http_info. |
| 38 AppCacheResponseInfo(AppCacheStorage* storage, const GURL& manifest_url, | 38 AppCacheResponseInfo(AppCacheStorage* storage, const GURL& manifest_url, |
| 39 int64 response_id, net::HttpResponseInfo* http_info, | 39 int64 response_id, net::HttpResponseInfo* http_info, |
| 40 int64 response_data_size); | 40 int64 response_data_size); |
| 41 | 41 |
| 42 const GURL& manifest_url() const { return manifest_url_; } | 42 const GURL& manifest_url() const { return manifest_url_; } |
| 43 int64 response_id() const { return response_id_; } | 43 int64 response_id() const { return response_id_; } |
| 44 const net::HttpResponseInfo* http_response_info() const { | 44 const net::HttpResponseInfo* http_response_info() const { |
| 45 return http_response_info_.get(); | 45 return http_response_info_.get(); |
| 46 } | 46 } |
| 47 int64 response_data_size() const { return response_data_size_; } | 47 int64 response_data_size() const { return response_data_size_; } |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 friend class base::RefCounted<AppCacheResponseInfo>; | 50 friend class base::RefCounted<AppCacheResponseInfo>; |
| 51 virtual ~AppCacheResponseInfo(); | 51 virtual ~AppCacheResponseInfo(); |
| 52 | 52 |
| 53 const GURL manifest_url_; | 53 const GURL manifest_url_; |
| 54 const int64 response_id_; | 54 const int64 response_id_; |
| 55 const scoped_ptr<net::HttpResponseInfo> http_response_info_; | 55 const scoped_ptr<net::HttpResponseInfo> http_response_info_; |
| 56 const int64 response_data_size_; | 56 const int64 response_data_size_; |
| 57 AppCacheStorage* storage_; | 57 AppCacheStorage* storage_; |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 // A refcounted wrapper for HttpResponseInfo so we can apply the | 60 // A refcounted wrapper for HttpResponseInfo so we can apply the |
| 61 // refcounting semantics used with IOBuffer with these structures too. | 61 // refcounting semantics used with IOBuffer with these structures too. |
| 62 struct WEBKIT_STORAGE_BROWSER_EXPORT HttpResponseInfoIOBuffer | 62 struct CONTENT_EXPORT HttpResponseInfoIOBuffer |
| 63 : public base::RefCountedThreadSafe<HttpResponseInfoIOBuffer> { | 63 : public base::RefCountedThreadSafe<HttpResponseInfoIOBuffer> { |
| 64 scoped_ptr<net::HttpResponseInfo> http_info; | 64 scoped_ptr<net::HttpResponseInfo> http_info; |
| 65 int response_data_size; | 65 int response_data_size; |
| 66 | 66 |
| 67 HttpResponseInfoIOBuffer(); | 67 HttpResponseInfoIOBuffer(); |
| 68 explicit HttpResponseInfoIOBuffer(net::HttpResponseInfo* info); | 68 explicit HttpResponseInfoIOBuffer(net::HttpResponseInfo* info); |
| 69 | 69 |
| 70 protected: | 70 protected: |
| 71 friend class base::RefCountedThreadSafe<HttpResponseInfoIOBuffer>; | 71 friend class base::RefCountedThreadSafe<HttpResponseInfoIOBuffer>; |
| 72 virtual ~HttpResponseInfoIOBuffer(); | 72 virtual ~HttpResponseInfoIOBuffer(); |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 // Low level storage API used by the response reader and writer. | 75 // Low level storage API used by the response reader and writer. |
| 76 class WEBKIT_STORAGE_BROWSER_EXPORT AppCacheDiskCacheInterface { | 76 class CONTENT_EXPORT AppCacheDiskCacheInterface { |
| 77 public: | 77 public: |
| 78 class Entry { | 78 class Entry { |
| 79 public: | 79 public: |
| 80 virtual int Read(int index, int64 offset, net::IOBuffer* buf, int buf_len, | 80 virtual int Read(int index, int64 offset, net::IOBuffer* buf, int buf_len, |
| 81 const net::CompletionCallback& callback) = 0; | 81 const net::CompletionCallback& callback) = 0; |
| 82 virtual int Write(int index, int64 offset, net::IOBuffer* buf, int buf_len, | 82 virtual int Write(int index, int64 offset, net::IOBuffer* buf, int buf_len, |
| 83 const net::CompletionCallback& callback) = 0; | 83 const net::CompletionCallback& callback) = 0; |
| 84 virtual int64 GetSize(int index) = 0; | 84 virtual int64 GetSize(int index) = 0; |
| 85 virtual void Close() = 0; | 85 virtual void Close() = 0; |
| 86 protected: | 86 protected: |
| 87 virtual ~Entry() {} | 87 virtual ~Entry() {} |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 virtual int CreateEntry(int64 key, Entry** entry, | 90 virtual int CreateEntry(int64 key, Entry** entry, |
| 91 const net::CompletionCallback& callback) = 0; | 91 const net::CompletionCallback& callback) = 0; |
| 92 virtual int OpenEntry(int64 key, Entry** entry, | 92 virtual int OpenEntry(int64 key, Entry** entry, |
| 93 const net::CompletionCallback& callback) = 0; | 93 const net::CompletionCallback& callback) = 0; |
| 94 virtual int DoomEntry(int64 key, const net::CompletionCallback& callback) = 0; | 94 virtual int DoomEntry(int64 key, const net::CompletionCallback& callback) = 0; |
| 95 | 95 |
| 96 protected: | 96 protected: |
| 97 friend class base::RefCounted<AppCacheDiskCacheInterface>; | 97 friend class base::RefCounted<AppCacheDiskCacheInterface>; |
| 98 virtual ~AppCacheDiskCacheInterface() {} | 98 virtual ~AppCacheDiskCacheInterface() {} |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 // Common base class for response reader and writer. | 101 // Common base class for response reader and writer. |
| 102 class WEBKIT_STORAGE_BROWSER_EXPORT AppCacheResponseIO { | 102 class CONTENT_EXPORT AppCacheResponseIO { |
| 103 public: | 103 public: |
| 104 virtual ~AppCacheResponseIO(); | 104 virtual ~AppCacheResponseIO(); |
| 105 int64 response_id() const { return response_id_; } | 105 int64 response_id() const { return response_id_; } |
| 106 | 106 |
| 107 protected: | 107 protected: |
| 108 AppCacheResponseIO(int64 response_id, | 108 AppCacheResponseIO(int64 response_id, |
| 109 int64 group_id, | 109 int64 group_id, |
| 110 AppCacheDiskCacheInterface* disk_cache); | 110 AppCacheDiskCacheInterface* disk_cache); |
| 111 | 111 |
| 112 virtual void OnIOComplete(int result) = 0; | 112 virtual void OnIOComplete(int result) = 0; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 128 base::WeakPtrFactory<AppCacheResponseIO> weak_factory_; | 128 base::WeakPtrFactory<AppCacheResponseIO> weak_factory_; |
| 129 | 129 |
| 130 private: | 130 private: |
| 131 void OnRawIOComplete(int result); | 131 void OnRawIOComplete(int result); |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 // Reads existing response data from storage. If the object is deleted | 134 // Reads existing response data from storage. If the object is deleted |
| 135 // and there is a read in progress, the implementation will return | 135 // and there is a read in progress, the implementation will return |
| 136 // 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 |
| 137 // operation. In other words, instances are safe to delete at will. | 137 // operation. In other words, instances are safe to delete at will. |
| 138 class WEBKIT_STORAGE_BROWSER_EXPORT AppCacheResponseReader | 138 class CONTENT_EXPORT AppCacheResponseReader |
| 139 : public AppCacheResponseIO { | 139 : public AppCacheResponseIO { |
| 140 public: | 140 public: |
| 141 virtual ~AppCacheResponseReader(); | 141 virtual ~AppCacheResponseReader(); |
| 142 | 142 |
| 143 // Reads http info from storage. Always returns the result of the read | 143 // Reads http info from storage. Always returns the result of the read |
| 144 // asynchronously through the 'callback'. Returns the number of bytes read | 144 // asynchronously through the 'callback'. Returns the number of bytes read |
| 145 // or a net:: error code. Guaranteed to not perform partial reads of | 145 // or a net:: error code. Guaranteed to not perform partial reads of |
| 146 // the info data. The reader acquires a reference to the 'info_buf' until | 146 // the info data. The reader acquires a reference to the 'info_buf' until |
| 147 // completion at which time the callback is invoked with either a negative | 147 // completion at which time the callback is invoked with either a negative |
| 148 // error code or the number of bytes read. The 'info_buf' argument should | 148 // error code or the number of bytes read. The 'info_buf' argument should |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 int range_length_; | 191 int range_length_; |
| 192 int read_position_; | 192 int read_position_; |
| 193 net::CompletionCallback open_callback_; | 193 net::CompletionCallback open_callback_; |
| 194 base::WeakPtrFactory<AppCacheResponseReader> weak_factory_; | 194 base::WeakPtrFactory<AppCacheResponseReader> weak_factory_; |
| 195 }; | 195 }; |
| 196 | 196 |
| 197 // Writes new response data to storage. If the object is deleted | 197 // Writes new response data to storage. If the object is deleted |
| 198 // and there is a write in progress, the implementation will return | 198 // and there is a write in progress, the implementation will return |
| 199 // immediately but will take care of any side effect of cancelling the | 199 // immediately but will take care of any side effect of cancelling the |
| 200 // operation. In other words, instances are safe to delete at will. | 200 // operation. In other words, instances are safe to delete at will. |
| 201 class WEBKIT_STORAGE_BROWSER_EXPORT AppCacheResponseWriter | 201 class CONTENT_EXPORT AppCacheResponseWriter |
| 202 : public AppCacheResponseIO { | 202 : public AppCacheResponseIO { |
| 203 public: | 203 public: |
| 204 virtual ~AppCacheResponseWriter(); | 204 virtual ~AppCacheResponseWriter(); |
| 205 | 205 |
| 206 // Writes the http info to storage. Always returns the result of the write | 206 // Writes the http info to storage. Always returns the result of the write |
| 207 // asynchronously through the 'callback'. Returns the number of bytes written | 207 // asynchronously through the 'callback'. Returns the number of bytes written |
| 208 // or a net:: error code. The writer acquires a reference to the 'info_buf' | 208 // or a net:: error code. The writer acquires a reference to the 'info_buf' |
| 209 // until completion at which time the callback is invoked with either a | 209 // until completion at which time the callback is invoked with either a |
| 210 // negative error code or the number of bytes written. The 'callback' is a | 210 // negative error code or the number of bytes written. The 'callback' is a |
| 211 // required parameter. The contents of 'info_buf' are not modified. | 211 // required parameter. The contents of 'info_buf' are not modified. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 void OnCreateEntryComplete(AppCacheDiskCacheInterface::Entry** entry, int rv); | 254 void OnCreateEntryComplete(AppCacheDiskCacheInterface::Entry** entry, int rv); |
| 255 | 255 |
| 256 int info_size_; | 256 int info_size_; |
| 257 int write_position_; | 257 int write_position_; |
| 258 int write_amount_; | 258 int write_amount_; |
| 259 CreationPhase creation_phase_; | 259 CreationPhase creation_phase_; |
| 260 net::CompletionCallback create_callback_; | 260 net::CompletionCallback create_callback_; |
| 261 base::WeakPtrFactory<AppCacheResponseWriter> weak_factory_; | 261 base::WeakPtrFactory<AppCacheResponseWriter> weak_factory_; |
| 262 }; | 262 }; |
| 263 | 263 |
| 264 } // namespace appcache | 264 } // namespace content |
| 265 | 265 |
| 266 #endif // WEBKIT_BROWSER_APPCACHE_APPCACHE_RESPONSE_H_ | 266 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_RESPONSE_H_ |
| OLD | NEW |