summaryrefslogtreecommitdiffstats
path: root/extensions/renderer/resources
diff options
context:
space:
mode:
authormikhail.pozdnyakov <mikhail.pozdnyakov@intel.com>2016-02-11 11:42:24 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-11 19:43:47 +0000
commitef0d3aa8a2e82e6db356e112c236ef0f8a2a8918 (patch)
treec1d439680acee131a2290b1ca36b00dac9d3ebaa /extensions/renderer/resources
parent0f0f3981f6ca07546cd9208c202ee512d4c807ba (diff)
downloadchromium_src-ef0d3aa8a2e82e6db356e112c236ef0f8a2a8918.zip
chromium_src-ef0d3aa8a2e82e6db356e112c236ef0f8a2a8918.tar.gz
chromium_src-ef0d3aa8a2e82e6db356e112c236ef0f8a2a8918.tar.bz2
[chrome.displaySource] Session notification improvements
This patch provides several fixes and improvements (simplifications) to the session life cycle notification mechanism: 1) The 'startSession'/'terminateSession' call completion callbacks are invoked when the session is actually started/terminated and in accordance with 'onSessionStarted'/'onSessionTerminated' events propagating (and as per documentation). 2) The notification from the required sink is filtered out in browser process avoiding unneeded IPC calls 3) Methods in mojo interface are renamed in order to improve readability BUG=242107 Review URL: https://codereview.chromium.org/1674583002 Cr-Commit-Position: refs/heads/master@{#374929}
Diffstat (limited to 'extensions/renderer/resources')
-rw-r--r--extensions/renderer/resources/display_source_custom_bindings.js66
1 files changed, 47 insertions, 19 deletions
diff --git a/extensions/renderer/resources/display_source_custom_bindings.js b/extensions/renderer/resources/display_source_custom_bindings.js
index 13e8167..a1345ff 100644
--- a/extensions/renderer/resources/display_source_custom_bindings.js
+++ b/extensions/renderer/resources/display_source_custom_bindings.js
@@ -8,34 +8,62 @@ var binding = require('binding').Binding.create('displaySource');
var chrome = requireNative('chrome').GetChrome();
var lastError = require('lastError');
var natives = requireNative('display_source');
+var logging = requireNative('logging');
+
+var callbacksInfo = {};
+
+function callbackWrapper(callback, method, message) {
+ if (callback == undefined)
+ return;
+
+ try {
+ if (message !== null)
+ lastError.set('displaySource.startSession', message, null, chrome);
+ callback();
+ } finally {
+ lastError.clear(chrome);
+ }
+}
+
+function callCompletionCallback(callbackId, error_message) {
+ try {
+ var callbackInfo = callbacksInfo[callbackId];
+ logging.DCHECK(callbackInfo != null);
+ callbackWrapper(callbackInfo.callback, callbackInfo.method, error_message);
+ } finally {
+ delete callbacksInfo[callbackId];
+ }
+}
binding.registerCustomHook(function(bindingsAPI, extensionId) {
var apiFunctions = bindingsAPI.apiFunctions;
- apiFunctions.setHandleRequest('startSession',
- function(sessionInfo, callback) {
+ apiFunctions.setHandleRequest(
+ 'startSession', function(sessionInfo, callback) {
try {
- natives.StartSession(sessionInfo);
+ var callId = natives.StartSession(sessionInfo, callbackWrapper);
+ callbacksInfo[callId] = {
+ callback: callback,
+ method: 'displaySource.startSession'
+ };
} catch (e) {
- lastError.set('displaySource.startSession', e.message, null, chrome);
- } finally {
- if (callback !== undefined)
- callback();
- lastError.clear(chrome);
+ callbackWrapper(callback, 'displaySource.startSession', e.message);
}
- });
- apiFunctions.setHandleRequest('terminateSession',
- function(sink_id, callback) {
+ });
+ apiFunctions.setHandleRequest(
+ 'terminateSession', function(sink_id, callback) {
try {
- natives.TerminateSession(sink_id);
+ var callId = natives.TerminateSession(sink_id, callbackWrapper);
+ callbacksInfo[callId] = {
+ callback: callback,
+ method: 'displaySource.terminateSession'
+ };
} catch (e) {
- lastError.set(
- 'displaySource.terminateSession', e.message, null, chrome);
- } finally {
- if (callback !== undefined)
- callback();
- lastError.clear(chrome);
+ callbackWrapper(
+ callback, 'displaySource.terminateSession', e.message);
}
- });
+ });
});
exports.$set('binding', binding.generate());
+// Called by C++.
+exports.$set('callCompletionCallback', callCompletionCallback);