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

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

Issue 1276163002: Revert of Sandbox html_viewer on Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/font_loader.h"
6
7 #include "components/font_service/public/cpp/font_service_thread.h"
8 #include "mojo/application/public/cpp/application_impl.h"
9
10 namespace font_service {
11
12 FontLoader::FontLoader(mojo::ApplicationImpl* application_impl) {
13 mojo::URLRequestPtr request(mojo::URLRequest::New());
14 request->url = mojo::String::From("mojo:font_service");
15 FontServicePtr font_service;
16 application_impl->ConnectToService(request.Pass(), &font_service);
17
18 thread_ = new internal::FontServiceThread(font_service.Pass());
19 }
20
21 FontLoader::~FontLoader() {}
22
23 bool FontLoader::matchFamilyName(const char family_name[],
24 SkTypeface::Style requested,
25 FontIdentity* out_font_identifier,
26 SkString* out_family_name,
27 SkTypeface::Style* out_style) {
28 return thread_->MatchFamilyName(family_name, requested, out_font_identifier,
29 out_family_name, out_style);
30 }
31
32 SkStreamAsset* FontLoader::openStream(const FontIdentity& identity) {
33 {
34 base::AutoLock lock(lock_);
35 auto mapped_font_files_it = mapped_font_files_.find(identity.fID);
36 if (mapped_font_files_it != mapped_font_files_.end())
37 return mapped_font_files_it->second->CreateMemoryStream();
38 }
39
40 scoped_refptr<internal::MappedFontFile> mapped_font_file =
41 thread_->OpenStream(identity);
42 if (!mapped_font_file)
43 return nullptr;
44
45 // Get notified with |mapped_font_file| is destroyed.
46 mapped_font_file->set_observer(this);
47
48 {
49 base::AutoLock lock(lock_);
50 auto mapped_font_files_it =
51 mapped_font_files_.insert(std::make_pair(mapped_font_file->font_id(),
52 mapped_font_file.get()))
53 .first;
54 return mapped_font_files_it->second->CreateMemoryStream();
55 }
56 }
57
58 void FontLoader::OnMappedFontFileDestroyed(internal::MappedFontFile* f) {
59 base::AutoLock lock(lock_);
60 mapped_font_files_.erase(f->font_id());
61 }
62
63 } // namespace font_service
OLDNEW
« no previous file with comments | « components/font_service/public/cpp/font_loader.h ('k') | components/font_service/public/cpp/font_service_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698