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_LIBRARY_LOADER_H_ |
| 6 #define SKY_ENGINE_TONIC_DART_LIBRARY_LOADER_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 #include <unordered_map> |
| 11 #include <unordered_set> |
| 12 #include <vector> |
| 13 |
| 14 #include "base/callback_forward.h" |
| 15 #include "base/macros.h" |
| 16 #include "base/memory/weak_ptr.h" |
| 17 #include "dart/runtime/include/dart_api.h" |
| 18 |
| 19 namespace blink { |
| 20 class DartDependency; |
| 21 class DartDependencyCatcher; |
| 22 class DartLibraryProvider; |
| 23 class DartState; |
| 24 |
| 25 // 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 |
| 27 // of inner classes that could potentially be factored out in some other way. |
| 28 class DartLibraryLoader { |
| 29 public: |
| 30 explicit DartLibraryLoader(DartState* dart_state); |
| 31 ~DartLibraryLoader(); |
| 32 |
| 33 // TODO(dart): This can be called both on the main thread from application |
| 34 // solates or from the handle watcher isolate thread. |
| 35 static Dart_Handle HandleLibraryTag(Dart_LibraryTag tag, |
| 36 Dart_Handle library, |
| 37 Dart_Handle url); |
| 38 |
| 39 void LoadLibrary(const std::string& name); |
| 40 |
| 41 void WaitForDependencies( |
| 42 const std::unordered_set<DartDependency*>& dependencies, |
| 43 const base::Closure& callback); |
| 44 |
| 45 void set_dependency_catcher(DartDependencyCatcher* dependency_catcher) { |
| 46 DCHECK(!dependency_catcher_ || !dependency_catcher); |
| 47 dependency_catcher_ = dependency_catcher; |
| 48 } |
| 49 |
| 50 DartState* dart_state() const { return dart_state_; } |
| 51 |
| 52 DartLibraryProvider* library_provider() const { return library_provider_; } |
| 53 |
| 54 // The |DartLibraryProvider| must outlive the |DartLibraryLoader|. |
| 55 void set_library_provider(DartLibraryProvider* library_provider) { |
| 56 library_provider_ = library_provider; |
| 57 } |
| 58 |
| 59 private: |
| 60 class Job; |
| 61 class ImportJob; |
| 62 class SourceJob; |
| 63 class DependencyWatcher; |
| 64 class WatcherSignaler; |
| 65 |
| 66 Dart_Handle Import(Dart_Handle library, Dart_Handle url); |
| 67 Dart_Handle Source(Dart_Handle library, Dart_Handle url); |
| 68 Dart_Handle CanonicalizeURL(Dart_Handle library, Dart_Handle url); |
| 69 void DidCompleteImportJob(ImportJob* job, const std::vector<uint8_t>& buffer); |
| 70 void DidCompleteSourceJob(SourceJob* job, const std::vector<uint8_t>& buffer); |
| 71 void DidFailJob(Job* job); |
| 72 |
| 73 DartState* dart_state_; |
| 74 DartLibraryProvider* library_provider_; |
| 75 std::unordered_map<std::string, Job*> pending_libraries_; |
| 76 std::unordered_set<std::unique_ptr<Job>> jobs_; |
| 77 std::unordered_set<std::unique_ptr<DependencyWatcher>> dependency_watchers_; |
| 78 DartDependencyCatcher* dependency_catcher_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(DartLibraryLoader); |
| 81 }; |
| 82 |
| 83 } // namespace blink |
| 84 |
| 85 #endif // SKY_ENGINE_TONIC_DART_LIBRARY_LOADER_H_ |
OLD | NEW |