Add job id to JobEventDetails.
Adding job id to JobEventDetails makes it easier to track jobs after they've been queued. BUG=684853 Review-Url: https://codereview.chromium.org/2692923006 Cr-Commit-Position: refs/heads/master@{#450766}
This commit is contained in:
chrome/browser/printing
printing
@ -137,8 +137,8 @@ void PrintJob::StartPrinting() {
|
||||
is_job_pending_ = true;
|
||||
|
||||
// Tell everyone!
|
||||
scoped_refptr<JobEventDetails> details(
|
||||
new JobEventDetails(JobEventDetails::NEW_DOC, document_.get(), nullptr));
|
||||
scoped_refptr<JobEventDetails> details(new JobEventDetails(
|
||||
JobEventDetails::NEW_DOC, 0, document_.get(), nullptr));
|
||||
content::NotificationService::current()->Notify(
|
||||
chrome::NOTIFICATION_PRINT_JOB_EVENT,
|
||||
content::Source<PrintJob>(this),
|
||||
@ -183,7 +183,7 @@ void PrintJob::Cancel() {
|
||||
}
|
||||
// Make sure a Cancel() is broadcast.
|
||||
scoped_refptr<JobEventDetails> details(
|
||||
new JobEventDetails(JobEventDetails::FAILED, nullptr, nullptr));
|
||||
new JobEventDetails(JobEventDetails::FAILED, 0, nullptr, nullptr));
|
||||
content::NotificationService::current()->Notify(
|
||||
chrome::NOTIFICATION_PRINT_JOB_EVENT,
|
||||
content::Source<PrintJob>(this),
|
||||
@ -408,8 +408,8 @@ void PrintJob::OnDocumentDone() {
|
||||
// Stop the worker thread.
|
||||
Stop();
|
||||
|
||||
scoped_refptr<JobEventDetails> details(
|
||||
new JobEventDetails(JobEventDetails::JOB_DONE, document_.get(), nullptr));
|
||||
scoped_refptr<JobEventDetails> details(new JobEventDetails(
|
||||
JobEventDetails::JOB_DONE, 0, document_.get(), nullptr));
|
||||
content::NotificationService::current()->Notify(
|
||||
chrome::NOTIFICATION_PRINT_JOB_EVENT,
|
||||
content::Source<PrintJob>(this),
|
||||
@ -466,12 +466,10 @@ void PrintJob::Quit() {
|
||||
|
||||
// Takes settings_ ownership and will be deleted in the receiving thread.
|
||||
JobEventDetails::JobEventDetails(Type type,
|
||||
int job_id,
|
||||
PrintedDocument* document,
|
||||
PrintedPage* page)
|
||||
: document_(document),
|
||||
page_(page),
|
||||
type_(type) {
|
||||
}
|
||||
: document_(document), page_(page), type_(type), job_id_(job_id) {}
|
||||
|
||||
JobEventDetails::~JobEventDetails() {
|
||||
}
|
||||
|
@ -211,7 +211,10 @@ class JobEventDetails : public base::RefCountedThreadSafe<JobEventDetails> {
|
||||
FAILED,
|
||||
};
|
||||
|
||||
JobEventDetails(Type type, PrintedDocument* document, PrintedPage* page);
|
||||
JobEventDetails(Type type,
|
||||
int job_id,
|
||||
PrintedDocument* document,
|
||||
PrintedPage* page);
|
||||
|
||||
// Getters.
|
||||
PrintedDocument* document() const;
|
||||
@ -219,6 +222,7 @@ class JobEventDetails : public base::RefCountedThreadSafe<JobEventDetails> {
|
||||
Type type() const {
|
||||
return type_;
|
||||
}
|
||||
int job_id() const { return job_id_; }
|
||||
|
||||
private:
|
||||
friend class base::RefCountedThreadSafe<JobEventDetails>;
|
||||
@ -228,6 +232,7 @@ class JobEventDetails : public base::RefCountedThreadSafe<JobEventDetails> {
|
||||
scoped_refptr<PrintedDocument> document_;
|
||||
scoped_refptr<PrintedPage> page_;
|
||||
const Type type_;
|
||||
int job_id_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(JobEventDetails);
|
||||
};
|
||||
|
@ -90,9 +90,11 @@ std::string PrintingContextDelegate::GetAppLocale() {
|
||||
|
||||
void NotificationCallback(PrintJobWorkerOwner* print_job,
|
||||
JobEventDetails::Type detail_type,
|
||||
int job_id,
|
||||
PrintedDocument* document,
|
||||
PrintedPage* page) {
|
||||
JobEventDetails* details = new JobEventDetails(detail_type, document, page);
|
||||
JobEventDetails* details =
|
||||
new JobEventDetails(detail_type, job_id, document, page);
|
||||
content::NotificationService::current()->Notify(
|
||||
chrome::NOTIFICATION_PRINT_JOB_EVENT,
|
||||
// We know that is is a PrintJob object in this circumstance.
|
||||
@ -370,6 +372,7 @@ void PrintJobWorker::OnDocumentDone() {
|
||||
DCHECK_EQ(page_number_, PageNumber::npos());
|
||||
DCHECK(document_.get());
|
||||
|
||||
int job_id = printing_context_->job_id();
|
||||
if (printing_context_->DocumentDone() != PrintingContext::OK) {
|
||||
OnFailure();
|
||||
return;
|
||||
@ -377,7 +380,7 @@ void PrintJobWorker::OnDocumentDone() {
|
||||
|
||||
owner_->PostTask(FROM_HERE,
|
||||
base::Bind(&NotificationCallback, base::RetainedRef(owner_),
|
||||
JobEventDetails::DOC_DONE,
|
||||
JobEventDetails::DOC_DONE, job_id,
|
||||
base::RetainedRef(document_), nullptr));
|
||||
|
||||
// Makes sure the variables are reinitialized.
|
||||
@ -392,8 +395,8 @@ void PrintJobWorker::SpoolPage(PrintedPage* page) {
|
||||
owner_->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(&NotificationCallback, base::RetainedRef(owner_),
|
||||
JobEventDetails::NEW_PAGE, base::RetainedRef(document_),
|
||||
base::RetainedRef(page)));
|
||||
JobEventDetails::NEW_PAGE, printing_context_->job_id(),
|
||||
base::RetainedRef(document_), base::RetainedRef(page)));
|
||||
|
||||
// Preprocess.
|
||||
if (printing_context_->NewPage() != PrintingContext::OK) {
|
||||
@ -418,8 +421,8 @@ void PrintJobWorker::SpoolPage(PrintedPage* page) {
|
||||
owner_->PostTask(
|
||||
FROM_HERE,
|
||||
base::Bind(&NotificationCallback, base::RetainedRef(owner_),
|
||||
JobEventDetails::PAGE_DONE, base::RetainedRef(document_),
|
||||
base::RetainedRef(page)));
|
||||
JobEventDetails::PAGE_DONE, printing_context_->job_id(),
|
||||
base::RetainedRef(document_), base::RetainedRef(page)));
|
||||
}
|
||||
|
||||
void PrintJobWorker::OnFailure() {
|
||||
@ -430,7 +433,7 @@ void PrintJobWorker::OnFailure() {
|
||||
|
||||
owner_->PostTask(FROM_HERE,
|
||||
base::Bind(&NotificationCallback, base::RetainedRef(owner_),
|
||||
JobEventDetails::FAILED,
|
||||
JobEventDetails::FAILED, 0,
|
||||
base::RetainedRef(document_), nullptr));
|
||||
Cancel();
|
||||
|
||||
|
@ -125,6 +125,8 @@ class PRINTING_EXPORT PrintingContext {
|
||||
return settings_;
|
||||
}
|
||||
|
||||
int job_id() const { return job_id_; }
|
||||
|
||||
protected:
|
||||
explicit PrintingContext(Delegate* delegate);
|
||||
|
||||
@ -146,6 +148,9 @@ class PRINTING_EXPORT PrintingContext {
|
||||
// Did the user cancel the print job.
|
||||
volatile bool abort_printing_;
|
||||
|
||||
// The job id for the current job. The value is 0 if no jobs are active.
|
||||
int job_id_;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(PrintingContext);
|
||||
};
|
||||
|
@ -45,9 +45,6 @@ class PRINTING_EXPORT PrintingContextChromeos : public PrintingContext {
|
||||
// Lazily initializes |printer_|.
|
||||
Result InitializeDevice(const std::string& device);
|
||||
|
||||
// id for ongoing print job. 0 if no job is active.
|
||||
int job_id_;
|
||||
|
||||
CupsConnection connection_;
|
||||
std::unique_ptr<CupsPrinter> printer_;
|
||||
|
||||
|
Reference in New Issue
Block a user