| 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 SKY_ENGINE_CORE_SCRIPT_DART_LOADER_H_ | 5 #ifndef SKY_ENGINE_TONIC_DART_LIBRARY_LOADER_H_ |
| 6 #define SKY_ENGINE_CORE_SCRIPT_DART_LOADER_H_ | 6 #define SKY_ENGINE_TONIC_DART_LIBRARY_LOADER_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "dart/runtime/include/dart_api.h" | 11 #include "dart/runtime/include/dart_api.h" |
| 12 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" | |
| 13 #include "sky/engine/wtf/HashMap.h" | 12 #include "sky/engine/wtf/HashMap.h" |
| 14 #include "sky/engine/wtf/HashSet.h" | 13 #include "sky/engine/wtf/HashSet.h" |
| 15 #include "sky/engine/wtf/OwnPtr.h" | 14 #include "sky/engine/wtf/OwnPtr.h" |
| 16 #include "sky/engine/wtf/Vector.h" | 15 #include "sky/engine/wtf/Vector.h" |
| 17 #include "sky/engine/wtf/text/WTFString.h" | 16 #include "sky/engine/wtf/text/WTFString.h" |
| 18 | 17 |
| 19 namespace blink { | 18 namespace blink { |
| 20 class DartState; | |
| 21 class DartDependency; | 19 class DartDependency; |
| 22 class DartDependencyCatcher; | 20 class DartDependencyCatcher; |
| 23 class KURL; | 21 class DartLibraryProvider; |
| 22 class DartState; |
| 24 | 23 |
| 25 // TODO(abarth): This class seems more complicated than it needs to be. Is | 24 // TODO(abarth): This class seems more complicated than it needs to be. Is |
| 26 // there some way of simplifying this system? For example, we have a bunch | 25 // there some way of simplifying this system? For example, we have a bunch |
| 27 // of inner classes that could potentially be factored out in some other way. | 26 // of inner classes that could potentially be factored out in some other way. |
| 28 class DartLoader { | 27 class DartLibraryLoader { |
| 29 public: | 28 public: |
| 30 explicit DartLoader(DartState* dart_state); | 29 explicit DartLibraryLoader(DartState* dart_state); |
| 31 ~DartLoader(); | 30 ~DartLibraryLoader(); |
| 32 | 31 |
| 33 // TODO(dart): This can be called both on the main thread from application iso
lates | 32 // TODO(dart): This can be called both on the main thread from application |
| 34 // or from the handle watcher isolate thread. | 33 // solates or from the handle watcher isolate thread. |
| 35 static Dart_Handle HandleLibraryTag(Dart_LibraryTag tag, | 34 static Dart_Handle HandleLibraryTag(Dart_LibraryTag tag, |
| 36 Dart_Handle library, | 35 Dart_Handle library, |
| 37 Dart_Handle url); | 36 Dart_Handle url); |
| 38 | 37 |
| 39 void LoadLibrary(const KURL& url, mojo::URLResponsePtr response = nullptr); | 38 void LoadLibrary(const String& name); |
| 40 | 39 |
| 41 void WaitForDependencies(const HashSet<DartDependency*>& dependencies, | 40 void WaitForDependencies(const HashSet<DartDependency*>& dependencies, |
| 42 const base::Closure& callback); | 41 const base::Closure& callback); |
| 43 | 42 |
| 44 void set_dependency_catcher(DartDependencyCatcher* dependency_catcher) { | 43 void set_dependency_catcher(DartDependencyCatcher* dependency_catcher) { |
| 45 DCHECK(!dependency_catcher_ || !dependency_catcher); | 44 DCHECK(!dependency_catcher_ || !dependency_catcher); |
| 46 dependency_catcher_ = dependency_catcher; | 45 dependency_catcher_ = dependency_catcher; |
| 47 } | 46 } |
| 48 | 47 |
| 49 DartState* dart_state() const { return dart_state_.get(); } | 48 DartState* dart_state() const { return dart_state_; } |
| 49 |
| 50 DartLibraryProvider* library_provider() const { return library_provider_; } |
| 51 |
| 52 // The |DartLibraryProvider| must outlive the |DartLibraryLoader|. |
| 53 void set_library_provider(DartLibraryProvider* library_provider) { |
| 54 library_provider_ = library_provider; |
| 55 } |
| 50 | 56 |
| 51 private: | 57 private: |
| 52 class Job; | 58 class Job; |
| 53 class ImportJob; | 59 class ImportJob; |
| 54 class SourceJob; | 60 class SourceJob; |
| 55 class DependencyWatcher; | 61 class DependencyWatcher; |
| 56 class WatcherSignaler; | 62 class WatcherSignaler; |
| 57 | 63 |
| 58 Dart_Handle Import(Dart_Handle library, Dart_Handle url); | 64 Dart_Handle Import(Dart_Handle library, Dart_Handle url); |
| 59 Dart_Handle Source(Dart_Handle library, Dart_Handle url); | 65 Dart_Handle Source(Dart_Handle library, Dart_Handle url); |
| 66 Dart_Handle CanonicalizeURL(Dart_Handle library, Dart_Handle url); |
| 60 void DidCompleteImportJob(ImportJob* job, const Vector<uint8_t>& buffer); | 67 void DidCompleteImportJob(ImportJob* job, const Vector<uint8_t>& buffer); |
| 61 void DidCompleteSourceJob(SourceJob* job, const Vector<uint8_t>& buffer); | 68 void DidCompleteSourceJob(SourceJob* job, const Vector<uint8_t>& buffer); |
| 62 void DidFailJob(Job* job); | 69 void DidFailJob(Job* job); |
| 63 | 70 |
| 64 base::WeakPtr<DartState> dart_state_; | 71 DartState* dart_state_; |
| 72 DartLibraryProvider* library_provider_; |
| 65 HashMap<String, Job*> pending_libraries_; | 73 HashMap<String, Job*> pending_libraries_; |
| 66 HashSet<OwnPtr<Job>> jobs_; | 74 HashSet<OwnPtr<Job>> jobs_; |
| 67 HashSet<OwnPtr<DependencyWatcher>> dependency_watchers_; | 75 HashSet<OwnPtr<DependencyWatcher>> dependency_watchers_; |
| 68 DartDependencyCatcher* dependency_catcher_; | 76 DartDependencyCatcher* dependency_catcher_; |
| 69 | 77 |
| 70 DISALLOW_COPY_AND_ASSIGN(DartLoader); | 78 DISALLOW_COPY_AND_ASSIGN(DartLibraryLoader); |
| 71 }; | 79 }; |
| 72 | 80 |
| 73 } // namespace blink | 81 } // namespace blink |
| 74 | 82 |
| 75 #endif // SKY_ENGINE_CORE_SCRIPT_DART_LOADER_H_ | 83 #endif // SKY_ENGINE_TONIC_DART_LIBRARY_LOADER_H_ |
| OLD | NEW |