Chromium Code Reviews| 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 "content/child/dwrite_font_proxy/dwrite_font_proxy_win.h" | 5 #include "content/child/dwrite_font_proxy/dwrite_font_proxy_win.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 uint32_t family_index = 0; | 90 uint32_t family_index = 0; |
| 91 base::string16 name(family_name); | 91 base::string16 name(family_name); |
| 92 | 92 |
| 93 auto iter = family_names_.find(name); | 93 auto iter = family_names_.find(name); |
| 94 if (iter != family_names_.end()) { | 94 if (iter != family_names_.end()) { |
| 95 *index = iter->second; | 95 *index = iter->second; |
| 96 *exists = iter->second != UINT_MAX; | 96 *exists = iter->second != UINT_MAX; |
| 97 return S_OK; | 97 return S_OK; |
| 98 } | 98 } |
| 99 | 99 |
| 100 if (!GetSender()->Send( | 100 if (!sender_.Run()->Send( |
| 101 new DWriteFontProxyMsg_FindFamily(name, &family_index))) { | 101 new DWriteFontProxyMsg_FindFamily(name, &family_index))) { |
| 102 LogFontProxyError(FIND_FAMILY_SEND_FAILED); | 102 LogFontProxyError(FIND_FAMILY_SEND_FAILED); |
| 103 return E_FAIL; | 103 return E_FAIL; |
| 104 } | 104 } |
| 105 | 105 |
| 106 if (family_index != UINT32_MAX) { | 106 if (family_index != UINT32_MAX) { |
| 107 if (!CreateFamily(family_index)) | 107 if (!CreateFamily(family_index)) |
| 108 return E_FAIL; | 108 return E_FAIL; |
| 109 *exists = TRUE; | 109 *exists = TRUE; |
| 110 *index = family_index; | 110 *index = family_index; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 135 return S_OK; | 135 return S_OK; |
| 136 } | 136 } |
| 137 | 137 |
| 138 UINT32 DWriteFontCollectionProxy::GetFontFamilyCount() { | 138 UINT32 DWriteFontCollectionProxy::GetFontFamilyCount() { |
| 139 if (family_count_ != UINT_MAX) | 139 if (family_count_ != UINT_MAX) |
| 140 return family_count_; | 140 return family_count_; |
| 141 | 141 |
| 142 TRACE_EVENT0("dwrite", "FontProxy::GetFontFamilyCount"); | 142 TRACE_EVENT0("dwrite", "FontProxy::GetFontFamilyCount"); |
| 143 | 143 |
| 144 uint32_t family_count = 0; | 144 uint32_t family_count = 0; |
| 145 if (!GetSender()->Send( | 145 if (!sender_.Run()->Send( |
| 146 new DWriteFontProxyMsg_GetFamilyCount(&family_count))) { | 146 new DWriteFontProxyMsg_GetFamilyCount(&family_count))) { |
| 147 LogFontProxyError(GET_FAMILY_COUNT_SEND_FAILED); | 147 LogFontProxyError(GET_FAMILY_COUNT_SEND_FAILED); |
| 148 return 0; | 148 return 0; |
| 149 } | 149 } |
| 150 | 150 |
| 151 LogFamilyCount(family_count); | 151 LogFamilyCount(family_count); |
| 152 family_count_ = family_count; | 152 family_count_ = family_count; |
| 153 return family_count; | 153 return family_count; |
| 154 } | 154 } |
| 155 | 155 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 if (*family_index >= GetFontFamilyCount()) { | 188 if (*family_index >= GetFontFamilyCount()) { |
| 189 LogFontProxyError(FAMILY_INDEX_OUT_OF_RANGE); | 189 LogFontProxyError(FAMILY_INDEX_OUT_OF_RANGE); |
| 190 return E_INVALIDARG; | 190 return E_INVALIDARG; |
| 191 } | 191 } |
| 192 | 192 |
| 193 // If we already loaded the family we should reuse the existing collection. | 193 // If we already loaded the family we should reuse the existing collection. |
| 194 DCHECK(!families_[*family_index]->IsLoaded()); | 194 DCHECK(!families_[*family_index]->IsLoaded()); |
| 195 | 195 |
| 196 std::vector<base::string16> file_names; | 196 std::vector<base::string16> file_names; |
| 197 std::vector<IPC::PlatformFileForTransit> file_handles; | 197 std::vector<IPC::PlatformFileForTransit> file_handles; |
| 198 if (!GetSender()->Send(new DWriteFontProxyMsg_GetFontFiles( | 198 if (!sender_.Run()->Send(new DWriteFontProxyMsg_GetFontFiles( |
| 199 *family_index, &file_names, &file_handles))) { | 199 *family_index, &file_names, &file_handles))) { |
| 200 LogFontProxyError(GET_FONT_FILES_SEND_FAILED); | 200 LogFontProxyError(GET_FONT_FILES_SEND_FAILED); |
| 201 return E_FAIL; | 201 return E_FAIL; |
| 202 } | 202 } |
| 203 | 203 |
| 204 std::vector<HANDLE> handles; | 204 std::vector<HANDLE> handles; |
| 205 file_handles.reserve(file_names.size() + file_handles.size()); | 205 file_handles.reserve(file_names.size() + file_handles.size()); |
| 206 for (const base::string16& file_name : file_names) { | 206 for (const base::string16& file_name : file_names) { |
| 207 // This leaks the handles, since they are used as the reference key to | 207 // This leaks the handles, since they are used as the reference key to |
| 208 // CreateStreamFromKey, and DirectWrite requires the reference keys to | 208 // CreateStreamFromKey, and DirectWrite requires the reference keys to |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 mswr::MakeAndInitialize<FontFileStream>(&stream, file_handle))) { | 252 mswr::MakeAndInitialize<FontFileStream>(&stream, file_handle))) { |
| 253 DCHECK(false); | 253 DCHECK(false); |
| 254 return E_FAIL; | 254 return E_FAIL; |
| 255 } | 255 } |
| 256 *font_file_stream = stream.Detach(); | 256 *font_file_stream = stream.Detach(); |
| 257 return S_OK; | 257 return S_OK; |
| 258 } | 258 } |
| 259 | 259 |
| 260 HRESULT DWriteFontCollectionProxy::RuntimeClassInitialize( | 260 HRESULT DWriteFontCollectionProxy::RuntimeClassInitialize( |
| 261 IDWriteFactory* factory, | 261 IDWriteFactory* factory, |
| 262 IPC::Sender* sender_override) { | 262 const base::Callback<IPC::Sender*(void)>& sender) { |
| 263 DCHECK(factory); | 263 DCHECK(factory); |
| 264 | 264 |
| 265 factory_ = factory; | 265 factory_ = factory; |
| 266 sender_override_ = sender_override; | 266 sender_ = sender; |
| 267 | 267 |
| 268 HRESULT hr = factory->RegisterFontCollectionLoader(this); | 268 HRESULT hr = factory->RegisterFontCollectionLoader(this); |
| 269 DCHECK(SUCCEEDED(hr)); | 269 DCHECK(SUCCEEDED(hr)); |
| 270 hr = factory_->RegisterFontFileLoader(this); | 270 hr = factory_->RegisterFontFileLoader(this); |
| 271 DCHECK(SUCCEEDED(hr)); | 271 DCHECK(SUCCEEDED(hr)); |
| 272 return S_OK; | 272 return S_OK; |
| 273 } | 273 } |
| 274 | 274 |
| 275 void DWriteFontCollectionProxy::Unregister() { | 275 void DWriteFontCollectionProxy::Unregister() { |
| 276 factory_->UnregisterFontCollectionLoader(this); | 276 factory_->UnregisterFontCollectionLoader(this); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 307 family.CopyTo(font_family); | 307 family.CopyTo(font_family); |
| 308 return true; | 308 return true; |
| 309 } | 309 } |
| 310 | 310 |
| 311 bool DWriteFontCollectionProxy::LoadFamilyNames( | 311 bool DWriteFontCollectionProxy::LoadFamilyNames( |
| 312 UINT32 family_index, | 312 UINT32 family_index, |
| 313 IDWriteLocalizedStrings** localized_strings) { | 313 IDWriteLocalizedStrings** localized_strings) { |
| 314 TRACE_EVENT0("dwrite", "FontProxy::LoadFamilyNames"); | 314 TRACE_EVENT0("dwrite", "FontProxy::LoadFamilyNames"); |
| 315 | 315 |
| 316 std::vector<std::pair<base::string16, base::string16>> strings; | 316 std::vector<std::pair<base::string16, base::string16>> strings; |
| 317 if (!GetSender()->Send( | 317 if (!sender_.Run()->Send( |
| 318 new DWriteFontProxyMsg_GetFamilyNames(family_index, &strings))) { | 318 new DWriteFontProxyMsg_GetFamilyNames(family_index, &strings))) { |
| 319 return false; | 319 return false; |
| 320 } | 320 } |
| 321 | 321 |
| 322 HRESULT hr = mswr::MakeAndInitialize<DWriteLocalizedStrings>( | 322 HRESULT hr = mswr::MakeAndInitialize<DWriteLocalizedStrings>( |
| 323 localized_strings, &strings); | 323 localized_strings, &strings); |
| 324 | 324 |
| 325 return SUCCEEDED(hr); | 325 return SUCCEEDED(hr); |
| 326 } | 326 } |
| 327 | 327 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 340 mswr::ComPtr<DWriteFontFamilyProxy> family; | 340 mswr::ComPtr<DWriteFontFamilyProxy> family; |
| 341 HRESULT hr = mswr::MakeAndInitialize<DWriteFontFamilyProxy>(&family, this, | 341 HRESULT hr = mswr::MakeAndInitialize<DWriteFontFamilyProxy>(&family, this, |
| 342 family_index); | 342 family_index); |
| 343 DCHECK(SUCCEEDED(hr)); | 343 DCHECK(SUCCEEDED(hr)); |
| 344 DCHECK_LT(family_index, families_.size()); | 344 DCHECK_LT(family_index, families_.size()); |
| 345 | 345 |
| 346 families_[family_index] = family; | 346 families_[family_index] = family; |
| 347 return true; | 347 return true; |
| 348 } | 348 } |
| 349 | 349 |
| 350 IPC::Sender* DWriteFontCollectionProxy::GetSender() { | |
| 351 return sender_override_ ? sender_override_ : ChildThread::Get(); | |
|
jam
2016/07/28 16:34:31
you can fix this by changing
ChildThread::Get()
t
Ilya Kulshin
2016/07/28 19:01:13
thread_safe_sender still needs to be called from t
| |
| 352 } | |
| 353 | |
| 354 DWriteFontFamilyProxy::DWriteFontFamilyProxy() = default; | 350 DWriteFontFamilyProxy::DWriteFontFamilyProxy() = default; |
| 355 | 351 |
| 356 DWriteFontFamilyProxy::~DWriteFontFamilyProxy() = default; | 352 DWriteFontFamilyProxy::~DWriteFontFamilyProxy() = default; |
| 357 | 353 |
| 358 HRESULT DWriteFontFamilyProxy::GetFontCollection( | 354 HRESULT DWriteFontFamilyProxy::GetFontCollection( |
| 359 IDWriteFontCollection** font_collection) { | 355 IDWriteFontCollection** font_collection) { |
| 360 DCHECK(font_collection); | 356 DCHECK(font_collection); |
| 361 | 357 |
| 362 proxy_collection_.CopyTo(font_collection); | 358 proxy_collection_.CopyTo(font_collection); |
| 363 return S_OK; | 359 return S_OK; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 | 608 |
| 613 data_.Initialize(base::File(duplicate_handle)); | 609 data_.Initialize(base::File(duplicate_handle)); |
| 614 if (!data_.IsValid()) { | 610 if (!data_.IsValid()) { |
| 615 LogFontProxyError(MAPPED_FILE_FAILED); | 611 LogFontProxyError(MAPPED_FILE_FAILED); |
| 616 return E_FAIL; | 612 return E_FAIL; |
| 617 } | 613 } |
| 618 return S_OK; | 614 return S_OK; |
| 619 } | 615 } |
| 620 | 616 |
| 621 } // namespace content | 617 } // namespace content |
| OLD | NEW |