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

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

Issue 1254383016: ApplicationConnection lifetime management changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 4 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 27 matching lines...) Expand all
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 // 43 //
44 // An ApplicationConnection's lifetime is managed by an ApplicationImpl. To 44 // An ApplicationConnection's lifetime is managed by an ApplicationImpl. To
45 // close a connection, call CloseConnection which will destroy this object. 45 // close a connection, call CloseConnection which will destroy this object.
46 class ApplicationConnection { 46 class ApplicationConnection {
47 public: 47 public:
48 ApplicationConnection(); 48 virtual ~ApplicationConnection() {}
49
50 // Closes the connection and destroys this object. This is the only valid way
51 // to destroy this object.
52 void CloseConnection();
53 49
54 // See class description for details. 50 // See class description for details.
55 virtual void SetServiceConnector(ServiceConnector* connector) = 0; 51 virtual void SetServiceConnector(ServiceConnector* connector) = 0;
56 52
57 // Makes Interface available as a service to the remote application. 53 // Makes Interface available as a service to the remote application.
58 // |factory| will create implementations of Interface on demand. 54 // |factory| will create implementations of Interface on demand.
59 // Returns true if the service was exposed, false if capability filtering 55 // Returns true if the service was exposed, false if capability filtering
60 // from the shell prevented the service from being exposed. 56 // from the shell prevented the service from being exposed.
61 template <typename Interface> 57 template <typename Interface>
62 bool AddService(InterfaceFactory<Interface>* factory) { 58 bool AddService(InterfaceFactory<Interface>* factory) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 // Returns the local application's ServiceProvider interface. The return 96 // Returns the local application's ServiceProvider interface. The return
101 // value is owned by this connection. 97 // value is owned by this connection.
102 virtual ServiceProvider* GetLocalServiceProvider() = 0; 98 virtual ServiceProvider* GetLocalServiceProvider() = 0;
103 99
104 // Register a handler to receive an error notification on the pipe to the 100 // Register a handler to receive an error notification on the pipe to the
105 // remote application's service provider. 101 // remote application's service provider.
106 virtual void SetRemoteServiceProviderConnectionErrorHandler( 102 virtual void SetRemoteServiceProviderConnectionErrorHandler(
107 const Closure& handler) = 0; 103 const Closure& handler) = 0;
108 104
109 protected: 105 protected:
110 virtual ~ApplicationConnection();
111
112 // Called to give the derived type to perform some cleanup before destruction.
113 virtual void OnCloseConnection() = 0;
114
115 private:
116 // Returns true if the connector was set, false if it was not set (e.g. by 106 // Returns true if the connector was set, false if it was not set (e.g. by
117 // some filtering policy preventing this interface from being exposed). 107 // some filtering policy preventing this interface from being exposed).
118 virtual bool SetServiceConnectorForName(ServiceConnector* service_connector, 108 virtual bool SetServiceConnectorForName(ServiceConnector* service_connector,
119 const std::string& name) = 0; 109 const std::string& name) = 0;
120
121 // Ensures that CloseConnection can only be called once and the
122 // ApplicationConnection's destructor can only be called after the connection
123 // is closed.
124 bool connection_closed_;
125 }; 110 };
126 111
127 } // namespace mojo 112 } // namespace mojo
128 113
129 #endif // MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_CONNECTION_H_ 114 #endif // MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_CONNECTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698