Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: chrome/service/cloud_print/printer_job_handler.cc

Issue 1907083002: Cloud Print Proxy: Delete print jobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/service/cloud_print/printer_job_handler.h" 5 #include "chrome/service/cloud_print/printer_job_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 void PrinterJobHandler::OnJobChanged() { 239 void PrinterJobHandler::OnJobChanged() {
240 // Some job on the printer changed. Loop through all our JobStatusUpdaters 240 // Some job on the printer changed. Loop through all our JobStatusUpdaters
241 // and have them check for updates. 241 // and have them check for updates.
242 for (const auto& it : job_status_updater_list_) { 242 for (const auto& it : job_status_updater_list_) {
243 base::ThreadTaskRunnerHandle::Get()->PostTask( 243 base::ThreadTaskRunnerHandle::Get()->PostTask(
244 FROM_HERE, base::Bind(&JobStatusUpdater::UpdateStatus, it.get())); 244 FROM_HERE, base::Bind(&JobStatusUpdater::UpdateStatus, it.get()));
245 } 245 }
246 } 246 }
247 247
248 void PrinterJobHandler::OnJobSpoolSucceeded(const PlatformJobId& job_id) { 248 void PrinterJobHandler::OnJobSpoolSucceeded(const PlatformJobId& job_id) {
249 DCHECK(base::MessageLoop::current() == print_thread_.message_loop()); 249 DCHECK(CurrentlyOnPrintThread());
250 job_spooler_->AddRef(); 250 job_spooler_->AddRef();
251 print_thread_.message_loop()->ReleaseSoon(FROM_HERE, job_spooler_.get()); 251 print_thread_.message_loop()->ReleaseSoon(FROM_HERE, job_spooler_.get());
252 job_spooler_ = NULL; 252 job_spooler_ = NULL;
253 job_handler_task_runner_->PostTask( 253 job_handler_task_runner_->PostTask(
254 FROM_HERE, base::Bind(&PrinterJobHandler::JobSpooled, this, job_id)); 254 FROM_HERE, base::Bind(&PrinterJobHandler::JobSpooled, this, job_id));
255 } 255 }
256 256
257 void PrinterJobHandler::OnJobSpoolFailed() { 257 void PrinterJobHandler::OnJobSpoolFailed() {
258 DCHECK(base::MessageLoop::current() == print_thread_.message_loop()); 258 DCHECK(CurrentlyOnPrintThread());
259 job_spooler_->AddRef(); 259 job_spooler_->AddRef();
260 print_thread_.message_loop()->ReleaseSoon(FROM_HERE, job_spooler_.get()); 260 print_thread_.message_loop()->ReleaseSoon(FROM_HERE, job_spooler_.get());
261 job_spooler_ = NULL; 261 job_spooler_ = NULL;
262 VLOG(1) << "CP_CONNECTOR: Job failed (spool failed)"; 262 VLOG(1) << "CP_CONNECTOR: Job failed (spool failed)";
263 job_handler_task_runner_->PostTask( 263 job_handler_task_runner_->PostTask(
264 FROM_HERE, base::Bind(&PrinterJobHandler::JobFailed, this, JOB_FAILED)); 264 FROM_HERE, base::Bind(&PrinterJobHandler::JobFailed, this, JOB_FAILED));
265 } 265 }
266 266
267 // static 267 // static
268 void PrinterJobHandler::ReportsStats() { 268 void PrinterJobHandler::ReportsStats() {
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 std::string()); 773 std::string());
774 } else { 774 } else {
775 // We are done here. Go to the Stop state 775 // We are done here. Go to the Stop state
776 VLOG(1) << "CP_CONNECTOR: Stopping printer job handler" 776 VLOG(1) << "CP_CONNECTOR: Stopping printer job handler"
777 << ", printer name: " << printer_name; 777 << ", printer name: " << printer_name;
778 base::ThreadTaskRunnerHandle::Get()->PostTask( 778 base::ThreadTaskRunnerHandle::Get()->PostTask(
779 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); 779 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this));
780 } 780 }
781 } 781 }
782 782
783 // The following methods are called on |print_thread_|. It is not safe to
784 // access any members other than |job_handler_task_runner_|,
785 // |job_spooler_| and |print_system_|.
786 void PrinterJobHandler::DoPrint(const JobDetails& job_details, 783 void PrinterJobHandler::DoPrint(const JobDetails& job_details,
787 const std::string& printer_name) { 784 const std::string& printer_name) {
785 DCHECK(CurrentlyOnPrintThread());
788 job_spooler_ = print_system_->CreateJobSpooler(); 786 job_spooler_ = print_system_->CreateJobSpooler();
789 UMA_HISTOGRAM_LONG_TIMES("CloudPrint.PrepareTime", 787 UMA_HISTOGRAM_LONG_TIMES("CloudPrint.PrepareTime",
790 base::Time::Now() - job_start_time_); 788 base::Time::Now() - job_start_time_);
791 DCHECK(job_spooler_.get()); 789 DCHECK(job_spooler_.get());
792 if (!job_spooler_.get())
793 return;
794 790
795 base::string16 document_name = 791 base::string16 document_name =
796 job_details.job_title_.empty() 792 job_details.job_title_.empty()
797 ? l10n_util::GetStringUTF16(IDS_DEFAULT_PRINT_DOCUMENT_TITLE) 793 ? l10n_util::GetStringUTF16(IDS_DEFAULT_PRINT_DOCUMENT_TITLE)
798 : base::UTF8ToUTF16(job_details.job_title_); 794 : base::UTF8ToUTF16(job_details.job_title_);
799 795
800 document_name = printing::FormatDocumentTitleWithOwner( 796 document_name = printing::FormatDocumentTitleWithOwner(
801 base::UTF8ToUTF16(job_details.job_owner_), document_name); 797 base::UTF8ToUTF16(job_details.job_owner_), document_name);
802 798
803 UMA_HISTOGRAM_ENUMERATION("CloudPrint.JobHandlerEvent", 799 UMA_HISTOGRAM_ENUMERATION("CloudPrint.JobHandlerEvent",
804 JOB_HANDLER_START_SPOOLING, JOB_HANDLER_MAX); 800 JOB_HANDLER_START_SPOOLING, JOB_HANDLER_MAX);
805 spooling_start_time_ = base::Time::Now(); 801 spooling_start_time_ = base::Time::Now();
806 if (!job_spooler_->Spool(job_details.print_ticket_, 802 if (!job_spooler_->Spool(job_details.print_ticket_,
807 job_details.print_ticket_mime_type_, 803 job_details.print_ticket_mime_type_,
808 job_details.print_data_file_path_, 804 job_details.print_data_file_path_,
809 job_details.print_data_mime_type_, 805 job_details.print_data_mime_type_,
810 printer_name, 806 printer_name,
811 base::UTF16ToUTF8(document_name), 807 base::UTF16ToUTF8(document_name),
812 job_details.tags_, 808 job_details.tags_,
813 this)) { 809 this)) {
814 OnJobSpoolFailed(); 810 OnJobSpoolFailed();
815 } 811 }
816 } 812 }
817 813
814 bool PrinterJobHandler::CurrentlyOnPrintThread() const {
815 return base::MessageLoop::current() == print_thread_.message_loop();
816 }
817
818 } // namespace cloud_print 818 } // namespace cloud_print
OLDNEW
« no previous file with comments | « chrome/service/cloud_print/printer_job_handler.h ('k') | chrome/service/service_utility_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698