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

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

Issue 1195003002: Mandoline: Introduce ApplicationConnection::CloseConnection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 5 years, 5 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
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_APPLICATION_PUBLIC_CPP_APPLICATION_CONNECTION_H_ 5 #ifndef MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_CONNECTION_H_
6 #define MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_CONNECTION_H_ 6 #define MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_CONNECTION_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "mojo/application/public/cpp/lib/interface_factory_connector.h" 10 #include "mojo/application/public/cpp/lib/interface_factory_connector.h"
(...skipping 22 matching lines...) Expand all
33 // connection->AddService<Bar>(&my_foo_and_bar_factory_); 33 // connection->AddService<Bar>(&my_foo_and_bar_factory_);
34 // 34 //
35 // The InterfaceFactory must outlive the ApplicationConnection. 35 // The InterfaceFactory must outlive the ApplicationConnection.
36 // 36 //
37 // Additionally you specify a ServiceConnector. If a ServiceConnector has 37 // Additionally you specify a ServiceConnector. If a ServiceConnector has
38 // been set and an InterfaceFactory has not been registered for the interface 38 // been set and an InterfaceFactory has not been registered for the interface
39 // request, than the interface request is sent to the ServiceConnector. 39 // request, than the interface request is sent to the ServiceConnector.
40 // 40 //
41 // Just as with InterfaceFactory, ServiceConnector must outlive 41 // Just as with InterfaceFactory, ServiceConnector must outlive
42 // ApplicationConnection. 42 // ApplicationConnection.
43 //
44 // An ApplicationConnection's lifetime is managed by an ApplicationImpl. To
45 // close a connection, call CloseConnection which will destroy this object.
43 class ApplicationConnection { 46 class ApplicationConnection {
44 public: 47 public:
45 virtual ~ApplicationConnection(); 48 ApplicationConnection();
49
50 // Closes the connection and destroys this object. This is the only valid way
51 // to destroy this object.
52 void CloseConnection();
46 53
47 // See class description for details. 54 // See class description for details.
48 virtual void SetServiceConnector(ServiceConnector* connector) = 0; 55 virtual void SetServiceConnector(ServiceConnector* connector) = 0;
49 56
50 // Makes Interface available as a service to the remote application. 57 // Makes Interface available as a service to the remote application.
51 // |factory| will create implementations of Interface on demand. 58 // |factory| will create implementations of Interface on demand.
52 template <typename Interface> 59 template <typename Interface>
53 void AddService(InterfaceFactory<Interface>* factory) { 60 void AddService(InterfaceFactory<Interface>* factory) {
54 SetServiceConnectorForName( 61 SetServiceConnectorForName(
55 new internal::InterfaceFactoryConnector<Interface>(factory), 62 new internal::InterfaceFactoryConnector<Interface>(factory),
(...skipping 25 matching lines...) Expand all
81 virtual const std::string& GetConnectionURL() = 0; 88 virtual const std::string& GetConnectionURL() = 0;
82 89
83 // Returns the URL identifying the remote application on this connection. 90 // Returns the URL identifying the remote application on this connection.
84 virtual const std::string& GetRemoteApplicationURL() = 0; 91 virtual const std::string& GetRemoteApplicationURL() = 0;
85 92
86 // Returns the raw proxy to the remote application's ServiceProvider 93 // Returns the raw proxy to the remote application's ServiceProvider
87 // interface. Most applications will just use ConnectToService() instead. 94 // interface. Most applications will just use ConnectToService() instead.
88 // Caller does not take ownership. 95 // Caller does not take ownership.
89 virtual ServiceProvider* GetServiceProvider() = 0; 96 virtual ServiceProvider* GetServiceProvider() = 0;
90 97
98 protected:
99 virtual ~ApplicationConnection();
100
101 // Called to give the derived type to perform some cleanup before destruction.
102 virtual void OnCloseConnection() = 0;
103
91 private: 104 private:
92 virtual void SetServiceConnectorForName(ServiceConnector* service_connector, 105 virtual void SetServiceConnectorForName(ServiceConnector* service_connector,
93 const std::string& name) = 0; 106 const std::string& name) = 0;
107
108 // Ensures that CloseConnection can only be called once and the
109 // ApplicationConnection's destructor can only be called after the connection
110 // is closed.
111 bool connection_closed_;
94 }; 112 };
95 113
96 } // namespace mojo 114 } // namespace mojo
97 115
98 #endif // MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_CONNECTION_H_ 116 #endif // MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_CONNECTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698