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

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

Issue 861683003: Move services code brought in from Mojo to live under //third_party. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 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
« 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
deleted file mode 100644
index a6a81ca3b9b75f5a900ac5b32fa3bb8341cb69b6..0000000000000000000000000000000000000000
--- a/mojo/services/public/js/service_provider.js
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-define("mojo/services/public/js/service_provider", [
- "mojo/public/js/bindings",
- "mojo/public/interfaces/application/service_provider.mojom",
- "mojo/public/js/connection",
-], function(bindings, spMojom, connection) {
-
- const ProxyBindings = bindings.ProxyBindings;
- const StubBindings = bindings.StubBindings;
- const ServiceProviderInterface = spMojom.ServiceProvider;
-
- function checkServiceProvider(sp) {
- if (!sp.providers_)
- throw new Error("Service was closed");
- }
-
- class ServiceProvider {
- constructor(servicesRequest, exposedServicesProxy) {
- this.proxy = exposedServicesProxy;
- this.providers_ = new Map(); // serviceName => see provideService() below
- this.pendingRequests_ = new Map(); // serviceName => serviceHandle
- if (servicesRequest)
- StubBindings(servicesRequest).delegate = this;
- }
-
- // Incoming requests
- connectToService(serviceName, serviceHandle) {
- if (!this.providers_) // We're closed.
- return;
-
- var provider = this.providers_.get(serviceName);
- if (!provider) {
- this.pendingRequests_.set(serviceName, serviceHandle);
- return;
- }
-
- var stub = connection.bindHandleToStub(serviceHandle, provider.service);
- StubBindings(stub).delegate = new provider.factory();
- provider.connections.push(StubBindings(stub).connection);
- }
-
- provideService(service, factory) {
- checkServiceProvider(this);
-
- var provider = {
- service: service, // A JS bindings interface object.
- factory: factory, // factory(clientProxy) => interface implemntation
- connections: [],
- };
- this.providers_.set(service.name, provider);
-
- if (this.pendingRequests_.has(service.name)) {
- this.connectToService(service.name, pendingRequests_.get(service.name));
- pendingRequests_.delete(service.name);
- }
- return this;
- }
-
- // Outgoing requests
- requestService(interfaceObject, clientImpl) {
- checkServiceProvider(this);
- if (!interfaceObject.name)
- throw new Error("Invalid service parameter");
- if (!clientImpl && interfaceObject.client)
- throw new Error("Client implementation must be provided");
-
- var serviceProxy;
- var serviceHandle = connection.bindProxy(
- function(sp) {serviceProxy = sp;}, interfaceObject);
- this.proxy.connectToService(interfaceObject.name, serviceHandle);
- return serviceProxy;
- };
-
- close() {
- this.providers_ = null;
- this.pendingRequests_ = null;
- }
- }
-
- var exports = {};
- exports.ServiceProvider = ServiceProvider;
- return exports;
-});
« 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