diff options
author | rsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-23 06:07:21 +0000 |
---|---|---|
committer | rsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-23 06:07:21 +0000 |
commit | 685df75500087627c71fcb796b1af001a9b0ae2d (patch) | |
tree | 1bf815ae355e36015cb5ee211db681eb88705941 /cloud_print/virtual_driver | |
parent | b0ff3f8e755f87da1aedeaf051b88f53662f8652 (diff) | |
download | chromium_src-685df75500087627c71fcb796b1af001a9b0ae2d.zip chromium_src-685df75500087627c71fcb796b1af001a9b0ae2d.tar.gz chromium_src-685df75500087627c71fcb796b1af001a9b0ae2d.tar.bz2 |
Virtual printer driver style cleanup
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/7467020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93787 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cloud_print/virtual_driver')
10 files changed, 69 insertions, 67 deletions
diff --git a/cloud_print/virtual_driver/posix/backend.gyp b/cloud_print/virtual_driver/posix/backend.gyp index 6e89012..f77fabf 100644 --- a/cloud_print/virtual_driver/posix/backend.gyp +++ b/cloud_print/virtual_driver/posix/backend.gyp @@ -18,7 +18,9 @@ 'sources' : [ 'virtual_driver_posix.cc', 'printer_driver_util_linux.cc', + 'printer_driver_util_posix.h', '../virtual_driver_switches.cc', + '../virtual_driver_switches.h', ] }, ], diff --git a/cloud_print/virtual_driver/posix/printer_driver_util_linux.cc b/cloud_print/virtual_driver/posix/printer_driver_util_linux.cc index 51d4198..81014f8 100644 --- a/cloud_print/virtual_driver/posix/printer_driver_util_linux.cc +++ b/cloud_print/virtual_driver/posix/printer_driver_util_linux.cc @@ -13,16 +13,17 @@ #include "cloud_print/virtual_driver/posix/printer_driver_util_posix.h" #include "cloud_print/virtual_driver/virtual_driver_switches.h" -void LaunchPrintDialog(std::string output_path, std::string job_title, - std::string current_user) { +void LaunchPrintDialog(const std::string& output_path, + const std::string& job_title, + const std::string& current_user) { std::string set_var; // Set Environment variable to control display. - set_var="/home/" + current_user + "/.Xauthority"; - if(setenv("DISPLAY",":0.0",0) == -1) { + set_var = "/home/" + current_user + "/.Xauthority"; + if (setenv("DISPLAY", ":0.0", 0) == -1) { LOG(ERROR) << "Unable to set DISPLAY environment variable"; } - if(setenv("XAUTHORITY",set_var.c_str(),0) == -1) { + if (setenv("XAUTHORITY", set_var.c_str(), 0) == -1) { LOG(ERROR) << "Unable to set XAUTHORITY environment variable"; } @@ -31,18 +32,15 @@ void LaunchPrintDialog(std::string output_path, std::string job_title, FilePath chrome_path("google-chrome"); FilePath job_path(output_path); CommandLine command_line(chrome_path); - command_line.AppendSwitchPath(switches::kCloudPrintFile,job_path); + command_line.AppendSwitchPath(switches::kCloudPrintFile, job_path); command_line.AppendSwitchNative(switches::kCloudPrintJobTitle, job_title); command_line.AppendSwitch(switches::kCloudPrintDeleteFile); LOG(INFO) << "Call to chrome is " << command_line.GetCommandLineString(); - if(system(command_line.GetCommandLineString().c_str())== -1 ) { + if (system(command_line.GetCommandLineString().c_str()) == -1) { LOG(ERROR) << "Unable to call Chrome"; exit(CUPS_BACKEND_CANCEL); } - - else { - LOG(INFO) << "Call to Chrome succeeded"; - } + LOG(INFO) << "Call to Chrome succeeded"; } diff --git a/cloud_print/virtual_driver/posix/printer_driver_util_posix.h b/cloud_print/virtual_driver/posix/printer_driver_util_posix.h index 4d8d7a5..821802b 100644 --- a/cloud_print/virtual_driver/posix/printer_driver_util_posix.h +++ b/cloud_print/virtual_driver/posix/printer_driver_util_posix.h @@ -1,12 +1,14 @@ // Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CLOUD_PRINT_VIRTUAL_DRIVER_LINUX_PRINTER_DRIVER_UTIL_POSIX_H_ -#define CLOUD_PRINT_VIRTUAL_DRIVER_LINUX_PRINTER_DRIVER_UTIL_POSIX_H_ +#ifndef CLOUD_PRINT_VIRTUAL_DRIVER_POSIX_PRINTER_DRIVER_UTIL_POSIX_H_ +#define CLOUD_PRINT_VIRTUAL_DRIVER_POSIX_PRINTER_DRIVER_UTIL_POSIX_H_ #pragma once + #include <string> -void LaunchPrintDialog(std::string output_path, std::string job_title, - std::string current_user); +void LaunchPrintDialog(const std::string& output_path, + const std::string& job_title, + const std::string& current_user); -#endif // CLOUD_PRINT_VIRTUAL_DRIVER_LINUX_PRINTER_DRIVER_UTIL_POSIX_H_ +#endif // CLOUD_PRINT_VIRTUAL_DRIVER_POSIX_PRINTER_DRIVER_UTIL_POSIX_H_ diff --git a/cloud_print/virtual_driver/posix/virtual_driver_posix.cc b/cloud_print/virtual_driver/posix/virtual_driver_posix.cc index 868228a..a5363f1 100644 --- a/cloud_print/virtual_driver/posix/virtual_driver_posix.cc +++ b/cloud_print/virtual_driver/posix/virtual_driver_posix.cc @@ -4,13 +4,12 @@ #include <pwd.h> #include <stdio.h> - -#include <cups/backend.h> - #include <sys/stat.h> #include <sys/types.h> #include <sys/wait.h> +#include <cups/backend.h> + #include "base/at_exit.h" #include "base/base_paths.h" #include "base/command_line.h" @@ -20,18 +19,16 @@ #include "cloud_print/virtual_driver/posix/printer_driver_util_posix.h" -using namespace std; - int WriteToTemp(FILE* input_pdf, FilePath output_path) { FILE* output_pdf; char buffer[128]; - output_pdf = fopen(output_path.value().c_str(),"w"); - if(output_pdf == NULL) { - LOG(ERROR) <<"Unable to open file handle for writing output file"; - exit(CUPS_BACKEND_CANCEL); + output_pdf = fopen(output_path.value().c_str(), "w"); + if (output_pdf == NULL) { + LOG(ERROR) << "Unable to open file handle for writing output file"; + exit(CUPS_BACKEND_CANCEL); } // Read from input file or stdin and write to output file. - while(fgets(buffer,128,input_pdf) != NULL){ + while (fgets(buffer, sizeof(buffer), input_pdf) != NULL) { fputs(buffer, output_pdf); } @@ -43,17 +40,17 @@ int WriteToTemp(FILE* input_pdf, FilePath output_path) { } void SetUser(const char* user) { - struct passwd* calling_user=NULL; - calling_user=getpwnam(user); - if(calling_user == NULL) { + struct passwd* calling_user = NULL; + calling_user = getpwnam(user); + if (calling_user == NULL) { LOG(ERROR) << "Unable to get calling user"; exit(CUPS_BACKEND_CANCEL); } - if(setgid(calling_user->pw_gid)==-1) { + if (setgid(calling_user->pw_gid) == -1) { LOG(ERROR) << "Unable to set group ID"; exit(CUPS_BACKEND_CANCEL); } - if(!setuid(calling_user->pw_uid)==-1) { + if (!setuid(calling_user->pw_uid) == -1) { LOG(ERROR) << "Unable to set UID"; exit(CUPS_BACKEND_CANCEL); } @@ -66,27 +63,27 @@ void SetUser(const char* user) { // Main function for backend. int main(int argc, const char* argv[]) { // With no arguments, send identification string as required by CUPS. - if (argc==1) { + if (argc == 1) { printf("file GCP-driver:/ \"GCP Virtual Driver\" \"GCP Virtual Driver\" " "\"MFG:Google Inc.;MDL:GCP Virtual Driver;DES:GCP Virtual Driver;" "CLS:PRINTER;CMD:POSTSCRIPT;\"\n"); return 0; } - if (argc<6 || argc>7) { - fprintf(stderr,"Usage: GCP-Driver job-id user" + if (argc < 6 || argc > 7) { + fprintf(stderr, "Usage: GCP-Driver job-id user" "title copies options [file]\n"); return 0; } - //AtExitManager is necessary to use the path service. + // AtExitManager is necessary to use the path service. base::AtExitManager aemanager; // File handler for the temporary PDF we pass onto Chrome. FILE* output_pdf; - //CommandLine is only setup to enable logging, never used subseqeuently. - CommandLine::Init(argc,argv); + // CommandLine is only setup to enable logging, never used subseqeuently. + CommandLine::Init(argc, argv); // Location for the log file. - std::string log_location="/var/log/GCP-Driver.log"; + std::string log_location = "/var/log/GCP-Driver.log"; // Set up logging. logging::InitLogging(log_location.c_str(), @@ -105,7 +102,7 @@ int main(int argc, const char* argv[]) { std::string file_name; // Get temp directory to hold spool file. - if(!PathService::Get(base::DIR_TEMP, &temp_dir)) { + if (!PathService::Get(base::DIR_TEMP, &temp_dir)) { LOG(ERROR) << "Unable to get DIR_TEMP"; return CUPS_BACKEND_CANCEL; } @@ -116,30 +113,30 @@ int main(int argc, const char* argv[]) { file_name = current_user + "-" + job_title + "-" + job_id; FilePath output_path = temp_dir.Append(file_name); - // Read from file if specified. - if(argc==7){ - FILE* input_pdf=fopen(argv[6],"r"); - if(input_pdf == NULL) { + if (argc == 7) { + // Read from file if specified. + FILE* input_pdf = fopen(argv[6], "r"); + if (input_pdf == NULL) { LOG(ERROR) << "Unable to read input PDF"; return CUPS_BACKEND_CANCEL; } // File is opened. - WriteToTemp(input_pdf,output_path); - } - // Otherwise, read from stdin. - else{ + WriteToTemp(input_pdf, output_path); + } else { + // Otherwise, read from stdin. WriteToTemp(stdin, output_path); } // Set File permissions to allow non-sudo user to read spool file. - if(chmod(output_path.value().c_str(),S_IRUSR|S_IWUSR|S_IROTH|S_IWOTH)!=0) { - LOG(ERROR)<<"Unable to change file permissions"; + if (chmod(output_path.value().c_str(), + S_IRUSR|S_IWUSR|S_IROTH|S_IWOTH) != 0) { + LOG(ERROR) << "Unable to change file permissions"; return CUPS_BACKEND_CANCEL; } - pid_t pid=fork(); + pid_t pid = fork(); - if(!pid) { + if (!pid) { // In child process. // Set the user to the one that initiated print job. @@ -149,8 +146,9 @@ int main(int argc, const char* argv[]) { LaunchPrintDialog(output_path.value(), job_title, current_user); return 0; - }// back in parent process. + } + // back in parent process. // wait for child, then terminate. - waitpid(pid,NULL,0); + waitpid(pid, NULL, 0); return 0; -}// main +} diff --git a/cloud_print/virtual_driver/virtual_driver_switches.cc b/cloud_print/virtual_driver/virtual_driver_switches.cc index 59022f1..72114bf 100644 --- a/cloud_print/virtual_driver/virtual_driver_switches.cc +++ b/cloud_print/virtual_driver/virtual_driver_switches.cc @@ -9,5 +9,5 @@ const char kCloudPrintDeleteFile[] = "cloud-print-delete-file"; const char kCloudPrintFile[] = "cloud-print-file"; const char kCloudPrintJobTitle[] = "cloud-print-job-title"; const char kCloudPrintFileType[] = "cloud-print-file-type"; -} //namespace switches +} // namespace switches diff --git a/cloud_print/virtual_driver/virtual_driver_switches.h b/cloud_print/virtual_driver/virtual_driver_switches.h index aa8f127..f30d9d1 100644 --- a/cloud_print/virtual_driver/virtual_driver_switches.h +++ b/cloud_print/virtual_driver/virtual_driver_switches.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CLOUD_PRINT_VIRTUAL_DRIVER_VIRTUAL_DRIVER_SWITCHES_H -#define CLOUD_PRINT_VIRTUAL_DRIVER_VIRTUAL_DRIVER_SWITCHES_H +#ifndef CLOUD_PRINT_VIRTUAL_DRIVER_VIRTUAL_DRIVER_SWITCHES_H_ +#define CLOUD_PRINT_VIRTUAL_DRIVER_VIRTUAL_DRIVER_SWITCHES_H_ #pragma once namespace switches { @@ -28,6 +28,6 @@ extern const char kCloudPrintJobTitle[]; // file referenced by cloud-print-file. // Defaults to "application/pdf" if unspecified. extern const char kCloudPrintFileType[]; -} //namespace switches +} // namespace switches -#endif // CLOUD_PRINT_VIRTUAL_DRIVER_VIRTUAL_DRIVER_SWITCHES_H +#endif // CLOUD_PRINT_VIRTUAL_DRIVER_VIRTUAL_DRIVER_SWITCHES_H_ diff --git a/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc b/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc index b17808f..fe3398f 100644 --- a/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc +++ b/cloud_print/virtual_driver/win/port_monitor/port_monitor.cc @@ -22,10 +22,10 @@ #include "base/win/registry.h" #include "base/win/scoped_handle.h" #include "base/win/windows_version.h" +#include "cloud_print/virtual_driver/virtual_driver_switches.h" #include "cloud_print/virtual_driver/win/port_monitor/spooler_win.h" #include "cloud_print/virtual_driver/win/virtual_driver_consts.h" #include "cloud_print/virtual_driver/win/virtual_driver_helpers.h" -#include "cloud_print/virtual_driver/virtual_driver_switches.h" namespace cloud_print { diff --git a/cloud_print/virtual_driver/win/port_monitor/virtual_driver_port_monitor.gyp b/cloud_print/virtual_driver/win/port_monitor/virtual_driver_port_monitor.gyp index 0a15c14..f909dcf 100644 --- a/cloud_print/virtual_driver/win/port_monitor/virtual_driver_port_monitor.gyp +++ b/cloud_print/virtual_driver/win/port_monitor/virtual_driver_port_monitor.gyp @@ -18,10 +18,11 @@ ], 'sources': [ '../../virtual_driver_switches.cc', - '../virtual_driver_consts.h', + '../../virtual_driver_switches.h', '../virtual_driver_consts.cc', - '../virtual_driver_helpers.h', + '../virtual_driver_consts.h', '../virtual_driver_helpers.cc', + '../virtual_driver_helpers.h', '../virtual_driver_common_resources.rc', 'port_monitor.cc', 'port_monitor.h', diff --git a/cloud_print/virtual_driver/win/virtual_driver_consts.h b/cloud_print/virtual_driver/win/virtual_driver_consts.h index b73e59c..78aab9c 100644 --- a/cloud_print/virtual_driver/win/virtual_driver_consts.h +++ b/cloud_print/virtual_driver/win/virtual_driver_consts.h @@ -9,7 +9,7 @@ namespace cloud_print { extern const wchar_t kPortName[]; extern const size_t kPortNameSize; -} +} // namespace cloud_print #endif // CLOUD_PRINT_VIRTUAL_DRIVER_WIN_VIRTUAL_DRIVER_CONSTS_H_ diff --git a/cloud_print/virtual_driver/win/virtual_driver_helpers.h b/cloud_print/virtual_driver/win/virtual_driver_helpers.h index bc777aa..a09edd1 100644 --- a/cloud_print/virtual_driver/win/virtual_driver_helpers.h +++ b/cloud_print/virtual_driver/win/virtual_driver_helpers.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CLOUD_PRINT_VIRTUAL_DRIVER_WIN_HELPERS_H_ -#define CLOUD_PRINT_VIRTUAL_DRIVER_WIN_HELPERS_H_ +#ifndef CLOUD_PRINT_VIRTUAL_DRIVER_WIN_VIRTUAL_DRIVER_HELPERS_H_ +#define CLOUD_PRINT_VIRTUAL_DRIVER_WIN_VIRTUAL_DRIVER_HELPERS_H_ #pragma once #include <windows.h> @@ -33,9 +33,10 @@ HRESULT GetPrinterDriverDir(FilePath* path); // Retrieves a string from the string table of the module that contains the // calling code. string16 LoadLocalString(DWORD string_id); -} -#endif // CLOUD_PRINT_VIRTUAL_DRIVER_WIN_HELPERS_H_ +} // namespace cloud_print + +#endif // CLOUD_PRINT_VIRTUAL_DRIVER_WIN_VIRTUAL_DRIVER_HELPERS_H_ |