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

Unified Diff: chrome/renderer/extensions/cast_streaming_native_handler.cc

Issue 170063006: Cast: Add JS API to get raw events logs from cast extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/extensions/cast_streaming_native_handler.cc
diff --git a/chrome/renderer/extensions/cast_streaming_native_handler.cc b/chrome/renderer/extensions/cast_streaming_native_handler.cc
index 71fd3e9a07d3f60900b534ad8bbb2560fec97eff..d14f9a94714c1b70908226248f4c408a16c81d4d 100644
--- a/chrome/renderer/extensions/cast_streaming_native_handler.cc
+++ b/chrome/renderer/extensions/cast_streaming_native_handler.cc
@@ -168,6 +168,15 @@ CastStreamingNativeHandler::CastStreamingNativeHandler(ChromeV8Context* context)
RouteFunction("SetDestinationCastUdpTransport",
base::Bind(&CastStreamingNativeHandler::SetDestinationCastUdpTransport,
base::Unretained(this)));
+ RouteFunction("StartLogging",
+ base::Bind(&CastStreamingNativeHandler::StartLogging,
+ base::Unretained(this)));
+ RouteFunction("GetRawEvents",
+ base::Bind(&CastStreamingNativeHandler::GetRawEvents,
+ base::Unretained(this)));
+ RouteFunction("GetStats",
+ base::Bind(&CastStreamingNativeHandler::GetStats,
+ base::Unretained(this)));
}
CastStreamingNativeHandler::~CastStreamingNativeHandler() {
@@ -218,9 +227,11 @@ void CastStreamingNativeHandler::CallCreateCallback(
v8::Context::Scope context_scope(context()->v8_context());
const int stream1_id = last_transport_id_++;
+ stream1->SetStreamId(stream1_id);
rtp_stream_map_[stream1_id] =
linked_ptr<CastRtpStream>(stream1.release());
const int stream2_id = last_transport_id_++;
+ stream2->SetStreamId(stream2_id);
rtp_stream_map_[stream2_id] =
linked_ptr<CastRtpStream>(stream2.release());
const int udp_id = last_transport_id_++;
@@ -409,6 +420,68 @@ void CastStreamingNativeHandler::SetDestinationCastUdpTransport(
transport->SetDestination(net::IPEndPoint(ip, destination->port));
}
+void CastStreamingNativeHandler::StartLogging(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ CHECK_EQ(1, args.Length());
+ CHECK(args[0]->IsInt32());
+ const int stream_id = args[0]->ToInt32()->Value();
+ CastRtpStream* stream = GetRtpStreamOrThrow(stream_id);
+ if (!stream)
+ return;
+
+ stream->StartLogging();
+}
+
+void CastStreamingNativeHandler::GetRawEvents(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ CHECK_EQ(2, args.Length());
+ CHECK(args[0]->IsInt32());
+ CHECK(args[1]->IsFunction());
+ const int transport_id = args[0]->ToInt32()->Value();
+ CastRtpStream* transport = GetRtpStreamOrThrow(transport_id);
+ if (!transport)
+ return;
+
+ linked_ptr<extensions::ScopedPersistent<v8::Function> > callback(
+ new extensions::ScopedPersistent<v8::Function>);
+ callback->reset(args[1].As<v8::Function>());
+ get_raw_events_callbacks_.insert(std::make_pair(transport_id, callback));
Alpha Left Google 2014/02/24 20:18:56 This is odd. Why not just pass the callback and v8
imcheng 2014/02/24 21:28:26 This is similar to CreateCastSession / CallCreateC
+
+ transport->GetRawEvents(
+ base::Bind(&CastStreamingNativeHandler::CallGetRawEventsCallback,
+ weak_factory_.GetWeakPtr(),
+ transport_id));
+}
+
+void CastStreamingNativeHandler::GetStats(
+ const v8::FunctionCallbackInfo<v8::Value>& args) {
+ CHECK_EQ(2, args.Length());
+ CHECK(args[0]->IsInt32());
+ CHECK(args[1]->IsFunction());
+
+ // TODO(imcheng): Implement this.
+}
+
+void CastStreamingNativeHandler::CallGetRawEventsCallback(
+ int transport_id,
+ scoped_ptr<std::string> raw_events) {
+ v8::Isolate* isolate = context()->isolate();
+ v8::HandleScope handle_scope(isolate);
+ v8::Context::Scope context_scope(context()->v8_context());
+
+ RtpStreamCallbackMap::iterator it =
+ get_raw_events_callbacks_.find(transport_id);
+ if (it != get_raw_events_callbacks_.end()) {
+ v8::Handle<v8::Value> callback_args[1];
+ callback_args[0] = v8::String::NewFromUtf8(isolate,
+ raw_events->data(),
+ v8::String::kNormalString,
+ raw_events->size());
+ context()->CallFunction(it->second->NewHandle(isolate), 1, callback_args);
+ get_raw_events_callbacks_.erase(it);
+ }
+}
+
CastRtpStream* CastStreamingNativeHandler::GetRtpStreamOrThrow(
int transport_id) const {
RtpStreamMap::const_iterator iter = rtp_stream_map_.find(

Powered by Google App Engine
This is Rietveld 408576698