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

Side by Side Diff: mojo/public/cpp/application/application_connection.h

Issue 1973653002: Add a new way of using ServiceProviderImpl without InterfaceFactory. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: RequestHandler -> InterfaceRequestHandler Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | mojo/public/cpp/application/lib/service_provider_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_ 5 #ifndef MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_
6 #define MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_ 6 #define MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "mojo/public/cpp/application/lib/interface_factory_connector.h" 10 #include "mojo/public/cpp/application/lib/interface_factory_connector.h"
11 #include "mojo/public/interfaces/application/service_provider.mojom.h" 11 #include "mojo/public/interfaces/application/service_provider.mojom.h"
12 12
13 namespace mojo { 13 namespace mojo {
14 14
15 struct ConnectionContext;
15 class ServiceConnector; 16 class ServiceConnector;
16 17
17 // Represents a connection to another application. An instance of this class is 18 // Represents a connection to another application. An instance of this class is
18 // passed to ApplicationDelegate's ConfigureIncomingConnection() method each 19 // passed to ApplicationDelegate's ConfigureIncomingConnection() method each
19 // time a connection is made to this app, and is returned by the 20 // time a connection is made to this app, and is returned by the
20 // ApplicationDelegate's ConnectToApplication() method when this app 21 // ApplicationDelegate's ConnectToApplication() method when this app
21 // connects to another. 22 // connects to another.
22 // 23 //
23 // To use, define a class that implements your specific service API (e.g., 24 // To use, define a class that implements your specific service API (e.g.,
24 // FooImpl to implement a service named Foo). Then implement an 25 // FooImpl to implement a service named Foo). Then implement an
25 // InterfaceFactory<Foo> that binds instances of FooImpl to 26 // InterfaceFactory<Foo> that binds instances of FooImpl to
26 // InterfaceRequest<Foo>s and register that on the connection like this: 27 // InterfaceRequest<Foo>s and register that on the connection like this:
27 // 28 //
28 // connection->AddService(&factory); 29 // connection->AddService(&factory);
29 // 30 //
30 // Or, if you have multiple factories implemented by the same type, explicitly 31 // Or, if you have multiple factories implemented by the same type, explicitly
31 // specify the interface to register the factory for: 32 // specify the interface to register the factory for:
32 // 33 //
33 // connection->AddService<Foo>(&my_foo_and_bar_factory_); 34 // connection->AddService<Foo>(&my_foo_and_bar_factory_);
34 // connection->AddService<Bar>(&my_foo_and_bar_factory_); 35 // connection->AddService<Bar>(&my_foo_and_bar_factory_);
35 // 36 //
36 // The InterfaceFactory must outlive the ApplicationConnection. 37 // The InterfaceFactory must outlive the ApplicationConnection.
38 //
39 // TODO(vtl): Don't get too attached to this class. I'm going to remove it.
37 class ApplicationConnection { 40 class ApplicationConnection {
38 public: 41 public:
39 virtual ~ApplicationConnection(); 42 virtual ~ApplicationConnection();
40 43
41 // Makes Interface available as a service to the remote application. 44 // Makes Interface available as a service to the remote application.
42 // |factory| will create implementations of Interface on demand. 45 // |factory| will create implementations of Interface on demand.
43 template <typename Interface> 46 template <typename Interface>
44 void AddService(InterfaceFactory<Interface>* factory) { 47 void AddService(InterfaceFactory<Interface>* factory) {
45 SetServiceConnectorForName( 48 SetServiceConnectorForName(
46 new internal::InterfaceFactoryConnector<Interface>(factory), 49 new internal::InterfaceFactoryConnector<Interface>(factory),
47 Interface::Name_); 50 Interface::Name_);
48 } 51 }
49 52
53 virtual const ConnectionContext& GetConnectionContext() const = 0;
54
50 // Returns the URL that was used by the source application to establish a 55 // Returns the URL that was used by the source application to establish a
51 // connection to the destination application. 56 // connection to the destination application.
52 // 57 //
53 // When ApplicationConnection is representing an incoming connection this can 58 // When ApplicationConnection is representing an incoming connection this can
54 // be different than the URL the application was initially loaded from, if the 59 // be different than the URL the application was initially loaded from, if the
55 // application handles multiple URLs. Note that this is the URL after all 60 // application handles multiple URLs. Note that this is the URL after all
56 // URL rewriting and HTTP redirects have been performed. 61 // URL rewriting and HTTP redirects have been performed.
57 // 62 //
58 // When ApplicationConnection is representing and outgoing connection, this 63 // When ApplicationConnection is representing and outgoing connection, this
59 // will be the same as the value returned by GetRemoveApplicationURL(). 64 // will be the same as the value returned by GetRemoveApplicationURL().
60 virtual const std::string& GetConnectionURL() = 0; 65 virtual const std::string& GetConnectionURL() = 0;
61 66
62 // Returns the URL identifying the remote application on this connection. 67 // Returns the URL identifying the remote application on this connection.
63 virtual const std::string& GetRemoteApplicationURL() = 0; 68 virtual const std::string& GetRemoteApplicationURL() = 0;
64 69
65 private: 70 private:
66 virtual void SetServiceConnectorForName(ServiceConnector* service_connector, 71 virtual void SetServiceConnectorForName(ServiceConnector* service_connector,
67 const std::string& name) = 0; 72 const std::string& name) = 0;
68 }; 73 };
69 74
70 } // namespace mojo 75 } // namespace mojo
71 76
72 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_ 77 #endif // MOJO_PUBLIC_APPLICATION_APPLICATION_CONNECTION_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/public/cpp/application/lib/service_provider_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698