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

Side by Side Diff: mojo/application/public/cpp/application_impl.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_IMPL_H_ 5 #ifndef MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_IMPL_H_
6 #define MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_IMPL_H_ 6 #define MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_IMPL_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/scoped_vector.h"
10 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
11 #include "mojo/application/public/cpp/app_lifetime_helper.h" 12 #include "mojo/application/public/cpp/app_lifetime_helper.h"
12 #include "mojo/application/public/cpp/application_connection.h" 13 #include "mojo/application/public/cpp/application_connection.h"
13 #include "mojo/application/public/cpp/application_delegate.h" 14 #include "mojo/application/public/cpp/application_delegate.h"
14 #include "mojo/application/public/cpp/lib/service_registry.h" 15 #include "mojo/application/public/cpp/lib/service_registry.h"
15 #include "mojo/application/public/interfaces/application.mojom.h" 16 #include "mojo/application/public/interfaces/application.mojom.h"
16 #include "mojo/application/public/interfaces/shell.mojom.h" 17 #include "mojo/application/public/interfaces/shell.mojom.h"
17 #include "mojo/public/cpp/bindings/callback.h" 18 #include "mojo/public/cpp/bindings/callback.h"
18 #include "mojo/public/cpp/system/core.h" 19 #include "mojo/public/cpp/system/core.h"
19 20
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // been invoked. It will remain valid until UnbindConnections() is invoked or 72 // been invoked. It will remain valid until UnbindConnections() is invoked or
72 // the ApplicationImpl is destroyed. 73 // the ApplicationImpl is destroyed.
73 Shell* shell() const { return shell_.get(); } 74 Shell* shell() const { return shell_.get(); }
74 75
75 const std::string& url() const { return url_; } 76 const std::string& url() const { return url_; }
76 77
77 AppLifetimeHelper* app_lifetime_helper() { return &app_lifetime_helper_; } 78 AppLifetimeHelper* app_lifetime_helper() { return &app_lifetime_helper_; }
78 79
79 // Requests a new connection to an application. Returns a pointer to the 80 // Requests a new connection to an application. Returns a pointer to the
80 // connection if the connection is permitted by this application's delegate, 81 // connection if the connection is permitted by this application's delegate,
81 // or nullptr otherwise. Caller does not take ownership. The pointer remains 82 // or nullptr otherwise. Caller takes ownership.
82 // valid until an error occurs on the connection with the Shell, until the
83 // ApplicationImpl is destroyed, or until the connection is closed through a
84 // call to ApplicationConnection::CloseConnection.
85 // TODO(beng): consider replacing default value in a separate CL per style 83 // TODO(beng): consider replacing default value in a separate CL per style
86 // guide. 84 // guide.
87 ApplicationConnection* ConnectToApplication( 85 scoped_ptr<ApplicationConnection> ConnectToApplication(
88 URLRequestPtr request, 86 URLRequestPtr request,
89 CapabilityFilterPtr filter = nullptr); 87 CapabilityFilterPtr filter = nullptr);
90 88
91 // Closes the |connection|.
92 void CloseConnection(ApplicationConnection* connection);
93
94 // Connect to application identified by |request->url| and connect to the 89 // Connect to application identified by |request->url| and connect to the
95 // service implementation of the interface identified by |Interface|. 90 // service implementation of the interface identified by |Interface|.
96 template <typename Interface> 91 template <typename Interface>
97 void ConnectToService(mojo::URLRequestPtr request, 92 void ConnectToService(mojo::URLRequestPtr request,
98 InterfacePtr<Interface>* ptr) { 93 InterfacePtr<Interface>* ptr) {
99 ApplicationConnection* connection = ConnectToApplication(request.Pass()); 94 scoped_ptr<ApplicationConnection> connection =
100 if (!connection) 95 ConnectToApplication(request.Pass());
96 if (!connection.get())
101 return; 97 return;
102 connection->ConnectToService(ptr); 98 connection->ConnectToService(ptr);
103 } 99 }
104 100
105 // Application implementation. 101 // Application implementation.
106 void Initialize(ShellPtr shell, const mojo::String& url) override; 102 void Initialize(ShellPtr shell, const mojo::String& url) override;
107 103
108 // Block until the Application is initialized, if it is not already. 104 // Block until the Application is initialized, if it is not already.
109 void WaitForInitialize(); 105 void WaitForInitialize();
110 106
(...skipping 11 matching lines...) Expand all
122 // Application implementation. 118 // Application implementation.
123 void AcceptConnection(const String& requestor_url, 119 void AcceptConnection(const String& requestor_url,
124 InterfaceRequest<ServiceProvider> services, 120 InterfaceRequest<ServiceProvider> services,
125 ServiceProviderPtr exposed_services, 121 ServiceProviderPtr exposed_services,
126 Array<String> allowed_interfaces, 122 Array<String> allowed_interfaces,
127 const String& url) override; 123 const String& url) override;
128 void OnQuitRequested(const Callback<void(bool)>& callback) override; 124 void OnQuitRequested(const Callback<void(bool)>& callback) override;
129 125
130 void OnConnectionError(); 126 void OnConnectionError();
131 127
132 void ClearConnections();
133
134 // Called from Quit() when there is no Shell connection, or asynchronously 128 // Called from Quit() when there is no Shell connection, or asynchronously
135 // from Quit() once the Shell has OK'ed shutdown. 129 // from Quit() once the Shell has OK'ed shutdown.
136 void QuitNow(); 130 void QuitNow();
137 131
138 typedef std::vector<internal::ServiceRegistry*> ServiceRegistryList; 132 // We track the lifetime of incoming connection registries as it more
139 133 // convenient for the client.
140 ServiceRegistryList incoming_service_registries_; 134 ScopedVector<ApplicationConnection> incoming_connections_;
141 ServiceRegistryList outgoing_service_registries_;
142 ApplicationDelegate* delegate_; 135 ApplicationDelegate* delegate_;
143 Binding<Application> binding_; 136 Binding<Application> binding_;
144 ShellPtr shell_; 137 ShellPtr shell_;
145 std::string url_; 138 std::string url_;
146 Closure termination_closure_; 139 Closure termination_closure_;
147 AppLifetimeHelper app_lifetime_helper_; 140 AppLifetimeHelper app_lifetime_helper_;
148 bool quit_requested_; 141 bool quit_requested_;
149 bool in_destructor_;
150 base::WeakPtrFactory<ApplicationImpl> weak_factory_; 142 base::WeakPtrFactory<ApplicationImpl> weak_factory_;
151 143
152 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); 144 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl);
153 }; 145 };
154 146
155 } // namespace mojo 147 } // namespace mojo
156 148
157 #endif // MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_IMPL_H_ 149 #endif // MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_IMPL_H_
OLDNEW
« no previous file with comments | « mojo/application/public/cpp/application_delegate.h ('k') | mojo/application/public/cpp/lib/application_connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698