| OLD | NEW |
| 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 "services/dart/dart_app.h" | 5 #include "services/dart/dart_app.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "mojo/common/data_pipe_utils.h" | 13 #include "mojo/common/data_pipe_utils.h" |
| 14 #include "mojo/dart/embedder/dart_controller.h" | 14 #include "mojo/dart/embedder/dart_controller.h" |
| 15 #include "mojo/dart/embedder/mojo_dart_state.h" | 15 #include "mojo/dart/embedder/mojo_dart_state.h" |
| 16 #include "mojo/public/cpp/bindings/interface_request.h" | 16 #include "mojo/public/cpp/bindings/interface_request.h" |
| 17 #include "third_party/zlib/google/zip_reader.h" | 17 #include "third_party/zlib/google/zip_reader.h" |
| 18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 19 | 19 |
| 20 using mojo::Application; | 20 using mojo::Application; |
| 21 | 21 |
| 22 namespace dart { | 22 namespace dart { |
| 23 | 23 |
| 24 DartApp::DartApp(mojo::InterfaceRequest<Application> application_request, | 24 DartApp::DartApp(mojo::InterfaceRequest<Application> application_request, |
| 25 const base::FilePath& application_dir, | 25 const base::FilePath& application_dir, |
| 26 bool strict) | 26 bool strict) |
| 27 : application_request_(application_request.Pass()), | 27 : application_request_(application_request.Pass()), |
| 28 application_dir_(application_dir) { | 28 application_dir_(application_dir) { |
| 29 base::FilePath package_root = application_dir_.AppendASCII("packages"); | |
| 30 base::FilePath entry_path = application_dir_.Append("lib") | |
| 31 .Append("main.dart"); | |
| 32 base::FilePath snapshot_path = application_dir_.Append("snapshot_blob.bin"); | 29 base::FilePath snapshot_path = application_dir_.Append("snapshot_blob.bin"); |
| 33 | 30 |
| 34 // Look for snapshot_blob.bin. If exists, then load from snapshot. | 31 // Look for snapshot_blob.bin. If exists, then load from snapshot. |
| 35 if (base::PathExists(snapshot_path)) { | 32 if (base::PathExists(snapshot_path)) { |
| 36 config_.script_uri = snapshot_path.AsUTF8Unsafe(); | 33 config_.script_uri = snapshot_path.AsUTF8Unsafe(); |
| 37 config_.package_root = ""; | 34 config_.package_root = ""; |
| 38 } else if (base::PathExists(entry_path)) { | |
| 39 config_.script_uri = entry_path.AsUTF8Unsafe(); | |
| 40 config_.package_root = package_root.AsUTF8Unsafe(); | |
| 41 } else { | 35 } else { |
| 42 LOG(ERROR) << "Dart entry point could not be found under: " | 36 LOG(ERROR) << "Dart entry point could not be found under: " |
| 43 << application_dir_.AsUTF8Unsafe(); | 37 << application_dir_.AsUTF8Unsafe(); |
| 44 base::MessageLoop::current()->QuitWhenIdle(); | 38 base::MessageLoop::current()->QuitWhenIdle(); |
| 45 } | 39 } |
| 46 | 40 |
| 47 config_.application_data = reinterpret_cast<void*>(this); | 41 config_.application_data = reinterpret_cast<void*>(this); |
| 48 config_.strict_compilation = strict; | 42 config_.strict_compilation = strict; |
| 49 config_.SetVmFlags(nullptr, 0); | 43 config_.SetVmFlags(nullptr, 0); |
| 50 | 44 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 config_.error = &error; | 110 config_.error = &error; |
| 117 bool success = mojo::dart::DartController::RunDartScript(config_); | 111 bool success = mojo::dart::DartController::RunDartScript(config_); |
| 118 if (!success) { | 112 if (!success) { |
| 119 LOG(ERROR) << error; | 113 LOG(ERROR) << error; |
| 120 free(error); | 114 free(error); |
| 121 } | 115 } |
| 122 base::MessageLoop::current()->QuitWhenIdle(); | 116 base::MessageLoop::current()->QuitWhenIdle(); |
| 123 } | 117 } |
| 124 | 118 |
| 125 } // namespace dart | 119 } // namespace dart |
| OLD | NEW |