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

Side by Side Diff: mojo/data_pipe_utils/data_pipe_drainer.cc

Issue 1841863002: Update monet. (Closed) Base URL: https://github.com/domokit/monet.git@master
Patch Set: Created 4 years, 8 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/data_pipe_utils/data_pipe_drainer.h ('k') | mojo/data_pipe_utils/data_pipe_file_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mojo/data_pipe_utils/data_pipe_drainer.h"
6
7 #include "base/bind.h"
8
9 namespace mojo {
10 namespace common {
11
12 DataPipeDrainer::DataPipeDrainer(Client* client,
13 mojo::ScopedDataPipeConsumerHandle source)
14 : client_(client), source_(source.Pass()), weak_factory_(this) {
15 DCHECK(client_);
16 ReadData();
17 }
18
19 DataPipeDrainer::~DataPipeDrainer() {}
20
21 void DataPipeDrainer::ReadData() {
22 const void* buffer = nullptr;
23 uint32_t num_bytes = 0;
24 MojoResult rv = BeginReadDataRaw(source_.get(), &buffer, &num_bytes,
25 MOJO_READ_DATA_FLAG_NONE);
26 if (rv == MOJO_RESULT_OK) {
27 client_->OnDataAvailable(buffer, num_bytes);
28 EndReadDataRaw(source_.get(), num_bytes);
29 WaitForData();
30 } else if (rv == MOJO_RESULT_SHOULD_WAIT) {
31 WaitForData();
32 } else if (rv == MOJO_RESULT_FAILED_PRECONDITION) {
33 client_->OnDataComplete();
34 } else {
35 DCHECK(false) << "Unhandled MojoResult: " << rv;
36 }
37 }
38
39 void DataPipeDrainer::WaitForData() {
40 handle_watcher_.Start(
41 source_.get(), MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE,
42 base::Bind(&DataPipeDrainer::WaitComplete, weak_factory_.GetWeakPtr()));
43 }
44
45 void DataPipeDrainer::WaitComplete(MojoResult result) {
46 ReadData();
47 }
48
49 } // namespace common
50 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/data_pipe_utils/data_pipe_drainer.h ('k') | mojo/data_pipe_utils/data_pipe_file_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698