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 13 matching lines...) Expand all Loading... | |
24 } | 24 } |
25 | 25 |
26 namespace webkit_media { | 26 namespace webkit_media { |
27 | 27 |
28 const int64 kPositionNotSpecified = -1; | 28 const int64 kPositionNotSpecified = -1; |
29 | 29 |
30 const char kHttpScheme[] = "http"; | 30 const char kHttpScheme[] = "http"; |
31 const char kHttpsScheme[] = "https"; | 31 const char kHttpsScheme[] = "https"; |
32 const char kDataScheme[] = "data"; | 32 const char kDataScheme[] = "data"; |
33 | 33 |
34 // BufferedResourceLoader is single threaded and must be accessed on the | 34 // BufferedResourceLoader is single threaded and must be accessed on the |
Ami GONE FROM CHROMIUM
2012/07/12 00:24:37
Promote threadedness comment to NotThreadSafe w/ c
scherkus (not reviewing)
2012/07/12 21:02:17
IMO overkill at this point in time
| |
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 BufferedResourceLoader : public WebKit::WebURLLoaderClient { | 38 class BufferedResourceLoader : public WebKit::WebURLLoaderClient { |
39 public: | 39 public: |
40 // kNeverDefer - Aggresively buffer; never defer loading while paused. | 40 // kNeverDefer - Aggresively buffer; never defer loading while paused. |
41 // kReadThenDefer - Request only enough data to fulfill read requests. | 41 // kReadThenDefer - Request only enough data to fulfill read requests. |
42 // kCapacityDefer - Try to keep amount of buffered data at capacity. | 42 // kCapacityDefer - Try to keep amount of buffered data at capacity. |
43 enum DeferStrategy { | 43 enum DeferStrategy { |
44 kNeverDefer, | 44 kNeverDefer, |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 int64* last_byte_position, int64* instance_size); | 206 int64* last_byte_position, int64* instance_size); |
207 | 207 |
208 private: | 208 private: |
209 friend class BufferedDataSourceTest; | 209 friend class BufferedDataSourceTest; |
210 friend class BufferedResourceLoaderTest; | 210 friend class BufferedResourceLoaderTest; |
211 friend class MockBufferedDataSource; | 211 friend class MockBufferedDataSource; |
212 | 212 |
213 // Updates the |buffer_|'s forward and backward capacities. | 213 // Updates the |buffer_|'s forward and backward capacities. |
214 void UpdateBufferWindow(); | 214 void UpdateBufferWindow(); |
215 | 215 |
216 // Returns true if we should defer resource loading based on the current | |
217 // buffering scheme. | |
218 bool ShouldEnableDefer() const; | |
219 | |
220 // Returns true if we should enable resource loading based on the current | |
221 // buffering scheme. | |
222 bool ShouldDisableDefer() const; | |
223 | |
224 // Updates deferring behavior based on current buffering scheme. | 216 // Updates deferring behavior based on current buffering scheme. |
225 void UpdateDeferBehavior(); | 217 void UpdateDeferBehavior(); |
226 | 218 |
227 // Set defer state to |deferred| and cease/continue downloading data | 219 // Sets |active_loader_|'s defer state and fires |loading_cb_| if the state |
228 // accordingly. | 220 // changed. |
229 void SetDeferred(bool deferred); | 221 void SetDeferred(bool deferred); |
230 | 222 |
223 // Returns true if we should defer resource loading based on the current | |
224 // buffering scheme. | |
225 bool ShouldDefer() const; | |
226 | |
231 // Returns true if the current read request can be fulfilled by what is in | 227 // Returns true if the current read request can be fulfilled by what is in |
232 // the buffer. | 228 // the buffer. |
233 bool CanFulfillRead() const; | 229 bool CanFulfillRead() const; |
234 | 230 |
235 // Returns true if the current read request will be fulfilled in the future. | 231 // Returns true if the current read request will be fulfilled in the future. |
236 bool WillFulfillRead() const; | 232 bool WillFulfillRead() const; |
237 | 233 |
238 // Method that does the actual read and calls the |read_cb_|, assuming the | 234 // Method that does the actual read and calls the |read_cb_|, assuming the |
239 // request range is in |buffer_|. | 235 // request range is in |buffer_|. |
240 void ReadInternal(); | 236 void ReadInternal(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 float playback_rate_; | 326 float playback_rate_; |
331 | 327 |
332 scoped_refptr<media::MediaLog> media_log_; | 328 scoped_refptr<media::MediaLog> media_log_; |
333 | 329 |
334 DISALLOW_COPY_AND_ASSIGN(BufferedResourceLoader); | 330 DISALLOW_COPY_AND_ASSIGN(BufferedResourceLoader); |
335 }; | 331 }; |
336 | 332 |
337 } // namespace webkit_media | 333 } // namespace webkit_media |
338 | 334 |
339 #endif // WEBKIT_MEDIA_BUFFERED_RESOURCE_LOADER_H_ | 335 #endif // WEBKIT_MEDIA_BUFFERED_RESOURCE_LOADER_H_ |
OLD | NEW |