Index: tonic/dart_class_library.cc |
diff --git a/tonic/dart_class_library.cc b/tonic/dart_class_library.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..60bc51900eedb3dfa571c80b83370dfc228c32d3 |
--- /dev/null |
+++ b/tonic/dart_class_library.cc |
@@ -0,0 +1,34 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "tonic/dart_class_library.h" |
+ |
+#include "base/logging.h" |
+#include "tonic/dart_wrapper_info.h" |
+ |
+namespace blink { |
+ |
+DartClassLibrary::DartClassLibrary() : provider_(nullptr) { |
+} |
+ |
+DartClassLibrary::~DartClassLibrary() { |
+ // Note that we don't need to delete these persistent handles because this |
+ // object lives as long as the isolate. The handles will get deleted when the |
+ // isolate dies. |
+} |
+ |
+Dart_PersistentHandle DartClassLibrary::GetClass(const DartWrapperInfo& info) { |
+ DCHECK(provider_); |
+ |
+ const auto& result = cache_.insert(std::make_pair(&info, nullptr)); |
+ if (!result.second) { |
+ // Already present, return value. |
+ return result.first->second; |
+ } |
+ Dart_Handle class_handle = provider_->GetClassByName(info.interface_name); |
+ result.first->second = Dart_NewPersistentHandle(class_handle); |
+ return result.first->second; |
+} |
+ |
+} // namespace blink |