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

Unified Diff: sky/engine/core/script/dart_snapshot_loader.cc

Issue 1197133004: Add support for snapshot loading to Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Fix mirror-system.sky Created 5 years, 6 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 | « sky/engine/core/script/dart_snapshot_loader.h ('k') | sky/engine/public/sky/sky_view.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/engine/core/script/dart_snapshot_loader.cc
diff --git a/sky/engine/core/script/dart_snapshot_loader.cc b/sky/engine/core/script/dart_snapshot_loader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fc296b33dd181b3c4a81a1705e4e68e46cad6bfc
--- /dev/null
+++ b/sky/engine/core/script/dart_snapshot_loader.cc
@@ -0,0 +1,66 @@
+// 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 "sky/engine/config.h"
+#include "sky/engine/core/script/dart_snapshot_loader.h"
+
+#include "base/callback.h"
+#include "base/trace_event/trace_event.h"
+#include "sky/engine/platform/weborigin/KURL.h"
+#include "sky/engine/tonic/dart_api_scope.h"
+#include "sky/engine/tonic/dart_converter.h"
+#include "sky/engine/tonic/dart_error.h"
+#include "sky/engine/tonic/dart_isolate_scope.h"
+#include "sky/engine/wtf/MainThread.h"
+
+using mojo::common::DataPipeDrainer;
+
+namespace blink {
+
+DartSnapshotLoader::DartSnapshotLoader(DartState* dart_state)
+ : dart_state_(dart_state->GetWeakPtr()) {
+}
+
+DartSnapshotLoader::~DartSnapshotLoader() {
+}
+
+void DartSnapshotLoader::LoadSnapshot(const KURL& url,
+ mojo::URLResponsePtr response,
+ const base::Closure& callback) {
+ TRACE_EVENT_ASYNC_BEGIN0("sky", "DartSnapshotLoader::LoadSnapshot", this);
+ callback_ = callback;
+
+ if (!response) {
+ fetcher_ = adoptPtr(new MojoFetcher(this, url));
+ } else {
+ OnReceivedResponse(response.Pass());
+ }
+}
+
+void DartSnapshotLoader::OnReceivedResponse(mojo::URLResponsePtr response) {
+ if (response->status_code != 200) {
+ callback_.Run();
+ return;
+ }
+ drainer_ = adoptPtr(new DataPipeDrainer(this, response->body.Pass()));
+}
+
+void DartSnapshotLoader::OnDataAvailable(const void* data, size_t num_bytes) {
+ buffer_.append(static_cast<const uint8_t*>(data), 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 | « sky/engine/core/script/dart_snapshot_loader.h ('k') | sky/engine/public/sky/sky_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698