OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 MEDIA_BLINK_RESOURCE_MULTIBUFFER_DATA_PROVIDER_H_ | 5 #ifndef MEDIA_BLINK_RESOURCE_MULTIBUFFER_DATA_PROVIDER_H_ |
6 #define MEDIA_BLINK_RESOURCE_MULTIBUFFER_DATA_PROVIDER_H_ | 6 #define MEDIA_BLINK_RESOURCE_MULTIBUFFER_DATA_PROVIDER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "media/blink/active_loader.h" | 15 #include "media/blink/active_loader.h" |
16 #include "media/blink/media_blink_export.h" | 16 #include "media/blink/media_blink_export.h" |
17 #include "media/blink/multibuffer.h" | 17 #include "media/blink/multibuffer.h" |
18 #include "media/blink/url_index.h" | 18 #include "media/blink/url_index.h" |
19 #include "third_party/WebKit/public/platform/WebURLLoader.h" | |
20 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | |
21 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 19 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 20 #include "third_party/WebKit/public/web/WebAssociatedURLLoaderClient.h" |
22 #include "third_party/WebKit/public/web/WebFrame.h" | 21 #include "third_party/WebKit/public/web/WebFrame.h" |
23 #include "url/gurl.h" | 22 #include "url/gurl.h" |
24 | 23 |
| 24 namespace blink { |
| 25 class WebAssociatedURLLoader; |
| 26 } // namespace blink |
| 27 |
25 namespace media { | 28 namespace media { |
26 | 29 |
27 class MEDIA_BLINK_EXPORT ResourceMultiBufferDataProvider | 30 class MEDIA_BLINK_EXPORT ResourceMultiBufferDataProvider |
28 : NON_EXPORTED_BASE(public MultiBuffer::DataProvider), | 31 : NON_EXPORTED_BASE(public MultiBuffer::DataProvider), |
29 NON_EXPORTED_BASE(public blink::WebURLLoaderClient) { | 32 NON_EXPORTED_BASE(public blink::WebAssociatedURLLoaderClient) { |
30 public: | 33 public: |
31 // NUmber of times we'll retry if the connection fails. | 34 // NUmber of times we'll retry if the connection fails. |
32 enum { kMaxRetries = 30 }; | 35 enum { kMaxRetries = 30 }; |
33 | 36 |
34 ResourceMultiBufferDataProvider(UrlData* url_data, MultiBufferBlockId pos); | 37 ResourceMultiBufferDataProvider(UrlData* url_data, MultiBufferBlockId pos); |
35 ~ResourceMultiBufferDataProvider() override; | 38 ~ResourceMultiBufferDataProvider() override; |
36 | 39 |
37 // Virtual for testing purposes. | 40 // Virtual for testing purposes. |
38 virtual void Start(); | 41 virtual void Start(); |
39 | 42 |
40 // MultiBuffer::DataProvider implementation | 43 // MultiBuffer::DataProvider implementation |
41 MultiBufferBlockId Tell() const override; | 44 MultiBufferBlockId Tell() const override; |
42 bool Available() const override; | 45 bool Available() const override; |
43 int64_t AvailableBytes() const override; | 46 int64_t AvailableBytes() const override; |
44 scoped_refptr<DataBuffer> Read() override; | 47 scoped_refptr<DataBuffer> Read() override; |
45 void SetDeferred(bool defer) override; | 48 void SetDeferred(bool defer) override; |
46 | 49 |
47 // blink::WebURLLoaderClient implementation. | 50 // blink::WebAssociatedURLLoaderClient implementation. |
48 bool willFollowRedirect( | 51 bool willFollowRedirect( |
49 blink::WebURLLoader* loader, | 52 const blink::WebURLRequest& newRequest, |
50 blink::WebURLRequest& newRequest, | |
51 const blink::WebURLResponse& redirectResponse) override; | 53 const blink::WebURLResponse& redirectResponse) override; |
52 void didSendData(blink::WebURLLoader* loader, | 54 void didSendData(unsigned long long bytesSent, |
53 unsigned long long bytesSent, | |
54 unsigned long long totalBytesToBeSent) override; | 55 unsigned long long totalBytesToBeSent) override; |
55 void didReceiveResponse(blink::WebURLLoader* loader, | 56 void didReceiveResponse(const blink::WebURLResponse& response) override; |
56 const blink::WebURLResponse& response) override; | 57 void didDownloadData(int data_length) override; |
57 void didDownloadData(blink::WebURLLoader* loader, | 58 void didReceiveData(const char* data, int data_length) override; |
58 int data_length, | 59 void didReceiveCachedMetadata(const char* data, int dataLength) override; |
59 int encoded_data_length) override; | 60 void didFinishLoading(double finishTime) override; |
60 void didReceiveData(blink::WebURLLoader* loader, | 61 void didFail(const blink::WebURLError&) override; |
61 const char* data, | |
62 int data_length, | |
63 int encoded_data_length, | |
64 int encoded_body_length) override; | |
65 void didReceiveCachedMetadata(blink::WebURLLoader* loader, | |
66 const char* data, | |
67 int dataLength) override; | |
68 void didFinishLoading(blink::WebURLLoader* loader, | |
69 double finishTime, | |
70 int64_t total_encoded_data_length) override; | |
71 void didFail(blink::WebURLLoader* loader, const blink::WebURLError&) override; | |
72 | 62 |
73 // Use protected instead of private for testing purposes. | 63 // Use protected instead of private for testing purposes. |
74 protected: | 64 protected: |
75 friend class MultibufferDataSourceTest; | 65 friend class MultibufferDataSourceTest; |
76 friend class ResourceMultiBufferDataProviderTest; | 66 friend class ResourceMultiBufferDataProviderTest; |
77 friend class MockBufferedDataSource; | 67 friend class MockBufferedDataSource; |
78 | 68 |
79 // Callback used when we're asked to fetch data after the end of the file. | 69 // Callback used when we're asked to fetch data after the end of the file. |
80 void Terminate(); | 70 void Terminate(); |
81 | 71 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 int retries_; | 103 int retries_; |
114 | 104 |
115 // Copy of url_data_->cors_mode() | 105 // Copy of url_data_->cors_mode() |
116 // const to make it obvious that redirects cannot change it. | 106 // const to make it obvious that redirects cannot change it. |
117 const UrlData::CORSMode cors_mode_; | 107 const UrlData::CORSMode cors_mode_; |
118 | 108 |
119 // The origin for the initial request. | 109 // The origin for the initial request. |
120 // const to make it obvious that redirects cannot change it. | 110 // const to make it obvious that redirects cannot change it. |
121 const GURL origin_; | 111 const GURL origin_; |
122 | 112 |
123 // Keeps track of an active WebURLLoader and associated state. | 113 // Keeps track of an active WebAssociatedURLLoader and associated state. |
124 std::unique_ptr<ActiveLoader> active_loader_; | 114 std::unique_ptr<ActiveLoader> active_loader_; |
125 | 115 |
126 // Injected WebURLLoader instance for testing purposes. | 116 // Injected WebAssociatedURLLoader instance for testing purposes. |
127 std::unique_ptr<blink::WebURLLoader> test_loader_; | 117 std::unique_ptr<blink::WebAssociatedURLLoader> test_loader_; |
128 | 118 |
129 // When we encounter a redirect, this is the source of the redirect. | 119 // When we encounter a redirect, this is the source of the redirect. |
130 GURL redirects_to_; | 120 GURL redirects_to_; |
131 | 121 |
132 base::WeakPtrFactory<ResourceMultiBufferDataProvider> weak_factory_; | 122 base::WeakPtrFactory<ResourceMultiBufferDataProvider> weak_factory_; |
133 }; | 123 }; |
134 | 124 |
135 } // namespace media | 125 } // namespace media |
136 | 126 |
137 #endif // MEDIA_BLINK_RESOURCE_MULTIBUFFER_DATA_PROVIDER_H_ | 127 #endif // MEDIA_BLINK_RESOURCE_MULTIBUFFER_DATA_PROVIDER_H_ |
OLD | NEW |