OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef SKY_ENGINE_TONIC_DART_STATE_H_ |
| 6 #define SKY_ENGINE_TONIC_DART_STATE_H_ |
| 7 |
| 8 #include "base/logging.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/supports_user_data.h" |
| 11 #include "dart/runtime/include/dart_api.h" |
| 12 #include "tonic/dart_api_scope.h" |
| 13 #include "tonic/dart_isolate_scope.h" |
| 14 #include "tonic/dart_persistent_value.h" |
| 15 |
| 16 namespace blink { |
| 17 class DartClassLibrary; |
| 18 class DartExceptionFactory; |
| 19 class DartLibraryLoader; |
| 20 class DartStringCache; |
| 21 class DartTimerHeap; |
| 22 |
| 23 // DartState represents the state associated with a given Dart isolate. The |
| 24 // lifetime of this object is controlled by the DartVM. If you want to hold a |
| 25 // reference to a DartState instance, please hold a base::WeakPtr<DartState>. |
| 26 // |
| 27 // DartState is analogous to gin::PerIsolateData and JSC::ExecState. |
| 28 class DartState : public base::SupportsUserData { |
| 29 public: |
| 30 class Scope { |
| 31 public: |
| 32 Scope(DartState* dart_state); |
| 33 ~Scope(); |
| 34 |
| 35 private: |
| 36 DartIsolateScope scope_; |
| 37 DartApiScope api_scope_; |
| 38 }; |
| 39 |
| 40 DartState(); |
| 41 virtual ~DartState(); |
| 42 |
| 43 static DartState* From(Dart_Isolate isolate); |
| 44 static DartState* Current(); |
| 45 |
| 46 base::WeakPtr<DartState> GetWeakPtr(); |
| 47 |
| 48 Dart_Isolate isolate() { return isolate_; } |
| 49 void SetIsolate(Dart_Isolate isolate); |
| 50 |
| 51 DartClassLibrary& class_library() { return *class_library_; } |
| 52 DartExceptionFactory& exception_factory() { return *exception_factory_; } |
| 53 DartLibraryLoader& library_loader() { return *library_loader_; } |
| 54 DartStringCache& string_cache() { return *string_cache_; } |
| 55 DartTimerHeap& timer_heap() { return *timer_heap_; } |
| 56 |
| 57 Dart_Handle index_handle() { return index_handle_.value(); } |
| 58 |
| 59 virtual void DidSetIsolate() {} |
| 60 |
| 61 private: |
| 62 Dart_Isolate isolate_; |
| 63 std::unique_ptr<DartClassLibrary> class_library_; |
| 64 std::unique_ptr<DartExceptionFactory> exception_factory_; |
| 65 std::unique_ptr<DartLibraryLoader> library_loader_; |
| 66 std::unique_ptr<DartStringCache> string_cache_; |
| 67 std::unique_ptr<DartTimerHeap> timer_heap_; |
| 68 DartPersistentValue index_handle_; |
| 69 |
| 70 protected: |
| 71 base::WeakPtrFactory<DartState> weak_factory_; |
| 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(DartState); |
| 74 }; |
| 75 |
| 76 } // namespace blink |
| 77 |
| 78 #endif // SKY_ENGINE_TONIC_DART_STATE_H_ |
OLD | NEW |