Index: media/blink/multibuffer_resource_loader.h |
diff --git a/media/blink/multibuffer_resource_loader.h b/media/blink/multibuffer_resource_loader.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fc545868328469cef1588223ee18bca5c65d01ad |
--- /dev/null |
+++ b/media/blink/multibuffer_resource_loader.h |
@@ -0,0 +1,142 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
liberato (no reviews please)
2015/10/16 21:50:36
this file is confusingly named -- it has no Multib
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MEDIA_BLINK_MULTIBUFFER_RESOURCE_LOADER_H_ |
+#define MEDIA_BLINK_MULTIBUFFER_RESOURCE_LOADER_H_ |
+ |
+#include <string> |
+ |
+#include "base/callback.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
+#include "media/base/media_export.h" |
+#include "media/blink/active_loader.h" |
+#include "media/blink/multibuffer.h" |
+#include "media/blink/url_index.h" |
+#include "third_party/WebKit/public/platform/WebURLLoader.h" |
+#include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
+#include "third_party/WebKit/public/platform/WebURLRequest.h" |
+#include "third_party/WebKit/public/web/WebFrame.h" |
+#include "url/gurl.h" |
+ |
+namespace media { |
+class MediaLog; |
+class ResourceMultiBufferDataProvider; |
+ |
+class MEDIA_EXPORT ResourceMultiBuffer |
+ : NON_EXPORTED_BASE(public MultiBuffer) { |
+public: |
+ explicit ResourceMultiBuffer(blink::WebFrame* frame); |
+ ~ResourceMultiBuffer() override; |
+ |
+ // A redirect, fail or new urldata. |
+ void OnRedirect(const scoped_refptr<UrlData>& from, |
+ const scoped_refptr<UrlData>& to); |
+ void Fail(const scoped_refptr<UrlData>& from); |
+ UrlIndex* url_index() { return &url_index_; } |
+ blink::WebFrame* frame() const { return frame_; } |
+protected: |
+ MultiBuffer::DataProvider* CreateWriter(const BlockId& pos) override; |
+private: |
+ friend class ResourceMultiBufferDataProvider; |
+ blink::WebFrame* frame_; |
+ UrlIndex url_index_; |
+}; |
+ |
+class MEDIA_EXPORT ResourceMultiBufferDataProvider |
+ : NON_EXPORTED_BASE(public MultiBuffer::DataProvider), |
+ NON_EXPORTED_BASE(public blink::WebURLLoaderClient) { |
+public: |
+ ResourceMultiBufferDataProvider( |
+ const MultiBufferBlockId& pos, |
+ ResourceMultiBuffer* resource_multibuffeer); |
+ ~ResourceMultiBufferDataProvider() override; |
+ |
+ // MultiBufferDataProvider implementation |
+ MultiBufferBlockId Tell() const override; |
+ bool Available() const override; |
+ scoped_refptr<DataBuffer> Read() override; |
+ void SetAvailableCallback(const base::Closure& cb) override; |
+ void SetDeferred(bool defer) override; |
+ |
+ // blink::WebURLLoaderClient implementation. |
+ void willFollowRedirect( |
+ blink::WebURLLoader* loader, |
+ blink::WebURLRequest& newRequest, |
+ const blink::WebURLResponse& redirectResponse) override; |
+ void didSendData( |
+ blink::WebURLLoader* loader, |
+ unsigned long long bytesSent, |
+ unsigned long long totalBytesToBeSent) override; |
+ void didReceiveResponse( |
+ blink::WebURLLoader* loader, |
+ const blink::WebURLResponse& response) override; |
+ void didDownloadData( |
+ blink::WebURLLoader* loader, |
+ int data_length, |
+ int encoded_data_length) override; |
+ void didReceiveData( |
+ blink::WebURLLoader* loader, |
+ const char* data, |
+ int data_length, |
+ int encoded_data_length) override; |
+ void didReceiveCachedMetadata( |
+ blink::WebURLLoader* loader, |
+ const char* data, int dataLength) override; |
+ void didFinishLoading( |
+ blink::WebURLLoader* loader, |
+ double finishTime, |
+ int64_t total_encoded_data_length) override; |
+ void didFail( |
+ blink::WebURLLoader* loader, |
+ const blink::WebURLError&) override; |
+ |
+ // Parse a Content-Range header into its component pieces and return true if |
+ // each of the expected elements was found & parsed correctly. |
+ // |*instance_size| may be set to kPositionNotSpecified if the range ends in |
+ // "/*". |
+ // NOTE: only public for testing! This is an implementation detail of |
+ // VerifyPartialResponse (a private method). |
+ static bool ParseContentRange( |
+ const std::string& content_range_str, int64* first_byte_position, |
+ int64* last_byte_position, int64* instance_size); |
+ |
+ // Virtual for testing purposes. |
+ virtual void Start(); |
+ |
+ protected: |
+ friend class MultibufferDataSourceTest; |
+ friend class MultibufferResourceLoaderTest; |
+ friend class MockBufferedDataSource; |
+ |
+ int64_t byte_pos() const; |
+ int64_t block_size() const; |
+ // If we have made a range request, verify the response from the server. |
+ bool VerifyPartialResponse(const blink::WebURLResponse& response); |
+ |
+ ResourceMultiBuffer* resource_multibuffer_; |
+ std::list<scoped_refptr<DataBuffer> > fifo_; |
+ int retries_; |
+ |
+ // Keeps track of an active WebURLLoader and associated state. |
+ scoped_ptr<ActiveLoader> active_loader_; |
+ MultiBufferBlockId pos_; |
+ |
+ // The url_data we got in the constructor. |
+ scoped_refptr<UrlData> original_url_data_; |
+ |
+ // When we encounter a redirect, this becomes the source of the redirect. |
+ scoped_refptr<UrlData> redirected_url_data_; |
+ |
+ // This is where we actually get read data from. |
+ scoped_refptr<UrlData> url_data_; |
+ |
+ // Callback from the multibuffer class. |
+ base::Closure cb_; |
+ base::WeakPtrFactory<ResourceMultiBufferDataProvider> weak_factory_; |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_BLINK_MULTIBUFFER_RESOURCE_LOADER_H_ |