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

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

Issue 1455833005: Convert ConnectToApplication to take a params class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 1 month 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/macros.h"
10 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
11 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
12 #include "mojo/application/public/cpp/app_lifetime_helper.h" 13 #include "mojo/application/public/cpp/app_lifetime_helper.h"
13 #include "mojo/application/public/cpp/application_connection.h" 14 #include "mojo/application/public/cpp/application_connection.h"
14 #include "mojo/application/public/cpp/application_delegate.h" 15 #include "mojo/application/public/cpp/application_delegate.h"
15 #include "mojo/application/public/cpp/lib/service_registry.h" 16 #include "mojo/application/public/cpp/lib/service_registry.h"
16 #include "mojo/application/public/interfaces/application.mojom.h" 17 #include "mojo/application/public/interfaces/application.mojom.h"
17 #include "mojo/application/public/interfaces/shell.mojom.h" 18 #include "mojo/application/public/interfaces/shell.mojom.h"
18 #include "mojo/public/cpp/bindings/binding.h" 19 #include "mojo/public/cpp/bindings/binding.h"
19 #include "mojo/public/cpp/bindings/callback.h" 20 #include "mojo/public/cpp/bindings/callback.h"
(...skipping 30 matching lines...) Expand all
50 // 51 //
51 // ApplicationImpl app(service_provider_handle); 52 // ApplicationImpl app(service_provider_handle);
52 // app.AddService<FooImpl>(); 53 // app.AddService<FooImpl>();
53 // 54 //
54 // BarContext context; 55 // BarContext context;
55 // app.AddService<BarImpl>(&context); 56 // app.AddService<BarImpl>(&context);
56 // 57 //
57 // 58 //
58 class ApplicationImpl : public Application { 59 class ApplicationImpl : public Application {
59 public: 60 public:
61 class ConnectParams {
62 public:
63 explicit ConnectParams(const std::string& url);
64 explicit ConnectParams(URLRequestPtr request);
65 ~ConnectParams();
66
67 URLRequestPtr TakeRequest() { return request_.Pass(); }
68 CapabilityFilterPtr TakeFilter() { return filter_.Pass(); }
69 void set_filter(CapabilityFilterPtr filter) {
70 filter_ = filter.Pass();
71 }
72
73 private:
74 URLRequestPtr request_;
75 CapabilityFilterPtr filter_;
76
77 DISALLOW_COPY_AND_ASSIGN(ConnectParams);
78 };
79
60 class TestApi { 80 class TestApi {
61 public: 81 public:
62 explicit TestApi(ApplicationImpl* application) 82 explicit TestApi(ApplicationImpl* application)
63 : application_(application) {} 83 : application_(application) {}
64 84
65 void UnbindConnections(InterfaceRequest<Application>* application_request, 85 void UnbindConnections(InterfaceRequest<Application>* application_request,
66 ShellPtr* shell) { 86 ShellPtr* shell) {
67 application_->UnbindConnections(application_request, shell); 87 application_->UnbindConnections(application_request, shell);
68 } 88 }
69 89
(...skipping 20 matching lines...) Expand all
90 110
91 const std::string& url() const { return url_; } 111 const std::string& url() const { return url_; }
92 112
93 AppLifetimeHelper* app_lifetime_helper() { return &app_lifetime_helper_; } 113 AppLifetimeHelper* app_lifetime_helper() { return &app_lifetime_helper_; }
94 114
95 // Requests a new connection to an application. Returns a pointer to the 115 // Requests a new connection to an application. Returns a pointer to the
96 // connection if the connection is permitted by this application's delegate, 116 // connection if the connection is permitted by this application's delegate,
97 // or nullptr otherwise. Caller takes ownership. 117 // or nullptr otherwise. Caller takes ownership.
98 scoped_ptr<ApplicationConnection> ConnectToApplication( 118 scoped_ptr<ApplicationConnection> ConnectToApplication(
99 const std::string& url); 119 const std::string& url);
100 scoped_ptr<ApplicationConnection> ConnectToApplication(URLRequestPtr request); 120 scoped_ptr<ApplicationConnection> ConnectToApplication(ConnectParams* params);
101 scoped_ptr<ApplicationConnection> ConnectToApplicationWithCapabilityFilter(
102 URLRequestPtr request,
103 CapabilityFilterPtr filter);
104 121
105 // Connect to application identified by |request->url| and connect to the 122 // Connect to application identified by |request->url| and connect to the
106 // service implementation of the interface identified by |Interface|. 123 // service implementation of the interface identified by |Interface|.
107 template <typename Interface> 124 template <typename Interface>
108 void ConnectToService(mojo::URLRequestPtr request, 125 void ConnectToService(ConnectParams* params, InterfacePtr<Interface>* ptr) {
109 InterfacePtr<Interface>* ptr) { 126 scoped_ptr<ApplicationConnection> connection = ConnectToApplication(params);
110 scoped_ptr<ApplicationConnection> connection =
111 ConnectToApplication(request.Pass());
112 if (!connection.get()) 127 if (!connection.get())
113 return; 128 return;
114 connection->ConnectToService(ptr); 129 connection->ConnectToService(ptr);
115 } 130 }
131 template <typename Interface>
132 void ConnectToService(const std::string& url, InterfacePtr<Interface>* ptr) {
133 ConnectParams params(url);
134 return ConnectToService(&params, ptr);
135 }
116 136
117 // Block the calling thread until the Initialize() method is called by the 137 // Block the calling thread until the Initialize() method is called by the
118 // shell. 138 // shell.
119 void WaitForInitialize(); 139 void WaitForInitialize();
120 140
121 // Initiate shutdown of this application. This may involve a round trip to the 141 // Initiate shutdown of this application. This may involve a round trip to the
122 // Shell to ensure there are no inbound service requests. 142 // Shell to ensure there are no inbound service requests.
123 void Quit(); 143 void Quit();
124 144
125 private: 145 private:
(...skipping 29 matching lines...) Expand all
155 AppLifetimeHelper app_lifetime_helper_; 175 AppLifetimeHelper app_lifetime_helper_;
156 bool quit_requested_; 176 bool quit_requested_;
157 base::WeakPtrFactory<ApplicationImpl> weak_factory_; 177 base::WeakPtrFactory<ApplicationImpl> weak_factory_;
158 178
159 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl); 179 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationImpl);
160 }; 180 };
161 181
162 } // namespace mojo 182 } // namespace mojo
163 183
164 #endif // MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_IMPL_H_ 184 #endif // MOJO_APPLICATION_PUBLIC_CPP_APPLICATION_IMPL_H_
OLDNEW
« no previous file with comments | « mojo/application/public/cpp/BUILD.gn ('k') | mojo/application/public/cpp/lib/application_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698