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

Unified Diff: mojo/services/public/js/service_provider.js

Issue 799113004: Update mojo sdk to rev 59145288bae55b0fce4276b017df6a1117bcf00f (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add mojo's ply to checklicenses whitelist Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/services/public/js/application.js ('k') | mojo/services/public/js/shell.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/services/public/js/service_provider.js
diff --git a/mojo/services/public/js/service_provider.js b/mojo/services/public/js/service_provider.js
index 7c82775049b8a67169b81079a31ea84be31b2aeb..88fef4ef265c944a3239bcef5b8d7a3b51accaf8 100644
--- a/mojo/services/public/js/service_provider.js
+++ b/mojo/services/public/js/service_provider.js
@@ -8,6 +8,7 @@ define("mojo/services/public/js/service_provider", [
"mojo/public/js/core",
], function(spInterfaceModule, connectionModule, coreModule) {
+ // Implementation of the Mojo ServiceProvider interface.
function connectToServiceImpl(serviceName, serviceHandle) {
var provider = this.providers_.get(serviceName);
if (!provider) {
@@ -20,41 +21,41 @@ define("mojo/services/public/js/service_provider", [
provider.service.stubClass,
provider.service.client && provider.service.client.proxyClass);
- serviceConnection.local.connection$ = serviceConnection;
serviceConnection.local.delegate$ =
new provider.factory(serviceConnection.remote);
provider.connections.push(serviceConnection);
}
+ function checkServiceProvider(sp) {
+ if (!sp.connections_)
+ throw new Error("Service was closed");
+ }
+
class ServiceProvider {
constructor(service) {
+ if (!(service instanceof spInterfaceModule.ServiceProvider.proxyClass))
+ throw new Error("service must be a ServiceProvider proxy");
+
+ service.client$ = {
+ connectToService: connectToServiceImpl.bind(this)
+ };
+
this.connections_ = new Map();
this.providers_ = new Map();
this.pendingRequests_ = new Map();
this.connection_ = null;
-
- if (service instanceof spInterfaceModule.ServiceProvider.proxyClass) {
- this.connection_ = service.getConnection$();
- } else {
- this.handle_ = service; // service is-a MessagePipe handle
- this.connection_ = new connectionModule.Connection(
- this.handle_,
- spInterfaceModule.ServiceProvider.client.stubClass,
- spInterfaceModule.ServiceProvider.proxyClass);
- };
- this.connection_.local.delegate$ = {
- connectToService: connectToServiceImpl.bind(this)
- }
+ this.connection_ = service.getConnection$();
}
provideService(service, factory) {
// TODO(hansmuller): if !factory, remove provider and close its
// connections.
- // TODO(hansmuller): if this.connection_ is null, throw an error.
+ checkServiceProvider(this);
+
var provider = {
- service: service,
- factory: factory,
+ service: service, // A JS bindings interface object.
+ factory: factory, // factory(clientProxy) => interface implemntation.
connections: [],
};
this.providers_.set(service.name, provider);
@@ -68,8 +69,10 @@ define("mojo/services/public/js/service_provider", [
}
connectToService(service, client) {
- // TODO(hansmuler): if service.name isn't defined, throw an error.
- // TODO(hansmuller): if this.connection_ is null, throw an error.
+ checkServiceProvider(this);
+ if (!service.name)
+ throw new Error("Invalid service parameter");
+
var serviceConnection = this.connections_.get(service.name);
if (serviceConnection)
return serviceConnection.remote;
« no previous file with comments | « mojo/services/public/js/application.js ('k') | mojo/services/public/js/shell.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698