OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/backend/print_backend.h" | 5 #include "printing/backend/print_backend.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #if !defined(OS_MACOSX) | 9 #if !defined(OS_MACOSX) |
10 #include <gcrypt.h> | 10 #include <gcrypt.h> |
11 #endif | 11 #endif |
12 #include <pthread.h> | 12 #include <pthread.h> |
13 | 13 |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
16 #include "base/lock.h" | |
17 #include "base/logging.h" | 16 #include "base/logging.h" |
18 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
| 18 #include "base/synchronization/lock.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
20 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
21 #include "printing/backend/cups_helper.h" | 21 #include "printing/backend/cups_helper.h" |
22 #include "printing/backend/print_backend_consts.h" | 22 #include "printing/backend/print_backend_consts.h" |
23 | 23 |
24 #if !defined(OS_MACOSX) | 24 #if !defined(OS_MACOSX) |
25 GCRY_THREAD_OPTION_PTHREAD_IMPL; | 25 GCRY_THREAD_OPTION_PTHREAD_IMPL; |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 } else { | 213 } else { |
214 HttpConnectionCUPS http(print_server_url_); | 214 HttpConnectionCUPS http(print_server_url_); |
215 http.SetBlocking(blocking_); | 215 http.SetBlocking(blocking_); |
216 return cupsGetDests2(http.http(), dests); | 216 return cupsGetDests2(http.http(), dests); |
217 } | 217 } |
218 } | 218 } |
219 | 219 |
220 FilePath PrintBackendCUPS::GetPPD(const char* name) { | 220 FilePath PrintBackendCUPS::GetPPD(const char* name) { |
221 // cupsGetPPD returns a filename stored in a static buffer in CUPS. | 221 // cupsGetPPD returns a filename stored in a static buffer in CUPS. |
222 // Protect this code with lock. | 222 // Protect this code with lock. |
223 static Lock ppd_lock; | 223 static base::Lock ppd_lock; |
224 AutoLock ppd_autolock(ppd_lock); | 224 base::AutoLock ppd_autolock(ppd_lock); |
225 FilePath ppd_path; | 225 FilePath ppd_path; |
226 const char* ppd_file_path = NULL; | 226 const char* ppd_file_path = NULL; |
227 if (print_server_url_.is_empty()) { // Use default (local) print server. | 227 if (print_server_url_.is_empty()) { // Use default (local) print server. |
228 ppd_file_path = cupsGetPPD(name); | 228 ppd_file_path = cupsGetPPD(name); |
229 if (ppd_file_path) | 229 if (ppd_file_path) |
230 ppd_path = FilePath(ppd_file_path); | 230 ppd_path = FilePath(ppd_file_path); |
231 } else { | 231 } else { |
232 // cupsGetPPD2 gets stuck sometimes in an infinite time due to network | 232 // cupsGetPPD2 gets stuck sometimes in an infinite time due to network |
233 // configuration/issues. To prevent that, use non-blocking http connection | 233 // configuration/issues. To prevent that, use non-blocking http connection |
234 // here. | 234 // here. |
(...skipping 23 matching lines...) Expand all Loading... |
258 << ", content length: " << content_len; | 258 << ", content length: " << content_len; |
259 file_util::Delete(ppd_path, false); | 259 file_util::Delete(ppd_path, false); |
260 ppd_path.clear(); | 260 ppd_path.clear(); |
261 } | 261 } |
262 } | 262 } |
263 } | 263 } |
264 return ppd_path; | 264 return ppd_path; |
265 } | 265 } |
266 | 266 |
267 } // namespace printing | 267 } // namespace printing |
OLD | NEW |