OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "components/font_service/public/cpp/font_loader.h" | 5 #include "components/font_service/public/cpp/font_loader.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/trace_event/trace_event.h" |
8 #include "components/font_service/public/cpp/font_service_thread.h" | 9 #include "components/font_service/public/cpp/font_service_thread.h" |
9 #include "mojo/application/public/cpp/application_impl.h" | 10 #include "mojo/application/public/cpp/application_impl.h" |
10 #include "mojo/application/public/cpp/connect.h" | 11 #include "mojo/application/public/cpp/connect.h" |
11 #include "mojo/application/public/interfaces/shell.mojom.h" | 12 #include "mojo/application/public/interfaces/shell.mojom.h" |
12 | 13 |
13 namespace font_service { | 14 namespace font_service { |
14 namespace { | 15 namespace { |
15 void OnGotContentHandlerID(uint32_t content_handler_id) {} | 16 void OnGotContentHandlerID(uint32_t content_handler_id) {} |
16 } // namespace | 17 } // namespace |
17 | 18 |
(...skipping 24 matching lines...) Expand all Loading... |
42 void FontLoader::Shutdown() { | 43 void FontLoader::Shutdown() { |
43 thread_->Stop(); | 44 thread_->Stop(); |
44 thread_ = nullptr; | 45 thread_ = nullptr; |
45 } | 46 } |
46 | 47 |
47 bool FontLoader::matchFamilyName(const char family_name[], | 48 bool FontLoader::matchFamilyName(const char family_name[], |
48 SkTypeface::Style requested, | 49 SkTypeface::Style requested, |
49 FontIdentity* out_font_identifier, | 50 FontIdentity* out_font_identifier, |
50 SkString* out_family_name, | 51 SkString* out_family_name, |
51 SkTypeface::Style* out_style) { | 52 SkTypeface::Style* out_style) { |
| 53 TRACE_EVENT1("font_service", "FontServiceThread::MatchFamilyName", |
| 54 "family_name", family_name); |
52 return thread_->MatchFamilyName(family_name, requested, out_font_identifier, | 55 return thread_->MatchFamilyName(family_name, requested, out_font_identifier, |
53 out_family_name, out_style); | 56 out_family_name, out_style); |
54 } | 57 } |
55 | 58 |
56 SkStreamAsset* FontLoader::openStream(const FontIdentity& identity) { | 59 SkStreamAsset* FontLoader::openStream(const FontIdentity& identity) { |
| 60 TRACE_EVENT2("font_loader", "FontLoader::openStream", |
| 61 "identity", identity.fID, |
| 62 "name", identity.fString.c_str()); |
57 { | 63 { |
58 base::AutoLock lock(lock_); | 64 base::AutoLock lock(lock_); |
59 auto mapped_font_files_it = mapped_font_files_.find(identity.fID); | 65 auto mapped_font_files_it = mapped_font_files_.find(identity.fID); |
60 if (mapped_font_files_it != mapped_font_files_.end()) | 66 if (mapped_font_files_it != mapped_font_files_.end()) |
61 return mapped_font_files_it->second->CreateMemoryStream(); | 67 return mapped_font_files_it->second->CreateMemoryStream(); |
62 } | 68 } |
63 | 69 |
64 scoped_refptr<internal::MappedFontFile> mapped_font_file = | 70 scoped_refptr<internal::MappedFontFile> mapped_font_file = |
65 thread_->OpenStream(identity); | 71 thread_->OpenStream(identity); |
66 if (!mapped_font_file) | 72 if (!mapped_font_file) |
67 return nullptr; | 73 return nullptr; |
68 | 74 |
69 // Get notified with |mapped_font_file| is destroyed. | 75 // Get notified with |mapped_font_file| is destroyed. |
70 mapped_font_file->set_observer(this); | 76 mapped_font_file->set_observer(this); |
71 | 77 |
72 { | 78 { |
73 base::AutoLock lock(lock_); | 79 base::AutoLock lock(lock_); |
74 auto mapped_font_files_it = | 80 auto mapped_font_files_it = |
75 mapped_font_files_.insert(std::make_pair(mapped_font_file->font_id(), | 81 mapped_font_files_.insert(std::make_pair(mapped_font_file->font_id(), |
76 mapped_font_file.get())) | 82 mapped_font_file.get())) |
77 .first; | 83 .first; |
78 return mapped_font_files_it->second->CreateMemoryStream(); | 84 return mapped_font_files_it->second->CreateMemoryStream(); |
79 } | 85 } |
80 } | 86 } |
81 | 87 |
82 void FontLoader::OnMappedFontFileDestroyed(internal::MappedFontFile* f) { | 88 void FontLoader::OnMappedFontFileDestroyed(internal::MappedFontFile* f) { |
| 89 TRACE_EVENT1("font_loader", "FontLoader::OnMappedFontFileDestroyed", |
| 90 "identity", f->font_id()); |
83 base::AutoLock lock(lock_); | 91 base::AutoLock lock(lock_); |
84 mapped_font_files_.erase(f->font_id()); | 92 mapped_font_files_.erase(f->font_id()); |
85 } | 93 } |
86 | 94 |
87 } // namespace font_service | 95 } // namespace font_service |
OLD | NEW |