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

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

Issue 1920793005: Merge to M51: Cloud Print Proxy: Delete print jobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // Some job on the printer changed. Loop through all our JobStatusUpdaters 242 // Some job on the printer changed. Loop through all our JobStatusUpdaters
243 // and have them check for updates. 243 // and have them check for updates.
244 for (JobStatusUpdaterList::iterator index = job_status_updater_list_.begin(); 244 for (JobStatusUpdaterList::iterator index = job_status_updater_list_.begin();
245 index != job_status_updater_list_.end(); index++) { 245 index != job_status_updater_list_.end(); index++) {
246 base::ThreadTaskRunnerHandle::Get()->PostTask( 246 base::ThreadTaskRunnerHandle::Get()->PostTask(
247 FROM_HERE, base::Bind(&JobStatusUpdater::UpdateStatus, index->get())); 247 FROM_HERE, base::Bind(&JobStatusUpdater::UpdateStatus, index->get()));
248 } 248 }
249 } 249 }
250 250
251 void PrinterJobHandler::OnJobSpoolSucceeded(const PlatformJobId& job_id) { 251 void PrinterJobHandler::OnJobSpoolSucceeded(const PlatformJobId& job_id) {
252 DCHECK(base::MessageLoop::current() == print_thread_.message_loop()); 252 DCHECK(CurrentlyOnPrintThread());
253 job_spooler_->AddRef(); 253 job_spooler_->AddRef();
254 print_thread_.message_loop()->ReleaseSoon(FROM_HERE, job_spooler_.get()); 254 print_thread_.message_loop()->ReleaseSoon(FROM_HERE, job_spooler_.get());
255 job_spooler_ = NULL; 255 job_spooler_ = NULL;
256 job_handler_task_runner_->PostTask( 256 job_handler_task_runner_->PostTask(
257 FROM_HERE, base::Bind(&PrinterJobHandler::JobSpooled, this, job_id)); 257 FROM_HERE, base::Bind(&PrinterJobHandler::JobSpooled, this, job_id));
258 } 258 }
259 259
260 void PrinterJobHandler::OnJobSpoolFailed() { 260 void PrinterJobHandler::OnJobSpoolFailed() {
261 DCHECK(base::MessageLoop::current() == print_thread_.message_loop()); 261 DCHECK(CurrentlyOnPrintThread());
262 job_spooler_->AddRef(); 262 job_spooler_->AddRef();
263 print_thread_.message_loop()->ReleaseSoon(FROM_HERE, job_spooler_.get()); 263 print_thread_.message_loop()->ReleaseSoon(FROM_HERE, job_spooler_.get());
264 job_spooler_ = NULL; 264 job_spooler_ = NULL;
265 VLOG(1) << "CP_CONNECTOR: Job failed (spool failed)"; 265 VLOG(1) << "CP_CONNECTOR: Job failed (spool failed)";
266 job_handler_task_runner_->PostTask( 266 job_handler_task_runner_->PostTask(
267 FROM_HERE, base::Bind(&PrinterJobHandler::JobFailed, this, JOB_FAILED)); 267 FROM_HERE, base::Bind(&PrinterJobHandler::JobFailed, this, JOB_FAILED));
268 } 268 }
269 269
270 // static 270 // static
271 void PrinterJobHandler::ReportsStats() { 271 void PrinterJobHandler::ReportsStats() {
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 std::string()); 777 std::string());
778 } else { 778 } else {
779 // We are done here. Go to the Stop state 779 // We are done here. Go to the Stop state
780 VLOG(1) << "CP_CONNECTOR: Stopping printer job handler" 780 VLOG(1) << "CP_CONNECTOR: Stopping printer job handler"
781 << ", printer name: " << printer_name; 781 << ", printer name: " << printer_name;
782 base::ThreadTaskRunnerHandle::Get()->PostTask( 782 base::ThreadTaskRunnerHandle::Get()->PostTask(
783 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); 783 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this));
784 } 784 }
785 } 785 }
786 786
787 // The following methods are called on |print_thread_|. It is not safe to
788 // access any members other than |job_handler_task_runner_|,
789 // |job_spooler_| and |print_system_|.
790 void PrinterJobHandler::DoPrint(const JobDetails& job_details, 787 void PrinterJobHandler::DoPrint(const JobDetails& job_details,
791 const std::string& printer_name) { 788 const std::string& printer_name) {
789 DCHECK(CurrentlyOnPrintThread());
792 job_spooler_ = print_system_->CreateJobSpooler(); 790 job_spooler_ = print_system_->CreateJobSpooler();
793 UMA_HISTOGRAM_LONG_TIMES("CloudPrint.PrepareTime", 791 UMA_HISTOGRAM_LONG_TIMES("CloudPrint.PrepareTime",
794 base::Time::Now() - job_start_time_); 792 base::Time::Now() - job_start_time_);
795 DCHECK(job_spooler_.get()); 793 DCHECK(job_spooler_.get());
796 if (!job_spooler_.get())
797 return;
798 794
799 base::string16 document_name = 795 base::string16 document_name =
800 job_details.job_title_.empty() 796 job_details.job_title_.empty()
801 ? l10n_util::GetStringUTF16(IDS_DEFAULT_PRINT_DOCUMENT_TITLE) 797 ? l10n_util::GetStringUTF16(IDS_DEFAULT_PRINT_DOCUMENT_TITLE)
802 : base::UTF8ToUTF16(job_details.job_title_); 798 : base::UTF8ToUTF16(job_details.job_title_);
803 799
804 document_name = printing::FormatDocumentTitleWithOwner( 800 document_name = printing::FormatDocumentTitleWithOwner(
805 base::UTF8ToUTF16(job_details.job_owner_), document_name); 801 base::UTF8ToUTF16(job_details.job_owner_), document_name);
806 802
807 UMA_HISTOGRAM_ENUMERATION("CloudPrint.JobHandlerEvent", 803 UMA_HISTOGRAM_ENUMERATION("CloudPrint.JobHandlerEvent",
808 JOB_HANDLER_START_SPOOLING, JOB_HANDLER_MAX); 804 JOB_HANDLER_START_SPOOLING, JOB_HANDLER_MAX);
809 spooling_start_time_ = base::Time::Now(); 805 spooling_start_time_ = base::Time::Now();
810 if (!job_spooler_->Spool(job_details.print_ticket_, 806 if (!job_spooler_->Spool(job_details.print_ticket_,
811 job_details.print_ticket_mime_type_, 807 job_details.print_ticket_mime_type_,
812 job_details.print_data_file_path_, 808 job_details.print_data_file_path_,
813 job_details.print_data_mime_type_, 809 job_details.print_data_mime_type_,
814 printer_name, 810 printer_name,
815 base::UTF16ToUTF8(document_name), 811 base::UTF16ToUTF8(document_name),
816 job_details.tags_, 812 job_details.tags_,
817 this)) { 813 this)) {
818 OnJobSpoolFailed(); 814 OnJobSpoolFailed();
819 } 815 }
820 } 816 }
821 817
818 bool PrinterJobHandler::CurrentlyOnPrintThread() const {
819 return base::MessageLoop::current() == print_thread_.message_loop();
820 }
821
822 } // namespace cloud_print 822 } // 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