OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MEDIA_BLINK_RESOURCE_MULTIBUFFER_DATA_PROVIDER_H_ |
| 6 #define MEDIA_BLINK_RESOURCE_MULTIBUFFER_DATA_PROVIDER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "media/blink/active_loader.h" |
| 14 #include "media/blink/media_blink_export.h" |
| 15 #include "media/blink/multibuffer.h" |
| 16 #include "media/blink/url_index.h" |
| 17 #include "third_party/WebKit/public/platform/WebURLLoader.h" |
| 18 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
| 19 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 20 #include "third_party/WebKit/public/web/WebFrame.h" |
| 21 #include "url/gurl.h" |
| 22 |
| 23 namespace media { |
| 24 class MediaLog; |
| 25 class ResourceMultiBuffer; |
| 26 |
| 27 class MEDIA_BLINK_EXPORT ResourceMultiBufferDataProvider |
| 28 : NON_EXPORTED_BASE(public MultiBuffer::DataProvider), |
| 29 NON_EXPORTED_BASE(public blink::WebURLLoaderClient) { |
| 30 public: |
| 31 ResourceMultiBufferDataProvider(const MultiBufferBlockId& pos, |
| 32 ResourceMultiBuffer* resource_multibuffeer); |
| 33 ~ResourceMultiBufferDataProvider() override; |
| 34 |
| 35 // MultiBufferDataProvider implementation |
| 36 MultiBufferBlockId Tell() const override; |
| 37 bool Available() const override; |
| 38 scoped_refptr<DataBuffer> Read() override; |
| 39 void SetAvailableCallback(const base::Closure& cb) override; |
| 40 void SetDeferred(bool defer) override; |
| 41 |
| 42 // blink::WebURLLoaderClient implementation. |
| 43 void willFollowRedirect( |
| 44 blink::WebURLLoader* loader, |
| 45 blink::WebURLRequest& newRequest, |
| 46 const blink::WebURLResponse& redirectResponse) override; |
| 47 void didSendData(blink::WebURLLoader* loader, |
| 48 unsigned long long bytesSent, |
| 49 unsigned long long totalBytesToBeSent) override; |
| 50 void didReceiveResponse(blink::WebURLLoader* loader, |
| 51 const blink::WebURLResponse& response) override; |
| 52 void didDownloadData(blink::WebURLLoader* loader, |
| 53 int data_length, |
| 54 int encoded_data_length) override; |
| 55 void didReceiveData(blink::WebURLLoader* loader, |
| 56 const char* data, |
| 57 int data_length, |
| 58 int encoded_data_length) override; |
| 59 void didReceiveCachedMetadata(blink::WebURLLoader* loader, |
| 60 const char* data, |
| 61 int dataLength) override; |
| 62 void didFinishLoading(blink::WebURLLoader* loader, |
| 63 double finishTime, |
| 64 int64_t total_encoded_data_length) override; |
| 65 void didFail(blink::WebURLLoader* loader, const blink::WebURLError&) override; |
| 66 |
| 67 // Parse a Content-Range header into its component pieces and return true if |
| 68 // each of the expected elements was found & parsed correctly. |
| 69 // |*instance_size| may be set to kPositionNotSpecified if the range ends in |
| 70 // "/*". |
| 71 // NOTE: only public for testing! This is an implementation detail of |
| 72 // VerifyPartialResponse (a private method). |
| 73 static bool ParseContentRange(const std::string& content_range_str, |
| 74 int64* first_byte_position, |
| 75 int64* last_byte_position, |
| 76 int64* instance_size); |
| 77 |
| 78 // Virtual for testing purposes. |
| 79 virtual void Start(); |
| 80 |
| 81 protected: |
| 82 friend class MultibufferDataSourceTest; |
| 83 friend class MultibufferResourceLoaderTest; |
| 84 friend class MockBufferedDataSource; |
| 85 |
| 86 int64_t byte_pos() const; |
| 87 int64_t block_size() const; |
| 88 // If we have made a range request, verify the response from the server. |
| 89 bool VerifyPartialResponse(const blink::WebURLResponse& response); |
| 90 |
| 91 // Current Position. |
| 92 MultiBufferBlockId pos_; |
| 93 |
| 94 ResourceMultiBuffer* resource_multibuffer_; |
| 95 |
| 96 // Temporary storage for incoming data. |
| 97 std::list<scoped_refptr<DataBuffer>> fifo_; |
| 98 |
| 99 // How many retries have we done at the current position. |
| 100 int retries_; |
| 101 |
| 102 // Keeps track of an active WebURLLoader and associated state. |
| 103 scoped_ptr<ActiveLoader> active_loader_; |
| 104 |
| 105 // The url_data we got in the constructor. |
| 106 scoped_refptr<UrlData> original_url_data_; |
| 107 |
| 108 // When we encounter a redirect, this becomes the source of the redirect. |
| 109 scoped_refptr<UrlData> redirected_url_data_; |
| 110 |
| 111 // This is where we actually get read data from. |
| 112 scoped_refptr<UrlData> url_data_; |
| 113 |
| 114 // Callback from the multibuffer class. |
| 115 base::Closure cb_; |
| 116 base::WeakPtrFactory<ResourceMultiBufferDataProvider> weak_factory_; |
| 117 }; |
| 118 |
| 119 } // namespace media |
| 120 |
| 121 #endif // MEDIA_BLINK_RESOURCE_MULTIBUFFER_RESOURCE_LOADER_H_ |
OLD | NEW |