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

Side by Side Diff: examples/moterm_example_app/moterm_example_app.cc

Issue 1682113003: Mojo C++ bindings: Generate InterfaceHandle<> instead of InterfacePtr<>. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 // This is a simple example application (with an embeddable view), which embeds 5 // This is a simple example application (with an embeddable view), which embeds
6 // the Moterm view, uses it to prompt the user, etc. 6 // the Moterm view, uses it to prompt the user, etc.
7 7
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <utility>
11 12
12 #include "base/bind.h" 13 #include "base/bind.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
15 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
17 #include "mojo/application/application_runner_chromium.h" 18 #include "mojo/application/application_runner_chromium.h"
18 #include "mojo/common/binding_set.h" 19 #include "mojo/common/binding_set.h"
19 #include "mojo/public/c/system/main.h" 20 #include "mojo/public/c/system/main.h"
20 #include "mojo/public/cpp/application/application_connection.h" 21 #include "mojo/public/cpp/application/application_connection.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 125
125 Fputs(moterm_file_.get(), 126 Fputs(moterm_file_.get(),
126 base::StringPrintf("\nGoing to %s ...\n", dest_url.c_str()).c_str()); 127 base::StringPrintf("\nGoing to %s ...\n", dest_url.c_str()).c_str());
127 moterm_file_.reset(); 128 moterm_file_.reset();
128 129
129 mojo::ServiceProviderPtr dest_sp; 130 mojo::ServiceProviderPtr dest_sp;
130 shell_->ConnectToApplication(dest_url, GetProxy(&dest_sp), nullptr); 131 shell_->ConnectToApplication(dest_url, GetProxy(&dest_sp), nullptr);
131 mojo::terminal::TerminalClientPtr dest_terminal_client; 132 mojo::terminal::TerminalClientPtr dest_terminal_client;
132 mojo::ConnectToService(dest_sp.get(), &dest_terminal_client); 133 mojo::ConnectToService(dest_sp.get(), &dest_terminal_client);
133 moterm_terminal_->ConnectToClient( 134 moterm_terminal_->ConnectToClient(
134 dest_terminal_client.Pass(), true, 135 std::move(dest_terminal_client), true,
135 base::Bind(&MotermExampleAppView::OnDestinationDone, 136 base::Bind(&MotermExampleAppView::OnDestinationDone,
136 weak_factory_.GetWeakPtr())); 137 weak_factory_.GetWeakPtr()));
137 } 138 }
138 void OnDestinationDone(mojo::files::Error error) { 139 void OnDestinationDone(mojo::files::Error error) {
139 // We should always succeed. (It'll only fail on synchronous failures, which 140 // We should always succeed. (It'll only fail on synchronous failures, which
140 // only occur when it's busy.) 141 // only occur when it's busy.)
141 DCHECK_EQ(error, mojo::files::Error::OK); 142 DCHECK_EQ(error, mojo::files::Error::OK);
142 StartPrompt(false); 143 StartPrompt(false);
143 } 144 }
144 145
(...skipping 30 matching lines...) Expand all
175 } 176 }
176 177
177 // |InterfaceFactory<mojo::ui::ViewProvider>|: 178 // |InterfaceFactory<mojo::ui::ViewProvider>|:
178 void Create(mojo::ApplicationConnection* connection, 179 void Create(mojo::ApplicationConnection* connection,
179 mojo::InterfaceRequest<mojo::ui::ViewProvider> request) override { 180 mojo::InterfaceRequest<mojo::ui::ViewProvider> request) override {
180 bindings_.AddBinding(this, request.Pass()); 181 bindings_.AddBinding(this, request.Pass());
181 } 182 }
182 183
183 // |ViewProvider|: 184 // |ViewProvider|:
184 void CreateView(mojo::InterfaceRequest<mojo::ServiceProvider> services, 185 void CreateView(mojo::InterfaceRequest<mojo::ServiceProvider> services,
185 mojo::ServiceProviderPtr exposed_services, 186 mojo::InterfaceHandle<mojo::ServiceProvider> exposed_services,
186 const CreateViewCallback& callback) override { 187 const CreateViewCallback& callback) override {
187 new MotermExampleAppView(application_impl_->shell(), callback); 188 new MotermExampleAppView(application_impl_->shell(), callback);
188 } 189 }
189 190
190 mojo::ApplicationImpl* application_impl_; 191 mojo::ApplicationImpl* application_impl_;
191 mojo::BindingSet<mojo::ui::ViewProvider> bindings_; 192 mojo::BindingSet<mojo::ui::ViewProvider> bindings_;
192 193
193 DISALLOW_COPY_AND_ASSIGN(MotermExampleApp); 194 DISALLOW_COPY_AND_ASSIGN(MotermExampleApp);
194 }; 195 };
195 196
196 MojoResult MojoMain(MojoHandle application_request) { 197 MojoResult MojoMain(MojoHandle application_request) {
197 mojo::ApplicationRunnerChromium runner(new MotermExampleApp()); 198 mojo::ApplicationRunnerChromium runner(new MotermExampleApp());
198 return runner.Run(application_request); 199 return runner.Run(application_request);
199 } 200 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698