Commit 895f2a67 authored by Vladislav Kuzkokov's avatar Vladislav Kuzkokov Committed by Commit Bot

Use OnceCallback in PrinterQuery::SetSettings.

Bug: 625126
Change-Id: I8929c0fa1825b6175dd9a92284aabc4ff4983461
Reviewed-on: https://chromium-review.googlesource.com/907548Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Vladislav Kuzkokov <vkuzkokov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#536077}
parent 8430ff87
...@@ -34,9 +34,9 @@ using base::TimeDelta; ...@@ -34,9 +34,9 @@ using base::TimeDelta;
namespace printing { namespace printing {
// Helper function to ensure |owner| is valid until at least |callback| returns. // Helper function to ensure |owner| is valid until at least |callback| returns.
void HoldRefCallback(const scoped_refptr<PrintJobWorkerOwner>& owner, void HoldRefCallback(scoped_refptr<PrintJobWorkerOwner> owner,
const base::Closure& callback) { base::OnceClosure callback) {
callback.Run(); std::move(callback).Run();
} }
PrintJob::PrintJob() PrintJob::PrintJob()
...@@ -124,11 +124,11 @@ void PrintJob::StartPrinting() { ...@@ -124,11 +124,11 @@ void PrintJob::StartPrinting() {
} }
// Real work is done in PrintJobWorker::StartPrinting(). // Real work is done in PrintJobWorker::StartPrinting().
worker_->PostTask(FROM_HERE, worker_->PostTask(
base::Bind(&HoldRefCallback, base::WrapRefCounted(this), FROM_HERE, base::BindOnce(&HoldRefCallback, base::WrapRefCounted(this),
base::Bind(&PrintJobWorker::StartPrinting, base::BindOnce(&PrintJobWorker::StartPrinting,
base::Unretained(worker_.get()), base::Unretained(worker_.get()),
base::RetainedRef(document_)))); base::RetainedRef(document_))));
// Set the flag right now. // Set the flag right now.
is_job_pending_ = true; is_job_pending_ = true;
...@@ -352,11 +352,12 @@ void PrintJob::UpdatePrintedDocument(PrintedDocument* new_document) { ...@@ -352,11 +352,12 @@ void PrintJob::UpdatePrintedDocument(PrintedDocument* new_document) {
if (worker_) { if (worker_) {
DCHECK(!is_job_pending_); DCHECK(!is_job_pending_);
// Sync the document with the worker. // Sync the document with the worker.
worker_->PostTask(FROM_HERE, worker_->PostTask(
base::Bind(&HoldRefCallback, base::WrapRefCounted(this), FROM_HERE,
base::Bind(&PrintJobWorker::OnDocumentChanged, base::BindOnce(&HoldRefCallback, base::WrapRefCounted(this),
base::Unretained(worker_.get()), base::BindOnce(&PrintJobWorker::OnDocumentChanged,
base::RetainedRef(document_)))); base::Unretained(worker_.get()),
base::RetainedRef(document_))));
} }
} }
......
...@@ -31,8 +31,8 @@ class PrintedPage; ...@@ -31,8 +31,8 @@ class PrintedPage;
#endif #endif
class PrinterQuery; class PrinterQuery;
void HoldRefCallback(const scoped_refptr<PrintJobWorkerOwner>& owner, void HoldRefCallback(scoped_refptr<PrintJobWorkerOwner> owner,
const base::Closure& callback); base::OnceClosure callback);
// Manages the print work for a specific document. Talks to the printer through // Manages the print work for a specific document. Talks to the printer through
// PrintingContext through PrintJobWorker. Hides access to PrintingContext in a // PrintingContext through PrintJobWorker. Hides access to PrintingContext in a
......
...@@ -61,7 +61,8 @@ void PrintQueriesQueue::Shutdown() { ...@@ -61,7 +61,8 @@ void PrintQueriesQueue::Shutdown() {
// corresponding PrintJob, so any pending preview requests are not covered // corresponding PrintJob, so any pending preview requests are not covered
// by PrintJobManager::StopJobs and should be stopped explicitly. // by PrintJobManager::StopJobs and should be stopped explicitly.
for (auto& query : queries_to_stop) { for (auto& query : queries_to_stop) {
query->PostTask(FROM_HERE, base::Bind(&PrinterQuery::StopWorker, query)); query->PostTask(FROM_HERE,
base::BindOnce(&PrinterQuery::StopWorker, query));
} }
} }
......
...@@ -102,11 +102,11 @@ void NotificationCallback(PrintJobWorkerOwner* print_job, ...@@ -102,11 +102,11 @@ void NotificationCallback(PrintJobWorkerOwner* print_job,
content::Details<JobEventDetails>(details)); content::Details<JobEventDetails>(details));
} }
void PostOnOwnerThread(const scoped_refptr<PrintJobWorkerOwner>& owner, void PostOnOwnerThread(scoped_refptr<PrintJobWorkerOwner> owner,
const PrintingContext::PrintSettingsCallback& callback, PrintingContext::PrintSettingsCallback callback,
PrintingContext::Result result) { PrintingContext::Result result) {
owner->PostTask(FROM_HERE, base::Bind(&HoldRefCallback, owner, owner->PostTask(FROM_HERE, base::BindOnce(&HoldRefCallback, owner,
base::Bind(callback, result))); base::BindOnce(callback, result)));
} }
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -178,16 +178,17 @@ void PrintJobWorker::GetSettings(bool ask_user_for_settings, ...@@ -178,16 +178,17 @@ void PrintJobWorker::GetSettings(bool ask_user_for_settings,
if (ask_user_for_settings) { if (ask_user_for_settings) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::BindOnce(&HoldRefCallback, base::WrapRefCounted(owner_), base::BindOnce(
base::Bind(&PrintJobWorker::GetSettingsWithUI, &HoldRefCallback, base::WrapRefCounted(owner_),
base::Unretained(this), document_page_count, base::BindOnce(&PrintJobWorker::GetSettingsWithUI,
has_selection, is_scripted))); base::Unretained(this), document_page_count,
has_selection, is_scripted)));
} else { } else {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::BindOnce(&HoldRefCallback, base::WrapRefCounted(owner_), base::BindOnce(&HoldRefCallback, base::WrapRefCounted(owner_),
base::Bind(&PrintJobWorker::UseDefaultSettings, base::BindOnce(&PrintJobWorker::UseDefaultSettings,
base::Unretained(this)))); base::Unretained(this))));
} }
} }
...@@ -199,8 +200,8 @@ void PrintJobWorker::SetSettings( ...@@ -199,8 +200,8 @@ void PrintJobWorker::SetSettings(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
base::BindOnce( base::BindOnce(
&HoldRefCallback, base::WrapRefCounted(owner_), &HoldRefCallback, base::WrapRefCounted(owner_),
base::Bind(&PrintJobWorker::UpdatePrintSettings, base::BindOnce(&PrintJobWorker::UpdatePrintSettings,
base::Unretained(this), base::Passed(&new_settings)))); base::Unretained(this), std::move(new_settings))));
} }
void PrintJobWorker::UpdatePrintSettings( void PrintJobWorker::UpdatePrintSettings(
...@@ -223,9 +224,9 @@ void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) { ...@@ -223,9 +224,9 @@ void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) {
// PrintJob will create the new PrintedDocument. // PrintJob will create the new PrintedDocument.
owner_->PostTask(FROM_HERE, owner_->PostTask(FROM_HERE,
base::Bind(&PrintJobWorkerOwner::GetSettingsDone, base::BindOnce(&PrintJobWorkerOwner::GetSettingsDone,
base::WrapRefCounted(owner_), base::WrapRefCounted(owner_),
printing_context_->settings(), result)); printing_context_->settings(), result));
} }
void PrintJobWorker::GetSettingsWithUI( void PrintJobWorker::GetSettingsWithUI(
...@@ -391,9 +392,9 @@ bool PrintJobWorker::IsRunning() const { ...@@ -391,9 +392,9 @@ bool PrintJobWorker::IsRunning() const {
} }
bool PrintJobWorker::PostTask(const base::Location& from_here, bool PrintJobWorker::PostTask(const base::Location& from_here,
const base::Closure& task) { base::OnceClosure task) {
if (task_runner_.get()) if (task_runner_.get())
return task_runner_->PostTask(from_here, task); return task_runner_->PostTask(from_here, std::move(task));
return false; return false;
} }
...@@ -422,10 +423,10 @@ void PrintJobWorker::OnDocumentDone() { ...@@ -422,10 +423,10 @@ void PrintJobWorker::OnDocumentDone() {
return; return;
} }
owner_->PostTask(FROM_HERE, owner_->PostTask(FROM_HERE, base::BindOnce(&NotificationCallback,
base::Bind(&NotificationCallback, base::RetainedRef(owner_), base::RetainedRef(owner_),
JobEventDetails::DOC_DONE, job_id, JobEventDetails::DOC_DONE, job_id,
base::RetainedRef(document_))); base::RetainedRef(document_)));
// Makes sure the variables are reinitialized. // Makes sure the variables are reinitialized.
document_ = NULL; document_ = NULL;
...@@ -473,8 +474,8 @@ void PrintJobWorker::OnFailure() { ...@@ -473,8 +474,8 @@ void PrintJobWorker::OnFailure() {
scoped_refptr<PrintJobWorkerOwner> handle(owner_); scoped_refptr<PrintJobWorkerOwner> handle(owner_);
owner_->PostTask( owner_->PostTask(
FROM_HERE, base::BindRepeating( FROM_HERE,
&NotificationCallback, base::RetainedRef(owner_), base::BindOnce(&NotificationCallback, base::RetainedRef(owner_),
JobEventDetails::FAILED, 0, base::RetainedRef(document_))); JobEventDetails::FAILED, 0, base::RetainedRef(document_)));
Cancel(); Cancel();
......
...@@ -76,7 +76,7 @@ class PrintJobWorker { ...@@ -76,7 +76,7 @@ class PrintJobWorker {
bool IsRunning() const; bool IsRunning() const;
// Posts the given task to be run. // Posts the given task to be run.
bool PostTask(const base::Location& from_here, const base::Closure& task); bool PostTask(const base::Location& from_here, base::OnceClosure task);
// Signals the thread to exit in the near future. // Signals the thread to exit in the near future.
void StopSoon(); void StopSoon();
......
...@@ -21,8 +21,8 @@ bool PrintJobWorkerOwner::RunsTasksInCurrentSequence() const { ...@@ -21,8 +21,8 @@ bool PrintJobWorkerOwner::RunsTasksInCurrentSequence() const {
} }
bool PrintJobWorkerOwner::PostTask(const base::Location& from_here, bool PrintJobWorkerOwner::PostTask(const base::Location& from_here,
const base::Closure& task) { base::OnceClosure task) {
return task_runner_->PostTask(from_here, task); return task_runner_->PostTask(from_here, std::move(task));
} }
} // namespace printing } // namespace printing
...@@ -47,7 +47,7 @@ class PrintJobWorkerOwner ...@@ -47,7 +47,7 @@ class PrintJobWorkerOwner
bool RunsTasksInCurrentSequence() const; bool RunsTasksInCurrentSequence() const;
// Posts the given task to be run. // Posts the given task to be run.
bool PostTask(const base::Location& from_here, const base::Closure& task); bool PostTask(const base::Location& from_here, base::OnceClosure task);
protected: protected:
friend class base::RefCountedThreadSafe<PrintJobWorkerOwner>; friend class base::RefCountedThreadSafe<PrintJobWorkerOwner>;
......
...@@ -93,10 +93,9 @@ void PrinterQuery::SetSettings( ...@@ -93,10 +93,9 @@ void PrinterQuery::SetSettings(
base::OnceClosure callback) { base::OnceClosure callback) {
StartWorker(std::move(callback)); StartWorker(std::move(callback));
worker_->PostTask(FROM_HERE, worker_->PostTask(FROM_HERE, base::BindOnce(&PrintJobWorker::SetSettings,
base::Bind(&PrintJobWorker::SetSettings, base::Unretained(worker_.get()),
base::Unretained(worker_.get()), std::move(new_settings)));
base::Passed(&new_settings)));
} }
void PrinterQuery::StartWorker(base::OnceClosure callback) { void PrinterQuery::StartWorker(base::OnceClosure callback) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment