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

Side by Side Diff: services/dart/content_handler_main.cc

Issue 1262493002: Enable HTTP loading in Mojo dart content handler (Closed) Base URL: git@github.com:domokit/mojo.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
« no previous file with comments | « mojo/tools/get_test_list.py ('k') | services/dart/dart_app.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "base/threading/platform_thread.h" 10 #include "base/threading/platform_thread.h"
11 #include "mojo/application/application_runner_chromium.h" 11 #include "mojo/application/application_runner_chromium.h"
12 #include "mojo/application/content_handler_factory.h" 12 #include "mojo/application/content_handler_factory.h"
13 #include "mojo/dart/embedder/dart_controller.h" 13 #include "mojo/dart/embedder/dart_controller.h"
14 #include "mojo/icu/icu.h" 14 #include "mojo/icu/icu.h"
15 #include "mojo/public/c/system/main.h" 15 #include "mojo/public/c/system/main.h"
16 #include "mojo/public/cpp/application/application_delegate.h" 16 #include "mojo/public/cpp/application/application_delegate.h"
17 #include "mojo/public/cpp/application/application_impl.h" 17 #include "mojo/public/cpp/application/application_impl.h"
18 #include "mojo/services/url_response_disk_cache/public/interfaces/url_response_d isk_cache.mojom.h" 18 #include "mojo/services/url_response_disk_cache/public/interfaces/url_response_d isk_cache.mojom.h"
19 #include "services/dart/content_handler_app_service_connector.h" 19 #include "services/dart/content_handler_app_service_connector.h"
20 #include "services/dart/dart_app.h" 20 #include "services/dart/dart_app.h"
21 #include "url/gurl.h" 21 #include "url/gurl.h"
22 22
23 namespace dart { 23 namespace dart {
24 24
25 static bool IsDartZip(std::string url) {
26 // If the url doesn't end with ".dart" we assume it is a zipped up
27 // dart application.
28 return !EndsWith(url, ".dart", false);
29 }
30
25 class DartContentHandlerApp; 31 class DartContentHandlerApp;
26 32
27 class DartContentHandler : public mojo::ContentHandlerFactory::ManagedDelegate { 33 class DartContentHandler : public mojo::ContentHandlerFactory::ManagedDelegate {
28 public: 34 public:
29 DartContentHandler(DartContentHandlerApp* app, bool strict) 35 DartContentHandler(DartContentHandlerApp* app, bool strict)
30 : app_(app), strict_(strict) { 36 : app_(app), strict_(strict) {
31 } 37 }
32 38
33 void set_handler_task_runner( 39 void set_handler_task_runner(
34 scoped_refptr<base::SingleThreadTaskRunner> handler_task_runner) { 40 scoped_refptr<base::SingleThreadTaskRunner> handler_task_runner) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 ContentHandlerAppServiceConnector* service_connector_; 142 ContentHandlerAppServiceConnector* service_connector_;
137 143
138 DISALLOW_COPY_AND_ASSIGN(DartContentHandlerApp); 144 DISALLOW_COPY_AND_ASSIGN(DartContentHandlerApp);
139 }; 145 };
140 146
141 scoped_ptr<mojo::ContentHandlerFactory::HandledApplicationHolder> 147 scoped_ptr<mojo::ContentHandlerFactory::HandledApplicationHolder>
142 DartContentHandler::CreateApplication( 148 DartContentHandler::CreateApplication(
143 mojo::InterfaceRequest<mojo::Application> application_request, 149 mojo::InterfaceRequest<mojo::Application> application_request,
144 mojo::URLResponsePtr response) { 150 mojo::URLResponsePtr response) {
145 base::FilePath application_dir; 151 base::FilePath application_dir;
146 { 152 std::string url = response->url.get();
153 if (IsDartZip(response->url.get())) {
154 // Loading a .dartzip:
155 // 1) Extract the .dartzip
156 // 2) Launch from temporary directory (|application_dir|).
147 handler_task_runner_->PostTask( 157 handler_task_runner_->PostTask(
148 FROM_HERE, 158 FROM_HERE,
149 base::Bind( 159 base::Bind(
150 &DartContentHandlerApp::ExtractApplication, base::Unretained(app_), 160 &DartContentHandlerApp::ExtractApplication, base::Unretained(app_),
151 base::Unretained(&application_dir), base::Passed(response.Pass()), 161 base::Unretained(&application_dir), base::Passed(response.Pass()),
152 base::Bind( 162 base::Bind(
153 base::IgnoreResult(&base::SingleThreadTaskRunner::PostTask), 163 base::IgnoreResult(&base::SingleThreadTaskRunner::PostTask),
154 base::MessageLoop::current()->task_runner(), FROM_HERE, 164 base::MessageLoop::current()->task_runner(), FROM_HERE,
155 base::MessageLoop::QuitWhenIdleClosure()))); 165 base::MessageLoop::QuitWhenIdleClosure())));
156 base::RunLoop().Run(); 166 base::RunLoop().Run();
167 return make_scoped_ptr(
168 new DartApp(application_request.Pass(), application_dir, strict_));
169 } else {
170 // Loading a raw .dart file pointed at by |url|.
171 return make_scoped_ptr(
172 new DartApp(application_request.Pass(), url, strict_));
157 } 173 }
158
159 return make_scoped_ptr(
160 new DartApp(application_request.Pass(), application_dir, strict_));
161 } 174 }
162 175
163 } // namespace dart 176 } // namespace dart
164 177
165 MojoResult MojoMain(MojoHandle application_request) { 178 MojoResult MojoMain(MojoHandle application_request) {
166 mojo::ApplicationRunnerChromium runner(new dart::DartContentHandlerApp); 179 mojo::ApplicationRunnerChromium runner(new dart::DartContentHandlerApp);
167 MojoResult r = runner.Run(application_request); 180 MojoResult r = runner.Run(application_request);
168 // TODO(johnmccutchan): Remove this once the Dart VM shuts down threads. 181 // TODO(johnmccutchan): Remove this once the Dart VM shuts down threads.
169 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); 182 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
170 return r; 183 return r;
171 } 184 }
OLDNEW
« no previous file with comments | « mojo/tools/get_test_list.py ('k') | services/dart/dart_app.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698