Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: tonic/dart_persistent_value.cc

Issue 1244493002: Wholesale move sky/engine/tonic to tonic (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tonic/dart_persistent_value.h ('k') | tonic/dart_snapshot_loader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tonic/dart_persistent_value.cc
diff --git a/tonic/dart_persistent_value.cc b/tonic/dart_persistent_value.cc
new file mode 100644
index 0000000000000000000000000000000000000000..191e1a4eb2dce5431c18bdac188a18adddb04f88
--- /dev/null
+++ b/tonic/dart_persistent_value.cc
@@ -0,0 +1,48 @@
+// 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_persistent_value.h"
+
+#include "tonic/dart_isolate_scope.h"
+#include "tonic/dart_state.h"
+
+namespace blink {
+
+DartPersistentValue::DartPersistentValue() : value_(nullptr) {
+}
+
+DartPersistentValue::DartPersistentValue(DartState* dart_state,
+ Dart_Handle value)
+ : value_(nullptr) {
+ Set(dart_state, value);
+}
+
+DartPersistentValue::~DartPersistentValue() {
+ Clear();
+}
+
+void DartPersistentValue::Set(DartState* dart_state, Dart_Handle value) {
+ DCHECK(is_empty());
+ dart_state_ = dart_state->GetWeakPtr();
+ value_ = Dart_NewPersistentHandle(value);
+}
+
+void DartPersistentValue::Clear() {
+ if (!value_ || !dart_state_.get())
+ return;
+
+ DartIsolateScope scope(dart_state_->isolate());
+ Dart_DeletePersistentHandle(value_);
+ dart_state_ = base::WeakPtr<DartState>();
+ value_ = nullptr;
+}
+
+Dart_Handle DartPersistentValue::Release() {
+ if (!value_)
+ return nullptr;
+ Dart_Handle local = Dart_HandleFromPersistent(value_);
+ Clear();
+ return local;
+}
+}
« no previous file with comments | « tonic/dart_persistent_value.h ('k') | tonic/dart_snapshot_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698