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 "chromeos/dbus/pipe_reader.h" | 5 #include "chromeos/dbus/pipe_reader.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/posix/eintr_wrapper.h" | 8 #include "base/posix/eintr_wrapper.h" |
9 #include "base/task_runner.h" | 9 #include "base/task_runner.h" |
10 #include "net/base/file_stream.h" | 10 #include "net/base/file_stream.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 base::File(pipe_fds[0]), task_runner_)); | 37 base::File(pipe_fds[0]), task_runner_)); |
38 | 38 |
39 // Post an initial async read to setup data collection | 39 // Post an initial async read to setup data collection |
40 int rv = data_stream_->Read( | 40 int rv = data_stream_->Read( |
41 io_buffer_.get(), io_buffer_->size(), | 41 io_buffer_.get(), io_buffer_->size(), |
42 base::Bind(&PipeReader::OnDataReady, weak_ptr_factory_.GetWeakPtr())); | 42 base::Bind(&PipeReader::OnDataReady, weak_ptr_factory_.GetWeakPtr())); |
43 if (rv != net::ERR_IO_PENDING) { | 43 if (rv != net::ERR_IO_PENDING) { |
44 LOG(ERROR) << "Unable to post initial read"; | 44 LOG(ERROR) << "Unable to post initial read"; |
45 return base::File(); | 45 return base::File(); |
46 } | 46 } |
47 return pipe_write_end.Pass(); | 47 return pipe_write_end; |
48 } | 48 } |
49 | 49 |
50 void PipeReader::OnDataReady(int byte_count) { | 50 void PipeReader::OnDataReady(int byte_count) { |
51 DVLOG(1) << "OnDataReady byte_count " << byte_count; | 51 DVLOG(1) << "OnDataReady byte_count " << byte_count; |
52 if (byte_count <= 0) { | 52 if (byte_count <= 0) { |
53 callback_.Run(); // signal creator to take data and delete us | 53 callback_.Run(); // signal creator to take data and delete us |
54 return; | 54 return; |
55 } | 55 } |
56 | 56 |
57 AcceptData(io_buffer_->data(), byte_count); | 57 AcceptData(io_buffer_->data(), byte_count); |
(...skipping 16 matching lines...) Expand all Loading... |
74 | 74 |
75 void PipeReaderForString::AcceptData(const char *data, int byte_count) { | 75 void PipeReaderForString::AcceptData(const char *data, int byte_count) { |
76 data_.append(data, byte_count); | 76 data_.append(data, byte_count); |
77 } | 77 } |
78 | 78 |
79 void PipeReaderForString::GetData(std::string* data) { | 79 void PipeReaderForString::GetData(std::string* data) { |
80 data_.swap(*data); | 80 data_.swap(*data); |
81 } | 81 } |
82 | 82 |
83 } // namespace chromeos | 83 } // namespace chromeos |
OLD | NEW |