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 |
| 25 class MEDIA_BLINK_EXPORT ResourceMultiBufferDataProvider |
| 26 : NON_EXPORTED_BASE(public MultiBuffer::DataProvider), |
| 27 NON_EXPORTED_BASE(public blink::WebURLLoaderClient) { |
| 28 public: |
| 29 ResourceMultiBufferDataProvider(UrlData* url_data, MultiBufferBlockId pos); |
| 30 ~ResourceMultiBufferDataProvider() override; |
| 31 |
| 32 // Virtual for testing purposes. |
| 33 virtual void Start(); |
| 34 |
| 35 // MultiBuffer::DataProvider implementation |
| 36 MultiBufferBlockId Tell() const override; |
| 37 bool Available() const override; |
| 38 scoped_refptr<DataBuffer> Read() override; |
| 39 void SetDeferred(bool defer) override; |
| 40 |
| 41 // blink::WebURLLoaderClient implementation. |
| 42 void willFollowRedirect( |
| 43 blink::WebURLLoader* loader, |
| 44 blink::WebURLRequest& newRequest, |
| 45 const blink::WebURLResponse& redirectResponse) override; |
| 46 void didSendData(blink::WebURLLoader* loader, |
| 47 unsigned long long bytesSent, |
| 48 unsigned long long totalBytesToBeSent) override; |
| 49 void didReceiveResponse(blink::WebURLLoader* loader, |
| 50 const blink::WebURLResponse& response) override; |
| 51 void didDownloadData(blink::WebURLLoader* loader, |
| 52 int data_length, |
| 53 int encoded_data_length) override; |
| 54 void didReceiveData(blink::WebURLLoader* loader, |
| 55 const char* data, |
| 56 int data_length, |
| 57 int encoded_data_length) override; |
| 58 void didReceiveCachedMetadata(blink::WebURLLoader* loader, |
| 59 const char* data, |
| 60 int dataLength) override; |
| 61 void didFinishLoading(blink::WebURLLoader* loader, |
| 62 double finishTime, |
| 63 int64_t total_encoded_data_length) override; |
| 64 void didFail(blink::WebURLLoader* loader, const blink::WebURLError&) override; |
| 65 |
| 66 // Use protected instead of private for testing purposes. |
| 67 protected: |
| 68 friend class MultibufferDataSourceTest; |
| 69 friend class ResourceMultiBufferDataProviderTest; |
| 70 friend class MockBufferedDataSource; |
| 71 |
| 72 // Parse a Content-Range header into its component pieces and return true if |
| 73 // each of the expected elements was found & parsed correctly. |
| 74 // |*instance_size| may be set to kPositionNotSpecified if the range ends in |
| 75 // "/*". |
| 76 // NOTE: only public for testing! This is an implementation detail of |
| 77 // VerifyPartialResponse (a private method). |
| 78 static bool ParseContentRange(const std::string& content_range_str, |
| 79 int64* first_byte_position, |
| 80 int64* last_byte_position, |
| 81 int64* instance_size); |
| 82 |
| 83 int64_t byte_pos() const; |
| 84 int64_t block_size() const; |
| 85 |
| 86 // If we have made a range request, verify the response from the server. |
| 87 bool VerifyPartialResponse(const blink::WebURLResponse& response); |
| 88 |
| 89 // Current Position. |
| 90 MultiBufferBlockId pos_; |
| 91 |
| 92 // This is where we actually get read data from. |
| 93 // We don't need (or want) a scoped_refptr for this one, because |
| 94 // we are owned by it. Note that we may change this when we encounter |
| 95 // a redirect because we actually change ownership. |
| 96 UrlData* url_data_; |
| 97 |
| 98 // Temporary storage for incoming data. |
| 99 std::list<scoped_refptr<DataBuffer>> fifo_; |
| 100 |
| 101 // How many retries have we done at the current position. |
| 102 int retries_; |
| 103 |
| 104 // Copy of url_data_->cors_mode() |
| 105 // const to make it obvious that redirects cannot change it. |
| 106 const UrlData::CORSMode cors_mode_; |
| 107 |
| 108 // The origin for the initial request. |
| 109 // const to make it obvious that redirects cannot change it. |
| 110 const GURL origin_; |
| 111 |
| 112 // Keeps track of an active WebURLLoader and associated state. |
| 113 scoped_ptr<ActiveLoader> active_loader_; |
| 114 |
| 115 // Injected WebURLLoader instance for testing purposes. |
| 116 scoped_ptr<blink::WebURLLoader> test_loader_; |
| 117 |
| 118 // When we encounter a redirect, this is the source of the redirect. |
| 119 GURL redirects_to_; |
| 120 |
| 121 base::WeakPtrFactory<ResourceMultiBufferDataProvider> weak_factory_; |
| 122 }; |
| 123 |
| 124 } // namespace media |
| 125 |
| 126 #endif // MEDIA_BLINK_RESOURCE_MULTIBUFFER_RESOURCE_LOADER_H_ |
OLD | NEW |