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