| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 base::MessageLoop::current()->task_runner()); | 345 base::MessageLoop::current()->task_runner()); |
| 346 // Install message notify callback. | 346 // Install message notify callback. |
| 347 Dart_SetMessageNotifyCallback(MessageNotifyCallback); | 347 Dart_SetMessageNotifyCallback(MessageNotifyCallback); |
| 348 isolate_data->set_message_notify_callback(MessageNotifyCallback); | 348 isolate_data->set_message_notify_callback(MessageNotifyCallback); |
| 349 } | 349 } |
| 350 | 350 |
| 351 // The VM is creating the service isolate. | 351 // The VM is creating the service isolate. |
| 352 if (Dart_IsServiceIsolate(isolate)) { | 352 if (Dart_IsServiceIsolate(isolate)) { |
| 353 service_isolate_spawned_ = true; | 353 service_isolate_spawned_ = true; |
| 354 const intptr_t port = | 354 const intptr_t port = |
| 355 (SupportDartMojoIo() && observatory_enabled_) ? 0 : -1; | 355 (SupportDartMojoIo() && enable_observatory_) ? 0 : -1; |
| 356 InitializeDartMojoIo(); | 356 InitializeDartMojoIo(); |
| 357 if (!VmService::Setup("127.0.0.1", port)) { | 357 if (!VmService::Setup("127.0.0.1", port)) { |
| 358 *error = strdup(VmService::GetErrorMessage()); | 358 *error = strdup(VmService::GetErrorMessage()); |
| 359 return nullptr; | 359 return nullptr; |
| 360 } | 360 } |
| 361 return isolate; | 361 return isolate; |
| 362 } | 362 } |
| 363 | 363 |
| 364 tonic::DartScriptLoaderSync::LoadScript( | 364 tonic::DartScriptLoaderSync::LoadScript( |
| 365 script_uri, | 365 script_uri, |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 delete isolate_data; | 506 delete isolate_data; |
| 507 } | 507 } |
| 508 | 508 |
| 509 | 509 |
| 510 bool DartController::initialized_ = false; | 510 bool DartController::initialized_ = false; |
| 511 MojoHandle DartController::handle_watcher_producer_handle_ = | 511 MojoHandle DartController::handle_watcher_producer_handle_ = |
| 512 MOJO_HANDLE_INVALID; | 512 MOJO_HANDLE_INVALID; |
| 513 bool DartController::service_isolate_running_ = false; | 513 bool DartController::service_isolate_running_ = false; |
| 514 bool DartController::service_isolate_spawned_ = false; | 514 bool DartController::service_isolate_spawned_ = false; |
| 515 bool DartController::strict_compilation_ = false; | 515 bool DartController::strict_compilation_ = false; |
| 516 bool DartController::observatory_enabled_ = true; | 516 bool DartController::enable_observatory_ = true; |
| 517 DartControllerServiceConnector* DartController::service_connector_ = nullptr; | 517 DartControllerServiceConnector* DartController::service_connector_ = nullptr; |
| 518 base::Lock DartController::lock_; | 518 base::Lock DartController::lock_; |
| 519 | 519 |
| 520 bool DartController::SupportDartMojoIo() { | 520 bool DartController::SupportDartMojoIo() { |
| 521 return service_connector_ != nullptr; | 521 return service_connector_ != nullptr; |
| 522 } | 522 } |
| 523 | 523 |
| 524 void DartController::InitializeDartMojoIo() { | 524 void DartController::InitializeDartMojoIo() { |
| 525 Dart_Isolate current_isolate = Dart_CurrentIsolate(); | 525 Dart_Isolate current_isolate = Dart_CurrentIsolate(); |
| 526 CHECK(current_isolate != nullptr); | 526 CHECK(current_isolate != nullptr); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 return array; | 608 return array; |
| 609 } | 609 } |
| 610 | 610 |
| 611 static Dart_Handle GetVMServiceAssetsArchiveCallback() { | 611 static Dart_Handle GetVMServiceAssetsArchiveCallback() { |
| 612 return MakeUint8Array( | 612 return MakeUint8Array( |
| 613 ::dart::observatory::observatory_assets_archive, | 613 ::dart::observatory::observatory_assets_archive, |
| 614 ::dart::observatory::observatory_assets_archive_len); | 614 ::dart::observatory::observatory_assets_archive_len); |
| 615 } | 615 } |
| 616 | 616 |
| 617 void DartController::InitVmIfNeeded(Dart_EntropySource entropy, | 617 void DartController::InitVmIfNeeded(Dart_EntropySource entropy, |
| 618 bool enable_dart_timeline, |
| 618 const char** vm_flags, | 619 const char** vm_flags, |
| 619 int vm_flags_count) { | 620 int vm_flags_count) { |
| 620 base::AutoLock al(lock_); | 621 base::AutoLock al(lock_); |
| 621 if (initialized_) { | 622 if (initialized_) { |
| 622 return; | 623 return; |
| 623 } | 624 } |
| 624 | 625 |
| 625 // Start a handle watcher. | 626 // Start a handle watcher. |
| 626 handle_watcher_producer_handle_ = HandleWatcher::Start(); | 627 handle_watcher_producer_handle_ = HandleWatcher::Start(); |
| 627 | 628 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 657 IsolateCreateCallback, | 658 IsolateCreateCallback, |
| 658 nullptr, // Deprecated isolate interrupt callback. Must pass nullptr. | 659 nullptr, // Deprecated isolate interrupt callback. Must pass nullptr. |
| 659 nullptr, // Deprecated unhandled exception callback. Must pass nullptr. | 660 nullptr, // Deprecated unhandled exception callback. Must pass nullptr. |
| 660 IsolateShutdownCallback, | 661 IsolateShutdownCallback, |
| 661 // File IO callbacks. | 662 // File IO callbacks. |
| 662 nullptr, nullptr, nullptr, nullptr, | 663 nullptr, nullptr, nullptr, nullptr, |
| 663 entropy, | 664 entropy, |
| 664 GetVMServiceAssetsArchiveCallback); | 665 GetVMServiceAssetsArchiveCallback); |
| 665 CHECK(error == nullptr); | 666 CHECK(error == nullptr); |
| 666 initialized_ = true; | 667 initialized_ = true; |
| 668 if (enable_dart_timeline) { |
| 669 Dart_GlobalTimelineSetRecordedStreams(DART_TIMELINE_STREAM_DART); |
| 670 } |
| 667 } | 671 } |
| 668 | 672 |
| 669 void DartController::BlockForServiceIsolate() { | 673 void DartController::BlockForServiceIsolate() { |
| 670 base::AutoLock al(lock_); | 674 base::AutoLock al(lock_); |
| 671 BlockForServiceIsolateLocked(); | 675 BlockForServiceIsolateLocked(); |
| 672 } | 676 } |
| 673 | 677 |
| 674 void DartController::BlockForServiceIsolateLocked() { | 678 void DartController::BlockForServiceIsolateLocked() { |
| 675 if (service_isolate_running_) { | 679 if (service_isolate_running_) { |
| 676 return; | 680 return; |
| 677 } | 681 } |
| 678 // By waiting for the load port, we ensure that the service isolate is fully | 682 // By waiting for the load port, we ensure that the service isolate is fully |
| 679 // running before returning. | 683 // running before returning. |
| 680 Dart_ServiceWaitForLoadPort(); | 684 Dart_ServiceWaitForLoadPort(); |
| 681 service_isolate_running_ = true; | 685 service_isolate_running_ = true; |
| 682 } | 686 } |
| 683 | 687 |
| 684 static bool GenerateEntropy(uint8_t* buffer, intptr_t length) { | 688 static bool GenerateEntropy(uint8_t* buffer, intptr_t length) { |
| 685 base::RandBytes(reinterpret_cast<void*>(buffer), length); | 689 base::RandBytes(reinterpret_cast<void*>(buffer), length); |
| 686 return true; | 690 return true; |
| 687 } | 691 } |
| 688 | 692 |
| 689 bool DartController::Initialize( | 693 bool DartController::Initialize( |
| 690 DartControllerServiceConnector* service_connector, | 694 DartControllerServiceConnector* service_connector, |
| 691 bool strict_compilation, | 695 bool strict_compilation, |
| 692 bool observatory_enabled, | 696 bool enable_observatory, |
| 697 bool enable_dart_timeline, |
| 693 const char** extra_args, | 698 const char** extra_args, |
| 694 int extra_args_count) { | 699 int extra_args_count) { |
| 695 service_connector_ = service_connector; | 700 service_connector_ = service_connector; |
| 696 observatory_enabled_ = observatory_enabled; | 701 enable_observatory_ = enable_observatory; |
| 697 strict_compilation_ = strict_compilation; | 702 strict_compilation_ = strict_compilation; |
| 698 InitVmIfNeeded(GenerateEntropy, extra_args, extra_args_count); | 703 InitVmIfNeeded(GenerateEntropy, |
| 704 enable_dart_timeline, |
| 705 extra_args, |
| 706 extra_args_count); |
| 699 return true; | 707 return true; |
| 700 } | 708 } |
| 701 | 709 |
| 702 bool DartController::RunToCompletion(Dart_Isolate isolate) { | 710 bool DartController::RunToCompletion(Dart_Isolate isolate) { |
| 703 return !RunIsolate(isolate); | 711 return !RunIsolate(isolate); |
| 704 } | 712 } |
| 705 | 713 |
| 706 void DartController::SetIsolateFlags(Dart_IsolateFlags* flags, | 714 void DartController::SetIsolateFlags(Dart_IsolateFlags* flags, |
| 707 bool strict_compilation) { | 715 bool strict_compilation) { |
| 708 flags->version = DART_FLAGS_CURRENT_VERSION; | 716 flags->version = DART_FLAGS_CURRENT_VERSION; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 } | 757 } |
| 750 BlockForServiceIsolateLocked(); | 758 BlockForServiceIsolateLocked(); |
| 751 HandleWatcher::StopAll(); | 759 HandleWatcher::StopAll(); |
| 752 Dart_Cleanup(); | 760 Dart_Cleanup(); |
| 753 service_isolate_running_ = false; | 761 service_isolate_running_ = false; |
| 754 initialized_ = false; | 762 initialized_ = false; |
| 755 } | 763 } |
| 756 | 764 |
| 757 } // namespace apps | 765 } // namespace apps |
| 758 } // namespace mojo | 766 } // namespace mojo |
| OLD | NEW |