Chromium Code Reviews| Index: mojo/public/go/application/connection.go |
| diff --git a/mojo/public/go/application/connection.go b/mojo/public/go/application/connection.go |
| index f3be55c9a691443630e02d33e3d7bbfe3ffe38db..025bc8a5abd5d5c26e6c07fc97e8089e61c30ed8 100644 |
| --- a/mojo/public/go/application/connection.go |
| +++ b/mojo/public/go/application/connection.go |
| @@ -11,6 +11,7 @@ import ( |
| "mojo/public/go/system" |
| sp "mojo/public/interfaces/application/service_provider" |
| + "mojo/public/interfaces/bindings/service_describer" |
| ) |
| type connectionInfo struct { |
| @@ -34,6 +35,10 @@ type ServiceRequest interface { |
| // Name returns the name of requested mojo service. |
| Name() string |
| + // ServiceDescription returns a service description, which can be queried to |
| + // examine the type information of the requested mojo service. |
|
rudominer
2015/10/22 21:28:47
s/of the requested mojo service/of the service ass
alexfandrianto
2015/10/22 22:58:11
Done.
|
| + ServiceDescription() service_describer.ServiceDescription |
| + |
| // PassMessagePipe passes ownership of the underlying message pipe |
| // handle to the newly created handle object, invalidating the |
| // underlying handle object in the process. |
| @@ -45,6 +50,10 @@ type ServiceFactory interface { |
| // Name returns the name of provided mojo service. |
| Name() string |
| + // ServiceDescription returns a service description, which can be queried to |
| + // examine the type information of the mojo service. |
|
rudominer
2015/10/22 21:28:47
"of the mojo service associated with this ServiceF
alexfandrianto
2015/10/22 22:58:11
Done.
|
| + ServiceDescription() service_describer.ServiceDescription |
| + |
| // Create binds an implementation of mojo service to the provided |
| // message pipe and runs it. |
| Create(pipe system.MessagePipeHandle) |
| @@ -62,6 +71,7 @@ type Connection struct { |
| localServices *bindings.Stub |
| outgoingConnection *OutgoingConnection |
| isClosed bool |
| + describer *ServiceDescriberFactory |
|
rudominer
2015/10/22 21:28:47
Please add a comment about what happens when the g
alexfandrianto
2015/10/22 22:58:11
The ServiceDescriber is functional, but the Servic
|
| } |
| func newConnection(requestorURL string, services *sp.ServiceProvider_Request, exposedServices *sp.ServiceProvider_Pointer, resolvedURL string) *Connection { |
| @@ -90,7 +100,7 @@ func newConnection(requestorURL string, services *sp.ServiceProvider_Request, ex |
| // Panics if called more than once. |
| func (c *Connection) ProvideServices(services ...ServiceFactory) *OutgoingConnection { |
| if c.servicesProvided { |
| - panic("ProvideServices can be called only once") |
| + panic("ProvideServices or ProvideServicesWithDescriber can be called only once") |
| } |
| c.servicesProvided = true |
| if c.servicesRequest == nil { |
| @@ -122,6 +132,31 @@ func (c *Connection) ProvideServices(services ...ServiceFactory) *OutgoingConnec |
| return c.outgoingConnection |
| } |
| +// ProvideServicesWithDescriber is an alternative to ProvideServices that, in |
| +// addition to providing the given services, also provides type descriptions of |
| +// the given services. See ProvideServices for a description of what it does. |
| +// This method will invoke ProvideServices after appending the ServiceDescriber |
| +// service to |services|. See service_describer.mojom for a description of the |
| +// ServiceDescriber interface. Client Mojo applications can choose to connect |
| +// to this ServiceDescriber interface, which describes the other services listed |
| +// in |services|. |
| +// Note that the implementation of ServiceDescriber will make the optional |
| +// DeclarationData available on all types, and in particular, the names used in |
| +// .mojom files will be exposed to client applications. |
| +func (c *Connection) ProvideServicesWithDescriber(services ...ServiceFactory) *OutgoingConnection { |
| + if c.servicesProvided { |
| + panic("ProvideServices or ProvideServicesWithDescriber can be called only once") |
| + } |
| + mapping := make(map[string]service_describer.ServiceDescription) |
| + for _, service := range services { |
| + mapping[service.Name()] = service.ServiceDescription() |
| + } |
| + c.describer = newServiceDescriberFactory(mapping) |
| + servicesWithDescriber := append(services, &service_describer.ServiceDescriber_ServiceFactory{c.describer}) |
| + |
| + return c.ProvideServices(servicesWithDescriber...) |
| +} |
| + |
| // Close closes both incoming and outgoing parts of the connection. |
| func (c *Connection) Close() { |
| if c.servicesRequest != nil { |
| @@ -130,6 +165,9 @@ func (c *Connection) Close() { |
| if c.localServices != nil { |
| c.localServices.Close() |
| } |
| + if c.describer != nil { |
| + c.describer.Close() |
| + } |
| if c.outgoingConnection.remoteServices != nil { |
| c.outgoingConnection.remoteServices.Close_Proxy() |
| } |