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; | |
xhwang
2015/11/19 23:34:17
not used?
hubbe
2015/11/20 23:24:23
Done.
| |
25 class ResourceMultiBuffer; | |
xhwang
2015/11/19 23:34:18
not used as well?
hubbe
2015/11/20 23:24:23
Done.
| |
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(UrlData* url_data, MultiBufferBlockId pos); | |
32 ~ResourceMultiBufferDataProvider() override; | |
33 | |
34 // MultiBufferDataProvider implementation | |
xhwang
2015/11/19 23:34:18
MultiBuffer::DataProvider ?
hubbe
2015/11/20 23:24:23
Done.
| |
35 MultiBufferBlockId Tell() const override; | |
36 bool Available() const override; | |
37 scoped_refptr<DataBuffer> Read() override; | |
38 void SetDeferred(bool defer) override; | |
39 | |
40 // blink::WebURLLoaderClient implementation. | |
41 void willFollowRedirect( | |
42 blink::WebURLLoader* loader, | |
43 blink::WebURLRequest& newRequest, | |
44 const blink::WebURLResponse& redirectResponse) override; | |
45 void didSendData(blink::WebURLLoader* loader, | |
46 unsigned long long bytesSent, | |
47 unsigned long long totalBytesToBeSent) override; | |
48 void didReceiveResponse(blink::WebURLLoader* loader, | |
49 const blink::WebURLResponse& response) override; | |
50 void didDownloadData(blink::WebURLLoader* loader, | |
51 int data_length, | |
52 int encoded_data_length) override; | |
53 void didReceiveData(blink::WebURLLoader* loader, | |
54 const char* data, | |
55 int data_length, | |
56 int encoded_data_length) override; | |
57 void didReceiveCachedMetadata(blink::WebURLLoader* loader, | |
58 const char* data, | |
59 int dataLength) override; | |
60 void didFinishLoading(blink::WebURLLoader* loader, | |
61 double finishTime, | |
62 int64_t total_encoded_data_length) override; | |
63 void didFail(blink::WebURLLoader* loader, const blink::WebURLError&) override; | |
64 | |
65 // Parse a Content-Range header into its component pieces and return true if | |
66 // each of the expected elements was found & parsed correctly. | |
67 // |*instance_size| may be set to kPositionNotSpecified if the range ends in | |
68 // "/*". | |
69 // NOTE: only public for testing! This is an implementation detail of | |
70 // VerifyPartialResponse (a private method). | |
xhwang
2015/11/19 23:34:18
Not seeing how this will be tested...
Given we h
hubbe
2015/11/20 23:24:23
Test is in a later CL I'm afraid.
I don't think it
| |
71 static bool ParseContentRange(const std::string& content_range_str, | |
72 int64* first_byte_position, | |
73 int64* last_byte_position, | |
74 int64* instance_size); | |
75 | |
76 // Virtual for testing purposes. | |
xhwang
2015/11/19 23:34:18
I don't see how this is used for testing and why i
hubbe
2015/11/20 23:24:23
Unfortunately tests are in a later CL.
xhwang
2015/11/23 23:09:21
Then does it make sense to add Start() in that lat
hubbe
2015/11/24 22:55:10
No, Start() is needed already, but I could remove
| |
77 virtual void Start(); | |
78 | |
79 protected: | |
xhwang
2015/11/19 23:34:18
Why not private?
hubbe
2015/11/20 23:24:23
Comment added.
| |
80 friend class MultibufferDataSourceTest; | |
81 friend class MultibufferResourceLoaderTest; | |
82 friend class MockBufferedDataSource; | |
83 | |
84 int64_t byte_pos() const; | |
85 int64_t block_size() const; | |
xhwang
2015/11/19 23:34:18
nit: empty line here
hubbe
2015/11/20 23:24:23
Done.
| |
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. | |
95 UrlData* url_data_; | |
xhwang
2015/11/19 23:34:18
const?
hubbe
2015/11/20 23:24:23
Unfortunately no, we change it when we change owne
xhwang
2015/11/23 23:09:21
Interesting fact! Worth a comment?
hubbe
2015/11/24 22:55:10
Absolutely.
| |
96 | |
97 // Temporary storage for incoming data. | |
98 std::list<scoped_refptr<DataBuffer>> fifo_; | |
99 | |
100 // How many retries have we done at the current position. | |
101 int retries_; | |
102 | |
103 // Copy of url_data_->cors_mode() | |
104 // const to make it obvious that redirects cannot change it. | |
105 const UrlData::CORSMode cors_mode_; | |
106 | |
107 // The origin for the initial request. | |
108 // const to make it obvious that redirects cannot change it. | |
109 const GURL origin_; | |
110 | |
111 // Keeps track of an active WebURLLoader and associated state. | |
112 scoped_ptr<ActiveLoader> active_loader_; | |
113 | |
114 // When we encounter a redirect, this is the source of the redirect. | |
115 GURL redirects_to_; | |
116 | |
117 base::WeakPtrFactory<ResourceMultiBufferDataProvider> weak_factory_; | |
118 }; | |
119 | |
120 } // namespace media | |
121 | |
122 #endif // MEDIA_BLINK_RESOURCE_MULTIBUFFER_RESOURCE_LOADER_H_ | |
OLD | NEW |