Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: media/blink/multibuffer_resource_loader.h

Issue 1399603003: Tie multibuffers to URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@media_cache
Patch Set: compile fixes Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // 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
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_MULTIBUFFER_RESOURCE_LOADER_H_
6 #define MEDIA_BLINK_MULTIBUFFER_RESOURCE_LOADER_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/base/media_export.h"
14 #include "media/blink/active_loader.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 ResourceMultiBufferDataProvider;
26
27 class MEDIA_EXPORT ResourceMultiBuffer
28 : NON_EXPORTED_BASE(public MultiBuffer) {
29 public:
30 explicit ResourceMultiBuffer(blink::WebFrame* frame);
31 ~ResourceMultiBuffer() override;
32
33 // A redirect, fail or new urldata.
34 void OnRedirect(const scoped_refptr<UrlData>& from,
35 const scoped_refptr<UrlData>& to);
36 void Fail(const scoped_refptr<UrlData>& from);
37 UrlIndex* url_index() { return &url_index_; }
38 blink::WebFrame* frame() const { return frame_; }
39 protected:
40 MultiBuffer::DataProvider* CreateWriter(const BlockId& pos) override;
41 private:
42 friend class ResourceMultiBufferDataProvider;
43 blink::WebFrame* frame_;
44 UrlIndex url_index_;
45 };
46
47 class MEDIA_EXPORT ResourceMultiBufferDataProvider
48 : NON_EXPORTED_BASE(public MultiBuffer::DataProvider),
49 NON_EXPORTED_BASE(public blink::WebURLLoaderClient) {
50 public:
51 ResourceMultiBufferDataProvider(
52 const MultiBufferBlockId& pos,
53 ResourceMultiBuffer* resource_multibuffeer);
54 ~ResourceMultiBufferDataProvider() override;
55
56 // MultiBufferDataProvider implementation
57 MultiBufferBlockId Tell() const override;
58 bool Available() const override;
59 scoped_refptr<DataBuffer> Read() override;
60 void SetAvailableCallback(const base::Closure& cb) override;
61 void SetDeferred(bool defer) override;
62
63 // blink::WebURLLoaderClient implementation.
64 void willFollowRedirect(
65 blink::WebURLLoader* loader,
66 blink::WebURLRequest& newRequest,
67 const blink::WebURLResponse& redirectResponse) override;
68 void didSendData(
69 blink::WebURLLoader* loader,
70 unsigned long long bytesSent,
71 unsigned long long totalBytesToBeSent) override;
72 void didReceiveResponse(
73 blink::WebURLLoader* loader,
74 const blink::WebURLResponse& response) override;
75 void didDownloadData(
76 blink::WebURLLoader* loader,
77 int data_length,
78 int encoded_data_length) override;
79 void didReceiveData(
80 blink::WebURLLoader* loader,
81 const char* data,
82 int data_length,
83 int encoded_data_length) override;
84 void didReceiveCachedMetadata(
85 blink::WebURLLoader* loader,
86 const char* data, int dataLength) override;
87 void didFinishLoading(
88 blink::WebURLLoader* loader,
89 double finishTime,
90 int64_t total_encoded_data_length) override;
91 void didFail(
92 blink::WebURLLoader* loader,
93 const blink::WebURLError&) override;
94
95 // Parse a Content-Range header into its component pieces and return true if
96 // each of the expected elements was found & parsed correctly.
97 // |*instance_size| may be set to kPositionNotSpecified if the range ends in
98 // "/*".
99 // NOTE: only public for testing! This is an implementation detail of
100 // VerifyPartialResponse (a private method).
101 static bool ParseContentRange(
102 const std::string& content_range_str, int64* first_byte_position,
103 int64* last_byte_position, int64* instance_size);
104
105 // Virtual for testing purposes.
106 virtual void Start();
107
108 protected:
109 friend class MultibufferDataSourceTest;
110 friend class MultibufferResourceLoaderTest;
111 friend class MockBufferedDataSource;
112
113 int64_t byte_pos() const;
114 int64_t block_size() const;
115 // If we have made a range request, verify the response from the server.
116 bool VerifyPartialResponse(const blink::WebURLResponse& response);
117
118 ResourceMultiBuffer* resource_multibuffer_;
119 std::list<scoped_refptr<DataBuffer> > fifo_;
120 int retries_;
121
122 // Keeps track of an active WebURLLoader and associated state.
123 scoped_ptr<ActiveLoader> active_loader_;
124 MultiBufferBlockId pos_;
125
126 // The url_data we got in the constructor.
127 scoped_refptr<UrlData> original_url_data_;
128
129 // When we encounter a redirect, this becomes the source of the redirect.
130 scoped_refptr<UrlData> redirected_url_data_;
131
132 // This is where we actually get read data from.
133 scoped_refptr<UrlData> url_data_;
134
135 // Callback from the multibuffer class.
136 base::Closure cb_;
137 base::WeakPtrFactory<ResourceMultiBufferDataProvider> weak_factory_;
138 };
139
140 } // namespace media
141
142 #endif // MEDIA_BLINK_MULTIBUFFER_RESOURCE_LOADER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698