Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 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_GLUE_MEDIA_BUFFERED_RESOURCE_LOADER_H_ | 5 #ifndef WEBKIT_GLUE_MEDIA_BUFFERED_RESOURCE_LOADER_H_ |
| 6 #define WEBKIT_GLUE_MEDIA_BUFFERED_RESOURCE_LOADER_H_ | 6 #define WEBKIT_GLUE_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/scoped_ptr.h" | 11 #include "base/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/glue/media/web_data_source.h" | 20 #include "webkit/glue/media/web_data_source.h" |
| 21 #include "webkit/glue/webmediaplayer_impl.h" | 21 #include "webkit/glue/webmediaplayer_impl.h" |
| 22 | 22 |
| 23 namespace webkit_glue { | 23 namespace webkit_glue { |
| 24 | 24 |
| 25 const int64 kPositionNotSpecified = -1; | 25 const int64 kPositionNotSpecified = -1; |
| 26 | 26 |
| 27 const char kHttpScheme[] = "http"; | 27 const char kHttpScheme[] = "http"; |
| 28 const char kHttpsScheme[] = "https"; | 28 const char kHttpsScheme[] = "https"; |
| 29 const char kDataScheme[] = "data"; | 29 const char kDataScheme[] = "data"; |
| 30 | 30 |
| 31 class BufferedDataSource; | |
| 32 class DeferStrategy; | |
| 31 // This class works inside demuxer thread and render thread. It contains a | 33 // This class works inside demuxer thread and render thread. It contains a |
| 32 // WebURLLoader and does the actual resource loading. This object does | 34 // WebURLLoader and does the actual resource loading. This object does |
| 33 // buffering internally, it defers the resource loading if buffer is full | 35 // buffering internally, it defers the resource loading if buffer is full |
| 34 // and un-defers the resource loading if it is under buffered. | 36 // and un-defers the resource loading if it is under buffered. |
| 35 class BufferedResourceLoader : | 37 class BufferedResourceLoader : |
| 36 public base::RefCountedThreadSafe<BufferedResourceLoader>, | 38 public base::RefCountedThreadSafe<BufferedResourceLoader>, |
| 37 public WebKit::WebURLLoaderClient { | 39 public WebKit::WebURLLoaderClient { |
| 38 public: | 40 public: |
| 39 typedef Callback0::Type NetworkEventCallback; | 41 typedef Callback0::Type NetworkEventCallback; |
| 40 | 42 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 // The read has failed because of an error with the network. | 80 // The read has failed because of an error with the network. |
| 79 // - net::ERR_CACHE_MISS | 81 // - net::ERR_CACHE_MISS |
| 80 // The read was made too far away from the current buffered position. | 82 // The read was made too far away from the current buffered position. |
| 81 virtual void Read(int64 position, int read_size, | 83 virtual void Read(int64 position, int read_size, |
| 82 uint8* buffer, net::CompletionCallback* callback); | 84 uint8* buffer, net::CompletionCallback* callback); |
| 83 | 85 |
| 84 // Returns the position of the last byte buffered. Returns | 86 // Returns the position of the last byte buffered. Returns |
| 85 // |kPositionNotSpecified| if such value is not available. | 87 // |kPositionNotSpecified| if such value is not available. |
| 86 virtual int64 GetBufferedPosition(); | 88 virtual int64 GetBufferedPosition(); |
| 87 | 89 |
| 88 // Sets whether deferring data is allowed or disallowed. | 90 // Changes the defer strategy based on the state of BufferedDataSource. |
| 89 virtual void SetAllowDefer(bool is_allowed); | 91 virtual void UpdateDeferStrategy(BufferedDataSource*); |
|
acolwell GONE FROM CHROMIUM
2011/03/25 04:35:28
missing parameter name. Shouldn't this take a Defe
vrk (LEFT CHROMIUM)
2011/03/25 21:33:32
Done.
| |
| 90 | 92 |
| 91 // Gets the content length in bytes of the instance after this loader has been | 93 // Gets the content length in bytes of the instance after this loader has been |
| 92 // started. If this value is |kPositionNotSpecified|, then content length is | 94 // started. If this value is |kPositionNotSpecified|, then content length is |
| 93 // unknown. | 95 // unknown. |
| 94 virtual int64 content_length(); | 96 virtual int64 content_length(); |
| 95 | 97 |
| 96 // Gets the original size of the file requested. If this value is | 98 // Gets the original size of the file requested. If this value is |
| 97 // |kPositionNotSpecified|, then the size is unknown. | 99 // |kPositionNotSpecified|, then the size is unknown. |
| 98 virtual int64 instance_size(); | 100 virtual int64 instance_size(); |
| 99 | 101 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 WebKit::WebURLLoader* loader, | 138 WebKit::WebURLLoader* loader, |
| 137 double finishTime); | 139 double finishTime); |
| 138 virtual void didFail( | 140 virtual void didFail( |
| 139 WebKit::WebURLLoader* loader, | 141 WebKit::WebURLLoader* loader, |
| 140 const WebKit::WebURLError&); | 142 const WebKit::WebURLError&); |
| 141 | 143 |
| 142 bool HasSingleOrigin() const; | 144 bool HasSingleOrigin() const; |
| 143 | 145 |
| 144 protected: | 146 protected: |
| 145 friend class base::RefCountedThreadSafe<BufferedResourceLoader>; | 147 friend class base::RefCountedThreadSafe<BufferedResourceLoader>; |
| 148 friend class DeferStrategy; | |
| 149 friend class NeverDeferStrategy; | |
| 150 friend class ThresholdDeferStrategy; | |
| 151 friend class ReadThenDeferStrategy; | |
|
acolwell GONE FROM CHROMIUM
2011/03/25 04:35:28
Not thrilled by all this friending. It feels like
vrk (LEFT CHROMIUM)
2011/03/25 21:33:32
N/A now!
| |
| 146 | 152 |
| 147 virtual ~BufferedResourceLoader(); | 153 virtual ~BufferedResourceLoader(); |
| 148 | 154 |
| 149 private: | 155 private: |
| 150 friend class BufferedResourceLoaderTest; | 156 friend class BufferedResourceLoaderTest; |
| 151 | 157 |
| 152 // Defer the resource loading if the buffer is full. | 158 // Defer the resource loading if the buffer is full. |
| 153 void EnableDeferIfNeeded(); | 159 void EnableDeferIfNeeded(); |
| 154 | 160 |
| 155 // Disable defer loading if we are under-buffered. | 161 // Disable defer loading if we are under-buffered. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 void NotifyNetworkEvent(); | 195 void NotifyNetworkEvent(); |
| 190 | 196 |
| 191 bool HasPendingRead() { return read_callback_.get() != NULL; } | 197 bool HasPendingRead() { return read_callback_.get() != NULL; } |
| 192 | 198 |
| 193 // A sliding window of buffer. | 199 // A sliding window of buffer. |
| 194 scoped_ptr<media::SeekableBuffer> buffer_; | 200 scoped_ptr<media::SeekableBuffer> buffer_; |
| 195 | 201 |
| 196 // True if resource loading was deferred. | 202 // True if resource loading was deferred. |
| 197 bool deferred_; | 203 bool deferred_; |
| 198 | 204 |
| 199 // True if resource loader is allowed to defer, false otherwise. | 205 // Strategy for deferring. |
| 200 bool defer_allowed_; | 206 DeferStrategy* defer_strategy_; |
| 201 | 207 |
| 202 // True if resource loading has completed. | 208 // True if resource loading has completed. |
| 203 bool completed_; | 209 bool completed_; |
| 204 | 210 |
| 205 // True if a range request was made. | 211 // True if a range request was made. |
| 206 bool range_requested_; | 212 bool range_requested_; |
| 207 | 213 |
| 208 // True if response data received is a partial range. | 214 // True if response data received is a partial range. |
| 209 bool partial_response_; | 215 bool partial_response_; |
| 210 | 216 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 239 | 245 |
| 240 // Used to ensure mocks for unittests are used instead of reset in Start(). | 246 // Used to ensure mocks for unittests are used instead of reset in Start(). |
| 241 bool keep_test_loader_; | 247 bool keep_test_loader_; |
| 242 | 248 |
| 243 DISALLOW_COPY_AND_ASSIGN(BufferedResourceLoader); | 249 DISALLOW_COPY_AND_ASSIGN(BufferedResourceLoader); |
| 244 }; | 250 }; |
| 245 | 251 |
| 246 } // namespace webkit_glue | 252 } // namespace webkit_glue |
| 247 | 253 |
| 248 #endif // WEBKIT_GLUE_MEDIA_BUFFERED_RESOURCE_LOADER_H_ | 254 #endif // WEBKIT_GLUE_MEDIA_BUFFERED_RESOURCE_LOADER_H_ |
| OLD | NEW |