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_MEDIA_BUFFERED_RESOURCE_LOADER_H_ | 5 #ifndef WEBKIT_MEDIA_BUFFERED_RESOURCE_LOADER_H_ |
| 6 #define WEBKIT_MEDIA_BUFFERED_RESOURCE_LOADER_H_ | 6 #define WEBKIT_MEDIA_BUFFERED_RESOURCE_LOADER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/timer.h" | 12 #include "base/timer.h" |
| 13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 14 #include "media/base/seekable_buffer.h" | 14 #include "media/base/seekable_buffer.h" |
| 15 #include "net/base/file_stream.h" | 15 #include "net/base/file_stream.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoader.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoader.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderClient.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderClient.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
| 20 #include "webkit/media/active_loader.h" | |
| 20 #include "webkit/media/web_data_source.h" | 21 #include "webkit/media/web_data_source.h" |
| 21 #include "webkit/media/webmediaplayer_impl.h" | 22 #include "webkit/media/webmediaplayer_impl.h" |
| 22 | 23 |
| 23 namespace media { | 24 namespace media { |
| 24 class MediaLog; | 25 class MediaLog; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace webkit_media { | 28 namespace webkit_media { |
| 28 | 29 |
| 29 const int64 kPositionNotSpecified = -1; | 30 const int64 kPositionNotSpecified = -1; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 // - net::ERR_INVALID_RESPONSE | 77 // - net::ERR_INVALID_RESPONSE |
| 77 // An invalid response is received from the server. | 78 // An invalid response is received from the server. |
| 78 // - (Anything else) | 79 // - (Anything else) |
| 79 // An error code that indicates the request has failed. | 80 // An error code that indicates the request has failed. |
| 80 // |event_callback| is called when the response is completed, data is | 81 // |event_callback| is called when the response is completed, data is |
| 81 // received, the request is suspended or resumed. | 82 // received, the request is suspended or resumed. |
| 82 virtual void Start(net::OldCompletionCallback* callback, | 83 virtual void Start(net::OldCompletionCallback* callback, |
| 83 const base::Closure& event_callback, | 84 const base::Closure& event_callback, |
| 84 WebKit::WebFrame* frame); | 85 WebKit::WebFrame* frame); |
| 85 | 86 |
| 86 // Stop this loader, cancels and request and release internal buffer. | 87 // Stops everything associated with this loader, including active loaders |
|
Ami GONE FROM CHROMIUM
2011/11/29 18:55:49
"loaders", plural? What?
scherkus (not reviewing)
2011/11/29 21:43:51
Done.
| |
| 88 // and any pending callbacks. | |
| 89 // | |
| 90 // It is safe to delete a BufferedResourceLoader after calling Stop(). | |
| 87 virtual void Stop(); | 91 virtual void Stop(); |
| 88 | 92 |
| 89 // Reads the specified |read_size| from |position| into |buffer| and when | 93 // Reads the specified |read_size| from |position| into |buffer| and when |
| 90 // the operation is done invoke |callback| with number of bytes read or an | 94 // the operation is done invoke |callback| with number of bytes read or an |
| 91 // error code. If necessary, will temporarily increase forward capacity of | 95 // error code. If necessary, will temporarily increase forward capacity of |
| 92 // buffer to accomodate an unusually large read. | 96 // buffer to accomodate an unusually large read. |
| 93 // |callback| is called with the following values: | 97 // |callback| is called with the following values: |
| 94 // - (Anything greater than or equal 0) | 98 // - (Anything greater than or equal 0) |
| 95 // Read was successful with the indicated number of bytes read. | 99 // Read was successful with the indicated number of bytes read. |
| 96 // - net::ERR_FAILED | 100 // - net::ERR_FAILED |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 115 | 119 |
| 116 // Returns true if the server supports byte range requests. | 120 // Returns true if the server supports byte range requests. |
| 117 virtual bool range_supported(); | 121 virtual bool range_supported(); |
| 118 | 122 |
| 119 // Returns true if the resource loader is currently downloading data. | 123 // Returns true if the resource loader is currently downloading data. |
| 120 virtual bool is_downloading_data(); | 124 virtual bool is_downloading_data(); |
| 121 | 125 |
| 122 // Returns resulting URL. | 126 // Returns resulting URL. |
| 123 virtual const GURL& url(); | 127 virtual const GURL& url(); |
| 124 | 128 |
| 125 // Used to inject a mock used for unittests. | 129 // Used to inject a mock used for unittests. |
|
Ami GONE FROM CHROMIUM
2011/11/29 18:55:49
IWBN to doco ownership transfer. Except AFAICT ow
scherkus (not reviewing)
2011/11/29 21:43:51
Going to make test_loader_ a scoped_ptr<> that get
| |
| 126 virtual void SetURLLoaderForTest(WebKit::WebURLLoader* mock_loader); | 130 virtual void SetURLLoaderForTest(WebKit::WebURLLoader* test_loader); |
| 127 | 131 |
| 128 // WebKit::WebURLLoaderClient implementation. | 132 // WebKit::WebURLLoaderClient implementation. |
| 129 virtual void willSendRequest( | 133 virtual void willSendRequest( |
| 130 WebKit::WebURLLoader* loader, | 134 WebKit::WebURLLoader* loader, |
| 131 WebKit::WebURLRequest& newRequest, | 135 WebKit::WebURLRequest& newRequest, |
| 132 const WebKit::WebURLResponse& redirectResponse); | 136 const WebKit::WebURLResponse& redirectResponse); |
| 133 virtual void didSendData( | 137 virtual void didSendData( |
| 134 WebKit::WebURLLoader* loader, | 138 WebKit::WebURLLoader* loader, |
| 135 unsigned long long bytesSent, | 139 unsigned long long bytesSent, |
| 136 unsigned long long totalBytesToBeSent); | 140 unsigned long long totalBytesToBeSent); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 | 178 |
| 175 private: | 179 private: |
| 176 friend class BufferedDataSourceTest; | 180 friend class BufferedDataSourceTest; |
| 177 friend class BufferedResourceLoaderTest; | 181 friend class BufferedResourceLoaderTest; |
| 178 | 182 |
| 179 // Updates the |buffer_|'s forward and backward capacities. | 183 // Updates the |buffer_|'s forward and backward capacities. |
| 180 void UpdateBufferWindow(); | 184 void UpdateBufferWindow(); |
| 181 | 185 |
| 182 // Returns true if we should defer resource loading, based | 186 // Returns true if we should defer resource loading, based |
| 183 // on current buffering scheme. | 187 // on current buffering scheme. |
| 184 bool ShouldEnableDefer(); | 188 bool ShouldEnableDefer() const; |
| 185 | 189 |
| 186 // Returns true if we should enable resource loading, based | 190 // Returns true if we should enable resource loading, based |
| 187 // on current buffering scheme. | 191 // on current buffering scheme. |
| 188 bool ShouldDisableDefer(); | 192 bool ShouldDisableDefer() const; |
| 189 | 193 |
| 190 // Updates deferring behavior based on current buffering scheme. | 194 // Updates deferring behavior based on current buffering scheme. |
| 191 void UpdateDeferBehavior(); | 195 void UpdateDeferBehavior(); |
| 192 | 196 |
| 193 // Set defer state to |deferred| and cease/continue downloading data | 197 // Set defer state to |deferred| and cease/continue downloading data |
| 194 // accordingly. | 198 // accordingly. |
| 195 void SetDeferred(bool deferred); | 199 void SetDeferred(bool deferred); |
| 196 | 200 |
| 197 // Returns true if the current read request can be fulfilled by what is in | 201 // Returns true if the current read request can be fulfilled by what is in |
| 198 // the buffer. | 202 // the buffer. |
| 199 bool CanFulfillRead(); | 203 bool CanFulfillRead() const; |
| 200 | 204 |
| 201 // Returns true if the current read request will be fulfilled in the future. | 205 // Returns true if the current read request will be fulfilled in the future. |
| 202 bool WillFulfillRead(); | 206 bool WillFulfillRead() const; |
| 203 | 207 |
| 204 // Method that does the actual read and calls the |read_callback_|, assuming | 208 // Method that does the actual read and calls the |read_callback_|, assuming |
| 205 // the request range is in |buffer_|. | 209 // the request range is in |buffer_|. |
| 206 void ReadInternal(); | 210 void ReadInternal(); |
| 207 | 211 |
| 208 // If we have made a range request, verify the response from the server. | 212 // If we have made a range request, verify the response from the server. |
| 209 bool VerifyPartialResponse(const WebKit::WebURLResponse& response); | 213 bool VerifyPartialResponse(const WebKit::WebURLResponse& response); |
| 210 | 214 |
| 211 // Returns the value for a range request header using parameters | 215 // Returns the value for a range request header using parameters |
| 212 // |first_byte_position| and |last_byte_position|. Negative numbers other | 216 // |first_byte_position| and |last_byte_position|. Negative numbers other |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 231 | 235 |
| 232 // Helper function that returns true if a range request was specified. | 236 // Helper function that returns true if a range request was specified. |
| 233 bool IsRangeRequest() const; | 237 bool IsRangeRequest() const; |
| 234 | 238 |
| 235 // Log everything interesting to |media_log_|. | 239 // Log everything interesting to |media_log_|. |
| 236 void Log(); | 240 void Log(); |
| 237 | 241 |
| 238 // A sliding window of buffer. | 242 // A sliding window of buffer. |
| 239 scoped_ptr<media::SeekableBuffer> buffer_; | 243 scoped_ptr<media::SeekableBuffer> buffer_; |
| 240 | 244 |
| 241 // True if resource loading was deferred. | 245 // Keeps track of an active WebURLLoader and associated state. |
| 242 bool deferred_; | 246 scoped_ptr<ActiveLoader> active_loader_; |
| 243 | 247 |
| 244 // Current buffering algorithm in place for resource loading. | 248 // Current buffering algorithm in place for resource loading. |
| 245 DeferStrategy defer_strategy_; | 249 DeferStrategy defer_strategy_; |
| 246 | 250 |
| 247 // True if resource loading has completed. | |
| 248 bool completed_; | |
| 249 | |
| 250 // True if a range request was made. | 251 // True if a range request was made. |
| 251 bool range_requested_; | 252 bool range_requested_; |
| 252 | 253 |
| 253 // True if Range header is supported. | 254 // True if Range header is supported. |
| 254 bool range_supported_; | 255 bool range_supported_; |
| 255 | 256 |
| 256 // Forward capacity to reset to after an extension. | 257 // Forward capacity to reset to after an extension. |
| 257 size_t saved_forward_capacity_; | 258 size_t saved_forward_capacity_; |
| 258 | 259 |
| 259 // Does the work of loading and sends data back to this client. | |
| 260 scoped_ptr<WebKit::WebURLLoader> url_loader_; | |
| 261 | |
| 262 GURL url_; | 260 GURL url_; |
| 263 int64 first_byte_position_; | 261 int64 first_byte_position_; |
| 264 int64 last_byte_position_; | 262 int64 last_byte_position_; |
| 265 bool single_origin_; | 263 bool single_origin_; |
| 266 | 264 |
| 267 // Callback method that listens to network events. | 265 // Callback method that listens to network events. |
| 268 base::Closure event_callback_; | 266 base::Closure event_callback_; |
| 269 | 267 |
| 270 // Members used during request start. | 268 // Members used during request start. |
| 271 scoped_ptr<net::OldCompletionCallback> start_callback_; | 269 scoped_ptr<net::OldCompletionCallback> start_callback_; |
| 272 int64 offset_; | 270 int64 offset_; |
| 273 int64 content_length_; | 271 int64 content_length_; |
| 274 int64 instance_size_; | 272 int64 instance_size_; |
| 275 | 273 |
| 276 // Members used during a read operation. They should be reset after each | 274 // Members used during a read operation. They should be reset after each |
| 277 // read has completed or failed. | 275 // read has completed or failed. |
| 278 scoped_ptr<net::OldCompletionCallback> read_callback_; | 276 scoped_ptr<net::OldCompletionCallback> read_callback_; |
| 279 int64 read_position_; | 277 int64 read_position_; |
| 280 size_t read_size_; | 278 size_t read_size_; |
| 281 uint8* read_buffer_; | 279 uint8* read_buffer_; |
| 282 | 280 |
| 283 // Offsets of the requested first byte and last byte in |buffer_|. They are | 281 // Offsets of the requested first byte and last byte in |buffer_|. They are |
| 284 // written by Read(). | 282 // written by Read(). |
| 285 int first_offset_; | 283 int first_offset_; |
| 286 int last_offset_; | 284 int last_offset_; |
| 287 | 285 |
| 288 // Used to ensure mocks for unittests are used instead of reset in Start(). | 286 // Used to inject a mocks WebURLLoader for tests during Start(). |
| 289 bool keep_test_loader_; | 287 WebKit::WebURLLoader* test_loader_; |
| 290 | 288 |
| 291 // Bitrate of the media. Set to 0 if unknown. | 289 // Bitrate of the media. Set to 0 if unknown. |
| 292 int bitrate_; | 290 int bitrate_; |
| 293 | 291 |
| 294 // Playback rate of the media. | 292 // Playback rate of the media. |
| 295 float playback_rate_; | 293 float playback_rate_; |
| 296 | 294 |
| 297 scoped_refptr<media::MediaLog> media_log_; | 295 scoped_refptr<media::MediaLog> media_log_; |
| 298 | 296 |
| 299 DISALLOW_COPY_AND_ASSIGN(BufferedResourceLoader); | 297 DISALLOW_COPY_AND_ASSIGN(BufferedResourceLoader); |
| 300 }; | 298 }; |
| 301 | 299 |
| 302 } // namespace webkit_media | 300 } // namespace webkit_media |
| 303 | 301 |
| 304 #endif // WEBKIT_MEDIA_BUFFERED_RESOURCE_LOADER_H_ | 302 #endif // WEBKIT_MEDIA_BUFFERED_RESOURCE_LOADER_H_ |
| OLD | NEW |