| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "build/build_config.h" | |
| 8 | |
| 9 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 10 #include <errno.h> | 8 #include <errno.h> |
| 11 #include <pthread.h> | 9 #include <pthread.h> |
| 12 | 10 |
| 13 #include "base/debug/leak_annotations.h" | 11 #include "base/debug/leak_annotations.h" |
| 14 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 15 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
| 16 #include "base/logging.h" | 14 #include "base/logging.h" |
| 17 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 if (print_server_url_.is_empty()) { // Use default (local) print server. | 260 if (print_server_url_.is_empty()) { // Use default (local) print server. |
| 263 ppd_file_path = cupsGetPPD(name); | 261 ppd_file_path = cupsGetPPD(name); |
| 264 if (ppd_file_path) | 262 if (ppd_file_path) |
| 265 ppd_path = base::FilePath(ppd_file_path); | 263 ppd_path = base::FilePath(ppd_file_path); |
| 266 } else { | 264 } else { |
| 267 // cupsGetPPD2 gets stuck sometimes in an infinite time due to network | 265 // cupsGetPPD2 gets stuck sometimes in an infinite time due to network |
| 268 // configuration/issues. To prevent that, use non-blocking http connection | 266 // configuration/issues. To prevent that, use non-blocking http connection |
| 269 // here. | 267 // here. |
| 270 // Note: After looking at CUPS sources, it looks like non-blocking | 268 // Note: After looking at CUPS sources, it looks like non-blocking |
| 271 // connection will timeout after 10 seconds of no data period. And it will | 269 // connection will timeout after 10 seconds of no data period. And it will |
| 272 // return the same way as if data was completely and sucessfully downloaded. | 270 // return the same way as if data was completely and successfully |
| 271 // downloaded. |
| 273 HttpConnectionCUPS http(print_server_url_, cups_encryption_); | 272 HttpConnectionCUPS http(print_server_url_, cups_encryption_); |
| 274 http.SetBlocking(blocking_); | 273 http.SetBlocking(blocking_); |
| 275 ppd_file_path = cupsGetPPD2(http.http(), name); | 274 ppd_file_path = cupsGetPPD2(http.http(), name); |
| 276 // Check if the get full PPD, since non-blocking call may simply return | 275 // Check if the get full PPD, since non-blocking call may simply return |
| 277 // normally after timeout expired. | 276 // normally after timeout expired. |
| 278 if (ppd_file_path) { | 277 if (ppd_file_path) { |
| 279 // There is no reliable way right now to detect full and complete PPD | 278 // There is no reliable way right now to detect full and complete PPD |
| 280 // get downloaded. If we reach http timeout, it may simply return | 279 // get downloaded. If we reach http timeout, it may simply return |
| 281 // downloaded part as a full response. It might be good enough to check | 280 // downloaded part as a full response. It might be good enough to check |
| 282 // http->data_remaining or http->_data_remaining, unfortunately http_t | 281 // http->data_remaining or http->_data_remaining, unfortunately http_t |
| (...skipping 12 matching lines...) Expand all Loading... |
| 295 << ", HTTP error: " << http_error; | 294 << ", HTTP error: " << http_error; |
| 296 base::DeleteFile(ppd_path, false); | 295 base::DeleteFile(ppd_path, false); |
| 297 ppd_path.clear(); | 296 ppd_path.clear(); |
| 298 } | 297 } |
| 299 } | 298 } |
| 300 } | 299 } |
| 301 return ppd_path; | 300 return ppd_path; |
| 302 } | 301 } |
| 303 | 302 |
| 304 } // namespace printing | 303 } // namespace printing |
| OLD | NEW |