Chromium Code Reviews| 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_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" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 // - Connection was terminated | 58 // - Connection was terminated |
| 59 // | 59 // |
| 60 // At this point you should delete the loader. | 60 // At this point you should delete the loader. |
| 61 kFailed, | 61 kFailed, |
| 62 | 62 |
| 63 // The loader will never be able to satisfy the read request. Please stop, | 63 // The loader will never be able to satisfy the read request. Please stop, |
| 64 // delete, create a new loader, and try again. | 64 // delete, create a new loader, and try again. |
| 65 kCacheMiss, | 65 kCacheMiss, |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 enum LoadingState { | |
| 69 kLoading, // Actively attempting to download data. | |
| 70 kLoadingDeferred, // Loading intentionally deferred. | |
| 71 kLoadingFinished, // Loading finished normally; no more data will arrive. | |
| 72 kLoadingFailed, // Loading finished abnormally; no more data will arrive. | |
| 73 }; | |
| 74 | |
| 68 // |url| - URL for the resource to be loaded. | 75 // |url| - URL for the resource to be loaded. |
| 69 // |first_byte_position| - First byte to start loading from, | 76 // |first_byte_position| - First byte to start loading from, |
| 70 // |kPositionNotSpecified| for not specified. | 77 // |kPositionNotSpecified| for not specified. |
| 71 // |last_byte_position| - Last byte to be loaded, | 78 // |last_byte_position| - Last byte to be loaded, |
| 72 // |kPositionNotSpecified| for not specified. | 79 // |kPositionNotSpecified| for not specified. |
| 73 // |strategy| is the initial loading strategy to use. | 80 // |strategy| is the initial loading strategy to use. |
| 74 // |bitrate| is the bitrate of the media, 0 if unknown. | 81 // |bitrate| is the bitrate of the media, 0 if unknown. |
| 75 // |playback_rate| is the current playback rate of the media. | 82 // |playback_rate| is the current playback rate of the media. |
| 76 BufferedResourceLoader(const GURL& url, | 83 BufferedResourceLoader(const GURL& url, |
| 77 int64 first_byte_position, | 84 int64 first_byte_position, |
| 78 int64 last_byte_position, | 85 int64 last_byte_position, |
| 79 DeferStrategy strategy, | 86 DeferStrategy strategy, |
| 80 int bitrate, | 87 int bitrate, |
| 81 float playback_rate, | 88 float playback_rate, |
| 82 media::MediaLog* media_log); | 89 media::MediaLog* media_log); |
| 83 virtual ~BufferedResourceLoader(); | 90 virtual ~BufferedResourceLoader(); |
| 84 | 91 |
| 85 // Start the resource loading with the specified URL and range. | 92 // Start the resource loading with the specified URL and range. |
| 86 // | 93 // |
| 87 // |event_cb| is called to notify the client of network activity in the | 94 // |progress_cb| is executed when additional data has arrived. |
| 88 // following situations: | 95 // |loading_cb| is executed when the loading state has changed. |
|
Ami GONE FROM CHROMIUM
2012/07/09 00:25:46
Flip order of these two lines to match the orders
scherkus (not reviewing)
2012/07/09 18:53:30
Done.
| |
| 89 // - Data was received | |
| 90 // - Reading was suspended/resumed | |
| 91 // - Loading completed | |
| 92 // - Loading failed | |
| 93 typedef base::Callback<void(Status)> StartCB; | 96 typedef base::Callback<void(Status)> StartCB; |
| 97 typedef base::Callback<void(LoadingState)> LoadingCB; | |
| 98 typedef base::Callback<void(int64)> ProgressCB; | |
| 94 void Start(const StartCB& start_cb, | 99 void Start(const StartCB& start_cb, |
| 95 const base::Closure& event_cb, | 100 const LoadingCB& loading_cb, |
| 101 const ProgressCB& progress_cb, | |
| 96 WebKit::WebFrame* frame); | 102 WebKit::WebFrame* frame); |
| 97 | 103 |
| 98 // Stops everything associated with this loader, including active URL loads | 104 // Stops everything associated with this loader, including active URL loads |
| 99 // and pending callbacks. | 105 // and pending callbacks. |
| 100 // | 106 // |
| 101 // It is safe to delete a BufferedResourceLoader after calling Stop(). | 107 // It is safe to delete a BufferedResourceLoader after calling Stop(). |
| 102 void Stop(); | 108 void Stop(); |
| 103 | 109 |
| 104 // Copies |read_size| bytes from |position| into |buffer|, executing |read_cb| | 110 // Copies |read_size| bytes from |position| into |buffer|, executing |read_cb| |
| 105 // when the operation has completed. | 111 // when the operation has completed. |
| 106 // | 112 // |
| 107 // The callback will contain the number of bytes read iff the status is kOk, | 113 // The callback will contain the number of bytes read iff the status is kOk, |
| 108 // zero otherwise. | 114 // zero otherwise. |
| 109 // | 115 // |
| 110 // If necessary will temporarily increase forward capacity of buffer to | 116 // If necessary will temporarily increase forward capacity of buffer to |
| 111 // accomodate an unusually large read. | 117 // accomodate an unusually large read. |
| 112 typedef base::Callback<void(Status, int)> ReadCB; | 118 typedef base::Callback<void(Status, int)> ReadCB; |
| 113 void Read(int64 position, int read_size, | 119 void Read(int64 position, int read_size, |
| 114 uint8* buffer, const ReadCB& read_cb); | 120 uint8* buffer, const ReadCB& read_cb); |
| 115 | 121 |
| 116 // Returns the position of the last byte buffered. Returns | |
| 117 // |kPositionNotSpecified| if such value is not available. | |
| 118 int64 GetBufferedPosition(); | |
|
Ami GONE FROM CHROMIUM
2012/07/09 00:25:46
hawt!
| |
| 119 | |
| 120 // Gets the content length in bytes of the instance after this loader has been | 122 // Gets the content length in bytes of the instance after this loader has been |
| 121 // started. If this value is |kPositionNotSpecified|, then content length is | 123 // started. If this value is |kPositionNotSpecified|, then content length is |
| 122 // unknown. | 124 // unknown. |
| 123 int64 content_length(); | 125 int64 content_length(); |
| 124 | 126 |
| 125 // Gets the original size of the file requested. If this value is | 127 // Gets the original size of the file requested. If this value is |
| 126 // |kPositionNotSpecified|, then the size is unknown. | 128 // |kPositionNotSpecified|, then the size is unknown. |
| 127 int64 instance_size(); | 129 int64 instance_size(); |
| 128 | 130 |
| 129 // Returns true if the server supports byte range requests. | 131 // Returns true if the server supports byte range requests. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 std::string GenerateHeaders(int64 first_byte_position, | 241 std::string GenerateHeaders(int64 first_byte_position, |
| 240 int64 last_byte_position); | 242 int64 last_byte_position); |
| 241 | 243 |
| 242 // Done with read. Invokes the read callback and reset parameters for the | 244 // Done with read. Invokes the read callback and reset parameters for the |
| 243 // read request. | 245 // read request. |
| 244 void DoneRead(Status status, int bytes_read); | 246 void DoneRead(Status status, int bytes_read); |
| 245 | 247 |
| 246 // Done with start. Invokes the start callback and reset it. | 248 // Done with start. Invokes the start callback and reset it. |
| 247 void DoneStart(Status status); | 249 void DoneStart(Status status); |
| 248 | 250 |
| 249 // Calls |event_cb_| in terms of a network event. | |
| 250 void NotifyNetworkEvent(); | |
| 251 | |
| 252 bool HasPendingRead() { return !read_cb_.is_null(); } | 251 bool HasPendingRead() { return !read_cb_.is_null(); } |
| 253 | 252 |
| 254 // Helper function that returns true if a range request was specified. | 253 // Helper function that returns true if a range request was specified. |
| 255 bool IsRangeRequest() const; | 254 bool IsRangeRequest() const; |
| 256 | 255 |
| 257 // Log everything interesting to |media_log_|. | 256 // Log everything interesting to |media_log_|. |
| 258 void Log(); | 257 void Log(); |
| 259 | 258 |
| 260 // A sliding window of buffer. | 259 // A sliding window of buffer. |
| 261 media::SeekableBuffer buffer_; | 260 media::SeekableBuffer buffer_; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 278 bool range_supported_; | 277 bool range_supported_; |
| 279 | 278 |
| 280 // Forward capacity to reset to after an extension. | 279 // Forward capacity to reset to after an extension. |
| 281 size_t saved_forward_capacity_; | 280 size_t saved_forward_capacity_; |
| 282 | 281 |
| 283 GURL url_; | 282 GURL url_; |
| 284 int64 first_byte_position_; | 283 int64 first_byte_position_; |
| 285 int64 last_byte_position_; | 284 int64 last_byte_position_; |
| 286 bool single_origin_; | 285 bool single_origin_; |
| 287 | 286 |
| 288 // Closure that listens to network events. | 287 // Executed whenever the state of resource loading has changed. |
| 289 base::Closure event_cb_; | 288 LoadingCB loading_cb_; |
|
Ami GONE FROM CHROMIUM
2012/07/09 00:25:46
LoadingStateChangedCB?
LoadingCB sounds to me like
scherkus (not reviewing)
2012/07/09 18:53:30
It's a mouthful but I agree that LoadingCB is a bi
| |
| 289 | |
| 290 // Executed whenever additional data has been downloaded and reports the | |
| 291 // zero-indexed file offset of the leading buffered byte. | |
|
Ami GONE FROM CHROMIUM
2012/07/09 00:25:46
s/leading/furthest/?
scherkus (not reviewing)
2012/07/09 18:53:30
Done.
| |
| 292 ProgressCB progress_cb_; | |
| 290 | 293 |
| 291 // Members used during request start. | 294 // Members used during request start. |
| 292 StartCB start_cb_; | 295 StartCB start_cb_; |
| 293 int64 offset_; | 296 int64 offset_; |
| 294 int64 content_length_; | 297 int64 content_length_; |
| 295 int64 instance_size_; | 298 int64 instance_size_; |
| 296 | 299 |
| 297 // Members used during a read operation. They should be reset after each | 300 // Members used during a read operation. They should be reset after each |
| 298 // read has completed or failed. | 301 // read has completed or failed. |
| 299 ReadCB read_cb_; | 302 ReadCB read_cb_; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 316 float playback_rate_; | 319 float playback_rate_; |
| 317 | 320 |
| 318 scoped_refptr<media::MediaLog> media_log_; | 321 scoped_refptr<media::MediaLog> media_log_; |
| 319 | 322 |
| 320 DISALLOW_COPY_AND_ASSIGN(BufferedResourceLoader); | 323 DISALLOW_COPY_AND_ASSIGN(BufferedResourceLoader); |
| 321 }; | 324 }; |
| 322 | 325 |
| 323 } // namespace webkit_media | 326 } // namespace webkit_media |
| 324 | 327 |
| 325 #endif // WEBKIT_MEDIA_BUFFERED_RESOURCE_LOADER_H_ | 328 #endif // WEBKIT_MEDIA_BUFFERED_RESOURCE_LOADER_H_ |
| OLD | NEW |