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 #include "sky/engine/config.h" | |
6 #include "sky/engine/core/script/dart_snapshot_loader.h" | |
7 | |
8 #include "base/callback.h" | |
9 #include "base/trace_event/trace_event.h" | |
10 #include "sky/engine/platform/weborigin/KURL.h" | |
11 #include "sky/engine/tonic/dart_api_scope.h" | |
12 #include "sky/engine/tonic/dart_converter.h" | |
13 #include "sky/engine/tonic/dart_error.h" | |
14 #include "sky/engine/tonic/dart_isolate_scope.h" | |
15 #include "sky/engine/wtf/MainThread.h" | |
16 | |
17 using mojo::common::DataPipeDrainer; | |
18 | |
19 namespace blink { | |
20 | |
21 DartSnapshotLoader::DartSnapshotLoader(DartState* dart_state) | |
22 : dart_state_(dart_state->GetWeakPtr()) { | |
23 } | |
24 | |
25 DartSnapshotLoader::~DartSnapshotLoader() { | |
26 } | |
27 | |
28 void DartSnapshotLoader::LoadSnapshot(const KURL& url, | |
29 mojo::URLResponsePtr response, | |
30 const base::Closure& callback) { | |
31 TRACE_EVENT_ASYNC_BEGIN0("sky", "DartSnapshotLoader::LoadSnapshot", this); | |
32 callback_ = callback; | |
33 | |
34 if (!response) { | |
eseidel
2015/06/23 06:21:39
I regret this design choice. We need to untangle
abarth-chromium
2015/06/23 14:50:43
Yeah, we should be able to untangle it then.
| |
35 fetcher_ = adoptPtr(new MojoFetcher(this, url)); | |
36 } else { | |
37 OnReceivedResponse(response.Pass()); | |
38 } | |
39 } | |
40 | |
41 void DartSnapshotLoader::OnReceivedResponse(mojo::URLResponsePtr response) { | |
42 if (response->status_code != 200) { | |
eseidel
2015/06/23 06:21:39
Are you sure you only want 200? You ahd me change
abarth-chromium
2015/06/23 14:50:43
I just cargo-culted this from the DartLoader. I c
| |
43 callback_.Run(); | |
44 return; | |
45 } | |
46 drainer_ = adoptPtr(new DataPipeDrainer(this, response->body.Pass())); | |
47 } | |
48 | |
49 void DartSnapshotLoader::OnDataAvailable(const void* data, size_t num_bytes) { | |
50 buffer_.append(static_cast<const uint8_t*>(data), num_bytes); | |
51 } | |
52 | |
53 void DartSnapshotLoader::OnDataComplete() { | |
54 TRACE_EVENT_ASYNC_END0("sky", "DartSnapshotLoader::LoadSnapshot", this); | |
55 | |
56 { | |
57 DartIsolateScope scope(dart_state_->isolate()); | |
58 DartApiScope api_scope; | |
59 | |
60 LogIfError(Dart_LoadScriptFromSnapshot(buffer_.data(), buffer_.size())); | |
61 } | |
62 | |
63 callback_.Run(); | |
64 } | |
65 | |
66 } // namespace blink | |
OLD | NEW |