| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/common/font_config_ipc_linux.h" | 5 #include "content/common/font_config_ipc_linux.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <sys/mman.h> | 9 #include <sys/mman.h> |
| 10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
| 11 #include <sys/stat.h> | 11 #include <sys/stat.h> |
| 12 #include <sys/uio.h> | 12 #include <sys/uio.h> |
| 13 #include <unistd.h> | 13 #include <unistd.h> |
| 14 | 14 |
| 15 #include "base/debug/trace_event.h" | 15 #include "base/debug/trace_event.h" |
| 16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
| 17 #include "base/pickle.h" | 17 #include "base/pickle.h" |
| 18 #include "base/posix/unix_domain_socket_linux.h" | 18 #include "base/posix/unix_domain_socket_linux.h" |
| 19 #include "skia/ext/refptr.h" | 19 #include "skia/ext/refptr.h" |
| 20 #include "skia/ext/skia_utils_base.h" | 20 #include "skia/ext/skia_utils_base.h" |
| 21 #include "third_party/skia/include/core/SkData.h" | 21 #include "third_party/skia/include/core/SkData.h" |
| 22 #include "third_party/skia/include/core/SkStream.h" | 22 #include "third_party/skia/include/core/SkStream.h" |
| 23 | 23 |
| 24 namespace content { | 24 namespace content { |
| 25 | 25 |
| 26 // Return a stream from the file descriptor, or NULL on failure. | 26 // Return a stream from the file descriptor, or nullptr on failure. |
| 27 SkStream* StreamFromFD(int fd) { | 27 SkStream* StreamFromFD(int fd) { |
| 28 skia::RefPtr<SkData> data = skia::AdoptRef(SkData::NewFromFD(fd)); | 28 skia::RefPtr<SkData> data = skia::AdoptRef(SkData::NewFromFD(fd)); |
| 29 if (!data) { | 29 if (!data) { |
| 30 return NULL; | 30 return nullptr; |
| 31 } | 31 } |
| 32 return new SkMemoryStream(data.get()); | 32 return new SkMemoryStream(data.get()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void CloseFD(int fd) { | 35 void CloseFD(int fd) { |
| 36 int err = IGNORE_EINTR(close(fd)); | 36 int err = IGNORE_EINTR(close(fd)); |
| 37 DCHECK(!err); | 37 DCHECK(!err); |
| 38 } | 38 } |
| 39 | 39 |
| 40 FontConfigIPC::FontConfigIPC(int fd) | 40 FontConfigIPC::FontConfigIPC(int fd) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 55 if (familyNameLen > kMaxFontFamilyLength) | 55 if (familyNameLen > kMaxFontFamilyLength) |
| 56 return false; | 56 return false; |
| 57 | 57 |
| 58 Pickle request; | 58 Pickle request; |
| 59 request.WriteInt(METHOD_MATCH); | 59 request.WriteInt(METHOD_MATCH); |
| 60 request.WriteData(familyName, familyNameLen); | 60 request.WriteData(familyName, familyNameLen); |
| 61 request.WriteUInt32(requestedStyle); | 61 request.WriteUInt32(requestedStyle); |
| 62 | 62 |
| 63 uint8_t reply_buf[2048]; | 63 uint8_t reply_buf[2048]; |
| 64 const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf, | 64 const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf, |
| 65 sizeof(reply_buf), NULL, | 65 sizeof(reply_buf), nullptr, |
| 66 request); | 66 request); |
| 67 if (r == -1) | 67 if (r == -1) |
| 68 return false; | 68 return false; |
| 69 | 69 |
| 70 Pickle reply(reinterpret_cast<char*>(reply_buf), r); | 70 Pickle reply(reinterpret_cast<char*>(reply_buf), r); |
| 71 PickleIterator iter(reply); | 71 PickleIterator iter(reply); |
| 72 bool result; | 72 bool result; |
| 73 if (!reply.ReadBool(&iter, &result)) | 73 if (!reply.ReadBool(&iter, &result)) |
| 74 return false; | 74 return false; |
| 75 if (!result) | 75 if (!result) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 100 request.WriteInt(METHOD_OPEN); | 100 request.WriteInt(METHOD_OPEN); |
| 101 request.WriteUInt32(identity.fID); | 101 request.WriteUInt32(identity.fID); |
| 102 | 102 |
| 103 int result_fd = -1; | 103 int result_fd = -1; |
| 104 uint8_t reply_buf[256]; | 104 uint8_t reply_buf[256]; |
| 105 const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf, | 105 const ssize_t r = UnixDomainSocket::SendRecvMsg(fd_, reply_buf, |
| 106 sizeof(reply_buf), | 106 sizeof(reply_buf), |
| 107 &result_fd, request); | 107 &result_fd, request); |
| 108 | 108 |
| 109 if (r == -1) | 109 if (r == -1) |
| 110 return NULL; | 110 return nullptr; |
| 111 | 111 |
| 112 Pickle reply(reinterpret_cast<char*>(reply_buf), r); | 112 Pickle reply(reinterpret_cast<char*>(reply_buf), r); |
| 113 bool result; | 113 bool result; |
| 114 PickleIterator iter(reply); | 114 PickleIterator iter(reply); |
| 115 if (!reply.ReadBool(&iter, &result) || | 115 if (!reply.ReadBool(&iter, &result) || |
| 116 !result) { | 116 !result) { |
| 117 if (result_fd) | 117 if (result_fd) |
| 118 CloseFD(result_fd); | 118 CloseFD(result_fd); |
| 119 return NULL; | 119 return nullptr; |
| 120 } | 120 } |
| 121 | 121 |
| 122 SkStream* stream = StreamFromFD(result_fd); | 122 SkStream* stream = StreamFromFD(result_fd); |
| 123 CloseFD(result_fd); | 123 CloseFD(result_fd); |
| 124 return stream; | 124 return stream; |
| 125 } | 125 } |
| 126 | 126 |
| 127 } // namespace content | 127 } // namespace content |
| 128 | 128 |
| OLD | NEW |