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

Side by Side Diff: mojo/common/data_pipe_drainer.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/common/data_pipe_drainer.h ('k') | mojo/edk/embedder/entrypoints.cc » ('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/common/data_pipe_drainer.h" 5 #include "mojo/common/data_pipe_drainer.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 12
13 namespace mojo { 13 namespace mojo {
14 namespace common { 14 namespace common {
15 15
16 DataPipeDrainer::DataPipeDrainer(Client* client, 16 DataPipeDrainer::DataPipeDrainer(Client* client,
17 mojo::ScopedDataPipeConsumerHandle source) 17 mojo::ScopedDataPipeConsumerHandle source)
18 : client_(client), 18 : client_(client),
19 source_(std::move(source)), 19 source_(std::move(source)),
20 handle_watcher_(FROM_HERE), 20 handle_watcher_(FROM_HERE, SimpleWatcher::ArmingPolicy::AUTOMATIC),
21 weak_factory_(this) { 21 weak_factory_(this) {
22 DCHECK(client_); 22 DCHECK(client_);
23 handle_watcher_.Start( 23 handle_watcher_.Watch(
24 source_.get(), MOJO_HANDLE_SIGNAL_READABLE, 24 source_.get(), MOJO_HANDLE_SIGNAL_READABLE,
25 base::Bind(&DataPipeDrainer::WaitComplete, weak_factory_.GetWeakPtr())); 25 base::Bind(&DataPipeDrainer::WaitComplete, weak_factory_.GetWeakPtr()));
26 } 26 }
27 27
28 DataPipeDrainer::~DataPipeDrainer() {} 28 DataPipeDrainer::~DataPipeDrainer() {}
29 29
30 void DataPipeDrainer::ReadData() { 30 void DataPipeDrainer::ReadData() {
31 const void* buffer = nullptr; 31 const void* buffer = nullptr;
32 uint32_t num_bytes = 0; 32 uint32_t num_bytes = 0;
33 MojoResult rv = BeginReadDataRaw(source_.get(), &buffer, &num_bytes, 33 MojoResult rv = BeginReadDataRaw(source_.get(), &buffer, &num_bytes,
34 MOJO_READ_DATA_FLAG_NONE); 34 MOJO_READ_DATA_FLAG_NONE);
35 if (rv == MOJO_RESULT_OK) { 35 if (rv == MOJO_RESULT_OK) {
36 client_->OnDataAvailable(buffer, num_bytes); 36 client_->OnDataAvailable(buffer, num_bytes);
37 EndReadDataRaw(source_.get(), num_bytes); 37 EndReadDataRaw(source_.get(), num_bytes);
38 } else if (rv == MOJO_RESULT_FAILED_PRECONDITION) { 38 } else if (rv == MOJO_RESULT_FAILED_PRECONDITION) {
39 client_->OnDataComplete(); 39 client_->OnDataComplete();
40 } else if (rv != MOJO_RESULT_SHOULD_WAIT) { 40 } else if (rv != MOJO_RESULT_SHOULD_WAIT) {
41 DCHECK(false) << "Unhandled MojoResult: " << rv; 41 DCHECK(false) << "Unhandled MojoResult: " << rv;
42 } 42 }
43 } 43 }
44 44
45 void DataPipeDrainer::WaitComplete(MojoResult result) { 45 void DataPipeDrainer::WaitComplete(MojoResult result) {
46 ReadData(); 46 ReadData();
47 } 47 }
48 48
49 } // namespace common 49 } // namespace common
50 } // namespace mojo 50 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/common/data_pipe_drainer.h ('k') | mojo/edk/embedder/entrypoints.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698