OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "third_party/mojo/src/mojo/edk/js/drain_data.h" | 5 #include "mojo/edk/js/drain_data.h" |
6 | 6 |
7 #include "gin/array_buffer.h" | 7 #include "gin/array_buffer.h" |
8 #include "gin/converter.h" | 8 #include "gin/converter.h" |
9 #include "gin/dictionary.h" | 9 #include "gin/dictionary.h" |
10 #include "gin/per_context_data.h" | 10 #include "gin/per_context_data.h" |
11 #include "gin/per_isolate_data.h" | 11 #include "gin/per_isolate_data.h" |
12 #include "mojo/public/cpp/environment/environment.h" | 12 #include "mojo/public/cpp/environment/environment.h" |
13 #include "mojo/public/cpp/system/core.h" | 13 #include "mojo/public/cpp/system/core.h" |
14 | 14 |
15 namespace mojo { | 15 namespace mojo { |
16 namespace js { | 16 namespace edk { |
17 | 17 |
18 DrainData::DrainData(v8::Isolate* isolate, mojo::Handle handle) | 18 DrainData::DrainData(v8::Isolate* isolate, mojo::Handle handle) |
19 : isolate_(isolate), | 19 : isolate_(isolate), |
20 handle_(DataPipeConsumerHandle(handle.value())), | 20 handle_(DataPipeConsumerHandle(handle.value())), |
21 wait_id_(0) { | 21 wait_id_(0) { |
22 | 22 |
23 v8::Handle<v8::Context> context(isolate_->GetCurrentContext()); | 23 v8::Handle<v8::Context> context(isolate_->GetCurrentContext()); |
24 runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr(); | 24 runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr(); |
25 | 25 |
26 WaitForData(); | 26 WaitForData(); |
27 } | 27 } |
28 | 28 |
29 v8::Handle<v8::Value> DrainData::GetPromise() { | 29 v8::Handle<v8::Value> DrainData::GetPromise() { |
30 CHECK(resolver_.IsEmpty()); | 30 CHECK(resolver_.IsEmpty()); |
31 v8::Handle<v8::Promise::Resolver> resolver( | 31 v8::Handle<v8::Promise::Resolver> resolver( |
32 v8::Promise::Resolver::New(isolate_)); | 32 v8::Promise::Resolver::New(isolate_)); |
33 resolver_.Reset(isolate_, resolver); | 33 resolver_.Reset(isolate_, resolver); |
34 return resolver->GetPromise(); | 34 return resolver->GetPromise(); |
35 } | 35 } |
36 | 36 |
37 DrainData::~DrainData() { | 37 DrainData::~DrainData() { |
38 if (wait_id_) | 38 if (wait_id_) |
39 Environment::GetDefaultAsyncWaiter()->CancelWait(wait_id_); | 39 Environment::GetDefaultAsyncWaiter()->CancelWait(wait_id_); |
40 resolver_.Reset(); | 40 resolver_.Reset(); |
41 } | 41 } |
42 | 42 |
43 void DrainData::WaitForData() { | 43 void DrainData::WaitForData() { |
44 wait_id_ = Environment::GetDefaultAsyncWaiter()->AsyncWait( | 44 wait_id_ = Environment::GetDefaultAsyncWaiter()->AsyncWait( |
45 2, handle_.get().value(), MOJO_HANDLE_SIGNAL_READABLE, | 45 handle_.get().value(), |
46 MOJO_DEADLINE_INDEFINITE, &DrainData::WaitCompleted, this); | 46 MOJO_HANDLE_SIGNAL_READABLE, |
| 47 MOJO_DEADLINE_INDEFINITE, |
| 48 &DrainData::WaitCompleted, |
| 49 this); |
47 } | 50 } |
48 | 51 |
49 void DrainData::DataReady(MojoResult result) { | 52 void DrainData::DataReady(MojoResult result) { |
50 wait_id_ = 0; | 53 wait_id_ = 0; |
51 if (result != MOJO_RESULT_OK) { | 54 if (result != MOJO_RESULT_OK) { |
52 DeliverData(result); | 55 DeliverData(result); |
53 return; | 56 return; |
54 } | 57 } |
55 while (result == MOJO_RESULT_OK) { | 58 while (result == MOJO_RESULT_OK) { |
56 result = ReadData(); | 59 result = ReadData(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 v8::Handle<v8::Value> settled_value(ConvertToV8(isolate_, dictionary)); | 120 v8::Handle<v8::Value> settled_value(ConvertToV8(isolate_, dictionary)); |
118 | 121 |
119 if (result == MOJO_RESULT_FAILED_PRECONDITION) | 122 if (result == MOJO_RESULT_FAILED_PRECONDITION) |
120 resolver->Resolve(settled_value); | 123 resolver->Resolve(settled_value); |
121 else | 124 else |
122 resolver->Reject(settled_value); | 125 resolver->Reject(settled_value); |
123 | 126 |
124 delete this; | 127 delete this; |
125 } | 128 } |
126 | 129 |
127 } // namespace js | 130 } // namespace edk |
128 } // namespace mojo | 131 } // namespace mojo |
OLD | NEW |