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

Side by Side Diff: mojo/edk/js/drain_data.cc

Issue 2725133002: Mojo: Armed Watchers (Closed)
Patch Set: . Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « mojo/edk/js/drain_data.h ('k') | mojo/edk/js/waiting_callback.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "mojo/edk/js/drain_data.h" 5 #include "mojo/edk/js/drain_data.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "gin/array_buffer.h" 12 #include "gin/array_buffer.h"
13 #include "gin/converter.h" 13 #include "gin/converter.h"
14 #include "gin/dictionary.h" 14 #include "gin/dictionary.h"
15 #include "gin/per_context_data.h" 15 #include "gin/per_context_data.h"
16 #include "gin/per_isolate_data.h" 16 #include "gin/per_isolate_data.h"
17 #include "mojo/public/cpp/system/core.h" 17 #include "mojo/public/cpp/system/core.h"
18 18
19 namespace mojo { 19 namespace mojo {
20 namespace edk { 20 namespace edk {
21 namespace js { 21 namespace js {
22 22
23 DrainData::DrainData(v8::Isolate* isolate, mojo::Handle handle) 23 DrainData::DrainData(v8::Isolate* isolate, mojo::Handle handle)
24 : isolate_(isolate), 24 : isolate_(isolate),
25 handle_(DataPipeConsumerHandle(handle.value())), 25 handle_(DataPipeConsumerHandle(handle.value())),
26 handle_watcher_(FROM_HERE) { 26 handle_watcher_(FROM_HERE, SimpleWatcher::ArmingPolicy::AUTOMATIC) {
27 v8::Handle<v8::Context> context(isolate_->GetCurrentContext()); 27 v8::Handle<v8::Context> context(isolate_->GetCurrentContext());
28 runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr(); 28 runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr();
29 29
30 WaitForData(); 30 WaitForData();
31 } 31 }
32 32
33 v8::Handle<v8::Value> DrainData::GetPromise() { 33 v8::Handle<v8::Value> DrainData::GetPromise() {
34 CHECK(resolver_.IsEmpty()); 34 CHECK(resolver_.IsEmpty());
35 v8::Handle<v8::Promise::Resolver> resolver( 35 v8::Handle<v8::Promise::Resolver> resolver(
36 v8::Promise::Resolver::New(isolate_)); 36 v8::Promise::Resolver::New(isolate_));
37 resolver_.Reset(isolate_, resolver); 37 resolver_.Reset(isolate_, resolver);
38 return resolver->GetPromise(); 38 return resolver->GetPromise();
39 } 39 }
40 40
41 DrainData::~DrainData() { 41 DrainData::~DrainData() {
42 resolver_.Reset(); 42 resolver_.Reset();
43 } 43 }
44 44
45 void DrainData::WaitForData() { 45 void DrainData::WaitForData() {
46 handle_watcher_.Start( 46 handle_watcher_.Watch(
47 handle_.get(), MOJO_HANDLE_SIGNAL_READABLE, 47 handle_.get(), MOJO_HANDLE_SIGNAL_READABLE,
48 base::Bind(&DrainData::DataReady, base::Unretained(this))); 48 base::Bind(&DrainData::DataReady, base::Unretained(this)));
49 } 49 }
50 50
51 void DrainData::DataReady(MojoResult result) { 51 void DrainData::DataReady(MojoResult result) {
52 if (result != MOJO_RESULT_OK) { 52 if (result != MOJO_RESULT_OK) {
53 DeliverData(result); 53 DeliverData(result);
54 return; 54 return;
55 } 55 }
56 while (result == MOJO_RESULT_OK) { 56 while (result == MOJO_RESULT_OK) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 resolver->Resolve(settled_value); 120 resolver->Resolve(settled_value);
121 else 121 else
122 resolver->Reject(settled_value); 122 resolver->Reject(settled_value);
123 123
124 delete this; 124 delete this;
125 } 125 }
126 126
127 } // namespace js 127 } // namespace js
128 } // namespace edk 128 } // namespace edk
129 } // namespace mojo 129 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/js/drain_data.h ('k') | mojo/edk/js/waiting_callback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698