Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / renderer / extensions / cast_streaming_native_handler.h
blob92e76a107339e7c486d4aabda31d5fa94413af49
1 // Copyright 2013 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.
5 #ifndef CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_
6 #define CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_
8 #include <map>
10 #include "base/memory/linked_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "extensions/renderer/object_backed_native_handler.h"
13 #include "extensions/renderer/scoped_persistent.h"
14 #include "v8/include/v8.h"
16 class CastRtpStream;
17 class CastUdpTransport;
19 namespace base {
20 class BinaryValue;
21 class DictionaryValue;
24 namespace extensions {
26 // Native code that handle chrome.webrtc custom bindings.
27 class CastStreamingNativeHandler : public ObjectBackedNativeHandler {
28 public:
29 explicit CastStreamingNativeHandler(ScriptContext* context);
30 virtual ~CastStreamingNativeHandler();
32 private:
33 void CreateCastSession(
34 const v8::FunctionCallbackInfo<v8::Value>& args);
36 void DestroyCastRtpStream(
37 const v8::FunctionCallbackInfo<v8::Value>& args);
38 void CreateParamsCastRtpStream(
39 const v8::FunctionCallbackInfo<v8::Value>& args);
40 void GetSupportedParamsCastRtpStream(
41 const v8::FunctionCallbackInfo<v8::Value>& args);
42 void StartCastRtpStream(
43 const v8::FunctionCallbackInfo<v8::Value>& args);
44 void StopCastRtpStream(
45 const v8::FunctionCallbackInfo<v8::Value>& args);
47 void DestroyCastUdpTransport(
48 const v8::FunctionCallbackInfo<v8::Value>& args);
49 void SetDestinationCastUdpTransport(
50 const v8::FunctionCallbackInfo<v8::Value>& args);
51 void SetOptionsCastUdpTransport(
52 const v8::FunctionCallbackInfo<v8::Value>& args);
53 void StopCastUdpTransport(
54 const v8::FunctionCallbackInfo<v8::Value>& args);
56 void ToggleLogging(const v8::FunctionCallbackInfo<v8::Value>& args);
57 void GetRawEvents(const v8::FunctionCallbackInfo<v8::Value>& args);
58 void GetStats(const v8::FunctionCallbackInfo<v8::Value>& args);
60 // Helper method to call the v8 callback function after a session is
61 // created.
62 void CallCreateCallback(scoped_ptr<CastRtpStream> stream1,
63 scoped_ptr<CastRtpStream> stream2,
64 scoped_ptr<CastUdpTransport> udp_transport);
66 void CallStartCallback(int stream_id);
67 void CallStopCallback(int stream_id);
68 void CallErrorCallback(int stream_id, const std::string& message);
70 void CallGetRawEventsCallback(int transport_id,
71 scoped_ptr<base::BinaryValue> raw_events);
72 void CallGetStatsCallback(int transport_id,
73 scoped_ptr<base::DictionaryValue> stats);
75 // Gets the RTP stream or UDP transport indexed by an ID.
76 // If not found, returns NULL and throws a V8 exception.
77 CastRtpStream* GetRtpStreamOrThrow(int stream_id) const;
78 CastUdpTransport* GetUdpTransportOrThrow(int transport_id) const;
80 int last_transport_id_;
82 typedef std::map<int, linked_ptr<CastRtpStream> > RtpStreamMap;
83 RtpStreamMap rtp_stream_map_;
85 typedef std::map<int, linked_ptr<CastUdpTransport> > UdpTransportMap;
86 UdpTransportMap udp_transport_map_;
88 extensions::ScopedPersistent<v8::Function> create_callback_;
90 typedef std::map<int,
91 linked_ptr<extensions::ScopedPersistent<v8::Function> > >
92 RtpStreamCallbackMap;
93 RtpStreamCallbackMap get_raw_events_callbacks_;
94 RtpStreamCallbackMap get_stats_callbacks_;
96 base::WeakPtrFactory<CastStreamingNativeHandler> weak_factory_;
98 DISALLOW_COPY_AND_ASSIGN(CastStreamingNativeHandler);
101 } // namespace extensions
103 #endif // CHROME_RENDERER_EXTENSIONS_CAST_STREAMING_NATIVE_HANDLER_H_