From bb338dd1999ce51513cf270d0e9d4ccc0eec7026 Mon Sep 17 00:00:00 2001 From: "vitalybuka@chromium.org" Date: Wed, 20 Aug 2014 09:53:45 +0000 Subject: [PATCH] Use scoped_ptr to pass settings in PrintJobWorker and PrinterQuery. BUG=374321 TBR=noamsml Review URL: https://codereview.chromium.org/488913002 Cr-Commit-Position: refs/heads/master@{#290799} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290799 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/printing/print_job_worker.cc | 6 +++--- chrome/browser/printing/print_job_worker.h | 11 +++++------ chrome/browser/printing/printer_query.cc | 4 ++-- chrome/browser/printing/printer_query.h | 2 +- chrome/browser/printing/printing_message_filter.cc | 4 +++- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/chrome/browser/printing/print_job_worker.cc b/chrome/browser/printing/print_job_worker.cc index 85d178bfbf20..4f468cff3998 100644 --- a/chrome/browser/printing/print_job_worker.cc +++ b/chrome/browser/printing/print_job_worker.cc @@ -116,7 +116,7 @@ void PrintJobWorker::GetSettings( } void PrintJobWorker::SetSettings( - const base::DictionaryValue* const new_settings) { + scoped_ptr new_settings) { DCHECK(task_runner_->RunsTasksOnCurrentThread()); BrowserThread::PostTask( @@ -126,11 +126,11 @@ void PrintJobWorker::SetSettings( make_scoped_refptr(owner_), base::Bind(&PrintJobWorker::UpdatePrintSettings, base::Unretained(this), - base::Owned(new_settings)))); + base::Passed(&new_settings)))); } void PrintJobWorker::UpdatePrintSettings( - const base::DictionaryValue* const new_settings) { + scoped_ptr new_settings) { PrintingContext::Result result = printing_context_->UpdatePrintSettings(*new_settings); GetSettingsDone(result); diff --git a/chrome/browser/printing/print_job_worker.h b/chrome/browser/printing/print_job_worker.h index c3c9cf51b046..e3e9a6747014 100644 --- a/chrome/browser/printing/print_job_worker.h +++ b/chrome/browser/printing/print_job_worker.h @@ -52,9 +52,9 @@ class PrintJobWorker { bool has_selection, MarginType margin_type); - // Set the new print settings. This function takes ownership of - // |new_settings|. - void SetSettings(const base::DictionaryValue* const new_settings); + // Set the new print settings. + void SetSettings( + scoped_ptr new_settings); // Starts the printing loop. Every pages are printed as soon as the data is // available. Makes sure the new_document is the right one. @@ -122,9 +122,8 @@ class PrintJobWorker { // back into the IO thread for GetSettingsDone(). void GetSettingsWithUIDone(PrintingContext::Result result); - // Called on the UI thread to update the print settings. This function takes - // the ownership of |new_settings|. - void UpdatePrintSettings(const base::DictionaryValue* const new_settings); + // Called on the UI thread to update the print settings. + void UpdatePrintSettings(scoped_ptr new_settings); // Reports settings back to owner_. void GetSettingsDone(PrintingContext::Result result); diff --git a/chrome/browser/printing/printer_query.cc b/chrome/browser/printing/printer_query.cc index 42684a14daf9..0120ba24574d 100644 --- a/chrome/browser/printing/printer_query.cc +++ b/chrome/browser/printing/printer_query.cc @@ -88,14 +88,14 @@ void PrinterQuery::GetSettings( margin_type)); } -void PrinterQuery::SetSettings(const base::DictionaryValue& new_settings, +void PrinterQuery::SetSettings(scoped_ptr new_settings, const base::Closure& callback) { StartWorker(callback); worker_->PostTask(FROM_HERE, base::Bind(&PrintJobWorker::SetSettings, base::Unretained(worker_.get()), - new_settings.DeepCopy())); + base::Passed(&new_settings))); } void PrinterQuery::SetWorkerDestination( diff --git a/chrome/browser/printing/printer_query.h b/chrome/browser/printing/printer_query.h index 7633c4e8bb43..d28437c1c054 100644 --- a/chrome/browser/printing/printer_query.h +++ b/chrome/browser/printing/printer_query.h @@ -53,7 +53,7 @@ class PrinterQuery : public PrintJobWorkerOwner { const base::Closure& callback); // Updates the current settings with |new_settings| dictionary values. - void SetSettings(const base::DictionaryValue& new_settings, + void SetSettings(scoped_ptr new_settings, const base::Closure& callback); // Set a destination for the worker. diff --git a/chrome/browser/printing/printing_message_filter.cc b/chrome/browser/printing/printing_message_filter.cc index 485cff692b27..163114bf9395 100644 --- a/chrome/browser/printing/printing_message_filter.cc +++ b/chrome/browser/printing/printing_message_filter.cc @@ -427,6 +427,8 @@ void PrintingMessageFilter::UpdateFileDescriptor(int render_view_id, int fd) { void PrintingMessageFilter::OnUpdatePrintSettings( int document_cookie, const base::DictionaryValue& job_settings, IPC::Message* reply_msg) { + scoped_ptr new_settings(job_settings.DeepCopy()); + scoped_refptr printer_query; if (!profile_io_data_->printing_enabled()->GetValue()) { // Reply with NULL query. @@ -437,7 +439,7 @@ void PrintingMessageFilter::OnUpdatePrintSettings( if (!printer_query) printer_query = queue_->CreatePrinterQuery(); printer_query->SetSettings( - job_settings, + new_settings.Pass(), base::Bind(&PrintingMessageFilter::OnUpdatePrintSettingsReply, this, printer_query, reply_msg)); } -- 2.11.4.GIT