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

Side by Side Diff: sky/engine/platform/fetcher/DrainDataPipeJob.cpp

Issue 650903006: Factor DrainDataPipeJob out of MojoLoader (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
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 "config.h"
6 #include "platform/fetcher/DrainDataPipeJob.h"
7
8 #include "base/bind.h"
9
10 namespace blink {
11
12 DrainDataPipeJob::DrainDataPipeJob(Client* client,
13 mojo::ScopedDataPipeConsumerHandle source)
14 : client_(client),
15 source_(source.Pass()),
16 weak_factory_(this) {
17 DCHECK(client_);
18 ReadData();
19 }
20
21 DrainDataPipeJob::~DrainDataPipeJob() {
22 }
23
24 void DrainDataPipeJob::ReadData() {
25 const void* buffer = nullptr;
26 uint32_t num_bytes = 0;
27 MojoResult rv = BeginReadDataRaw(source_.get(),
28 &buffer, &num_bytes, MOJO_READ_DATA_FLAG_NONE);
29 if (rv == MOJO_RESULT_OK) {
30 client_->OnDataAvailable(buffer, num_bytes);
31 EndReadDataRaw(source_.get(), num_bytes);
32 WaitForData();
33 } else if (rv == MOJO_RESULT_SHOULD_WAIT) {
34 WaitForData();
35 } else if (rv == MOJO_RESULT_FAILED_PRECONDITION) {
36 client_->OnDataComplete();
37 } else {
38 DCHECK(false);
39 }
40 }
41
42 void DrainDataPipeJob::WaitForData() {
43 handle_watcher_.Start(source_.get(),
44 MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE,
45 base::Bind(&DrainDataPipeJob::WaitComplete, weak_factory_.GetWeakPtr()));
46 }
47
48 void DrainDataPipeJob::WaitComplete(MojoResult result) {
49 ReadData();
50 }
51
52 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698