OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // An extremely simple implementation of DataSource that downloads the entire | 5 // An extremely simple implementation of DataSource that downloads the entire |
6 // media resource into memory before signaling that initialization has finished. | 6 // media resource into memory before signaling that initialization has finished. |
7 // Primarily used to test <audio> and <video> with buffering/caching removed | 7 // Primarily used to test <audio> and <video> with buffering/caching removed |
8 // from the equation. | 8 // from the equation. |
9 | 9 |
10 #ifndef WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_ | 10 #ifndef WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_ |
11 #define WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_ | 11 #define WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_ |
12 | 12 |
13 #include <algorithm> | |
14 #include <string> | |
15 | |
13 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
14 #include "base/scoped_ptr.h" | 17 #include "base/scoped_ptr.h" |
15 #include "media/base/filters.h" | 18 #include "media/base/filters.h" |
16 #include "webkit/glue/media/media_resource_loader_bridge_factory.h" | 19 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
scherkus (not reviewing)
2010/11/22 21:27:29
ditto here as in buffered_data_source.cc (removing
annacc
2010/11/24 21:34:44
Nope, I really do need them explicitly.
| |
20 #include "third_party/WebKit/WebKit/chromium/public/WebURLLoader.h" | |
21 #include "third_party/WebKit/WebKit/chromium/public/WebURLLoaderClient.h" | |
22 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" | |
23 #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" | |
17 #include "webkit/glue/media/web_data_source.h" | 24 #include "webkit/glue/media/web_data_source.h" |
18 | 25 |
19 class MessageLoop; | 26 class MessageLoop; |
20 class WebMediaPlayerDelegateImpl; | 27 class WebMediaPlayerDelegateImpl; |
21 | 28 |
29 using WebKit::WebFrame; | |
scherkus (not reviewing)
2010/11/22 21:27:29
ditto -- don't think you need this since you're al
annacc
2010/11/24 21:34:44
Done.
| |
30 | |
22 namespace webkit_glue { | 31 namespace webkit_glue { |
23 | 32 |
24 class SimpleDataSource : public WebDataSource, | 33 class SimpleDataSource : public WebDataSource, |
25 public webkit_glue::ResourceLoaderBridge::Peer { | 34 public WebKit::WebURLLoaderClient { |
26 public: | 35 public: |
27 SimpleDataSource( | 36 SimpleDataSource( |
28 MessageLoop* render_loop, | 37 MessageLoop* render_loop, |
scherkus (not reviewing)
2010/11/22 21:27:29
argument wrapping style.. in fact I think this who
annacc
2010/11/24 21:34:44
Done.
| |
29 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory); | 38 WebKit::WebFrame* frame); |
30 virtual ~SimpleDataSource(); | 39 virtual ~SimpleDataSource(); |
31 | 40 |
32 // MediaFilter implementation. | 41 // MediaFilter implementation. |
33 virtual void Stop(media::FilterCallback* callback); | 42 virtual void Stop(media::FilterCallback* callback); |
34 | 43 |
35 // DataSource implementation. | 44 // DataSource implementation. |
36 virtual void Initialize(const std::string& url, | 45 virtual void Initialize(const std::string& url, |
37 media::FilterCallback* callback); | 46 media::FilterCallback* callback); |
38 virtual const media::MediaFormat& media_format(); | 47 virtual const media::MediaFormat& media_format(); |
39 virtual void Read(int64 position, size_t size, | 48 virtual void Read(int64 position, size_t size, |
40 uint8* data, ReadCallback* read_callback); | 49 uint8* data, ReadCallback* read_callback); |
41 virtual bool GetSize(int64* size_out); | 50 virtual bool GetSize(int64* size_out); |
42 virtual bool IsStreaming(); | 51 virtual bool IsStreaming(); |
43 | 52 |
44 // webkit_glue::ResourceLoaderBridge::Peer implementation. | 53 // Used to inject a mock used for unittests. |
45 virtual void OnUploadProgress(uint64 position, uint64 size) {} | 54 virtual void SetURLLoaderForTest(WebKit::WebURLLoader* mock_loader); |
46 virtual bool OnReceivedRedirect( | 55 |
47 const GURL& new_url, | 56 // WebKit::WebURLLoaderClient implementations. |
48 const webkit_glue::ResourceResponseInfo& info, | 57 virtual void willSendRequest( |
49 bool* has_new_first_party_for_cookies, | 58 WebKit::WebURLLoader* loader, |
50 GURL* new_first_party_for_cookies); | 59 WebKit::WebURLRequest& newRequest, |
51 virtual void OnReceivedResponse( | 60 const WebKit::WebURLResponse& redirectResponse); |
52 const webkit_glue::ResourceResponseInfo& info, | 61 virtual void didSendData( |
53 bool content_filtered); | 62 WebKit::WebURLLoader* loader, |
54 virtual void OnDownloadedData(int len) {} | 63 unsigned long long bytesSent, |
55 virtual void OnReceivedData(const char* data, int len); | 64 unsigned long long totalBytesToBeSent); |
56 virtual void OnCompletedRequest(const URLRequestStatus& status, | 65 virtual void didReceiveResponse( |
57 const std::string& security_info, | 66 WebKit::WebURLLoader* loader, |
58 const base::Time& completion_time); | 67 const WebKit::WebURLResponse& response); |
68 virtual void didDownloadData( | |
69 WebKit::WebURLLoader* loader, | |
70 int dataLength); | |
71 virtual void didReceiveData( | |
72 WebKit::WebURLLoader* loader, | |
73 const char* data, | |
74 int dataLength); | |
75 virtual void didReceiveCachedMetadata( | |
76 WebKit::WebURLLoader* loader, | |
77 const char* data, int dataLength); | |
78 virtual void didFinishLoading( | |
79 WebKit::WebURLLoader* loader, | |
80 double finishTime); | |
81 virtual void didFail( | |
82 WebKit::WebURLLoader* loader, | |
83 const WebKit::WebURLError&); | |
59 | 84 |
60 // webkit_glue::WebDataSource implementation. | 85 // webkit_glue::WebDataSource implementation. |
61 virtual bool HasSingleOrigin(); | 86 virtual bool HasSingleOrigin(); |
62 virtual void Abort(); | 87 virtual void Abort(); |
63 | 88 |
64 private: | 89 private: |
65 // Updates |url_| and |media_format_| with the given URL. | 90 // Updates |url_| and |media_format_| with the given URL. |
66 void SetURL(const GURL& url); | 91 void SetURL(const GURL& url); |
67 | 92 |
68 // Creates and starts the resource loading on the render thread. | 93 // Creates and starts the resource loading on the render thread. |
69 void StartTask(); | 94 void StartTask(); |
70 | 95 |
71 // Cancels and deletes the resource loading on the render thread. | 96 // Cancels and deletes the resource loading on the render thread. |
72 void CancelTask(); | 97 void CancelTask(); |
73 | 98 |
74 // Perform initialization completion tasks under a lock. | 99 // Perform initialization completion tasks under a lock. |
75 void DoneInitialization_Locked(bool success); | 100 void DoneInitialization_Locked(bool success); |
76 | 101 |
77 // Primarily used for asserting the bridge is loading on the render thread. | 102 // Primarily used for asserting the bridge is loading on the render thread. |
78 MessageLoop* render_loop_; | 103 MessageLoop* render_loop_; |
79 | 104 |
80 // Factory to create a bridge. | 105 // A webframe for loading. |
81 scoped_ptr<webkit_glue::MediaResourceLoaderBridgeFactory> bridge_factory_; | 106 WebKit::WebFrame* frame_; |
82 | 107 |
83 // Bridge used to load the media resource. | 108 // Does the work of loading and sends data back to this client. |
84 scoped_ptr<webkit_glue::ResourceLoaderBridge> bridge_; | 109 scoped_ptr<WebKit::WebURLLoader> url_loader_; |
85 | 110 |
86 media::MediaFormat media_format_; | 111 media::MediaFormat media_format_; |
87 GURL url_; | 112 GURL url_; |
88 std::string data_; | 113 std::string data_; |
89 int64 size_; | 114 int64 size_; |
90 bool single_origin_; | 115 bool single_origin_; |
91 | 116 |
92 // Simple state tracking variable. | 117 // Simple state tracking variable. |
93 enum State { | 118 enum State { |
94 UNINITIALIZED, | 119 UNINITIALIZED, |
95 INITIALIZING, | 120 INITIALIZING, |
96 INITIALIZED, | 121 INITIALIZED, |
97 STOPPED, | 122 STOPPED, |
98 }; | 123 }; |
99 State state_; | 124 State state_; |
100 | 125 |
101 // Used for accessing |state_|. | 126 // Used for accessing |state_|. |
102 Lock lock_; | 127 Lock lock_; |
103 | 128 |
104 // Filter callbacks. | 129 // Filter callbacks. |
105 scoped_ptr<media::FilterCallback> initialize_callback_; | 130 scoped_ptr<media::FilterCallback> initialize_callback_; |
106 | 131 |
132 // Used to ensure mocks for unittests are used instead of reset in Start(). | |
133 bool keep_test_loader; | |
scherkus (not reviewing)
2010/11/22 21:27:29
member variables end with _
annacc
2010/11/24 21:34:44
Done.
| |
134 | |
107 DISALLOW_COPY_AND_ASSIGN(SimpleDataSource); | 135 DISALLOW_COPY_AND_ASSIGN(SimpleDataSource); |
108 }; | 136 }; |
109 | 137 |
110 } // namespace webkit_glue | 138 } // namespace webkit_glue |
111 | 139 |
112 #endif // WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_ | 140 #endif // WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_ |
OLD | NEW |