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_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/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/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 APPCACHE_EXPORT AppCacheResponseInfo | 29 class WEBKIT_STORAGE_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 APPCACHE_EXPORT HttpResponseInfoIOBuffer | 57 struct WEBKIT_STORAGE_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 APPCACHE_EXPORT AppCacheDiskCacheInterface { | 71 class WEBKIT_STORAGE_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 const net::CompletionCallback& 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 const net::CompletionCallback& callback) = 0; | 88 const net::CompletionCallback& callback) = 0; |
89 virtual int DoomEntry(int64 key, const net::CompletionCallback& 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 WEBKIT_STORAGE_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 AppCacheResponseIO(int64 response_id, | 103 AppCacheResponseIO(int64 response_id, |
104 int64 group_id, | 104 int64 group_id, |
105 AppCacheDiskCacheInterface* disk_cache); | 105 AppCacheDiskCacheInterface* disk_cache); |
106 | 106 |
107 virtual void OnIOComplete(int result) = 0; | 107 virtual void OnIOComplete(int result) = 0; |
(...skipping 15 matching lines...) Expand all Loading... |
123 base::WeakPtrFactory<AppCacheResponseIO> weak_factory_; | 123 base::WeakPtrFactory<AppCacheResponseIO> weak_factory_; |
124 | 124 |
125 private: | 125 private: |
126 void OnRawIOComplete(int result); | 126 void OnRawIOComplete(int result); |
127 }; | 127 }; |
128 | 128 |
129 // Reads existing response data from storage. If the object is deleted | 129 // Reads existing response data from storage. If the object is deleted |
130 // and there is a read in progress, the implementation will return | 130 // and there is a read in progress, the implementation will return |
131 // immediately but will take care of any side effect of cancelling the | 131 // immediately but will take care of any side effect of cancelling the |
132 // operation. In other words, instances are safe to delete at will. | 132 // operation. In other words, instances are safe to delete at will. |
133 class APPCACHE_EXPORT AppCacheResponseReader : public AppCacheResponseIO { | 133 class WEBKIT_STORAGE_EXPORT AppCacheResponseReader : public AppCacheResponseIO { |
134 public: | 134 public: |
135 virtual ~AppCacheResponseReader(); | 135 virtual ~AppCacheResponseReader(); |
136 | 136 |
137 // Reads http info from storage. Always returns the result of the read | 137 // Reads http info from storage. Always returns the result of the read |
138 // asynchronously through the 'callback'. Returns the number of bytes read | 138 // asynchronously through the 'callback'. Returns the number of bytes read |
139 // or a net:: error code. Guaranteed to not perform partial reads of | 139 // or a net:: error code. Guaranteed to not perform partial reads of |
140 // the info data. The reader acquires a reference to the 'info_buf' until | 140 // the info data. The reader acquires a reference to the 'info_buf' until |
141 // completion at which time the callback is invoked with either a negative | 141 // completion at which time the callback is invoked with either a negative |
142 // error code or the number of bytes read. The 'info_buf' argument should | 142 // error code or the number of bytes read. The 'info_buf' argument should |
143 // contain a NULL http_info when ReadInfo is called. The 'callback' is a | 143 // 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... |
185 int range_length_; | 185 int range_length_; |
186 int read_position_; | 186 int read_position_; |
187 net::CompletionCallback open_callback_; | 187 net::CompletionCallback open_callback_; |
188 base::WeakPtrFactory<AppCacheResponseReader> weak_factory_; | 188 base::WeakPtrFactory<AppCacheResponseReader> weak_factory_; |
189 }; | 189 }; |
190 | 190 |
191 // Writes new response data to storage. If the object is deleted | 191 // Writes new response data to storage. If the object is deleted |
192 // and there is a write in progress, the implementation will return | 192 // and there is a write in progress, the implementation will return |
193 // immediately but will take care of any side effect of cancelling the | 193 // immediately but will take care of any side effect of cancelling the |
194 // operation. In other words, instances are safe to delete at will. | 194 // operation. In other words, instances are safe to delete at will. |
195 class APPCACHE_EXPORT AppCacheResponseWriter : public AppCacheResponseIO { | 195 class WEBKIT_STORAGE_EXPORT AppCacheResponseWriter : public AppCacheResponseIO { |
196 public: | 196 public: |
197 virtual ~AppCacheResponseWriter(); | 197 virtual ~AppCacheResponseWriter(); |
198 | 198 |
199 // Writes the http info to storage. Always returns the result of the write | 199 // Writes the http info to storage. Always returns the result of the write |
200 // asynchronously through the 'callback'. Returns the number of bytes written | 200 // asynchronously through the 'callback'. Returns the number of bytes written |
201 // or a net:: error code. The writer acquires a reference to the 'info_buf' | 201 // or a net:: error code. The writer acquires a reference to the 'info_buf' |
202 // until completion at which time the callback is invoked with either a | 202 // until completion at which time the callback is invoked with either a |
203 // negative error code or the number of bytes written. The 'callback' is a | 203 // negative error code or the number of bytes written. The 'callback' is a |
204 // required parameter. The contents of 'info_buf' are not modified. | 204 // required parameter. The contents of 'info_buf' are not modified. |
205 // Should only be called where there is no Write operation in progress. | 205 // Should only be called where there is no Write operation in progress. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 int write_amount_; | 250 int write_amount_; |
251 CreationPhase creation_phase_; | 251 CreationPhase creation_phase_; |
252 net::CompletionCallback create_callback_; | 252 net::CompletionCallback create_callback_; |
253 base::WeakPtrFactory<AppCacheResponseWriter> weak_factory_; | 253 base::WeakPtrFactory<AppCacheResponseWriter> weak_factory_; |
254 }; | 254 }; |
255 | 255 |
256 } // namespace appcache | 256 } // namespace appcache |
257 | 257 |
258 #endif // WEBKIT_APPCACHE_APPCACHE_RESPONSE_H_ | 258 #endif // WEBKIT_APPCACHE_APPCACHE_RESPONSE_H_ |
259 | 259 |
OLD | NEW |