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; | |
|
acolwell GONE FROM CHROMIUM
2011/03/25 23:08:14
No longer necessary.
vrk (LEFT CHROMIUM)
2011/03/29 00:53:00
Done.
| |
| 31 // This class works inside demuxer thread and render thread. It contains a | 32 // This class works inside demuxer thread and render thread. It contains a |
| 32 // WebURLLoader and does the actual resource loading. This object does | 33 // WebURLLoader and does the actual resource loading. This object does |
| 33 // buffering internally, it defers the resource loading if buffer is full | 34 // buffering internally, it defers the resource loading if buffer is full |
| 34 // and un-defers the resource loading if it is under buffered. | 35 // and un-defers the resource loading if it is under buffered. |
| 35 class BufferedResourceLoader : | 36 class BufferedResourceLoader : |
| 36 public base::RefCountedThreadSafe<BufferedResourceLoader>, | 37 public base::RefCountedThreadSafe<BufferedResourceLoader>, |
| 37 public WebKit::WebURLLoaderClient { | 38 public WebKit::WebURLLoaderClient { |
| 38 public: | 39 public: |
| 40 enum DeferStrategy { | |
|
acolwell GONE FROM CHROMIUM
2011/03/25 23:08:14
Brief comments about each of these.
vrk (LEFT CHROMIUM)
2011/03/29 00:53:00
Done.
I also changed the naming style to match th
acolwell GONE FROM CHROMIUM
2011/03/29 05:52:03
I think the kXXX style is good here. I think Pipel
| |
| 41 NeverDefer, | |
| 42 ReadThenDefer, | |
| 43 ThresholdDefer | |
| 44 }; | |
| 45 | |
| 39 typedef Callback0::Type NetworkEventCallback; | 46 typedef Callback0::Type NetworkEventCallback; |
| 40 | 47 |
| 41 // |url| - URL for the resource to be loaded. | 48 // |url| - URL for the resource to be loaded. |
| 42 // |first_byte_position| - First byte to start loading from, | 49 // |first_byte_position| - First byte to start loading from, |
| 43 // |kPositionNotSpecified| for not specified. | 50 // |kPositionNotSpecified| for not specified. |
| 44 // |last_byte_position| - Last byte to be loaded, | 51 // |last_byte_position| - Last byte to be loaded, |
| 45 // |kPositionNotSpecified| for not specified. | 52 // |kPositionNotSpecified| for not specified. |
| 46 BufferedResourceLoader(const GURL& url, | 53 BufferedResourceLoader(const GURL& url, |
| 47 int64 first_byte_position, | 54 int64 first_byte_position, |
| 48 int64 last_byte_position); | 55 int64 last_byte_position); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 78 // The read has failed because of an error with the network. | 85 // The read has failed because of an error with the network. |
| 79 // - net::ERR_CACHE_MISS | 86 // - net::ERR_CACHE_MISS |
| 80 // The read was made too far away from the current buffered position. | 87 // The read was made too far away from the current buffered position. |
| 81 virtual void Read(int64 position, int read_size, | 88 virtual void Read(int64 position, int read_size, |
| 82 uint8* buffer, net::CompletionCallback* callback); | 89 uint8* buffer, net::CompletionCallback* callback); |
| 83 | 90 |
| 84 // Returns the position of the last byte buffered. Returns | 91 // Returns the position of the last byte buffered. Returns |
| 85 // |kPositionNotSpecified| if such value is not available. | 92 // |kPositionNotSpecified| if such value is not available. |
| 86 virtual int64 GetBufferedPosition(); | 93 virtual int64 GetBufferedPosition(); |
| 87 | 94 |
| 88 // Sets whether deferring data is allowed or disallowed. | |
| 89 virtual void SetAllowDefer(bool is_allowed); | |
| 90 | |
| 91 // Gets the content length in bytes of the instance after this loader has been | 95 // 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 | 96 // started. If this value is |kPositionNotSpecified|, then content length is |
| 93 // unknown. | 97 // unknown. |
| 94 virtual int64 content_length(); | 98 virtual int64 content_length(); |
| 95 | 99 |
| 96 // Gets the original size of the file requested. If this value is | 100 // Gets the original size of the file requested. If this value is |
| 97 // |kPositionNotSpecified|, then the size is unknown. | 101 // |kPositionNotSpecified|, then the size is unknown. |
| 98 virtual int64 instance_size(); | 102 virtual int64 instance_size(); |
| 99 | 103 |
| 100 // Returns true if the response for this loader is a partial response. | 104 // Returns true if the response for this loader is a partial response. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 const char* data, int dataLength); | 138 const char* data, int dataLength); |
| 135 virtual void didFinishLoading( | 139 virtual void didFinishLoading( |
| 136 WebKit::WebURLLoader* loader, | 140 WebKit::WebURLLoader* loader, |
| 137 double finishTime); | 141 double finishTime); |
| 138 virtual void didFail( | 142 virtual void didFail( |
| 139 WebKit::WebURLLoader* loader, | 143 WebKit::WebURLLoader* loader, |
| 140 const WebKit::WebURLError&); | 144 const WebKit::WebURLError&); |
| 141 | 145 |
| 142 bool HasSingleOrigin() const; | 146 bool HasSingleOrigin() const; |
| 143 | 147 |
| 148 void SetDeferStrategy(DeferStrategy strategy); | |
| 149 | |
| 150 // Updates deferring behavior based on current buffering scheme. | |
| 151 void UpdateDeferBehavior(); | |
|
acolwell GONE FROM CHROMIUM
2011/03/25 23:08:14
I believe this can become private once the one cal
vrk (LEFT CHROMIUM)
2011/03/29 00:53:00
Done.
| |
| 152 | |
| 144 protected: | 153 protected: |
| 145 friend class base::RefCountedThreadSafe<BufferedResourceLoader>; | 154 friend class base::RefCountedThreadSafe<BufferedResourceLoader>; |
| 146 | |
| 147 virtual ~BufferedResourceLoader(); | 155 virtual ~BufferedResourceLoader(); |
| 148 | 156 |
| 149 private: | 157 private: |
| 158 | |
|
acolwell GONE FROM CHROMIUM
2011/03/25 23:08:14
Remove blank line
vrk (LEFT CHROMIUM)
2011/03/29 00:53:00
Done.
| |
| 150 friend class BufferedResourceLoaderTest; | 159 friend class BufferedResourceLoaderTest; |
| 151 | 160 |
| 152 // Defer the resource loading if the buffer is full. | 161 // Toggles whether the resource loading is deferred or not. |
| 153 void EnableDeferIfNeeded(); | 162 // Returns true if a network event was fired. |
| 163 bool ToggleDeferring(); | |
| 154 | 164 |
| 155 // Disable defer loading if we are under-buffered. | 165 // Returns true if we should defer resource loading, based |
| 156 void DisableDeferIfNeeded(); | 166 // on current buffering scheme. |
| 167 bool ShouldEnableDefer(); | |
| 168 | |
| 169 // Returns true if we should enable resource loading, based | |
| 170 // on current buffering scheme. | |
| 171 bool ShouldDisableDefer(); | |
| 157 | 172 |
| 158 // Returns true if the current read request can be fulfilled by what is in | 173 // Returns true if the current read request can be fulfilled by what is in |
| 159 // the buffer. | 174 // the buffer. |
| 160 bool CanFulfillRead(); | 175 bool CanFulfillRead(); |
| 161 | 176 |
| 162 // Returns true if the current read request will be fulfilled in the future. | 177 // Returns true if the current read request will be fulfilled in the future. |
| 163 bool WillFulfillRead(); | 178 bool WillFulfillRead(); |
| 164 | 179 |
| 165 // Method that does the actual read and calls the |read_callback_|, assuming | 180 // Method that does the actual read and calls the |read_callback_|, assuming |
| 166 // the request range is in |buffer_|. | 181 // the request range is in |buffer_|. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 189 void NotifyNetworkEvent(); | 204 void NotifyNetworkEvent(); |
| 190 | 205 |
| 191 bool HasPendingRead() { return read_callback_.get() != NULL; } | 206 bool HasPendingRead() { return read_callback_.get() != NULL; } |
| 192 | 207 |
| 193 // A sliding window of buffer. | 208 // A sliding window of buffer. |
| 194 scoped_ptr<media::SeekableBuffer> buffer_; | 209 scoped_ptr<media::SeekableBuffer> buffer_; |
| 195 | 210 |
| 196 // True if resource loading was deferred. | 211 // True if resource loading was deferred. |
| 197 bool deferred_; | 212 bool deferred_; |
| 198 | 213 |
| 199 // True if resource loader is allowed to defer, false otherwise. | 214 DeferStrategy defer_strategy_; |
| 200 bool defer_allowed_; | |
| 201 | 215 |
| 202 // True if resource loading has completed. | 216 // True if resource loading has completed. |
| 203 bool completed_; | 217 bool completed_; |
| 204 | 218 |
| 205 // True if a range request was made. | 219 // True if a range request was made. |
| 206 bool range_requested_; | 220 bool range_requested_; |
| 207 | 221 |
| 208 // True if response data received is a partial range. | 222 // True if response data received is a partial range. |
| 209 bool partial_response_; | 223 bool partial_response_; |
| 210 | 224 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 239 | 253 |
| 240 // Used to ensure mocks for unittests are used instead of reset in Start(). | 254 // Used to ensure mocks for unittests are used instead of reset in Start(). |
| 241 bool keep_test_loader_; | 255 bool keep_test_loader_; |
| 242 | 256 |
| 243 DISALLOW_COPY_AND_ASSIGN(BufferedResourceLoader); | 257 DISALLOW_COPY_AND_ASSIGN(BufferedResourceLoader); |
| 244 }; | 258 }; |
| 245 | 259 |
| 246 } // namespace webkit_glue | 260 } // namespace webkit_glue |
| 247 | 261 |
| 248 #endif // WEBKIT_GLUE_MEDIA_BUFFERED_RESOURCE_LOADER_H_ | 262 #endif // WEBKIT_GLUE_MEDIA_BUFFERED_RESOURCE_LOADER_H_ |
| OLD | NEW |