| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CONTENT_RENDERER_MEDIA_BUFFERED_RESOURCE_LOADER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_BUFFERED_RESOURCE_LOADER_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_BUFFERED_RESOURCE_LOADER_H_ | 6 #define CONTENT_RENDERER_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" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 const int64 kPositionNotSpecified = -1; | 29 const int64 kPositionNotSpecified = -1; |
| 30 | 30 |
| 31 const char kHttpScheme[] = "http"; | 31 const char kHttpScheme[] = "http"; |
| 32 const char kHttpsScheme[] = "https"; | 32 const char kHttpsScheme[] = "https"; |
| 33 | 33 |
| 34 // BufferedResourceLoader is single threaded and must be accessed on the | 34 // BufferedResourceLoader is single threaded and must be accessed on the |
| 35 // render thread. It wraps a WebURLLoader and does in-memory buffering, | 35 // render thread. It wraps a WebURLLoader and does in-memory buffering, |
| 36 // pausing resource loading when the in-memory buffer is full and resuming | 36 // pausing resource loading when the in-memory buffer is full and resuming |
| 37 // resource loading when there is available capacity. | 37 // resource loading when there is available capacity. |
| 38 class CONTENT_EXPORT BufferedResourceLoader | 38 class CONTENT_EXPORT BufferedResourceLoader |
| 39 : NON_EXPORTED_BASE(public WebKit::WebURLLoaderClient) { | 39 : NON_EXPORTED_BASE(public blink::WebURLLoaderClient) { |
| 40 public: | 40 public: |
| 41 // kNeverDefer - Aggresively buffer; never defer loading while paused. | 41 // kNeverDefer - Aggresively buffer; never defer loading while paused. |
| 42 // kReadThenDefer - Request only enough data to fulfill read requests. | 42 // kReadThenDefer - Request only enough data to fulfill read requests. |
| 43 // kCapacityDefer - Try to keep amount of buffered data at capacity. | 43 // kCapacityDefer - Try to keep amount of buffered data at capacity. |
| 44 enum DeferStrategy { | 44 enum DeferStrategy { |
| 45 kNeverDefer, | 45 kNeverDefer, |
| 46 kReadThenDefer, | 46 kReadThenDefer, |
| 47 kCapacityDefer, | 47 kCapacityDefer, |
| 48 }; | 48 }; |
| 49 | 49 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // Start the resource loading with the specified URL and range. | 99 // Start the resource loading with the specified URL and range. |
| 100 // | 100 // |
| 101 // |loading_cb| is executed when the loading state has changed. | 101 // |loading_cb| is executed when the loading state has changed. |
| 102 // |progress_cb| is executed when additional data has arrived. | 102 // |progress_cb| is executed when additional data has arrived. |
| 103 typedef base::Callback<void(Status)> StartCB; | 103 typedef base::Callback<void(Status)> StartCB; |
| 104 typedef base::Callback<void(LoadingState)> LoadingStateChangedCB; | 104 typedef base::Callback<void(LoadingState)> LoadingStateChangedCB; |
| 105 typedef base::Callback<void(int64)> ProgressCB; | 105 typedef base::Callback<void(int64)> ProgressCB; |
| 106 void Start(const StartCB& start_cb, | 106 void Start(const StartCB& start_cb, |
| 107 const LoadingStateChangedCB& loading_cb, | 107 const LoadingStateChangedCB& loading_cb, |
| 108 const ProgressCB& progress_cb, | 108 const ProgressCB& progress_cb, |
| 109 WebKit::WebFrame* frame); | 109 blink::WebFrame* frame); |
| 110 | 110 |
| 111 // Stops everything associated with this loader, including active URL loads | 111 // Stops everything associated with this loader, including active URL loads |
| 112 // and pending callbacks. | 112 // and pending callbacks. |
| 113 // | 113 // |
| 114 // It is safe to delete a BufferedResourceLoader after calling Stop(). | 114 // It is safe to delete a BufferedResourceLoader after calling Stop(). |
| 115 void Stop(); | 115 void Stop(); |
| 116 | 116 |
| 117 // Copies |read_size| bytes from |position| into |buffer|, executing |read_cb| | 117 // Copies |read_size| bytes from |position| into |buffer|, executing |read_cb| |
| 118 // when the operation has completed. | 118 // when the operation has completed. |
| 119 // | 119 // |
| (...skipping 11 matching lines...) Expand all Loading... |
| 131 // unknown. | 131 // unknown. |
| 132 int64 content_length(); | 132 int64 content_length(); |
| 133 | 133 |
| 134 // Gets the original size of the file requested. If this value is | 134 // Gets the original size of the file requested. If this value is |
| 135 // |kPositionNotSpecified|, then the size is unknown. | 135 // |kPositionNotSpecified|, then the size is unknown. |
| 136 int64 instance_size(); | 136 int64 instance_size(); |
| 137 | 137 |
| 138 // Returns true if the server supports byte range requests. | 138 // Returns true if the server supports byte range requests. |
| 139 bool range_supported(); | 139 bool range_supported(); |
| 140 | 140 |
| 141 // WebKit::WebURLLoaderClient implementation. | 141 // blink::WebURLLoaderClient implementation. |
| 142 virtual void willSendRequest( | 142 virtual void willSendRequest( |
| 143 WebKit::WebURLLoader* loader, | 143 blink::WebURLLoader* loader, |
| 144 WebKit::WebURLRequest& newRequest, | 144 blink::WebURLRequest& newRequest, |
| 145 const WebKit::WebURLResponse& redirectResponse); | 145 const blink::WebURLResponse& redirectResponse); |
| 146 virtual void didSendData( | 146 virtual void didSendData( |
| 147 WebKit::WebURLLoader* loader, | 147 blink::WebURLLoader* loader, |
| 148 unsigned long long bytesSent, | 148 unsigned long long bytesSent, |
| 149 unsigned long long totalBytesToBeSent); | 149 unsigned long long totalBytesToBeSent); |
| 150 virtual void didReceiveResponse( | 150 virtual void didReceiveResponse( |
| 151 WebKit::WebURLLoader* loader, | 151 blink::WebURLLoader* loader, |
| 152 const WebKit::WebURLResponse& response); | 152 const blink::WebURLResponse& response); |
| 153 virtual void didDownloadData( | 153 virtual void didDownloadData( |
| 154 WebKit::WebURLLoader* loader, | 154 blink::WebURLLoader* loader, |
| 155 int data_length, | 155 int data_length, |
| 156 int encoded_data_length); | 156 int encoded_data_length); |
| 157 virtual void didReceiveData( | 157 virtual void didReceiveData( |
| 158 WebKit::WebURLLoader* loader, | 158 blink::WebURLLoader* loader, |
| 159 const char* data, | 159 const char* data, |
| 160 int data_length, | 160 int data_length, |
| 161 int encoded_data_length); | 161 int encoded_data_length); |
| 162 virtual void didReceiveCachedMetadata( | 162 virtual void didReceiveCachedMetadata( |
| 163 WebKit::WebURLLoader* loader, | 163 blink::WebURLLoader* loader, |
| 164 const char* data, int dataLength); | 164 const char* data, int dataLength); |
| 165 virtual void didFinishLoading( | 165 virtual void didFinishLoading( |
| 166 WebKit::WebURLLoader* loader, | 166 blink::WebURLLoader* loader, |
| 167 double finishTime); | 167 double finishTime); |
| 168 virtual void didFail( | 168 virtual void didFail( |
| 169 WebKit::WebURLLoader* loader, | 169 blink::WebURLLoader* loader, |
| 170 const WebKit::WebURLError&); | 170 const blink::WebURLError&); |
| 171 | 171 |
| 172 // Returns true if the media resource has a single origin, false otherwise. | 172 // Returns true if the media resource has a single origin, false otherwise. |
| 173 // Only valid to call after Start() has completed. | 173 // Only valid to call after Start() has completed. |
| 174 bool HasSingleOrigin() const; | 174 bool HasSingleOrigin() const; |
| 175 | 175 |
| 176 // Returns true if the media resource passed a CORS access control check. | 176 // Returns true if the media resource passed a CORS access control check. |
| 177 // Only valid to call after Start() has completed. | 177 // Only valid to call after Start() has completed. |
| 178 bool DidPassCORSAccessCheck() const; | 178 bool DidPassCORSAccessCheck() const; |
| 179 | 179 |
| 180 // Sets the defer strategy to the given value unless it seems unwise. | 180 // Sets the defer strategy to the given value unless it seems unwise. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 bool CanFulfillRead() const; | 228 bool CanFulfillRead() const; |
| 229 | 229 |
| 230 // Returns true if the current read request will be fulfilled in the future. | 230 // Returns true if the current read request will be fulfilled in the future. |
| 231 bool WillFulfillRead() const; | 231 bool WillFulfillRead() const; |
| 232 | 232 |
| 233 // Method that does the actual read and calls the |read_cb_|, assuming the | 233 // Method that does the actual read and calls the |read_cb_|, assuming the |
| 234 // request range is in |buffer_|. | 234 // request range is in |buffer_|. |
| 235 void ReadInternal(); | 235 void ReadInternal(); |
| 236 | 236 |
| 237 // If we have made a range request, verify the response from the server. | 237 // If we have made a range request, verify the response from the server. |
| 238 bool VerifyPartialResponse(const WebKit::WebURLResponse& response); | 238 bool VerifyPartialResponse(const blink::WebURLResponse& response); |
| 239 | 239 |
| 240 // Returns the value for a range request header using parameters | 240 // Returns the value for a range request header using parameters |
| 241 // |first_byte_position| and |last_byte_position|. Negative numbers other | 241 // |first_byte_position| and |last_byte_position|. Negative numbers other |
| 242 // than |kPositionNotSpecified| are not allowed for |first_byte_position| and | 242 // than |kPositionNotSpecified| are not allowed for |first_byte_position| and |
| 243 // |last_byte_position|. |first_byte_position| should always be less than or | 243 // |last_byte_position|. |first_byte_position| should always be less than or |
| 244 // equal to |last_byte_position| if they are both not |kPositionNotSpecified|. | 244 // equal to |last_byte_position| if they are both not |kPositionNotSpecified|. |
| 245 // Empty string is returned on invalid parameters. | 245 // Empty string is returned on invalid parameters. |
| 246 std::string GenerateHeaders(int64 first_byte_position, | 246 std::string GenerateHeaders(int64 first_byte_position, |
| 247 int64 last_byte_position); | 247 int64 last_byte_position); |
| 248 | 248 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 int64 read_position_; | 309 int64 read_position_; |
| 310 int read_size_; | 310 int read_size_; |
| 311 uint8* read_buffer_; | 311 uint8* read_buffer_; |
| 312 | 312 |
| 313 // Offsets of the requested first byte and last byte in |buffer_|. They are | 313 // Offsets of the requested first byte and last byte in |buffer_|. They are |
| 314 // written by Read(). | 314 // written by Read(). |
| 315 int first_offset_; | 315 int first_offset_; |
| 316 int last_offset_; | 316 int last_offset_; |
| 317 | 317 |
| 318 // Injected WebURLLoader instance for testing purposes. | 318 // Injected WebURLLoader instance for testing purposes. |
| 319 scoped_ptr<WebKit::WebURLLoader> test_loader_; | 319 scoped_ptr<blink::WebURLLoader> test_loader_; |
| 320 | 320 |
| 321 // Bitrate of the media. Set to 0 if unknown. | 321 // Bitrate of the media. Set to 0 if unknown. |
| 322 int bitrate_; | 322 int bitrate_; |
| 323 | 323 |
| 324 // Playback rate of the media. | 324 // Playback rate of the media. |
| 325 float playback_rate_; | 325 float playback_rate_; |
| 326 | 326 |
| 327 scoped_refptr<media::MediaLog> media_log_; | 327 scoped_refptr<media::MediaLog> media_log_; |
| 328 | 328 |
| 329 DISALLOW_COPY_AND_ASSIGN(BufferedResourceLoader); | 329 DISALLOW_COPY_AND_ASSIGN(BufferedResourceLoader); |
| 330 }; | 330 }; |
| 331 | 331 |
| 332 } // namespace content | 332 } // namespace content |
| 333 | 333 |
| 334 #endif // CONTENT_RENDERER_MEDIA_BUFFERED_RESOURCE_LOADER_H_ | 334 #endif // CONTENT_RENDERER_MEDIA_BUFFERED_RESOURCE_LOADER_H_ |
| OLD | NEW |