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

Side by Side Diff: components/font_service/public/cpp/mapped_font_file.cc

Issue 1274743004: Sandbox html_viewer on Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Style stuff. Created 5 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/font_service/public/cpp/mapped_font_file.h"
6
7 #include "base/files/file_util.h"
8 #include "base/threading/thread_restrictions.h"
9 #include "skia/ext/refptr.h"
10 #include "skia/ext/skia_utils_base.h"
11 #include "third_party/skia/include/core/SkData.h"
12 #include "third_party/skia/include/core/SkStream.h"
13
14 namespace font_service {
15 namespace internal {
16
17 MappedFontFile::MappedFontFile(uint32_t font_id)
18 : font_id_(font_id), observer_(nullptr) {}
19
20 bool MappedFontFile::Initialize(base::File file) {
21 base::ThreadRestrictions::ScopedAllowIO allow_mmap;
22 return mapped_font_file_.Initialize(file.Pass());
23 }
24
25 SkMemoryStream* MappedFontFile::CreateMemoryStream() {
26 DCHECK(mapped_font_file_.IsValid());
27 auto data = skia::AdoptRef(
28 SkData::NewWithProc(mapped_font_file_.data(), mapped_font_file_.length(),
29 &MappedFontFile::ReleaseProc, this));
30 if (!data)
31 return nullptr;
32 AddRef();
33 return new SkMemoryStream(data.get());
34 }
35
36 MappedFontFile::~MappedFontFile() {
37 if (observer_)
38 observer_->OnMappedFontFileDestroyed(this);
39 }
40
41 // static
42 void MappedFontFile::ReleaseProc(const void* ptr, void* context) {
43 base::ThreadRestrictions::ScopedAllowIO allow_munmap;
44 static_cast<MappedFontFile*>(context)->Release();
45 }
46
47 } // namespace internal
48 } // namespace font_service
OLDNEW
« no previous file with comments | « components/font_service/public/cpp/mapped_font_file.h ('k') | components/font_service/public/interfaces/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698