Chromium Code Reviews| Index: components/pdf/renderer/ppb_pdf_impl.cc |
| diff --git a/components/pdf/renderer/ppb_pdf_impl.cc b/components/pdf/renderer/ppb_pdf_impl.cc |
| index aa0a33a05747ff4484f839353d301293d8aaf6b3..5d28ecb10d35771b7d00933377fcec43d0529fce 100644 |
| --- a/components/pdf/renderer/ppb_pdf_impl.cc |
| +++ b/components/pdf/renderer/ppb_pdf_impl.cc |
| @@ -5,9 +5,11 @@ |
| #include "components/pdf/renderer/ppb_pdf_impl.h" |
| #include "base/files/scoped_file.h" |
| +#include "base/lazy_instance.h" |
| #include "base/metrics/histogram.h" |
| #include "base/numerics/safe_conversions.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "base/threading/thread_local.h" |
| #include "build/build_config.h" |
| #include "components/pdf/common/pdf_messages.h" |
| #include "components/pdf/renderer/pdf_resource_util.h" |
| @@ -35,7 +37,8 @@ |
| namespace pdf { |
| namespace { |
| -PPB_PDF_Impl::PrintClient* g_print_client = NULL; |
| +base::LazyInstance<base::ThreadLocalPointer<PPB_PDF_Impl::PrintClient> >::Leaky |
| + g_print_client_tls = LAZY_INSTANCE_INITIALIZER; |
|
dmichael (off chromium)
2015/02/11 17:35:00
Please add a comment briefly explaining why we're
|
| #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| class PrivateFontFile : public ppapi::Resource { |
| @@ -257,7 +260,8 @@ PP_Bool IsFeatureEnabled(PP_Instance instance, PP_PDFFeature feature) { |
| case PP_PDFFEATURE_HIDPI: |
| return PP_TRUE; |
| case PP_PDFFEATURE_PRINTING: |
| - return (g_print_client && g_print_client->IsPrintingEnabled(instance)) |
| + return (g_print_client_tls.Pointer()->Get() && |
| + g_print_client_tls.Pointer()->Get()->IsPrintingEnabled(instance)) |
| ? PP_TRUE |
| : PP_FALSE; |
| } |
| @@ -371,12 +375,15 @@ const PPB_PDF* PPB_PDF_Impl::GetInterface() { |
| // static |
| bool PPB_PDF_Impl::InvokePrintingForInstance(PP_Instance instance_id) { |
| - return g_print_client ? g_print_client->Print(instance_id) : false; |
| + return g_print_client_tls.Pointer()->Get() |
| + ? g_print_client_tls.Pointer()->Get()->Print(instance_id) |
| + : false; |
| } |
| void PPB_PDF_Impl::SetPrintClient(PPB_PDF_Impl::PrintClient* client) { |
| - CHECK(!g_print_client) << "There should only be a single PrintClient."; |
| - g_print_client = client; |
| + CHECK(!g_print_client_tls.Pointer()->Get()) |
| + << "There should only be a single PrintClient for one RenderThread."; |
| + g_print_client_tls.Pointer()->Set(client); |
| } |
| } // namespace pdf |