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

Side by Side Diff: services/native_support/redirectors.cc

Issue 1375313006: For c++, Generate enum classes instead of enum from mojom. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 2 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
OLDNEW
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 mojo::Array<uint8_t> bytes_to_write(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) {
91 LOG(WARNING) << "Failed to write to Mojo File"; 91 LOG(WARNING) << "Failed to write to Mojo File";
92 // TODO(vtl): Should maybe close |file_|? 92 // TODO(vtl): Should maybe close |file_|?
93 return; 93 return;
94 } 94 }
95 95
96 CHECK_GT(num_bytes_, offset_); 96 CHECK_GT(num_bytes_, offset_);
97 size_t num_bytes_to_write = num_bytes_ - offset_; 97 size_t num_bytes_to_write = num_bytes_ - offset_;
98 if (num_bytes_written > num_bytes_to_write) { 98 if (num_bytes_written > num_bytes_to_write) {
99 LOG(ERROR) << "Bad result from write to Mojo File"; 99 LOG(ERROR) << "Bad result from write to Mojo File";
100 return; 100 return;
(...skipping 23 matching lines...) Expand all
124 124
125 MojoFileToFDRedirector::~MojoFileToFDRedirector() {} 125 MojoFileToFDRedirector::~MojoFileToFDRedirector() {}
126 126
127 void MojoFileToFDRedirector::Start() { 127 void MojoFileToFDRedirector::Start() {
128 running_ = true; 128 running_ = true;
129 129
130 if (read_pending_) 130 if (read_pending_)
131 return; 131 return;
132 132
133 file_->Read( 133 file_->Read(
134 static_cast<uint32_t>(buffer_size_), 0, mojo::files::WHENCE_FROM_CURRENT, 134 static_cast<uint32_t>(buffer_size_), 0, mojo::files::Whence::FROM_CURRENT,
135 base::Bind(&MojoFileToFDRedirector::DidRead, weak_factory_.GetWeakPtr())); 135 base::Bind(&MojoFileToFDRedirector::DidRead, weak_factory_.GetWeakPtr()));
136 read_pending_ = true; 136 read_pending_ = true;
137 } 137 }
138 138
139 void MojoFileToFDRedirector::Stop() { 139 void MojoFileToFDRedirector::Stop() {
140 running_ = false; 140 running_ = false;
141 } 141 }
142 142
143 void MojoFileToFDRedirector::DidRead(mojo::files::Error error, 143 void MojoFileToFDRedirector::DidRead(mojo::files::Error error,
144 mojo::Array<uint8_t> bytes_read) { 144 mojo::Array<uint8_t> bytes_read) {
145 DCHECK(read_pending_); 145 DCHECK(read_pending_);
146 read_pending_ = false; 146 read_pending_ = false;
147 147
148 if (error != mojo::files::ERROR_OK) { 148 if (error != mojo::files::Error::OK) {
149 LOG(ERROR) << "Read failed"; 149 LOG(ERROR) << "Read failed";
150 // TODO(vtl): Should maybe close |file_|? 150 // TODO(vtl): Should maybe close |file_|?
151 return; 151 return;
152 } 152 }
153 153
154 ssize_t result = HANDLE_EINTR(write(fd_, &bytes_read[0], bytes_read.size())); 154 ssize_t result = HANDLE_EINTR(write(fd_, &bytes_read[0], bytes_read.size()));
155 if (result < 0) { 155 if (result < 0) {
156 if (errno == EAGAIN || errno == EWOULDBLOCK) { 156 if (errno == EAGAIN || errno == EWOULDBLOCK) {
157 LOG(ERROR) << "Could not write to FD without blocking"; 157 LOG(ERROR) << "Could not write to FD without blocking";
158 if (running_) 158 if (running_)
159 Start(); 159 Start();
160 return; 160 return;
161 } 161 }
162 PLOG(WARNING) << "Failed to write to FD"; 162 PLOG(WARNING) << "Failed to write to FD";
163 // TODO(vtl): Should maybe close |file_|? 163 // TODO(vtl): Should maybe close |file_|?
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
OLDNEW
« no previous file with comments | « services/native_support/process_impl_unittest.cc ('k') | services/native_viewport/native_viewport_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698