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

Unified Diff: examples/content_handler_demo/content_handler_demo.cc

Issue 687273002: mojo: Update content handler API (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Add missing comment Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « examples/content_handler_demo/BUILD.gn ('k') | examples/pdf_viewer/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/content_handler_demo/content_handler_demo.cc
diff --git a/examples/content_handler_demo/content_handler_demo.cc b/examples/content_handler_demo/content_handler_demo.cc
index 3abf0f78ff295859fae84d1313636490ffd846d9..81723a87dbd57e0c319c9b5fef7c1145cfc6e826 100644
--- a/examples/content_handler_demo/content_handler_demo.cc
+++ b/examples/content_handler_demo/content_handler_demo.cc
@@ -4,45 +4,34 @@
#include <stdio.h>
+#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl.h"
+#include "mojo/public/cpp/application/application_runner.h"
#include "mojo/public/cpp/application/interface_factory_impl.h"
#include "mojo/services/public/interfaces/content_handler/content_handler.mojom.h"
namespace mojo {
namespace examples {
-class ContentHandlerApp;
-
-class ContentHandlerImpl : public InterfaceImpl<ContentHandler> {
- public:
- explicit ContentHandlerImpl(ContentHandlerApp* content_handler_app)
- : content_handler_app_(content_handler_app) {
- }
- virtual ~ContentHandlerImpl() {}
-
- private:
- virtual void OnConnect(
- const mojo::String& requestor_url,
- URLResponsePtr response,
- InterfaceRequest<ServiceProvider> service_provider) override;
-
- ContentHandlerApp* content_handler_app_;
-};
-
-class ContentHandlerApp : public ApplicationDelegate {
+class PrintBodyApplication : public InterfaceImpl<Application> {
public:
- ContentHandlerApp() : content_handler_factory_(this) {
+ PrintBodyApplication(ShellPtr shell, ScopedDataPipeConsumerHandle body)
+ : shell_(shell.Pass()), body_(body.Pass()) {
+ shell_.set_client(this);
}
- virtual void Initialize(ApplicationImpl* app) override {}
+ virtual void Initialize(Array<String> args) override {}
- virtual bool ConfigureIncomingConnection(
- ApplicationConnection* connection) override {
- connection->AddService(&content_handler_factory_);
- return true;
+ virtual void AcceptConnection(const String& requestor_url,
+ ServiceProviderPtr service_provider) override {
+ printf("ContentHandler::OnConnect - requestor_url:%s - body follows\n\n",
+ requestor_url.To<std::string>().c_str());
+ PrintResponse(body_.Pass());
+ delete this;
}
+ private:
void PrintResponse(ScopedDataPipeConsumerHandle body) const {
for (;;) {
char buf[512];
@@ -66,25 +55,47 @@ class ContentHandlerApp : public ApplicationDelegate {
}
}
+ ShellPtr shell_;
+ ScopedDataPipeConsumerHandle body_;
+
+ MOJO_DISALLOW_COPY_AND_ASSIGN(PrintBodyApplication);
+};
+
+class ContentHandlerImpl : public InterfaceImpl<ContentHandler> {
+ public:
+ explicit ContentHandlerImpl() {}
+ virtual ~ContentHandlerImpl() {}
+
private:
- InterfaceFactoryImplWithContext<ContentHandlerImpl,
- ContentHandlerApp> content_handler_factory_;
+ virtual void StartApplication(ShellPtr shell,
+ URLResponsePtr response) override {
+ // The application will delete itself after being connected to.
+ new PrintBodyApplication(shell.Pass(), response->body.Pass());
+ }
};
-void ContentHandlerImpl::OnConnect(
- const mojo::String& requestor_url,
- URLResponsePtr response,
- InterfaceRequest<ServiceProvider> service_provider) {
- printf("ContentHandler::OnConnect - requestor_url:%s - body follows\n\n",
- requestor_url.To<std::string>().c_str());
- content_handler_app_->PrintResponse(response->body.Pass());
-}
+class ContentHandlerApp : public ApplicationDelegate {
+ public:
+ ContentHandlerApp() : content_handler_factory_() {}
-} // namespace examples
+ virtual void Initialize(ApplicationImpl* app) override {}
-// static
-ApplicationDelegate* ApplicationDelegate::Create() {
- return new examples::ContentHandlerApp();
-}
+ virtual bool ConfigureIncomingConnection(
+ ApplicationConnection* connection) override {
+ connection->AddService(&content_handler_factory_);
+ return true;
+ }
+
+ private:
+ InterfaceFactoryImpl<ContentHandlerImpl> content_handler_factory_;
+ MOJO_DISALLOW_COPY_AND_ASSIGN(ContentHandlerApp);
+};
+
+} // namespace examples
} // namespace mojo
+
+MojoResult MojoMain(MojoHandle shell_handle) {
+ mojo::ApplicationRunner runner(new mojo::examples::ContentHandlerApp);
+ return runner.Run(shell_handle);
+}
« no previous file with comments | « examples/content_handler_demo/BUILD.gn ('k') | examples/pdf_viewer/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698