| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sky/engine/tonic/dart_snapshot_loader.h" | 5 #include "sky/engine/tonic/dart_snapshot_loader.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
| 9 #include "sky/engine/tonic/dart_api_scope.h" | 9 #include "sky/engine/tonic/dart_api_scope.h" |
| 10 #include "sky/engine/tonic/dart_converter.h" | 10 #include "sky/engine/tonic/dart_converter.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 void DartSnapshotLoader::LoadSnapshot(mojo::ScopedDataPipeConsumerHandle pipe, | 26 void DartSnapshotLoader::LoadSnapshot(mojo::ScopedDataPipeConsumerHandle pipe, |
| 27 const base::Closure& callback) { | 27 const base::Closure& callback) { |
| 28 TRACE_EVENT_ASYNC_BEGIN0("sky", "DartSnapshotLoader::LoadSnapshot", this); | 28 TRACE_EVENT_ASYNC_BEGIN0("sky", "DartSnapshotLoader::LoadSnapshot", this); |
| 29 | 29 |
| 30 callback_ = callback; | 30 callback_ = callback; |
| 31 drainer_ = adoptPtr(new DataPipeDrainer(this, pipe.Pass())); | 31 drainer_ = adoptPtr(new DataPipeDrainer(this, pipe.Pass())); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void DartSnapshotLoader::OnDataAvailable(const void* data, size_t num_bytes) { | 34 void DartSnapshotLoader::OnDataAvailable(const void* data, size_t num_bytes) { |
| 35 buffer_.append(static_cast<const uint8_t*>(data), num_bytes); | 35 const uint8_t* bytes = static_cast<const uint8_t*>(data); |
| 36 buffer_.insert(buffer_.end(), bytes, bytes + num_bytes); |
| 36 } | 37 } |
| 37 | 38 |
| 38 void DartSnapshotLoader::OnDataComplete() { | 39 void DartSnapshotLoader::OnDataComplete() { |
| 39 TRACE_EVENT_ASYNC_END0("sky", "DartSnapshotLoader::LoadSnapshot", this); | 40 TRACE_EVENT_ASYNC_END0("sky", "DartSnapshotLoader::LoadSnapshot", this); |
| 40 | 41 |
| 41 { | 42 { |
| 42 DartIsolateScope scope(dart_state_->isolate()); | 43 DartIsolateScope scope(dart_state_->isolate()); |
| 43 DartApiScope api_scope; | 44 DartApiScope api_scope; |
| 44 | 45 |
| 45 LogIfError(Dart_LoadScriptFromSnapshot(buffer_.data(), buffer_.size())); | 46 LogIfError(Dart_LoadScriptFromSnapshot(buffer_.data(), buffer_.size())); |
| 46 } | 47 } |
| 47 | 48 |
| 48 callback_.Run(); | 49 callback_.Run(); |
| 49 } | 50 } |
| 50 | 51 |
| 51 } // namespace blink | 52 } // namespace blink |
| OLD | NEW |