Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #ifndef WEBKIT_GLUE_MEDIA_BUFFERED_DATA_SOURCE_H_ | 5 #ifndef WEBKIT_GLUE_MEDIA_BUFFERED_DATA_SOURCE_H_ |
| 6 #define WEBKIT_GLUE_MEDIA_BUFFERED_DATA_SOURCE_H_ | 6 #define WEBKIT_GLUE_MEDIA_BUFFERED_DATA_SOURCE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/lock.h" | 10 #include "base/lock.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 int64 first_byte_position, | 44 int64 first_byte_position, |
| 45 int64 last_byte_position); | 45 int64 last_byte_position); |
| 46 virtual ~BufferedResourceLoader(); | 46 virtual ~BufferedResourceLoader(); |
| 47 | 47 |
| 48 // Start the resource loading with the specified URL and range. | 48 // Start the resource loading with the specified URL and range. |
| 49 // This method operates in asynchronous mode. Once there's a response from the | 49 // This method operates in asynchronous mode. Once there's a response from the |
| 50 // server, success or fail |callback| is called with the result. | 50 // server, success or fail |callback| is called with the result. |
| 51 // |callback| is called with the following values: | 51 // |callback| is called with the following values: |
| 52 // - net::OK | 52 // - net::OK |
| 53 // The request has started successfully. | 53 // The request has started successfully. |
| 54 // - net::ERR_REQUEST_RANGE_NOT_SATISFIABLE | |
| 55 // A range request was made to the server but the server doesn't support it. | |
| 56 // - net::ERR_FAILED | 54 // - net::ERR_FAILED |
| 57 // The request has failed because of an error with the network. | 55 // The request has failed because of an error with the network. |
| 58 // - net::ERR_INVALID_RESPONSE | 56 // - net::ERR_INVALID_RESPONSE |
| 59 // An invalid response is received from the server. | 57 // An invalid response is received from the server. |
| 60 // - (Anything else) | 58 // - (Anything else) |
| 61 // An error code that indicates the request has failed. | 59 // An error code that indicates the request has failed. |
| 62 virtual void Start(net::CompletionCallback* callback); | 60 virtual void Start(net::CompletionCallback* callback); |
| 63 | 61 |
| 64 // Stop this loader, cancels and request and release internal buffer. | 62 // Stop this loader, cancels and request and release internal buffer. |
| 65 virtual void Stop(); | 63 virtual void Stop(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 78 uint8* buffer, net::CompletionCallback* callback); | 76 uint8* buffer, net::CompletionCallback* callback); |
| 79 | 77 |
| 80 // Gets the content length in bytes of the instance after this loader has been | 78 // Gets the content length in bytes of the instance after this loader has been |
| 81 // started. If this value is -1, then content length is unknown. | 79 // started. If this value is -1, then content length is unknown. |
| 82 virtual int64 content_length() { return content_length_; } | 80 virtual int64 content_length() { return content_length_; } |
| 83 | 81 |
| 84 // Gets the original size of the file requested. If this value is -1, then | 82 // Gets the original size of the file requested. If this value is -1, then |
| 85 // the size is unknown. | 83 // the size is unknown. |
| 86 virtual int64 instance_size() { return instance_size_; } | 84 virtual int64 instance_size() { return instance_size_; } |
| 87 | 85 |
| 86 // Returns true if the response for this loader is a partial response. | |
| 87 // It means a 206 response in HTTP/HTTPS protocol. | |
| 88 virtual bool partial_response() { return partial_response_; } | |
| 89 | |
| 88 ///////////////////////////////////////////////////////////////////////////// | 90 ///////////////////////////////////////////////////////////////////////////// |
| 89 // webkit_glue::ResourceLoaderBridge::Peer implementations. | 91 // webkit_glue::ResourceLoaderBridge::Peer implementations. |
| 90 virtual void OnUploadProgress(uint64 position, uint64 size) {} | 92 virtual void OnUploadProgress(uint64 position, uint64 size) {} |
| 91 virtual bool OnReceivedRedirect( | 93 virtual bool OnReceivedRedirect( |
| 92 const GURL& new_url, | 94 const GURL& new_url, |
| 93 const webkit_glue::ResourceLoaderBridge::ResponseInfo& info); | 95 const webkit_glue::ResourceLoaderBridge::ResponseInfo& info); |
| 94 virtual void OnReceivedResponse( | 96 virtual void OnReceivedResponse( |
| 95 const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, | 97 const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, |
| 96 bool content_filtered); | 98 bool content_filtered); |
| 97 virtual void OnReceivedData(const char* data, int len); | 99 virtual void OnReceivedData(const char* data, int len); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 void DoneRead(int error); | 132 void DoneRead(int error); |
| 131 | 133 |
| 132 // Done with start. Invokes the start callback and reset it. | 134 // Done with start. Invokes the start callback and reset it. |
| 133 void DoneStart(int error); | 135 void DoneStart(int error); |
| 134 | 136 |
| 135 bool HasPendingRead() { return read_callback_.get() != NULL; } | 137 bool HasPendingRead() { return read_callback_.get() != NULL; } |
| 136 | 138 |
| 137 // A sliding window of buffer. | 139 // A sliding window of buffer. |
| 138 scoped_ptr<media::SeekableBuffer> buffer_; | 140 scoped_ptr<media::SeekableBuffer> buffer_; |
| 139 | 141 |
| 142 // True if resource loading is deffered. | |
|
scherkus (not reviewing)
2009/09/29 23:10:34
deffered -> deferred
| |
| 140 bool deferred_; | 143 bool deferred_; |
| 144 | |
| 145 // True if resource loading is completed. | |
|
scherkus (not reviewing)
2009/09/29 23:10:34
is -> has
| |
| 141 bool completed_; | 146 bool completed_; |
| 147 | |
| 148 // True if a range request is made. | |
|
scherkus (not reviewing)
2009/09/29 23:10:34
is -> was
| |
| 142 bool range_requested_; | 149 bool range_requested_; |
| 143 | 150 |
| 151 // True if response data received is a partial range. | |
|
scherkus (not reviewing)
2009/09/29 23:10:34
is -> was
| |
| 152 bool partial_response_; | |
| 153 | |
| 144 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory_; | 154 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory_; |
| 145 GURL url_; | 155 GURL url_; |
| 146 int64 first_byte_position_; | 156 int64 first_byte_position_; |
| 147 int64 last_byte_position_; | 157 int64 last_byte_position_; |
| 148 | 158 |
| 149 // Members used during request start. | 159 // Members used during request start. |
| 150 scoped_ptr<net::CompletionCallback> start_callback_; | 160 scoped_ptr<net::CompletionCallback> start_callback_; |
| 151 scoped_ptr<webkit_glue::ResourceLoaderBridge> bridge_; | 161 scoped_ptr<webkit_glue::ResourceLoaderBridge> bridge_; |
| 152 int64 offset_; | 162 int64 offset_; |
| 153 int64 content_length_; | 163 int64 content_length_; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 // Calls |read_callback_| and reset all read parameters. | 260 // Calls |read_callback_| and reset all read parameters. |
| 251 void DoneRead(int error); | 261 void DoneRead(int error); |
| 252 | 262 |
| 253 // Calls |initialize_callback_| and reset it. | 263 // Calls |initialize_callback_| and reset it. |
| 254 void DoneInitialization(); | 264 void DoneInitialization(); |
| 255 | 265 |
| 256 // Callback method for |loader_|. This method is called when response for | 266 // Callback method for |loader_|. This method is called when response for |
| 257 // initial request is received. | 267 // initial request is received. |
| 258 void InitialStartCallback(int error); | 268 void InitialStartCallback(int error); |
| 259 | 269 |
| 260 // Callback method for |probe_loader_|. This method is called when the | |
| 261 // response for probe request is received. | |
| 262 void ProbeStartCallback(int error); | |
| 263 | |
| 264 // Callback method to be passed to BufferedResourceLoader during range | 270 // Callback method to be passed to BufferedResourceLoader during range |
| 265 // request. Once a resource request has started, this method will be called | 271 // request. Once a resource request has started, this method will be called |
| 266 // with the error code. This method will be executed on the thread | 272 // with the error code. This method will be executed on the thread |
| 267 // BufferedResourceLoader lives, i.e. render thread. | 273 // BufferedResourceLoader lives, i.e. render thread. |
| 268 void PartialReadStartCallback(int error); | 274 void PartialReadStartCallback(int error); |
| 269 | 275 |
| 270 // Callback method for making a read request to BufferedResourceLoader. | 276 // Callback method for making a read request to BufferedResourceLoader. |
| 271 // If data arrives or the request has failed, this method is called with | 277 // If data arrives or the request has failed, this method is called with |
| 272 // the error code or the number of bytes read. | 278 // the error code or the number of bytes read. |
| 273 void ReadCallback(int error); | 279 void ReadCallback(int error); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 286 // This value will be true if this data source can only support streaming. | 292 // This value will be true if this data source can only support streaming. |
| 287 // i.e. range request is not supported. | 293 // i.e. range request is not supported. |
| 288 bool streaming_; | 294 bool streaming_; |
| 289 | 295 |
| 290 // A factory object to produce ResourceLoaderBridge. | 296 // A factory object to produce ResourceLoaderBridge. |
| 291 scoped_ptr<webkit_glue::MediaResourceLoaderBridgeFactory> bridge_factory_; | 297 scoped_ptr<webkit_glue::MediaResourceLoaderBridgeFactory> bridge_factory_; |
| 292 | 298 |
| 293 // A resource loader for the media resource. | 299 // A resource loader for the media resource. |
| 294 scoped_refptr<BufferedResourceLoader> loader_; | 300 scoped_refptr<BufferedResourceLoader> loader_; |
| 295 | 301 |
| 296 // A resource loader that probes the server's ability to serve range requests. | |
| 297 scoped_refptr<BufferedResourceLoader> probe_loader_; | |
| 298 | |
| 299 // Callback method from the pipeline for initialization. | 302 // Callback method from the pipeline for initialization. |
| 300 scoped_ptr<media::FilterCallback> initialize_callback_; | 303 scoped_ptr<media::FilterCallback> initialize_callback_; |
| 301 | 304 |
| 302 // Read parameters received from the Read() method call. | 305 // Read parameters received from the Read() method call. |
| 303 scoped_ptr<media::DataSource::ReadCallback> read_callback_; | 306 scoped_ptr<media::DataSource::ReadCallback> read_callback_; |
| 304 int64 read_position_; | 307 int64 read_position_; |
| 305 int read_size_; | 308 int read_size_; |
| 306 uint8* read_buffer_; | 309 uint8* read_buffer_; |
| 307 base::Time read_submitted_time_; | 310 base::Time read_submitted_time_; |
| 308 int read_attempts_; | 311 int read_attempts_; |
| 309 | 312 |
| 310 // This flag is set to true if the initial request has started. | |
| 311 bool initial_response_received_; | |
| 312 | |
| 313 // This flag is set to true if the probe request has started. | |
| 314 bool probe_response_received_; | |
| 315 | |
| 316 // This buffer is intermediate, we use it for BufferedResourceLoader to write | 313 // This buffer is intermediate, we use it for BufferedResourceLoader to write |
| 317 // to. And when read in BufferedResourceLoader is done, we copy data from | 314 // to. And when read in BufferedResourceLoader is done, we copy data from |
| 318 // this buffer to |read_buffer_|. The reason for an additional copy is that | 315 // this buffer to |read_buffer_|. The reason for an additional copy is that |
| 319 // we don't own |read_buffer_|. But since the read operation is asynchronous, | 316 // we don't own |read_buffer_|. But since the read operation is asynchronous, |
| 320 // |read_buffer| can be destroyed at any time, so we only copy into | 317 // |read_buffer| can be destroyed at any time, so we only copy into |
| 321 // |read_buffer| in the final step when it is safe. | 318 // |read_buffer| in the final step when it is safe. |
| 322 // Memory is allocated for this member during initialization of this object | 319 // Memory is allocated for this member during initialization of this object |
| 323 // because we want buffer to be passed into BufferedResourceLoader to be | 320 // because we want buffer to be passed into BufferedResourceLoader to be |
| 324 // always non-null. And by initializing this member with a default size we can | 321 // always non-null. And by initializing this member with a default size we can |
| 325 // avoid creating zero-sized buffered if the first read has zero size. | 322 // avoid creating zero-sized buffered if the first read has zero size. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 345 // loop. The RepeatingTimer does PostDelayedTask() internally, by using it | 342 // loop. The RepeatingTimer does PostDelayedTask() internally, by using it |
| 346 // the message loop doesn't hold a reference for the watch dog task. | 343 // the message loop doesn't hold a reference for the watch dog task. |
| 347 base::RepeatingTimer<BufferedDataSource> watch_dog_timer_; | 344 base::RepeatingTimer<BufferedDataSource> watch_dog_timer_; |
| 348 | 345 |
| 349 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); | 346 DISALLOW_COPY_AND_ASSIGN(BufferedDataSource); |
| 350 }; | 347 }; |
| 351 | 348 |
| 352 } // namespace webkit_glue | 349 } // namespace webkit_glue |
| 353 | 350 |
| 354 #endif // WEBKIT_GLUE_MEDIA_BUFFERED_DATA_SOURCE_H_ | 351 #endif // WEBKIT_GLUE_MEDIA_BUFFERED_DATA_SOURCE_H_ |
| OLD | NEW |