summaryrefslogtreecommitdiffstats
path: root/mojo/edk/js/drain_data.cc
diff options
context:
space:
mode:
authorblundell <blundell@chromium.org>2015-01-19 09:18:33 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-19 17:19:27 +0000
commit70fb54767b472a5edfb859e489beeeec7abdb0e4 (patch)
tree28e534ec774391a9f6571a1770e12a0d63ebf833 /mojo/edk/js/drain_data.cc
parentba5f0233fa38f949e24f6274ba891fa652eab640 (diff)
downloadchromium_src-70fb54767b472a5edfb859e489beeeec7abdb0e4.zip
chromium_src-70fb54767b472a5edfb859e489beeeec7abdb0e4.tar.gz
chromium_src-70fb54767b472a5edfb859e489beeeec7abdb0e4.tar.bz2
Move //mojo/{public, edk} underneath //third_party
This CL move //mojo/public and //mojo/edk to live in the following locations: - //third_party/mojo/src/mojo/public - //third_party/mojo/src/mojo/edk It moves the related gypfiles from //mojo to //third_party/mojo and updates them as necessary to account for the file moves. It also updates clients of the mojo SDK and EDK targets in both GYP and GN. (Note that for GN, the mojo SDK and EDK build systems are maintained in the Mojo repo and designed to be flexible wrt the location of the SDK/EDK in a client repo, so no changes are needed. This CL does not update include paths to the code being moved to limit the number of moving parts, instead relying on the include_dirs that the SDK and EDK targets supply to their direct dependents to ensure that include paths continue to resolve correctly. NOPRESUBMIT=true Review URL: https://codereview.chromium.org/814543006 Cr-Commit-Position: refs/heads/master@{#312129}
Diffstat (limited to 'mojo/edk/js/drain_data.cc')
-rw-r--r--mojo/edk/js/drain_data.cc131
1 files changed, 0 insertions, 131 deletions
diff --git a/mojo/edk/js/drain_data.cc b/mojo/edk/js/drain_data.cc
deleted file mode 100644
index 0667c64..0000000
--- a/mojo/edk/js/drain_data.cc
+++ /dev/null
@@ -1,131 +0,0 @@
-// Copyright 2014 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 "mojo/edk/js/drain_data.h"
-
-#include "gin/array_buffer.h"
-#include "gin/converter.h"
-#include "gin/dictionary.h"
-#include "gin/per_context_data.h"
-#include "gin/per_isolate_data.h"
-#include "mojo/public/cpp/environment/environment.h"
-#include "mojo/public/cpp/system/core.h"
-
-namespace mojo {
-namespace js {
-
-DrainData::DrainData(v8::Isolate* isolate, mojo::Handle handle)
- : isolate_(isolate),
- handle_(DataPipeConsumerHandle(handle.value())),
- wait_id_(0) {
-
- v8::Handle<v8::Context> context(isolate_->GetCurrentContext());
- runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr();
-
- WaitForData();
-}
-
-v8::Handle<v8::Value> DrainData::GetPromise() {
- CHECK(resolver_.IsEmpty());
- v8::Handle<v8::Promise::Resolver> resolver(
- v8::Promise::Resolver::New(isolate_));
- resolver_.Reset(isolate_, resolver);
- return resolver->GetPromise();
-}
-
-DrainData::~DrainData() {
- if (wait_id_)
- Environment::GetDefaultAsyncWaiter()->CancelWait(wait_id_);
- resolver_.Reset();
-}
-
-void DrainData::WaitForData() {
- wait_id_ = Environment::GetDefaultAsyncWaiter()->AsyncWait(
- handle_.get().value(),
- MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE,
- &DrainData::WaitCompleted,
- this);
-}
-
-void DrainData::DataReady(MojoResult result) {
- wait_id_ = 0;
- if (result != MOJO_RESULT_OK) {
- DeliverData(result);
- return;
- }
- while (result == MOJO_RESULT_OK) {
- result = ReadData();
- if (result == MOJO_RESULT_SHOULD_WAIT)
- WaitForData();
- else if (result != MOJO_RESULT_OK)
- DeliverData(result);
- }
-}
-
-MojoResult DrainData::ReadData() {
- const void* buffer;
- uint32_t num_bytes = 0;
- MojoResult result = BeginReadDataRaw(
- handle_.get(), &buffer, &num_bytes, MOJO_READ_DATA_FLAG_NONE);
- if (result != MOJO_RESULT_OK)
- return result;
- const char* p = static_cast<const char*>(buffer);
- DataBuffer* data_buffer = new DataBuffer(p, p + num_bytes);
- data_buffers_.push_back(data_buffer);
- return EndReadDataRaw(handle_.get(), num_bytes);
-}
-
-void DrainData::DeliverData(MojoResult result) {
- if (!runner_) {
- delete this;
- return;
- }
-
- size_t total_bytes = 0;
- for (unsigned i = 0; i < data_buffers_.size(); i++)
- total_bytes += data_buffers_[i]->size();
-
- // Create a total_bytes length ArrayBuffer return value.
- gin::Runner::Scope scope(runner_.get());
- v8::Handle<v8::ArrayBuffer> array_buffer =
- v8::ArrayBuffer::New(isolate_, total_bytes);
- gin::ArrayBuffer buffer;
- ConvertFromV8(isolate_, array_buffer, &buffer);
- CHECK_EQ(total_bytes, buffer.num_bytes());
-
- // Copy the data_buffers into the ArrayBuffer.
- char* array_buffer_ptr = static_cast<char*>(buffer.bytes());
- size_t offset = 0;
- for (size_t i = 0; i < data_buffers_.size(); i++) {
- size_t num_bytes = data_buffers_[i]->size();
- if (num_bytes == 0)
- continue;
- const char* data_buffer_ptr = &((*data_buffers_[i])[0]);
- memcpy(array_buffer_ptr + offset, data_buffer_ptr, num_bytes);
- offset += num_bytes;
- }
-
- // The "settled" value of the promise always includes all of the data
- // that was read before either an error occurred or the remote pipe handle
- // was closed. The latter is indicated by MOJO_RESULT_FAILED_PRECONDITION.
-
- v8::Handle<v8::Promise::Resolver> resolver(
- v8::Local<v8::Promise::Resolver>::New(isolate_, resolver_));
-
- gin::Dictionary dictionary = gin::Dictionary::CreateEmpty(isolate_);
- dictionary.Set("result", result);
- dictionary.Set("buffer", array_buffer);
- v8::Handle<v8::Value> settled_value(ConvertToV8(isolate_, dictionary));
-
- if (result == MOJO_RESULT_FAILED_PRECONDITION)
- resolver->Resolve(settled_value);
- else
- resolver->Reject(settled_value);
-
- delete this;
-}
-
-} // namespace js
-} // namespace mojo