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/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/printing/print_job.h" | 8 #include "chrome/browser/printing/print_job.h" |
9 #include "chrome/browser/printing/printer_query.h" | 9 #include "chrome/browser/printing/printer_query.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 69 |
70 PrintJobManager::PrintJobManager() : is_shutdown_(false) { | 70 PrintJobManager::PrintJobManager() : is_shutdown_(false) { |
71 registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_EVENT, | 71 registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_EVENT, |
72 content::NotificationService::AllSources()); | 72 content::NotificationService::AllSources()); |
73 } | 73 } |
74 | 74 |
75 PrintJobManager::~PrintJobManager() { | 75 PrintJobManager::~PrintJobManager() { |
76 } | 76 } |
77 | 77 |
78 scoped_refptr<PrintQueriesQueue> PrintJobManager::queue() { | 78 scoped_refptr<PrintQueriesQueue> PrintJobManager::queue() { |
79 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 79 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
80 if (!queue_.get()) | 80 if (!queue_.get()) |
81 queue_ = new PrintQueriesQueue(); | 81 queue_ = new PrintQueriesQueue(); |
82 return queue_; | 82 return queue_; |
83 } | 83 } |
84 | 84 |
85 void PrintJobManager::Shutdown() { | 85 void PrintJobManager::Shutdown() { |
86 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 86 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
87 DCHECK(!is_shutdown_); | 87 DCHECK(!is_shutdown_); |
88 is_shutdown_ = true; | 88 is_shutdown_ = true; |
89 registrar_.RemoveAll(); | 89 registrar_.RemoveAll(); |
90 StopJobs(true); | 90 StopJobs(true); |
91 if (queue_.get()) | 91 if (queue_.get()) |
92 queue_->Shutdown(); | 92 queue_->Shutdown(); |
93 queue_ = NULL; | 93 queue_ = NULL; |
94 } | 94 } |
95 | 95 |
96 void PrintJobManager::StopJobs(bool wait_for_finish) { | 96 void PrintJobManager::StopJobs(bool wait_for_finish) { |
97 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 97 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
98 // Copy the array since it can be modified in transit. | 98 // Copy the array since it can be modified in transit. |
99 PrintJobs to_stop; | 99 PrintJobs to_stop; |
100 to_stop.swap(current_jobs_); | 100 to_stop.swap(current_jobs_); |
101 | 101 |
102 for (PrintJobs::const_iterator job = to_stop.begin(); job != to_stop.end(); | 102 for (PrintJobs::const_iterator job = to_stop.begin(); job != to_stop.end(); |
103 ++job) { | 103 ++job) { |
104 // Wait for two minutes for the print job to be spooled. | 104 // Wait for two minutes for the print job to be spooled. |
105 if (wait_for_finish) | 105 if (wait_for_finish) |
106 (*job)->FlushJob(base::TimeDelta::FromMinutes(2)); | 106 (*job)->FlushJob(base::TimeDelta::FromMinutes(2)); |
107 (*job)->Stop(); | 107 (*job)->Stop(); |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
111 void PrintJobManager::Observe(int type, | 111 void PrintJobManager::Observe(int type, |
112 const content::NotificationSource& source, | 112 const content::NotificationSource& source, |
113 const content::NotificationDetails& details) { | 113 const content::NotificationDetails& details) { |
114 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 114 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
115 switch (type) { | 115 switch (type) { |
116 case chrome::NOTIFICATION_PRINT_JOB_EVENT: { | 116 case chrome::NOTIFICATION_PRINT_JOB_EVENT: { |
117 OnPrintJobEvent(content::Source<PrintJob>(source).ptr(), | 117 OnPrintJobEvent(content::Source<PrintJob>(source).ptr(), |
118 *content::Details<JobEventDetails>(details).ptr()); | 118 *content::Details<JobEventDetails>(details).ptr()); |
119 break; | 119 break; |
120 } | 120 } |
121 default: { | 121 default: { |
122 NOTREACHED(); | 122 NOTREACHED(); |
123 break; | 123 break; |
124 } | 124 } |
(...skipping 30 matching lines...) Expand all Loading... |
155 break; | 155 break; |
156 } | 156 } |
157 default: { | 157 default: { |
158 NOTREACHED(); | 158 NOTREACHED(); |
159 break; | 159 break; |
160 } | 160 } |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 } // namespace printing | 164 } // namespace printing |
OLD | NEW |