OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "printing/pdf_metafile_cg_mac.h" | 5 #include "printing/pdf_metafile_cg_mac.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 // is used to hold the destination context, and then about five layers down on | 28 // is used to hold the destination context, and then about five layers down on |
29 // the callstack, a PdfMetafileCg is used to hold the source PDF. If the source | 29 // the callstack, a PdfMetafileCg is used to hold the source PDF. If the source |
30 // PDF is drawn into the destination PDF context and then released, accessing | 30 // PDF is drawn into the destination PDF context and then released, accessing |
31 // the destination PDF context will crash. So the outermost instantiation of | 31 // the destination PDF context will crash. So the outermost instantiation of |
32 // PdfMetafileCg creates a pool for deeper instantiations to dump their used | 32 // PdfMetafileCg creates a pool for deeper instantiations to dump their used |
33 // PDFs into rather than releasing them. When the top-level PDF is closed, then | 33 // PDFs into rather than releasing them. When the top-level PDF is closed, then |
34 // it's safe to clear the pool. A thread local is used to allow this to work in | 34 // it's safe to clear the pool. A thread local is used to allow this to work in |
35 // single-process mode. TODO(avi): This Apple bug appears fixed in 10.7; when | 35 // single-process mode. TODO(avi): This Apple bug appears fixed in 10.7; when |
36 // 10.7 is the minimum required version for Chromium, remove this hack. | 36 // 10.7 is the minimum required version for Chromium, remove this hack. |
37 | 37 |
38 base::LazyInstance< | 38 base::LazyInstance<base::ThreadLocalPointer<struct __CFSet> >::Leaky |
39 base::ThreadLocalPointer<struct __CFSet>, | 39 thread_pdf_docs = LAZY_INSTANCE_INITIALIZER; |
40 base::LeakyLazyInstanceTraits<base::ThreadLocalPointer<struct __CFSet> > > | |
41 thread_pdf_docs = LAZY_INSTANCE_INITIALIZER; | |
42 | 40 |
43 } // namespace | 41 } // namespace |
44 | 42 |
45 namespace printing { | 43 namespace printing { |
46 | 44 |
47 PdfMetafileCg::PdfMetafileCg() | 45 PdfMetafileCg::PdfMetafileCg() |
48 : page_is_open_(false), | 46 : page_is_open_(false), |
49 thread_pdf_docs_owned_(false) { | 47 thread_pdf_docs_owned_(false) { |
50 if (!thread_pdf_docs.Pointer()->Get() && | 48 if (!thread_pdf_docs.Pointer()->Get() && |
51 base::mac::IsOSSnowLeopardOrEarlier()) { | 49 base::mac::IsOSSnowLeopardOrEarlier()) { |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 289 |
292 if (!pdf_doc_.get()) { | 290 if (!pdf_doc_.get()) { |
293 ScopedCFTypeRef<CGDataProviderRef> pdf_data_provider( | 291 ScopedCFTypeRef<CGDataProviderRef> pdf_data_provider( |
294 CGDataProviderCreateWithCFData(pdf_data_)); | 292 CGDataProviderCreateWithCFData(pdf_data_)); |
295 pdf_doc_.reset(CGPDFDocumentCreateWithProvider(pdf_data_provider)); | 293 pdf_doc_.reset(CGPDFDocumentCreateWithProvider(pdf_data_provider)); |
296 } | 294 } |
297 return pdf_doc_.get(); | 295 return pdf_doc_.get(); |
298 } | 296 } |
299 | 297 |
300 } // namespace printing | 298 } // namespace printing |
OLD | NEW |