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

Side by Side Diff: chrome/browser/printing/print_job_manager.cc

Issue 11572033: Merge 171447 (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1312/src/
Patch Set: Created 8 years 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/printing/print_job_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/browser/printing/print_job_manager.h" 5 #include "chrome/browser/printing/print_job_manager.h"
6 6
7 #include "chrome/browser/printing/print_job.h" 7 #include "chrome/browser/printing/print_job.h"
8 #include "chrome/browser/printing/printer_query.h" 8 #include "chrome/browser/printing/printer_query.h"
9 #include "chrome/common/chrome_notification_types.h" 9 #include "chrome/common/chrome_notification_types.h"
10 #include "content/public/browser/notification_service.h" 10 #include "content/public/browser/notification_service.h"
(...skipping 11 matching lines...) Expand all
22 base::AutoLock lock(lock_); 22 base::AutoLock lock(lock_);
23 queued_queries_.clear(); 23 queued_queries_.clear();
24 } 24 }
25 25
26 void PrintJobManager::OnQuit() { 26 void PrintJobManager::OnQuit() {
27 StopJobs(true); 27 StopJobs(true);
28 registrar_.RemoveAll(); 28 registrar_.RemoveAll();
29 } 29 }
30 30
31 void PrintJobManager::StopJobs(bool wait_for_finish) { 31 void PrintJobManager::StopJobs(bool wait_for_finish) {
32 if (current_jobs_.empty()) 32 // Copy the array since it can be modified in transit.
33 return; 33 PrintJobs to_stop;
34 { 34 to_stop.swap(current_jobs_);
35 // Copy the array since it can be modified in transit. 35
36 PrintJobs current_jobs(current_jobs_); 36 for (PrintJobs::const_iterator job = to_stop.begin(); job != to_stop.end();
37 // Wait for each job to finish. 37 ++job) {
38 for (size_t i = 0; i < current_jobs.size(); ++i) { 38 // Wait for two minutes for the print job to be spooled.
39 PrintJob* job = current_jobs[i]; 39 if (wait_for_finish)
40 if (!job) 40 (*job)->FlushJob(base::TimeDelta::FromMinutes(2));
41 continue; 41 (*job)->Stop();
42 // Wait for two minutes for the print job to be spooled.
43 if (wait_for_finish)
44 job->FlushJob(base::TimeDelta::FromMinutes(2));
45 job->Stop();
46 }
47 } 42 }
48 current_jobs_.clear();
49 } 43 }
50 44
51 void PrintJobManager::SetPrintDestination( 45 void PrintJobManager::SetPrintDestination(
52 PrintDestinationInterface* destination) { 46 PrintDestinationInterface* destination) {
53 destination_ = destination; 47 destination_ = destination;
54 } 48 }
55 49
56 void PrintJobManager::QueuePrinterQuery(PrinterQuery* job) { 50 void PrintJobManager::QueuePrinterQuery(PrinterQuery* job) {
57 base::AutoLock lock(lock_); 51 base::AutoLock lock(lock_);
58 DCHECK(job); 52 DCHECK(job);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 break; 85 break;
92 } 86 }
93 } 87 }
94 } 88 }
95 89
96 void PrintJobManager::OnPrintJobEvent( 90 void PrintJobManager::OnPrintJobEvent(
97 PrintJob* print_job, 91 PrintJob* print_job,
98 const JobEventDetails& event_details) { 92 const JobEventDetails& event_details) {
99 switch (event_details.type()) { 93 switch (event_details.type()) {
100 case JobEventDetails::NEW_DOC: { 94 case JobEventDetails::NEW_DOC: {
101 DCHECK(current_jobs_.end() == std::find(current_jobs_.begin(), 95 DCHECK(current_jobs_.end() == current_jobs_.find(print_job));
102 current_jobs_.end(),
103 print_job));
104 // Causes a AddRef(). 96 // Causes a AddRef().
105 current_jobs_.push_back(make_scoped_refptr(print_job)); 97 current_jobs_.insert(print_job);
106 break; 98 break;
107 } 99 }
108 case JobEventDetails::JOB_DONE: { 100 case JobEventDetails::JOB_DONE: {
109 PrintJobs::iterator itr = std::find(current_jobs_.begin(), 101 DCHECK(current_jobs_.end() != current_jobs_.find(print_job));
110 current_jobs_.end(), 102 current_jobs_.erase(print_job);
111 print_job);
112 DCHECK(current_jobs_.end() != itr);
113 current_jobs_.erase(itr);
114 DCHECK(current_jobs_.end() == std::find(current_jobs_.begin(),
115 current_jobs_.end(),
116 print_job));
117 destination_ = NULL;
118 break; 103 break;
119 } 104 }
120 case JobEventDetails::FAILED: { 105 case JobEventDetails::FAILED: {
121 PrintJobs::iterator itr = std::find(current_jobs_.begin(), 106 current_jobs_.erase(print_job);
122 current_jobs_.end(),
123 print_job);
124 // A failed job may have never started.
125 if (current_jobs_.end() != itr) {
126 current_jobs_.erase(itr);
127 DCHECK(current_jobs_.end() ==
128 std::find(current_jobs_.begin(),
129 current_jobs_.end(),
130 print_job));
131 }
132 break; 107 break;
133 } 108 }
134 case JobEventDetails::USER_INIT_DONE: 109 case JobEventDetails::USER_INIT_DONE:
135 case JobEventDetails::USER_INIT_CANCELED: 110 case JobEventDetails::USER_INIT_CANCELED:
136 case JobEventDetails::DEFAULT_INIT_DONE: 111 case JobEventDetails::DEFAULT_INIT_DONE:
137 case JobEventDetails::NEW_PAGE: 112 case JobEventDetails::NEW_PAGE:
138 case JobEventDetails::PAGE_DONE: 113 case JobEventDetails::PAGE_DONE:
139 case JobEventDetails::DOC_DONE: 114 case JobEventDetails::DOC_DONE:
140 case JobEventDetails::ALL_PAGES_REQUESTED: { 115 case JobEventDetails::ALL_PAGES_REQUESTED: {
141 // Don't care. 116 // Don't care.
142 break; 117 break;
143 } 118 }
144 default: { 119 default: {
145 NOTREACHED(); 120 NOTREACHED();
146 break; 121 break;
147 } 122 }
148 } 123 }
149 } 124 }
150 125
151 } // namespace printing 126 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_job_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698