| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef MOJO_DART_EMBEDDER_DART_STATE_H_ | 5 #ifndef MOJO_DART_EMBEDDER_DART_STATE_H_ |
| 6 #define MOJO_DART_EMBEDDER_DART_STATE_H_ | 6 #define MOJO_DART_EMBEDDER_DART_STATE_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "mojo/public/c/system/types.h" | 12 #include "mojo/public/c/system/types.h" |
| 13 #include "mojo/public/cpp/system/message_pipe.h" | 13 #include "mojo/public/cpp/system/message_pipe.h" |
| 14 #include "mojo/services/network/interfaces/network_service.mojom.h" | 14 #include "mojo/services/network/interfaces/network_service.mojom.h" |
| 15 #include "tonic/dart_library_provider.h" | 15 #include "tonic/dart_library_provider.h" |
| 16 #include "tonic/dart_state.h" | 16 #include "tonic/dart_state.h" |
| 17 | 17 |
| 18 namespace mojo { | 18 namespace mojo { |
| 19 namespace dart { | 19 namespace dart { |
| 20 | 20 |
| 21 struct IsolateCallbacks { | 21 struct IsolateCallbacks { |
| 22 base::Callback<void(Dart_Handle)> exception; | 22 base::Callback<void(Dart_Handle, int64_t)> exception; |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 // State associated with an isolate (retrieved via |Dart_CurrentIsolateData|). | 25 // State associated with an isolate (retrieved via |Dart_CurrentIsolateData|). |
| 26 class MojoDartState : public tonic::DartState { | 26 class MojoDartState : public tonic::DartState { |
| 27 public: | 27 public: |
| 28 MojoDartState(void* application_data, | 28 MojoDartState(void* application_data, |
| 29 bool strict_compilation, | 29 bool strict_compilation, |
| 30 IsolateCallbacks callbacks, | 30 IsolateCallbacks callbacks, |
| 31 std::string script_uri, | 31 std::string script_uri, |
| 32 std::string package_root) | 32 std::string package_root) |
| 33 : application_data_(application_data), | 33 : application_data_(application_data), |
| 34 strict_compilation_(strict_compilation), | 34 strict_compilation_(strict_compilation), |
| 35 callbacks_(callbacks), | 35 callbacks_(callbacks), |
| 36 script_uri_(script_uri), | 36 script_uri_(script_uri), |
| 37 package_root_(package_root), | 37 package_root_(package_root), |
| 38 library_provider_(nullptr) { | 38 library_provider_(nullptr) { |
| 39 } | 39 } |
| 40 | 40 |
| 41 void* application_data() const { return application_data_; } | 41 void* application_data() const { return application_data_; } |
| 42 bool strict_compilation() const { return strict_compilation_; } | 42 bool strict_compilation() const { return strict_compilation_; } |
| 43 const IsolateCallbacks& callbacks() const { return callbacks_; } | 43 const IsolateCallbacks& callbacks() const { return callbacks_; } |
| 44 const std::string& script_uri() const { return script_uri_; } | 44 const std::string& script_uri() const { return script_uri_; } |
| 45 const std::string& package_root() const { return package_root_; } | 45 const std::string& package_root() const { return package_root_; } |
| 46 std::set<MojoHandle>& unclosed_handles() { | |
| 47 return unclosed_handles_; | |
| 48 } | |
| 49 | |
| 50 const std::set<MojoHandle>& unclosed_handles() const { | |
| 51 return unclosed_handles_; | |
| 52 } | |
| 53 | |
| 54 | 46 |
| 55 void set_library_provider(tonic::DartLibraryProvider* library_provider) { | 47 void set_library_provider(tonic::DartLibraryProvider* library_provider) { |
| 56 library_provider_.reset(library_provider); | 48 library_provider_.reset(library_provider); |
| 57 DCHECK(library_provider_.get() == library_provider); | 49 DCHECK(library_provider_.get() == library_provider); |
| 58 } | 50 } |
| 59 | 51 |
| 60 // Takes ownership of |raw_handle|. | 52 // Takes ownership of |raw_handle|. |
| 61 void BindNetworkService(MojoHandle raw_handle) { | 53 void BindNetworkService(MojoHandle raw_handle) { |
| 62 if (raw_handle == MOJO_HANDLE_INVALID) { | 54 if (raw_handle == MOJO_HANDLE_INVALID) { |
| 63 return; | 55 return; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 92 static MojoDartState* Cast(void* data) { | 84 static MojoDartState* Cast(void* data) { |
| 93 return reinterpret_cast<MojoDartState*>(data); | 85 return reinterpret_cast<MojoDartState*>(data); |
| 94 } | 86 } |
| 95 | 87 |
| 96 private: | 88 private: |
| 97 void* application_data_; | 89 void* application_data_; |
| 98 bool strict_compilation_; | 90 bool strict_compilation_; |
| 99 IsolateCallbacks callbacks_; | 91 IsolateCallbacks callbacks_; |
| 100 std::string script_uri_; | 92 std::string script_uri_; |
| 101 std::string package_root_; | 93 std::string package_root_; |
| 102 std::set<MojoHandle> unclosed_handles_; | |
| 103 std::unique_ptr<tonic::DartLibraryProvider> library_provider_; | 94 std::unique_ptr<tonic::DartLibraryProvider> library_provider_; |
| 104 mojo::NetworkServicePtr network_service_; | 95 mojo::NetworkServicePtr network_service_; |
| 105 }; | 96 }; |
| 106 | 97 |
| 107 } // namespace dart | 98 } // namespace dart |
| 108 } // namespace mojo | 99 } // namespace mojo |
| 109 | 100 |
| 110 #endif // MOJO_DART_EMBEDDER_DART_STATE_H_ | 101 #endif // MOJO_DART_EMBEDDER_DART_STATE_H_ |
| OLD | NEW |