OLD | NEW |
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 18 matching lines...) Expand all Loading... |
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 if (current_jobs_.empty()) |
33 return; | 33 return; |
34 { | 34 { |
35 // Copy the array since it can be modified in transit. | 35 // Copy the array since it can be modified in transit. |
36 PrintJobs current_jobs(current_jobs_); | 36 PrintJobs current_jobs(current_jobs_); |
37 // Wait for each job to finish. | 37 // Wait for each job to finish. |
38 for (size_t i = 0; i < current_jobs.size(); ++i) { | 38 for (size_t i = 0; i < current_jobs.size(); ++i) { |
39 PrintJob* job = current_jobs[i]; | 39 PrintJob* job = current_jobs[i].get(); |
40 if (!job) | 40 if (!job) |
41 continue; | 41 continue; |
42 // Wait for two minutes for the print job to be spooled. | 42 // Wait for two minutes for the print job to be spooled. |
43 if (wait_for_finish) | 43 if (wait_for_finish) |
44 job->FlushJob(base::TimeDelta::FromMinutes(2)); | 44 job->FlushJob(base::TimeDelta::FromMinutes(2)); |
45 job->Stop(); | 45 job->Stop(); |
46 } | 46 } |
47 } | 47 } |
48 current_jobs_.clear(); | 48 current_jobs_.clear(); |
49 } | 49 } |
50 | 50 |
51 void PrintJobManager::SetPrintDestination( | 51 void PrintJobManager::SetPrintDestination( |
52 PrintDestinationInterface* destination) { | 52 PrintDestinationInterface* destination) { |
53 destination_ = destination; | 53 destination_ = destination; |
54 } | 54 } |
55 | 55 |
56 void PrintJobManager::QueuePrinterQuery(PrinterQuery* job) { | 56 void PrintJobManager::QueuePrinterQuery(PrinterQuery* job) { |
57 base::AutoLock lock(lock_); | 57 base::AutoLock lock(lock_); |
58 DCHECK(job); | 58 DCHECK(job); |
59 queued_queries_.push_back(make_scoped_refptr(job)); | 59 queued_queries_.push_back(make_scoped_refptr(job)); |
60 DCHECK(job->is_valid()); | 60 DCHECK(job->is_valid()); |
61 } | 61 } |
62 | 62 |
63 void PrintJobManager::PopPrinterQuery(int document_cookie, | 63 void PrintJobManager::PopPrinterQuery(int document_cookie, |
64 scoped_refptr<PrinterQuery>* job) { | 64 scoped_refptr<PrinterQuery>* job) { |
65 base::AutoLock lock(lock_); | 65 base::AutoLock lock(lock_); |
66 for (PrinterQueries::iterator itr = queued_queries_.begin(); | 66 for (PrinterQueries::iterator itr = queued_queries_.begin(); |
67 itr != queued_queries_.end(); | 67 itr != queued_queries_.end(); |
68 ++itr) { | 68 ++itr) { |
69 PrinterQuery* current_query = *itr; | 69 PrinterQuery* current_query = *itr.get(); |
70 if (current_query->cookie() == document_cookie && | 70 if (current_query->cookie() == document_cookie && |
71 !current_query->is_callback_pending()) { | 71 !current_query->is_callback_pending()) { |
72 *job = current_query; | 72 *job = current_query; |
73 queued_queries_.erase(itr); | 73 queued_queries_.erase(itr); |
74 DCHECK(current_query->is_valid()); | 74 DCHECK(current_query->is_valid()); |
75 return; | 75 return; |
76 } | 76 } |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 break; | 142 break; |
143 } | 143 } |
144 default: { | 144 default: { |
145 NOTREACHED(); | 145 NOTREACHED(); |
146 break; | 146 break; |
147 } | 147 } |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 } // namespace printing | 151 } // namespace printing |
OLD | NEW |