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/prefs/pref_service.h" | |
8 #include "chrome/browser/printing/print_job.h" | 7 #include "chrome/browser/printing/print_job.h" |
9 #include "chrome/browser/printing/printer_query.h" | 8 #include "chrome/browser/printing/printer_query.h" |
10 #include "chrome/common/chrome_notification_types.h" | 9 #include "chrome/common/chrome_notification_types.h" |
11 #include "chrome/common/pref_names.h" | |
12 #include "content/public/browser/browser_thread.h" | |
13 #include "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
14 #include "printing/printed_document.h" | 11 #include "printing/printed_document.h" |
15 #include "printing/printed_page.h" | 12 #include "printing/printed_page.h" |
16 | 13 |
17 using content::BrowserThread; | |
18 | |
19 namespace printing { | 14 namespace printing { |
20 | 15 |
21 PrintJobManager::PrintJobManager() { | 16 PrintJobManager::PrintJobManager() { |
22 registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_EVENT, | 17 registrar_.Add(this, chrome::NOTIFICATION_PRINT_JOB_EVENT, |
23 content::NotificationService::AllSources()); | 18 content::NotificationService::AllSources()); |
24 } | 19 } |
25 | 20 |
26 PrintJobManager::~PrintJobManager() { | 21 PrintJobManager::~PrintJobManager() { |
27 base::AutoLock lock(lock_); | 22 base::AutoLock lock(lock_); |
28 queued_queries_.clear(); | 23 queued_queries_.clear(); |
29 } | 24 } |
30 | 25 |
31 void PrintJobManager::InitOnUIThread(PrefService* prefs) { | |
32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
33 printing_enabled_.Init(prefs::kPrintingEnabled, prefs, NULL); | |
34 printing_enabled_.MoveToThread(BrowserThread::IO); | |
35 } | |
36 | |
37 void PrintJobManager::OnQuit() { | 26 void PrintJobManager::OnQuit() { |
38 StopJobs(true); | 27 StopJobs(true); |
39 registrar_.RemoveAll(); | 28 registrar_.RemoveAll(); |
40 } | 29 } |
41 | 30 |
42 void PrintJobManager::StopJobs(bool wait_for_finish) { | 31 void PrintJobManager::StopJobs(bool wait_for_finish) { |
43 if (current_jobs_.empty()) | 32 if (current_jobs_.empty()) |
44 return; | 33 return; |
45 { | 34 { |
46 // Copy the array since it can be modified in transit. | 35 // Copy the array since it can be modified in transit. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 if (current_query->cookie() == document_cookie && | 70 if (current_query->cookie() == document_cookie && |
82 !current_query->is_callback_pending()) { | 71 !current_query->is_callback_pending()) { |
83 *job = current_query; | 72 *job = current_query; |
84 queued_queries_.erase(itr); | 73 queued_queries_.erase(itr); |
85 DCHECK(current_query->is_valid()); | 74 DCHECK(current_query->is_valid()); |
86 return; | 75 return; |
87 } | 76 } |
88 } | 77 } |
89 } | 78 } |
90 | 79 |
91 // static | |
92 void PrintJobManager::RegisterPrefs(PrefService* prefs) { | |
93 prefs->RegisterBooleanPref(prefs::kPrintingEnabled, true); | |
94 } | |
95 | |
96 void PrintJobManager::Observe(int type, | 80 void PrintJobManager::Observe(int type, |
97 const content::NotificationSource& source, | 81 const content::NotificationSource& source, |
98 const content::NotificationDetails& details) { | 82 const content::NotificationDetails& details) { |
99 switch (type) { | 83 switch (type) { |
100 case chrome::NOTIFICATION_PRINT_JOB_EVENT: { | 84 case chrome::NOTIFICATION_PRINT_JOB_EVENT: { |
101 OnPrintJobEvent(content::Source<PrintJob>(source).ptr(), | 85 OnPrintJobEvent(content::Source<PrintJob>(source).ptr(), |
102 *content::Details<JobEventDetails>(details).ptr()); | 86 *content::Details<JobEventDetails>(details).ptr()); |
103 break; | 87 break; |
104 } | 88 } |
105 default: { | 89 default: { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // Don't care. | 141 // Don't care. |
158 break; | 142 break; |
159 } | 143 } |
160 default: { | 144 default: { |
161 NOTREACHED(); | 145 NOTREACHED(); |
162 break; | 146 break; |
163 } | 147 } |
164 } | 148 } |
165 } | 149 } |
166 | 150 |
167 bool PrintJobManager::printing_enabled() const { | |
168 return *printing_enabled_; | |
169 } | |
170 | |
171 } // namespace printing | 151 } // namespace printing |
OLD | NEW |