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

Unified Diff: tonic/dart_snapshot_loader.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_snapshot_loader.h ('k') | tonic/dart_state.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tonic/dart_snapshot_loader.cc
diff --git a/tonic/dart_snapshot_loader.cc b/tonic/dart_snapshot_loader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..65d408fa07c10edb0c6997c7a25262604bead543
--- /dev/null
+++ b/tonic/dart_snapshot_loader.cc
@@ -0,0 +1,52 @@
+// 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_snapshot_loader.h"
+
+#include "base/callback.h"
+#include "base/trace_event/trace_event.h"
+#include "tonic/dart_api_scope.h"
+#include "tonic/dart_converter.h"
+#include "tonic/dart_error.h"
+#include "tonic/dart_isolate_scope.h"
+
+using mojo::common::DataPipeDrainer;
+
+namespace blink {
+
+DartSnapshotLoader::DartSnapshotLoader(DartState* dart_state)
+ : dart_state_(dart_state->GetWeakPtr()) {
+}
+
+DartSnapshotLoader::~DartSnapshotLoader() {
+}
+
+void DartSnapshotLoader::LoadSnapshot(mojo::ScopedDataPipeConsumerHandle pipe,
+ const base::Closure& callback) {
+ TRACE_EVENT_ASYNC_BEGIN0("sky", "DartSnapshotLoader::LoadSnapshot", this);
+
+ callback_ = callback;
+ drainer_ = std::unique_ptr<mojo::common::DataPipeDrainer>(
+ new DataPipeDrainer(this, pipe.Pass()));
+}
+
+void DartSnapshotLoader::OnDataAvailable(const void* data, size_t num_bytes) {
+ const uint8_t* bytes = static_cast<const uint8_t*>(data);
+ buffer_.insert(buffer_.end(), bytes, bytes + num_bytes);
+}
+
+void DartSnapshotLoader::OnDataComplete() {
+ TRACE_EVENT_ASYNC_END0("sky", "DartSnapshotLoader::LoadSnapshot", this);
+
+ {
+ DartIsolateScope scope(dart_state_->isolate());
+ DartApiScope api_scope;
+
+ LogIfError(Dart_LoadScriptFromSnapshot(buffer_.data(), buffer_.size()));
+ }
+
+ callback_.Run();
+}
+
+} // namespace blink
« no previous file with comments | « tonic/dart_snapshot_loader.h ('k') | tonic/dart_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698