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

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

Issue 2015643002: Add (optional) options to Run[Main]Application(). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: doh Created 4 years, 7 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 #include <stdio.h> 5 #include <stdio.h>
6 6
7 #include <memory>
8
9 #include "mojo/public/c/system/main.h" 7 #include "mojo/public/c/system/main.h"
10 #include "mojo/public/cpp/application/application_delegate.h" 8 #include "mojo/public/cpp/application/application_impl_base.h"
11 #include "mojo/public/cpp/application/application_impl.h"
12 #include "mojo/public/cpp/application/application_runner.h"
13 #include "mojo/public/cpp/application/connect.h" 9 #include "mojo/public/cpp/application/connect.h"
10 #include "mojo/public/cpp/application/run_application.h"
14 #include "mojo/public/cpp/system/wait.h" 11 #include "mojo/public/cpp/system/wait.h"
15 #include "mojo/public/cpp/utility/run_loop.h" 12 #include "mojo/public/cpp/utility/run_loop.h"
16 #include "mojo/services/network/interfaces/network_service.mojom.h" 13 #include "mojo/services/network/interfaces/network_service.mojom.h"
17 #include "mojo/services/network/interfaces/url_loader.mojom.h" 14 #include "mojo/services/network/interfaces/url_loader.mojom.h"
18 15
19 namespace mojo { 16 namespace mojo {
20 namespace examples { 17 namespace examples {
21 namespace { 18 namespace {
22 19
23 class ResponsePrinter { 20 class ResponsePrinter {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 break; 65 break;
69 } 66 }
70 } 67 }
71 68
72 printf("\n>>> EOF <<<\n"); 69 printf("\n>>> EOF <<<\n");
73 } 70 }
74 }; 71 };
75 72
76 } // namespace 73 } // namespace
77 74
78 class WGetApp : public ApplicationDelegate { 75 class WGetApp : public ApplicationImplBase {
79 public: 76 public:
80 void Initialize(ApplicationImpl* app) override { 77 void OnInitialize() override {
81 ConnectToService(app->shell(), "mojo:network_service", 78 ConnectToService(shell(), "mojo:network_service",
82 GetProxy(&network_service_)); 79 GetProxy(&network_service_));
83 Start(app->args()); 80 Start(args());
84 } 81 }
85 82
86 private: 83 private:
87 void Start(const std::vector<std::string>& args) { 84 void Start(const std::vector<std::string>& args) {
88 std::string url((args.size() > 1) ? args[1] : PromptForURL()); 85 std::string url((args.size() > 1) ? args[1] : PromptForURL());
89 printf("Loading: %s\n", url.c_str()); 86 printf("Loading: %s\n", url.c_str());
90 87
91 network_service_->CreateURLLoader(GetProxy(&url_loader_)); 88 network_service_->CreateURLLoader(GetProxy(&url_loader_));
92 89
93 URLRequestPtr request(URLRequest::New()); 90 URLRequestPtr request(URLRequest::New());
(...skipping 13 matching lines...) Expand all
107 } 104 }
108 105
109 NetworkServicePtr network_service_; 106 NetworkServicePtr network_service_;
110 URLLoaderPtr url_loader_; 107 URLLoaderPtr url_loader_;
111 }; 108 };
112 109
113 } // namespace examples 110 } // namespace examples
114 } // namespace mojo 111 } // namespace mojo
115 112
116 MojoResult MojoMain(MojoHandle application_request) { 113 MojoResult MojoMain(MojoHandle application_request) {
117 mojo::ApplicationRunner runner( 114 mojo::examples::WGetApp wget_app;
118 std::unique_ptr<mojo::examples::WGetApp>(new mojo::examples::WGetApp())); 115 return mojo::RunMainApplication(application_request, &wget_app);
119 return runner.Run(application_request);
120 } 116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698