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

Side by Side Diff: webkit/glue/media/simple_data_source.h

Issue 3863002: Refactoring BufferedDataSource to work with WebURLLoader instead of a MediaResourceLoaderBridge. (Closed) Base URL: http://git.chromium.org/git/chromium.git
Patch Set: little indent Created 10 years 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 | Annotate | Revision Log
OLDNEW
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"
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
22 namespace webkit_glue { 29 namespace webkit_glue {
23 30
24 class SimpleDataSource : public WebDataSource, 31 class SimpleDataSource : public WebDataSource,
25 public webkit_glue::ResourceLoaderBridge::Peer { 32 public WebKit::WebURLLoaderClient {
26 public: 33 public:
27 SimpleDataSource( 34 SimpleDataSource(MessageLoop* render_loop, WebKit::WebFrame* frame);
28 MessageLoop* render_loop,
29 webkit_glue::MediaResourceLoaderBridgeFactory* bridge_factory);
30 virtual ~SimpleDataSource(); 35 virtual ~SimpleDataSource();
31 36
32 // MediaFilter implementation. 37 // MediaFilter implementation.
33 virtual void Stop(media::FilterCallback* callback); 38 virtual void Stop(media::FilterCallback* callback);
34 39
35 // DataSource implementation. 40 // DataSource implementation.
36 virtual void Initialize(const std::string& url, 41 virtual void Initialize(const std::string& url,
37 media::FilterCallback* callback); 42 media::FilterCallback* callback);
38 virtual const media::MediaFormat& media_format(); 43 virtual const media::MediaFormat& media_format();
39 virtual void Read(int64 position, size_t size, 44 virtual void Read(int64 position, size_t size,
40 uint8* data, ReadCallback* read_callback); 45 uint8* data, ReadCallback* read_callback);
41 virtual bool GetSize(int64* size_out); 46 virtual bool GetSize(int64* size_out);
42 virtual bool IsStreaming(); 47 virtual bool IsStreaming();
43 48
44 // webkit_glue::ResourceLoaderBridge::Peer implementation. 49 // Used to inject a mock used for unittests.
45 virtual void OnUploadProgress(uint64 position, uint64 size) {} 50 virtual void SetURLLoaderForTest(WebKit::WebURLLoader* mock_loader);
46 virtual bool OnReceivedRedirect( 51
47 const GURL& new_url, 52 // WebKit::WebURLLoaderClient implementations.
48 const webkit_glue::ResourceResponseInfo& info, 53 virtual void willSendRequest(
49 bool* has_new_first_party_for_cookies, 54 WebKit::WebURLLoader* loader,
50 GURL* new_first_party_for_cookies); 55 WebKit::WebURLRequest& newRequest,
51 virtual void OnReceivedResponse( 56 const WebKit::WebURLResponse& redirectResponse);
52 const webkit_glue::ResourceResponseInfo& info, 57 virtual void didSendData(
53 bool content_filtered); 58 WebKit::WebURLLoader* loader,
54 virtual void OnDownloadedData(int len) {} 59 unsigned long long bytesSent,
55 virtual void OnReceivedData(const char* data, int len); 60 unsigned long long totalBytesToBeSent);
56 virtual void OnCompletedRequest(const URLRequestStatus& status, 61 virtual void didReceiveResponse(
57 const std::string& security_info, 62 WebKit::WebURLLoader* loader,
58 const base::Time& completion_time); 63 const WebKit::WebURLResponse& response);
64 virtual void didDownloadData(
65 WebKit::WebURLLoader* loader,
66 int dataLength);
67 virtual void didReceiveData(
68 WebKit::WebURLLoader* loader,
69 const char* data,
70 int dataLength);
71 virtual void didReceiveCachedMetadata(
72 WebKit::WebURLLoader* loader,
73 const char* data, int dataLength);
74 virtual void didFinishLoading(
75 WebKit::WebURLLoader* loader,
76 double finishTime);
77 virtual void didFail(
78 WebKit::WebURLLoader* loader,
79 const WebKit::WebURLError&);
59 80
60 // webkit_glue::WebDataSource implementation. 81 // webkit_glue::WebDataSource implementation.
61 virtual bool HasSingleOrigin(); 82 virtual bool HasSingleOrigin();
62 virtual void Abort(); 83 virtual void Abort();
63 84
64 private: 85 private:
65 // Updates |url_| and |media_format_| with the given URL. 86 // Updates |url_| and |media_format_| with the given URL.
66 void SetURL(const GURL& url); 87 void SetURL(const GURL& url);
67 88
68 // Creates and starts the resource loading on the render thread. 89 // Creates and starts the resource loading on the render thread.
69 void StartTask(); 90 void StartTask();
70 91
71 // Cancels and deletes the resource loading on the render thread. 92 // Cancels and deletes the resource loading on the render thread.
72 void CancelTask(); 93 void CancelTask();
73 94
74 // Perform initialization completion tasks under a lock. 95 // Perform initialization completion tasks under a lock.
75 void DoneInitialization_Locked(bool success); 96 void DoneInitialization_Locked(bool success);
76 97
77 // Primarily used for asserting the bridge is loading on the render thread. 98 // Primarily used for asserting the bridge is loading on the render thread.
78 MessageLoop* render_loop_; 99 MessageLoop* render_loop_;
79 100
80 // Factory to create a bridge. 101 // A webframe for loading.
81 scoped_ptr<webkit_glue::MediaResourceLoaderBridgeFactory> bridge_factory_; 102 WebKit::WebFrame* frame_;
82 103
83 // Bridge used to load the media resource. 104 // Does the work of loading and sends data back to this client.
84 scoped_ptr<webkit_glue::ResourceLoaderBridge> bridge_; 105 scoped_ptr<WebKit::WebURLLoader> url_loader_;
85 106
86 media::MediaFormat media_format_; 107 media::MediaFormat media_format_;
87 GURL url_; 108 GURL url_;
88 std::string data_; 109 std::string data_;
89 int64 size_; 110 int64 size_;
90 bool single_origin_; 111 bool single_origin_;
91 112
92 // Simple state tracking variable. 113 // Simple state tracking variable.
93 enum State { 114 enum State {
94 UNINITIALIZED, 115 UNINITIALIZED,
95 INITIALIZING, 116 INITIALIZING,
96 INITIALIZED, 117 INITIALIZED,
97 STOPPED, 118 STOPPED,
98 }; 119 };
99 State state_; 120 State state_;
100 121
101 // Used for accessing |state_|. 122 // Used for accessing |state_|.
102 Lock lock_; 123 Lock lock_;
103 124
104 // Filter callbacks. 125 // Filter callbacks.
105 scoped_ptr<media::FilterCallback> initialize_callback_; 126 scoped_ptr<media::FilterCallback> initialize_callback_;
106 127
128 // Used to ensure mocks for unittests are used instead of reset in Start().
129 bool keep_test_loader_;
130
107 DISALLOW_COPY_AND_ASSIGN(SimpleDataSource); 131 DISALLOW_COPY_AND_ASSIGN(SimpleDataSource);
108 }; 132 };
109 133
110 } // namespace webkit_glue 134 } // namespace webkit_glue
111 135
112 #endif // WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_ 136 #endif // WEBKIT_GLUE_MEDIA_SIMPLE_DATA_SOURCE_H_
OLDNEW
« no previous file with comments | « webkit/glue/media/buffered_data_source_unittest.cc ('k') | webkit/glue/media/simple_data_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698