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 <pwd.h> | 5 #include <pwd.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <sys/stat.h> | 7 #include <sys/stat.h> |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 #include <sys/wait.h> | 9 #include <sys/wait.h> |
10 | 10 |
11 #include <cups/backend.h> | 11 #include <cups/backend.h> |
12 | 12 |
13 #include "base/at_exit.h" | 13 #include "base/at_exit.h" |
14 #include "base/base_paths.h" | 14 #include "base/base_paths.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/file_path.h" | 16 #include "base/file_path.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
19 | 19 |
20 #include "cloud_print/virtual_driver/posix/printer_driver_util_posix.h" | 20 #include "cloud_print/virtual_driver/posix/printer_driver_util_posix.h" |
21 | 21 |
22 int WriteToTemp(FILE* input_pdf, FilePath output_path) { | 22 void WriteToTemp(FILE* input_pdf, FilePath output_path) { |
23 FILE* output_pdf; | 23 FILE* output_pdf; |
24 char buffer[128]; | 24 char buffer[128]; |
25 output_pdf = fopen(output_path.value().c_str(), "w"); | 25 output_pdf = fopen(output_path.value().c_str(), "w"); |
26 if (output_pdf == NULL) { | 26 if (output_pdf == NULL) { |
27 LOG(ERROR) << "Unable to open file handle for writing output file"; | 27 LOG(ERROR) << "Unable to open file handle for writing output file"; |
28 exit(CUPS_BACKEND_CANCEL); | 28 exit(CUPS_BACKEND_CANCEL); |
29 } | 29 } |
30 // Read from input file or stdin and write to output file. | 30 // Read from input file or stdin and write to output file. |
31 while (fgets(buffer, sizeof(buffer), input_pdf) != NULL) { | 31 while (fgets(buffer, sizeof(buffer), input_pdf) != NULL) { |
32 fputs(buffer, output_pdf); | 32 fputs(buffer, output_pdf); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 71 } |
72 | 72 |
73 if (argc < 6 || argc > 7) { | 73 if (argc < 6 || argc > 7) { |
74 fprintf(stderr, "Usage: GCP-Driver job-id user" | 74 fprintf(stderr, "Usage: GCP-Driver job-id user" |
75 "title copies options [file]\n"); | 75 "title copies options [file]\n"); |
76 return 0; | 76 return 0; |
77 } | 77 } |
78 | 78 |
79 // AtExitManager is necessary to use the path service. | 79 // AtExitManager is necessary to use the path service. |
80 base::AtExitManager aemanager; | 80 base::AtExitManager aemanager; |
81 // File handler for the temporary PDF we pass onto Chrome. | |
82 FILE* output_pdf; | |
83 // CommandLine is only setup to enable logging, never used subseqeuently. | 81 // CommandLine is only setup to enable logging, never used subseqeuently. |
84 CommandLine::Init(argc, argv); | 82 CommandLine::Init(argc, argv); |
85 // Location for the log file. | 83 // Location for the log file. |
86 std::string log_location = "/var/log/GCP-Driver.log"; | 84 std::string log_location = "/var/log/GCP-Driver.log"; |
87 | 85 |
88 // Set up logging. | 86 // Set up logging. |
89 logging::InitLogging(log_location.c_str(), | 87 logging::InitLogging(log_location.c_str(), |
90 logging::LOG_ONLY_TO_FILE, | 88 logging::LOG_ONLY_TO_FILE, |
91 logging::LOCK_LOG_FILE, | 89 logging::LOCK_LOG_FILE, |
92 logging::APPEND_TO_OLD_LOG_FILE, | 90 logging::APPEND_TO_OLD_LOG_FILE, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // Launch Chrome and pass the print job onto Cloud Print. | 143 // Launch Chrome and pass the print job onto Cloud Print. |
146 LaunchPrintDialog(output_path.value(), job_title, current_user); | 144 LaunchPrintDialog(output_path.value(), job_title, current_user); |
147 | 145 |
148 return 0; | 146 return 0; |
149 } | 147 } |
150 // back in parent process. | 148 // back in parent process. |
151 // wait for child, then terminate. | 149 // wait for child, then terminate. |
152 waitpid(pid, NULL, 0); | 150 waitpid(pid, NULL, 0); |
153 return 0; | 151 return 0; |
154 } | 152 } |
OLD | NEW |