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

Side by Side Diff: content/common/font_config_ipc_linux.cc

Issue 12918004: mmap the opened file descriptor in the renderer process, close the fd in the browser process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/renderer_host/render_sandbox_host_linux.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/socket.h> 10 #include <sys/socket.h>
11 #include <sys/stat.h>
10 #include <sys/uio.h> 12 #include <sys/uio.h>
11 #include <unistd.h> 13 #include <unistd.h>
12 14
15 #include "base/file_util.h"
13 #include "base/pickle.h" 16 #include "base/pickle.h"
14 #include "base/posix/unix_domain_socket_linux.h" 17 #include "base/posix/unix_domain_socket_linux.h"
15 #include "skia/ext/skia_utils_base.h" 18 #include "skia/ext/skia_utils_base.h"
16 #include "third_party/skia/include/core/SkStream.h" 19 #include "third_party/skia/include/core/SkStream.h"
17 20
18 namespace content { 21 namespace content {
19 22
23 // Takes "ownership" of the file descriptor, and will close() it.
24 class SkFileDescriptorStream : public SkStream {
25 public:
jln (very slow on Chromium) 2013/03/18 19:21:28 Nit: public should be only indented with one space
reed1 2013/03/18 19:26:39 Done.
26 SkFileDescriptorStream(int fd) : memory_(NULL), offset_(0), length_(0) {
27 struct stat st;
28 if (fstat(fd, &st)) {
29 DCHECK(!HANDLE_EINTR(close(fd)));
30 return;
31 }
32
33 void* memory = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
34 DCHECK(!HANDLE_EINTR(close(fd)));
35 if (memory == MAP_FAILED)
36 return;
37
38 memory_ = reinterpret_cast<uint8_t*>(memory);
39 length_ = st.st_size;
40 }
41
42 virtual ~SkFileDescriptorStream() {
43 if (memory_)
44 munmap(const_cast<uint8_t*>(memory_), length_);
45 }
46
47 virtual bool rewind() OVERRIDE {
48 offset_ = 0;
49 return true;
50 }
51
52 // SkStream implementation.
53 virtual size_t read(void* buffer, size_t size) OVERRIDE {
54 if (!buffer && !size) {
55 // This is request for the length of the stream.
56 return length_;
57 }
58
59 size_t remaining = length_ - offset_;
60 if (size > remaining)
61 size = remaining;
62 if (buffer)
63 memcpy(buffer, memory_ + offset_, size);
64
65 offset_ += size;
66 return size;
67 }
68
69 virtual const void* getMemoryBase() OVERRIDE {
70 return memory_;
71 }
72
73 private:
74 const uint8_t* memory_;
75 size_t offset_, length_;
76 };
77
20 FontConfigIPC::FontConfigIPC(int fd) 78 FontConfigIPC::FontConfigIPC(int fd)
21 : fd_(fd) { 79 : fd_(fd) {
22 } 80 }
23 81
24 FontConfigIPC::~FontConfigIPC() { 82 FontConfigIPC::~FontConfigIPC() {
25 close(fd_); 83 close(fd_);
26 } 84 }
27 85
28 bool FontConfigIPC::matchFamilyName(const char familyName[], 86 bool FontConfigIPC::matchFamilyName(const char familyName[],
29 SkTypeface::Style requestedStyle, 87 SkTypeface::Style requestedStyle,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 Pickle reply(reinterpret_cast<char*>(reply_buf), r); 148 Pickle reply(reinterpret_cast<char*>(reply_buf), r);
91 bool result; 149 bool result;
92 PickleIterator iter(reply); 150 PickleIterator iter(reply);
93 if (!reply.ReadBool(&iter, &result) || 151 if (!reply.ReadBool(&iter, &result) ||
94 !result) { 152 !result) {
95 if (result_fd) 153 if (result_fd)
96 close(result_fd); 154 close(result_fd);
97 return NULL; 155 return NULL;
98 } 156 }
99 157
100 return new SkFDStream(result_fd, true); 158 return new SkFileDescriptorStream(result_fd);
101 } 159 }
102 160
103 } // namespace content 161 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_sandbox_host_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698