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_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/platform_handle/platform_handle_functions.h" | 13 #include "mojo/public/cpp/system/platform_handle.h" |
14 | 14 |
15 namespace font_service { | 15 namespace font_service { |
16 namespace internal { | 16 namespace internal { |
17 | 17 |
18 namespace { | 18 namespace { |
19 const char kFontThreadName[] = "Font_Proxy_Thread"; | 19 const char kFontThreadName[] = "Font_Proxy_Thread"; |
20 } // namespace | 20 } // namespace |
21 | 21 |
22 FontServiceThread::FontServiceThread(mojom::FontServicePtr font_service) | 22 FontServiceThread::FontServiceThread(mojom::FontServicePtr font_service) |
23 : base::Thread(kFontThreadName), | 23 : base::Thread(kFontThreadName), |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 font_service_->OpenStream( | 150 font_service_->OpenStream( |
151 id_number, base::Bind(&FontServiceThread::OnOpenStreamComplete, this, | 151 id_number, base::Bind(&FontServiceThread::OnOpenStreamComplete, this, |
152 done_event, output_file)); | 152 done_event, output_file)); |
153 } | 153 } |
154 | 154 |
155 void FontServiceThread::OnOpenStreamComplete(base::WaitableEvent* done_event, | 155 void FontServiceThread::OnOpenStreamComplete(base::WaitableEvent* done_event, |
156 base::File* output_file, | 156 base::File* output_file, |
157 mojo::ScopedHandle handle) { | 157 mojo::ScopedHandle handle) { |
158 pending_waitable_events_.erase(done_event); | 158 pending_waitable_events_.erase(done_event); |
159 if (handle.is_valid()) { | 159 if (handle.is_valid()) { |
160 MojoPlatformHandle platform_handle; | 160 base::PlatformFile platform_file; |
161 CHECK(MojoExtractPlatformHandle(handle.release().value(), | 161 CHECK_EQ(mojo::UnwrapPlatformFile(std::move(handle), &platform_file), |
162 &platform_handle) == MOJO_RESULT_OK); | 162 MOJO_RESULT_OK); |
163 *output_file = base::File(platform_handle); | 163 *output_file = base::File(platform_file); |
164 } | 164 } |
165 | 165 |
166 done_event->Signal(); | 166 done_event->Signal(); |
167 } | 167 } |
168 | 168 |
169 void FontServiceThread::OnFontServiceConnectionError() { | 169 void FontServiceThread::OnFontServiceConnectionError() { |
170 std::set<base::WaitableEvent*> events; | 170 std::set<base::WaitableEvent*> events; |
171 events.swap(pending_waitable_events_); | 171 events.swap(pending_waitable_events_); |
172 for (base::WaitableEvent* event : events) | 172 for (base::WaitableEvent* event : events) |
173 event->Signal(); | 173 event->Signal(); |
174 } | 174 } |
175 | 175 |
176 void FontServiceThread::Init() { | 176 void FontServiceThread::Init() { |
177 font_service_.Bind(std::move(font_service_info_)); | 177 font_service_.Bind(std::move(font_service_info_)); |
178 font_service_.set_connection_error_handler( | 178 font_service_.set_connection_error_handler( |
179 base::Bind(&FontServiceThread::OnFontServiceConnectionError, | 179 base::Bind(&FontServiceThread::OnFontServiceConnectionError, |
180 weak_factory_.GetWeakPtr())); | 180 weak_factory_.GetWeakPtr())); |
181 } | 181 } |
182 | 182 |
183 void FontServiceThread::CleanUp() { | 183 void FontServiceThread::CleanUp() { |
184 font_service_.reset(); | 184 font_service_.reset(); |
185 } | 185 } |
186 | 186 |
187 } // namespace internal | 187 } // namespace internal |
188 } // namespace font_service | 188 } // namespace font_service |
OLD | NEW |