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

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 "base/memory/weak_ptr.h"
10 #include "mojo/application/public/cpp/lib/interface_factory_connector.h" 11 #include "mojo/application/public/cpp/lib/interface_factory_connector.h"
11 #include "mojo/application/public/interfaces/service_provider.mojom.h" 12 #include "mojo/application/public/interfaces/service_provider.mojom.h"
12 13
13 namespace mojo { 14 namespace mojo {
14 15
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 to ApplicationDelegate's 20 // time a connection is made to this app, and to ApplicationDelegate's
(...skipping 18 matching lines...) Expand all
38 // been set and an InterfaceFactory has not been registered for the interface 39 // been set and an InterfaceFactory has not been registered for the interface
39 // request, than the interface request is sent to the ServiceConnector. 40 // request, than the interface request is sent to the ServiceConnector.
40 // 41 //
41 // Just as with InterfaceFactory, ServiceConnector must outlive 42 // Just as with InterfaceFactory, ServiceConnector must outlive
42 // ApplicationConnection. 43 // ApplicationConnection.
43 // 44 //
44 // An ApplicationConnection's lifetime is managed by an ApplicationImpl. To 45 // An ApplicationConnection's lifetime is managed by an ApplicationImpl. To
45 // close a connection, call CloseConnection which will destroy this object. 46 // close a connection, call CloseConnection which will destroy this object.
46 class ApplicationConnection { 47 class ApplicationConnection {
47 public: 48 public:
48 ApplicationConnection(); 49 virtual ~ApplicationConnection() {}
49 50
50 // Closes the connection and destroys this object. This is the only valid way 51 class TestApi {
51 // to destroy this object. 52 public:
52 void CloseConnection(); 53 explicit TestApi(ApplicationConnection* connection)
54 : connection_(connection) {
55 }
56 base::WeakPtr<ApplicationConnection> GetWeakPtr() {
57 return connection_->GetWeakPtr();
58 }
59
60 private:
61 ApplicationConnection* connection_;
62 };
53 63
54 // See class description for details. 64 // See class description for details.
55 virtual void SetServiceConnector(ServiceConnector* connector) = 0; 65 virtual void SetServiceConnector(ServiceConnector* connector) = 0;
56 66
57 // Makes Interface available as a service to the remote application. 67 // Makes Interface available as a service to the remote application.
58 // |factory| will create implementations of Interface on demand. 68 // |factory| will create implementations of Interface on demand.
59 // Returns true if the service was exposed, false if capability filtering 69 // Returns true if the service was exposed, false if capability filtering
60 // from the shell prevented the service from being exposed. 70 // from the shell prevented the service from being exposed.
61 template <typename Interface> 71 template <typename Interface>
62 bool AddService(InterfaceFactory<Interface>* factory) { 72 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 110 // Returns the local application's ServiceProvider interface. The return
101 // value is owned by this connection. 111 // value is owned by this connection.
102 virtual ServiceProvider* GetLocalServiceProvider() = 0; 112 virtual ServiceProvider* GetLocalServiceProvider() = 0;
103 113
104 // Register a handler to receive an error notification on the pipe to the 114 // Register a handler to receive an error notification on the pipe to the
105 // remote application's service provider. 115 // remote application's service provider.
106 virtual void SetRemoteServiceProviderConnectionErrorHandler( 116 virtual void SetRemoteServiceProviderConnectionErrorHandler(
107 const Closure& handler) = 0; 117 const Closure& handler) = 0;
108 118
109 protected: 119 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 120 // 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). 121 // some filtering policy preventing this interface from being exposed).
118 virtual bool SetServiceConnectorForName(ServiceConnector* service_connector, 122 virtual bool SetServiceConnectorForName(ServiceConnector* service_connector,
119 const std::string& name) = 0; 123 const std::string& name) = 0;
120 124
121 // Ensures that CloseConnection can only be called once and the 125 virtual base::WeakPtr<ApplicationConnection> GetWeakPtr() = 0;
122 // ApplicationConnection's destructor can only be called after the connection
123 // is closed.
124 bool connection_closed_;
125 }; 126 };
126 127
127 } // namespace mojo 128 } // namespace mojo
128 129
129 #endif // MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_CONNECTION_H_ 130 #endif // MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_CONNECTION_H_
OLDNEW
« no previous file with comments | « mojo/application/public/cpp/BUILD.gn ('k') | mojo/application/public/cpp/application_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698