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

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

Issue 1916003002: Fixes possible deadlock in fontservice (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « components/font_service/public/cpp/font_service_thread.h ('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 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_service_thread.h" 5 #include "components/font_service/public/cpp/font_service_thread.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
11 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
12 #include "components/font_service/public/cpp/mapped_font_file.h" 12 #include "components/font_service/public/cpp/mapped_font_file.h"
13 #include "mojo/message_pump/message_pump_mojo.h" 13 #include "mojo/message_pump/message_pump_mojo.h"
14 #include "mojo/platform_handle/platform_handle_functions.h" 14 #include "mojo/platform_handle/platform_handle_functions.h"
15 15
16 namespace font_service { 16 namespace font_service {
17 namespace internal { 17 namespace internal {
18 18
19 namespace { 19 namespace {
20 const char kFontThreadName[] = "Font_Proxy_Thread"; 20 const char kFontThreadName[] = "Font_Proxy_Thread";
21 } // namespace 21 } // namespace
22 22
23 FontServiceThread::FontServiceThread(FontServicePtr font_service) 23 FontServiceThread::FontServiceThread(FontServicePtr font_service)
24 : base::Thread(kFontThreadName), 24 : base::Thread(kFontThreadName),
25 font_service_info_(font_service.PassInterface()) { 25 font_service_info_(font_service.PassInterface()),
26 weak_factory_(this) {
26 base::Thread::Options options; 27 base::Thread::Options options;
27 options.message_pump_factory = 28 options.message_pump_factory =
28 base::Bind(&mojo::common::MessagePumpMojo::Create); 29 base::Bind(&mojo::common::MessagePumpMojo::Create);
29 StartWithOptions(options); 30 StartWithOptions(options);
30 } 31 }
31 32
32 bool FontServiceThread::MatchFamilyName( 33 bool FontServiceThread::MatchFamilyName(
33 const char family_name[], 34 const char family_name[],
34 SkFontStyle requested_style, 35 SkFontStyle requested_style,
35 SkFontConfigInterface::FontIdentity* out_font_identity, 36 SkFontConfigInterface::FontIdentity* out_font_identity,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 141
141 void FontServiceThread::OpenStreamImpl(base::WaitableEvent* done_event, 142 void FontServiceThread::OpenStreamImpl(base::WaitableEvent* done_event,
142 base::File* output_file, 143 base::File* output_file,
143 const uint32_t id_number) { 144 const uint32_t id_number) {
144 DCHECK_EQ(GetThreadId(), base::PlatformThread::CurrentId()); 145 DCHECK_EQ(GetThreadId(), base::PlatformThread::CurrentId());
145 if (font_service_.encountered_error()) { 146 if (font_service_.encountered_error()) {
146 done_event->Signal(); 147 done_event->Signal();
147 return; 148 return;
148 } 149 }
149 150
151 pending_waitable_events_.insert(done_event);
150 font_service_->OpenStream( 152 font_service_->OpenStream(
151 id_number, base::Bind(&FontServiceThread::OnOpenStreamComplete, this, 153 id_number, base::Bind(&FontServiceThread::OnOpenStreamComplete, this,
152 done_event, output_file)); 154 done_event, output_file));
153 } 155 }
154 156
155 void FontServiceThread::OnOpenStreamComplete(base::WaitableEvent* done_event, 157 void FontServiceThread::OnOpenStreamComplete(base::WaitableEvent* done_event,
156 base::File* output_file, 158 base::File* output_file,
157 mojo::ScopedHandle handle) { 159 mojo::ScopedHandle handle) {
160 pending_waitable_events_.erase(done_event);
158 if (handle.is_valid()) { 161 if (handle.is_valid()) {
159 MojoPlatformHandle platform_handle; 162 MojoPlatformHandle platform_handle;
160 CHECK(MojoExtractPlatformHandle(handle.release().value(), 163 CHECK(MojoExtractPlatformHandle(handle.release().value(),
161 &platform_handle) == MOJO_RESULT_OK); 164 &platform_handle) == MOJO_RESULT_OK);
162 *output_file = base::File(platform_handle); 165 *output_file = base::File(platform_handle);
163 } 166 }
164 167
165 done_event->Signal(); 168 done_event->Signal();
166 } 169 }
167 170
171 void FontServiceThread::OnFontServiceConnectionError() {
172 std::set<base::WaitableEvent*> events;
173 events.swap(pending_waitable_events_);
174 for (base::WaitableEvent* event : events)
175 event->Signal();
176 }
177
168 void FontServiceThread::Init() { 178 void FontServiceThread::Init() {
169 font_service_.Bind(std::move(font_service_info_)); 179 font_service_.Bind(std::move(font_service_info_));
180 font_service_.set_connection_error_handler(
181 base::Bind(&FontServiceThread::OnFontServiceConnectionError,
182 weak_factory_.GetWeakPtr()));
170 } 183 }
171 184
172 void FontServiceThread::CleanUp() { 185 void FontServiceThread::CleanUp() {
173 font_service_.reset(); 186 font_service_.reset();
174 } 187 }
175 188
176 } // namespace internal 189 } // namespace internal
177 } // namespace font_service 190 } // namespace font_service
OLDNEW
« no previous file with comments | « components/font_service/public/cpp/font_service_thread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698