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

Unified Diff: sky/engine/core/script/dart_service_isolate.cc

Issue 1107803002: Add Observatory to sky dart_controller (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 8 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
Index: sky/engine/core/script/dart_service_isolate.cc
diff --git a/mojo/dart/embedder/vmservice.cc b/sky/engine/core/script/dart_service_isolate.cc
similarity index 60%
copy from mojo/dart/embedder/vmservice.cc
copy to sky/engine/core/script/dart_service_isolate.cc
index 51efaf97be78ff4a27d184b6cbbe08934e67b409..b74c5061363d364e48adf0d5cadb762b46c309c0 100644
--- a/mojo/dart/embedder/vmservice.cc
+++ b/sky/engine/core/script/dart_service_isolate.cc
@@ -2,16 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "mojo/dart/embedder/vmservice.h"
+#include "dart_service_isolate.h"
#include "base/logging.h"
#include "dart/runtime/include/dart_api.h"
-#include "mojo/dart/embedder/builtin.h"
-#include "mojo/dart/embedder/common.h"
-#include "mojo/dart/embedder/dart_controller.h"
-
-namespace mojo {
-namespace dart {
+#include "sky/engine/tonic/dart_error.h"
+#include "sky/engine/tonic/dart_string.h"
#define RETURN_ERROR_HANDLE(handle) \
if (Dart_IsError(handle)) { \
@@ -20,14 +16,14 @@ namespace dart {
#define SHUTDOWN_ON_ERROR(handle) \
if (Dart_IsError(handle)) { \
- error_msg_ = strdup(Dart_GetError(handle)); \
+ *error = strdup(Dart_GetError(handle)); \
Dart_ExitScope(); \
Dart_ShutdownIsolate(); \
return false; \
}
-#define kLibrarySourceNamePrefix "/vmservice"
-static const char* kVMServiceIOLibraryScriptResourceName = "main.dart";
+#define kLibrarySourceNamePrefix "/dart_service_isolate"
+static const char* kServiceIsolateScript = "main.dart";
struct ResourcesEntry {
const char* path_;
@@ -35,7 +31,13 @@ struct ResourcesEntry {
int length_;
};
-extern ResourcesEntry __dart_embedder_service_isolate_resources_[];
+namespace mojo {
+ namespace dart {
+ extern ResourcesEntry __sky_embedder_service_isolate_resources_[];
+ }
+}
+
+namespace blink {
class Resources {
public:
@@ -75,102 +77,76 @@ class Resources {
return NULL;
}
static ResourcesEntry* ResourcesTable() {
- return &__dart_embedder_service_isolate_resources_[0];
+ return &mojo::dart::__sky_embedder_service_isolate_resources_[0];
}
};
-void ServiceIsolate_TriggerResourceLoad(Dart_NativeArguments args) {
+void DartServiceIsolate::TriggerResourceLoad(Dart_NativeArguments args) {
Dart_Handle library = Dart_RootLibrary();
DCHECK(!Dart_IsError(library));
- Dart_Handle result = VmService::LoadResources(library);
+ Dart_Handle result = LoadResources(library);
DCHECK(!Dart_IsError(result));
}
-void ServiceIsolate_NotifyServerState(Dart_NativeArguments args) {
- Dart_EnterScope();
- const char* ip_chars;
- Dart_Handle ip_arg = Dart_GetNativeArgument(args, 0);
- if (Dart_IsError(ip_arg)) {
- VmService::SetServerIPAndPort("", 0);
- Dart_ExitScope();
- return;
- }
- Dart_Handle result = Dart_StringToCString(ip_arg, &ip_chars);
- if (Dart_IsError(result)) {
- VmService::SetServerIPAndPort("", 0);
- Dart_ExitScope();
- return;
- }
- Dart_Handle port_arg = Dart_GetNativeArgument(args, 1);
- if (Dart_IsError(port_arg)) {
- VmService::SetServerIPAndPort("", 0);
- Dart_ExitScope();
- return;
- }
- int64_t port = DartEmbedder::GetInt64ValueCheckRange(port_arg, 0, 65535);
- VmService::SetServerIPAndPort(ip_chars, port);
- Dart_ExitScope();
+void DartServiceIsolate::NotifyServerState(Dart_NativeArguments args) {
+ // NO-OP.
}
-void ServiceIsolate_Shutdown(Dart_NativeArguments args) {
- Dart_EnterScope();
- DartController::ShutdownDartMojoIo();
- Dart_ExitScope();
+void DartServiceIsolate::Shutdown(Dart_NativeArguments args) {
+ // NO-OP.
}
-struct VmServiceIONativeEntry {
- const char* name;
- int num_arguments;
- Dart_NativeFunction function;
-};
-
-
-static VmServiceIONativeEntry _VmServiceIONativeEntries[] = {
- {"ServiceIsolate_TriggerResourceLoad", 0, ServiceIsolate_TriggerResourceLoad},
- {"ServiceIsolate_NotifyServerState", 2, ServiceIsolate_NotifyServerState},
- {"ServiceIsolate_Shutdown", 0, ServiceIsolate_Shutdown },
+DartBuiltin::Natives DartServiceIsolate::native_entries_[] = {
+ {"ServiceIsolate_TriggerResourceLoad", TriggerResourceLoad, 0 },
+ {"ServiceIsolate_NotifyServerState", NotifyServerState, 2 },
+ {"ServiceIsolate_Shutdown", Shutdown, 0 },
};
-
-static Dart_NativeFunction VmServiceIONativeResolver(Dart_Handle name,
- int num_arguments,
- bool* auto_setup_scope) {
- const char* function_name = NULL;
- Dart_Handle result = Dart_StringToCString(name, &function_name);
- DCHECK(!Dart_IsError(result));
- DCHECK(function_name != NULL);
- *auto_setup_scope = true;
- intptr_t n =
- sizeof(_VmServiceIONativeEntries) / sizeof(_VmServiceIONativeEntries[0]);
- for (intptr_t i = 0; i < n; i++) {
- VmServiceIONativeEntry entry = _VmServiceIONativeEntries[i];
- if ((strcmp(function_name, entry.name) == 0) &&
- (num_arguments == entry.num_arguments)) {
- return entry.function;
- }
- }
- return NULL;
+Dart_NativeFunction DartServiceIsolate::NativeResolver(Dart_Handle name,
+ int argument_count,
+ bool* auto_setup_scope) {
+ CHECK(builtins_);
+ return builtins_->Resolver(name, argument_count, auto_setup_scope);
}
+const uint8_t* DartServiceIsolate::NativeSymbolizer(
+ Dart_NativeFunction native_function) {
+ CHECK(builtins_);
+ return builtins_->Symbolizer(native_function);
+}
-const char* VmService::error_msg_ = NULL;
-char VmService::server_ip_[kServerIpStringBufferSize];
-intptr_t VmService::server_port_ = 0;
+Dart_LibraryTagHandler DartServiceIsolate::embedder_tag_handler_ = nullptr;
+DartBuiltin* DartServiceIsolate::builtins_ = nullptr;
-bool VmService::Setup(const char* server_ip, intptr_t server_port) {
+bool DartServiceIsolate::Startup(std::string server_ip,
+ intptr_t server_port,
+ Dart_LibraryTagHandler embedder_tag_handler,
+ char** error) {
Dart_Isolate isolate = Dart_CurrentIsolate();
- DCHECK(isolate != NULL);
- SetServerIPAndPort("", 0);
+ CHECK(isolate);
+
+ // Remember the embedder's library tag handler.
+ embedder_tag_handler_ = embedder_tag_handler;
+ CHECK(embedder_tag_handler_);
+
+ // Setup native entries.
+ builtins_ =
+ new DartBuiltin(&DartServiceIsolate::native_entries_[0],
+ sizeof(native_entries_) / sizeof(native_entries_[0]));
eseidel 2015/04/27 17:38:37 I thought we had a macro in base for this?
Cutch 2015/05/05 22:07:23 Done.
Dart_Handle result;
+ // Use our own library tag handler when loading service isolate sources.
+ Dart_SetLibraryTagHandler(DartServiceIsolate::LibraryTagHandler);
// Load main script.
- Dart_SetLibraryTagHandler(VmService::LibraryTagHandler);
- Dart_Handle library = LoadScript(kVMServiceIOLibraryScriptResourceName);
+ Dart_Handle library = LoadScript(kServiceIsolateScript);
DCHECK(library != Dart_Null());
SHUTDOWN_ON_ERROR(library);
- result = Dart_SetNativeResolver(library, VmServiceIONativeResolver, NULL);
+ // Setup native entry resolution.
+ result = Dart_SetNativeResolver(library, NativeResolver, NativeSymbolizer);
+
SHUTDOWN_ON_ERROR(result);
+ // Finalize loading.
result = Dart_FinalizeLoading(false);
SHUTDOWN_ON_ERROR(result);
@@ -181,7 +157,7 @@ bool VmService::Setup(const char* server_ip, intptr_t server_port) {
if (!retval) {
Dart_EnterIsolate(isolate);
Dart_ShutdownIsolate();
- error_msg_ = "Invalid isolate state - Unable to make it runnable.";
+ *error = strdup("Invalid isolate state - Unable to make it runnable.");
return false;
}
Dart_EnterIsolate(isolate);
@@ -190,8 +166,11 @@ bool VmService::Setup(const char* server_ip, intptr_t server_port) {
library = Dart_RootLibrary();
SHUTDOWN_ON_ERROR(library);
- // Set HTTP server state.
- DartEmbedder::SetStringField(library, "_ip", server_ip);
+ // Set the HTTP server's ip.
+ result = Dart_SetField(library,
+ Dart_NewStringFromCString("_ip"),
+ Dart_NewStringFromCString(server_ip.c_str()));
+ SHUTDOWN_ON_ERROR(result);
// If we have a port specified, start the server immediately.
bool auto_start = server_port >= 0;
if (server_port < 0) {
@@ -199,31 +178,19 @@ bool VmService::Setup(const char* server_ip, intptr_t server_port) {
// port when the HTTP server is started.
server_port = 0;
}
- DartEmbedder::SetIntegerField(library, "_port", server_port);
+ // Set the HTTP's servers port.
result = Dart_SetField(library,
- DartEmbedder::NewCString("_autoStart"),
+ Dart_NewStringFromCString("_port"),
+ Dart_NewInteger(server_port));
+ SHUTDOWN_ON_ERROR(result);
+ result = Dart_SetField(library,
+ Dart_NewStringFromCString("_autoStart"),
Dart_NewBoolean(auto_start));
SHUTDOWN_ON_ERROR(result);
return true;
}
-
-const char* VmService::GetErrorMessage() {
- return error_msg_ == NULL ? "No error." : error_msg_;
-}
-
-
-void VmService::SetServerIPAndPort(const char* ip, intptr_t port) {
- if (ip == NULL) {
- ip = "";
- }
- strncpy(server_ip_, ip, kServerIpStringBufferSize);
- server_ip_[kServerIpStringBufferSize - 1] = '\0';
- server_port_ = port;
-}
-
-
-Dart_Handle VmService::GetSource(const char* name) {
+Dart_Handle DartServiceIsolate::GetSource(const char* name) {
const intptr_t kBufferSize = 512;
char buffer[kBufferSize];
snprintf(&buffer[0], kBufferSize-1, "%s/%s", kLibrarySourceNamePrefix, name);
@@ -233,22 +200,19 @@ Dart_Handle VmService::GetSource(const char* name) {
return Dart_NewStringFromCString(vmservice_source);
}
-
-Dart_Handle VmService::LoadScript(const char* name) {
- Dart_Handle url = Dart_NewStringFromCString("dart:vmservice_io");
+Dart_Handle DartServiceIsolate::LoadScript(const char* name) {
+ Dart_Handle url = Dart_NewStringFromCString("dart:vmservice_sky");
Dart_Handle source = GetSource(name);
return Dart_LoadScript(url, source, 0, 0);
}
-
-Dart_Handle VmService::LoadSource(Dart_Handle library, const char* name) {
+Dart_Handle DartServiceIsolate::LoadSource(Dart_Handle library, const char* name) {
Dart_Handle url = Dart_NewStringFromCString(name);
Dart_Handle source = GetSource(name);
return Dart_LoadSource(library, url, source, 0, 0);
}
-
-Dart_Handle VmService::LoadResource(Dart_Handle library,
+Dart_Handle DartServiceIsolate::LoadResource(Dart_Handle library,
const char* resource_name) {
// Prepare for invoke call.
Dart_Handle name = Dart_NewStringFromCString(resource_name);
@@ -282,8 +246,7 @@ Dart_Handle VmService::LoadResource(Dart_Handle library,
return result;
}
-
-Dart_Handle VmService::LoadResources(Dart_Handle library) {
+Dart_Handle DartServiceIsolate::LoadResources(Dart_Handle library) {
Dart_Handle result = Dart_Null();
intptr_t prefixLen = strlen(kLibrarySourceNamePrefix);
for (intptr_t i = 0; Resources::Path(i) != NULL; i++) {
@@ -300,8 +263,7 @@ Dart_Handle VmService::LoadResources(Dart_Handle library) {
return result;
}
-
-Dart_Handle VmService::LibraryTagHandler(Dart_LibraryTag tag,
+Dart_Handle DartServiceIsolate::LibraryTagHandler(Dart_LibraryTag tag,
Dart_Handle library,
Dart_Handle url) {
if (!Dart_IsLibrary(library)) {
@@ -323,13 +285,14 @@ Dart_Handle VmService::LibraryTagHandler(Dart_LibraryTag tag,
}
if (tag == Dart_kImportTag) {
// Embedder handles all requests for external libraries.
- return DartController::LibraryTagHandler(tag, library, url);
+ return embedder_tag_handler_(tag, library, url);
}
DCHECK((tag == Dart_kSourceTag) || (tag == Dart_kCanonicalizeUrl));
if (tag == Dart_kCanonicalizeUrl) {
// url is already canonicalized.
return url;
}
+ // Get source from builtin resources.
Dart_Handle source = GetSource(url_string);
if (Dart_IsError(source)) {
return source;
@@ -338,5 +301,4 @@ Dart_Handle VmService::LibraryTagHandler(Dart_LibraryTag tag,
}
-} // namespace dart
-} // namespace mojo
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698