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

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 {
jln (very slow on Chromium) 2013/03/18 18:25:37 General nit: why are you using a 4 spaces indent?
reed1 2013/03/18 18:42:35 Done.
25 public:
26 SkFileDescriptorStream(int fd) {
27 memory_ = NULL;
jln (very slow on Chromium) 2013/03/18 18:25:37 You don't want to use an initialization list inste
reed1 2013/03/18 18:42:35 Done.
28 offset_ = 0;
29
30 // this ensures that if we fail in the constructor, we will safely
jln (very slow on Chromium) 2013/03/18 18:25:37 Nit: s/this/This
reed1 2013/03/18 18:42:35 Done.
31 // ignore all subsequent calls to read() because we will always trim
jln (very slow on Chromium) 2013/03/18 18:25:37 I don't think this currently works. You just do re
32 // the requested size down to 0
jln (very slow on Chromium) 2013/03/18 18:25:37 Nit: final "."
reed1 2013/03/18 18:42:35 Done.
33 length_ = 0;
34
35 struct stat st;
36 if (fstat(fd, &st))
jln (very slow on Chromium) 2013/03/18 18:25:37 close the fd here as well ?
reed1 2013/03/18 18:42:35 Done.
37 return;
38
39 void* memory = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
40 DCHECK(!HANDLE_EINTR(close(fd)));
41 if (memory == MAP_FAILED)
42 return;
43
44 memory_ = reinterpret_cast<uint8_t*>(memory);
45 length_ = st.st_size;
46 }
47
48 virtual ~SkFileDescriptorStream() {
jln (very slow on Chromium) 2013/03/18 18:25:37 This works, because length == 0 will make the kern
reed1 2013/03/18 18:42:35 Done.
49 munmap(const_cast<uint8_t*>(memory_), length_);
50 }
51
52 virtual bool rewind() OVERRIDE {
53 offset_ = 0;
54 return true;
55 }
56
57 // SkStream implementation.
58 virtual size_t read(void* buffer, size_t size) OVERRIDE {
59 if (!buffer && !size) {
60 // This is request for the length of the stream.
61 return length_;
62 }
63
64 size_t remaining = length_ - offset_;
65 if (size > remaining)
66 size = remaining;
67 if (buffer)
jln (very slow on Chromium) 2013/03/18 18:25:37 Shouldn't we just CHECK buffer at the start of thi
reed1 2013/03/18 18:42:35 buffer == NULL is defined to mean "skip", so it is
68 memcpy(buffer, memory_ + offset_, size);
69
70 offset_ += size;
71 return size;
72 }
73
74 virtual const void* getMemoryBase() OVERRIDE {
75 return memory_;
76 }
77
78 private:
79 const uint8_t* memory_;
80 size_t offset_, length_;
81 };
82
20 FontConfigIPC::FontConfigIPC(int fd) 83 FontConfigIPC::FontConfigIPC(int fd)
21 : fd_(fd) { 84 : fd_(fd) {
22 } 85 }
23 86
24 FontConfigIPC::~FontConfigIPC() { 87 FontConfigIPC::~FontConfigIPC() {
25 close(fd_); 88 close(fd_);
26 } 89 }
27 90
28 bool FontConfigIPC::matchFamilyName(const char familyName[], 91 bool FontConfigIPC::matchFamilyName(const char familyName[],
29 SkTypeface::Style requestedStyle, 92 SkTypeface::Style requestedStyle,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 Pickle reply(reinterpret_cast<char*>(reply_buf), r); 153 Pickle reply(reinterpret_cast<char*>(reply_buf), r);
91 bool result; 154 bool result;
92 PickleIterator iter(reply); 155 PickleIterator iter(reply);
93 if (!reply.ReadBool(&iter, &result) || 156 if (!reply.ReadBool(&iter, &result) ||
94 !result) { 157 !result) {
95 if (result_fd) 158 if (result_fd)
96 close(result_fd); 159 close(result_fd);
97 return NULL; 160 return NULL;
98 } 161 }
99 162
100 return new SkFDStream(result_fd, true); 163 return new SkFileDescriptorStream(result_fd);
101 } 164 }
102 165
103 } // namespace content 166 } // 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