Skip to content

Commit

Permalink
Fix deletion of temp files from port monitor.
Browse files Browse the repository at this point in the history
Adds a new switch to Chrome that will delete the printed file once the print dialog finishes.

BUG=
TEST=

Review URL: http://codereview.chromium.org/6882092

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82651 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
abodenha@google.com committed Apr 22, 2011
1 parent 83216ff commit 6ddda23
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 23 deletions.
16 changes: 15 additions & 1 deletion chrome/browser/printing/print_dialog_cloud.cc
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ CloudPrintHtmlDialogDelegate::CloudPrintHtmlDialogDelegate(
print_job_title,
file_type)),
modal_(modal),
owns_flow_handler_(true) {
owns_flow_handler_(true),
path_to_file_(path_to_file) {
Init(width, height, json_arguments);
}

Expand Down Expand Up @@ -489,6 +490,14 @@ void CloudPrintHtmlDialogDelegate::OnDialogClosed(
const std::string& json_retval) {
// Get the final dialog size and store it.
flow_handler_->StoreDialogClientSize();

if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kCloudPrintDeleteFile)) {
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
NewRunnableFunction(&internal_cloud_print_helpers::Delete,
path_to_file_));
}

// If we're modal we can show the dialog with no browser.
// End the keep-alive so that Chrome can exit.
if (!modal_)
Expand Down Expand Up @@ -558,6 +567,11 @@ void CreateDialogImpl(const FilePath& path_to_file,
}
}

// Provides a runnable function to delete a file.
void Delete(const FilePath& file_path) {
file_util::Delete(file_path, false);
}

} // namespace internal_cloud_print_helpers

namespace print_dialog_cloud {
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/printing/print_dialog_cloud_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class CloudPrintHtmlDialogDelegate : public HtmlDialogUIDelegate {
CloudPrintFlowHandler* flow_handler_;
bool modal_;
mutable bool owns_flow_handler_;
FilePath path_to_file_;

// The parameters needed to display a modal HTML dialog.
HtmlDialogUI::HtmlDialogParams params_;
Expand All @@ -185,6 +186,8 @@ void CreateDialogImpl(const FilePath& path_to_file,
const std::string& file_type,
bool modal);

void Delete(const FilePath& path_to_file);

} // namespace internal_cloud_print_helpers

#endif // CHROME_BROWSER_PRINTING_PRINT_DIALOG_CLOUD_INTERNAL_H_
16 changes: 10 additions & 6 deletions chrome/common/chrome_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,26 @@ const char kChromeFrame[] = "chrome-frame";
// this version cannot be loaded, Chrome will exit.
const char kChromeVersion[] = "chrome-version";

// The unique id to be used for this cloud print proxy instance.
const char kCloudPrintProxyId[] = "cloud-print-proxy-id";
// Used with kCloudPrintFile. Tells Chrome to delete the file when
// finished displaying the print dialog.
const char kCloudPrintDeleteFile[] = "cloud-print-delete-file";

// Tells chrome to display the cloud print dialog and upload the
// specified file for printing.
const char kCloudPrintFile[] = "cloud-print-file";

// Used with kCloudPrintFile to specify a title for the resulting print
// job.
const char kCloudPrintJobTitle[] = "cloud-print-job-title";

// Specifies the mime type to be used when uploading data from the
// file referenced by cloud-print-file.
// Defaults to "application/pdf" if unspecified.
const char kCloudPrintFileType[] = "cloud-print-file-type";

// Used with kCloudPrintFile to specify a title for the resulting print
// job.
const char kCloudPrintJobTitle[] = "cloud-print-job-title";

// The unique id to be used for this cloud print proxy instance.
const char kCloudPrintProxyId[] = "cloud-print-proxy-id";

// The URL of the cloud print service to use, overrides any value
// stored in preferences, and the default. Only used if the cloud
// print service has been enabled (see enable-cloud-print).
Expand Down
1 change: 1 addition & 0 deletions chrome/common/chrome_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ extern const char kBrowserCrashTest[];
extern const char kCheckForUpdateIntervalSec[];
extern const char kChromeFrame[];
extern const char kChromeVersion[];
extern const char kCloudPrintDeleteFile[];
extern const char kCloudPrintFile[];
extern const char kCloudPrintJobTitle[];
extern const char kCloudPrintFileType[];
Expand Down
24 changes: 8 additions & 16 deletions cloud_print/virtual_driver/win/port_monitor/port_monitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ namespace switches {
// in order to avoid dependency problems.
// TODO(abodenha@chromium.org) Reunify them in some sensible manner.

// Used with kCloudPrintFile. Tells Chrome to delete the file when
// finished displaying the print dialog.
const char kCloudPrintDeleteFile[] = "cloud-print-delete-file";

// Tells chrome to display the cloud print dialog and upload the
// specified file for printing.
const char kCloudPrintFile[] = "cloud-print-file";
Expand Down Expand Up @@ -191,11 +195,8 @@ void HandlePortUi(HWND hwnd, const string16& caption) {
// Launches the Cloud Print dialog in Chrome.
// xps_path references a file to print.
// job_title is the title to be used for the resulting print job.
// process_handle is set to the handle of the resulting process.
bool LaunchPrintDialog(const string16& xps_path,
const string16& job_title,
base::ProcessHandle* process_handle) {
DCHECK(process_handle != NULL);
const string16& job_title) {
HANDLE token = NULL;
if (!OpenThreadToken(GetCurrentThread(),
TOKEN_QUERY|TOKEN_DUPLICATE|TOKEN_ASSIGN_PRIMARY,
Expand Down Expand Up @@ -227,10 +228,11 @@ bool LaunchPrintDialog(const string16& xps_path,
kXpsMimeType);
command_line.AppendSwitchNative(switches::kCloudPrintJobTitle,
job_title);
command_line.AppendSwitch(switches::kCloudPrintDeleteFile);
base::LaunchAppAsUser(primary_token_scoped,
command_line.command_line_string(),
false,
process_handle);
NULL);
return true;
}

Expand Down Expand Up @@ -452,7 +454,6 @@ BOOL WINAPI Monitor2ReadPort(HANDLE, BYTE*, DWORD, DWORD* read_bytes) {

BOOL WINAPI Monitor2EndDocPort(HANDLE port_handle) {
LOG(INFO) << "Monitor2EndDocPort";
HANDLE process_handle = NULL;
if (!ValidateCurrentUser()) {
// TODO(abodenha@chromium.org) Abort the print job.
return FALSE;
Expand All @@ -473,16 +474,7 @@ BOOL WINAPI Monitor2EndDocPort(HANDLE port_handle) {
&job_title);
}
LaunchPrintDialog(port_data->file_path->value().c_str(),
job_title,
&process_handle);

// Wait for the print dialog process to exit and then delete the file.
// TODO(abodenha@chromium.org) Consider launching a thread to handle the
// deletion.
if (process_handle != NULL) {
WaitForSingleObject(process_handle, INFINITE);
}
file_util::Delete(*(port_data->file_path), false);
job_title);
}
if (port_data->printer_handle != NULL) {
// Tell the spooler that the job is complete.
Expand Down

0 comments on commit 6ddda23

Please sign in to comment.