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

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

Issue 184853003: Cast: Add GetStats() extensions API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add files 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 46d4f4bafbde9fc496c55ffd73149ab87e86b1d6..dd5a4bc53c4344acb47ef117c5c8d102fd8855ef 100644
--- a/chrome/renderer/extensions/cast_streaming_native_handler.cc
+++ b/chrome/renderer/extensions/cast_streaming_native_handler.cc
@@ -459,8 +459,20 @@ void CastStreamingNativeHandler::GetStats(
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;
- // TODO(imcheng): Implement this.
+ linked_ptr<extensions::ScopedPersistent<v8::Function> > callback(
+ new extensions::ScopedPersistent<v8::Function>);
+ callback->reset(args[1].As<v8::Function>());
+ get_stats_callbacks_.insert(std::make_pair(transport_id, callback));
+
+ transport->GetStats(
+ base::Bind(&CastStreamingNativeHandler::CallGetStatsCallback,
+ weak_factory_.GetWeakPtr(),
+ transport_id));
}
void CastStreamingNativeHandler::CallGetRawEventsCallback(
@@ -472,15 +484,33 @@ void CastStreamingNativeHandler::CallGetRawEventsCallback(
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);
- }
+ if (it == get_raw_events_callbacks_.end())
+ return;
+ 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);
+}
+
+void CastStreamingNativeHandler::CallGetStatsCallback(
+ int transport_id,
+ scoped_ptr<base::DictionaryValue> stats) {
+ v8::Isolate* isolate = context()->isolate();
+ v8::HandleScope handle_scope(isolate);
+ v8::Context::Scope context_scope(context()->v8_context());
+
+ RtpStreamCallbackMap::iterator it = get_stats_callbacks_.find(transport_id);
+ if (it == get_stats_callbacks_.end())
+ return;
+
+ scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
+ v8::Handle<v8::Value> callback_args[1];
+ callback_args[0] = converter->ToV8Value(stats.get(), context()->v8_context());
+ context()->CallFunction(it->second->NewHandle(isolate), 1, callback_args);
+ get_stats_callbacks_.erase(it);
}
CastRtpStream* CastStreamingNativeHandler::GetRtpStreamOrThrow(

Powered by Google App Engine
This is Rietveld 408576698