OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "services/native_support/redirectors.h" | 5 #include "services/native_support/redirectors.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 void FDToMojoFileRedirector::OnFileCanWriteWithoutBlocking(int /*fd*/) { | 71 void FDToMojoFileRedirector::OnFileCanWriteWithoutBlocking(int /*fd*/) { |
72 NOTREACHED(); | 72 NOTREACHED(); |
73 } | 73 } |
74 | 74 |
75 void FDToMojoFileRedirector::DoWrite() { | 75 void FDToMojoFileRedirector::DoWrite() { |
76 CHECK_GT(num_bytes_, offset_); | 76 CHECK_GT(num_bytes_, offset_); |
77 size_t num_bytes_to_write = num_bytes_ - offset_; | 77 size_t num_bytes_to_write = num_bytes_ - offset_; |
78 | 78 |
79 // TODO(vtl): Is there a more natural (or efficient) way to do this? | 79 // TODO(vtl): Is there a more natural (or efficient) way to do this? |
80 mojo::Array<uint8_t> bytes_to_write(num_bytes_to_write); | 80 auto bytes_to_write = mojo::Array<uint8_t>::New(num_bytes_to_write); |
81 memcpy(&bytes_to_write[offset_], buffer_.get(), num_bytes_to_write); | 81 memcpy(&bytes_to_write[offset_], buffer_.get(), num_bytes_to_write); |
82 | 82 |
83 file_->Write(bytes_to_write.Pass(), 0, mojo::files::Whence::FROM_CURRENT, | 83 file_->Write(bytes_to_write.Pass(), 0, mojo::files::Whence::FROM_CURRENT, |
84 base::Bind(&FDToMojoFileRedirector::DidWrite, | 84 base::Bind(&FDToMojoFileRedirector::DidWrite, |
85 weak_factory_.GetWeakPtr())); | 85 weak_factory_.GetWeakPtr())); |
86 } | 86 } |
87 | 87 |
88 void FDToMojoFileRedirector::DidWrite(mojo::files::Error error, | 88 void FDToMojoFileRedirector::DidWrite(mojo::files::Error error, |
89 uint32_t num_bytes_written) { | 89 uint32_t num_bytes_written) { |
90 if (error != mojo::files::Error::OK) { | 90 if (error != mojo::files::Error::OK) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 return; | 164 return; |
165 } | 165 } |
166 if (static_cast<size_t>(result) != bytes_read.size()) | 166 if (static_cast<size_t>(result) != bytes_read.size()) |
167 LOG(ERROR) << "Failed to write everything to FD"; | 167 LOG(ERROR) << "Failed to write everything to FD"; |
168 | 168 |
169 if (running_) | 169 if (running_) |
170 Start(); | 170 Start(); |
171 } | 171 } |
172 | 172 |
173 } // namespace native_support | 173 } // namespace native_support |
OLD | NEW |