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/service/cloud_print/print_system.h" | 5 #include "chrome/service/cloud_print/print_system.h" |
6 | 6 |
7 #include <cups/cups.h> | 7 #include <cups/cups.h> |
8 #include <dlfcn.h> | 8 #include <dlfcn.h> |
9 #include <errno.h> | 9 #include <errno.h> |
10 #include <pthread.h> | 10 #include <pthread.h> |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 return update_timeout_; | 120 return update_timeout_; |
121 } | 121 } |
122 | 122 |
123 bool NotifyDelete() const { | 123 bool NotifyDelete() const { |
124 // Notify about deleted printers only when we | 124 // Notify about deleted printers only when we |
125 // fetched printers list without errors. | 125 // fetched printers list without errors. |
126 return notify_delete_ && printer_enum_succeeded_; | 126 return notify_delete_ && printer_enum_succeeded_; |
127 } | 127 } |
128 | 128 |
129 private: | 129 private: |
| 130 virtual ~PrintSystemCUPS() {} |
| 131 |
130 // Following functions are wrappers around corresponding CUPS functions. | 132 // Following functions are wrappers around corresponding CUPS functions. |
131 // <functions>2() are called when print server is specified, and plain | 133 // <functions>2() are called when print server is specified, and plain |
132 // version in another case. There is an issue specifing CUPS_HTTP_DEFAULT | 134 // version in another case. There is an issue specifing CUPS_HTTP_DEFAULT |
133 // in the <functions>2(), it does not work in CUPS prior to 1.4. | 135 // in the <functions>2(), it does not work in CUPS prior to 1.4. |
134 int GetJobs(cups_job_t** jobs, const GURL& url, const char* name, | 136 int GetJobs(cups_job_t** jobs, const GURL& url, const char* name, |
135 int myjobs, int whichjobs); | 137 int myjobs, int whichjobs); |
136 int PrintFile(const GURL& url, const char* name, const char* filename, | 138 int PrintFile(const GURL& url, const char* name, const char* filename, |
137 const char* title, int num_options, cups_option_t* options); | 139 const char* title, int num_options, cups_option_t* options); |
138 | 140 |
139 void InitPrintBackends(const DictionaryValue* print_system_settings); | 141 void InitPrintBackends(const DictionaryValue* print_system_settings); |
(...skipping 26 matching lines...) Expand all Loading... |
166 bool notify_delete_; | 168 bool notify_delete_; |
167 }; | 169 }; |
168 | 170 |
169 class PrintServerWatcherCUPS | 171 class PrintServerWatcherCUPS |
170 : public PrintSystem::PrintServerWatcher { | 172 : public PrintSystem::PrintServerWatcher { |
171 public: | 173 public: |
172 explicit PrintServerWatcherCUPS(PrintSystemCUPS* print_system) | 174 explicit PrintServerWatcherCUPS(PrintSystemCUPS* print_system) |
173 : print_system_(print_system), | 175 : print_system_(print_system), |
174 delegate_(NULL) { | 176 delegate_(NULL) { |
175 } | 177 } |
176 ~PrintServerWatcherCUPS() { | |
177 StopWatching(); | |
178 } | |
179 | 178 |
180 // PrintSystem::PrintServerWatcher implementation. | 179 // PrintSystem::PrintServerWatcher implementation. |
181 virtual bool StartWatching( | 180 virtual bool StartWatching( |
182 PrintSystem::PrintServerWatcher::Delegate* delegate) OVERRIDE { | 181 PrintSystem::PrintServerWatcher::Delegate* delegate) OVERRIDE { |
183 delegate_ = delegate; | 182 delegate_ = delegate; |
184 printers_hash_ = GetPrintersHash(); | 183 printers_hash_ = GetPrintersHash(); |
185 MessageLoop::current()->PostDelayedTask( | 184 MessageLoop::current()->PostDelayedTask( |
186 FROM_HERE, | 185 FROM_HERE, |
187 base::Bind(&PrintServerWatcherCUPS::CheckForUpdates, this), | 186 base::Bind(&PrintServerWatcherCUPS::CheckForUpdates, this), |
188 print_system_->GetUpdateTimeout()); | 187 print_system_->GetUpdateTimeout()); |
(...skipping 13 matching lines...) Expand all Loading... |
202 if (printers_hash_ != new_hash) { | 201 if (printers_hash_ != new_hash) { |
203 printers_hash_ = new_hash; | 202 printers_hash_ = new_hash; |
204 delegate_->OnPrinterAdded(); | 203 delegate_->OnPrinterAdded(); |
205 } | 204 } |
206 MessageLoop::current()->PostDelayedTask( | 205 MessageLoop::current()->PostDelayedTask( |
207 FROM_HERE, | 206 FROM_HERE, |
208 base::Bind(&PrintServerWatcherCUPS::CheckForUpdates, this), | 207 base::Bind(&PrintServerWatcherCUPS::CheckForUpdates, this), |
209 print_system_->GetUpdateTimeout()); | 208 print_system_->GetUpdateTimeout()); |
210 } | 209 } |
211 | 210 |
| 211 protected: |
| 212 virtual ~PrintServerWatcherCUPS() { |
| 213 StopWatching(); |
| 214 } |
| 215 |
212 private: | 216 private: |
213 std::string GetPrintersHash() { | 217 std::string GetPrintersHash() { |
214 printing::PrinterList printer_list; | 218 printing::PrinterList printer_list; |
215 print_system_->EnumeratePrinters(&printer_list); | 219 print_system_->EnumeratePrinters(&printer_list); |
216 | 220 |
217 // Sort printer names. | 221 // Sort printer names. |
218 std::vector<std::string> printers; | 222 std::vector<std::string> printers; |
219 printing::PrinterList::iterator it; | 223 printing::PrinterList::iterator it; |
220 for (it = printer_list.begin(); it != printer_list.end(); ++it) | 224 for (it = printer_list.begin(); it != printer_list.end(); ++it) |
221 printers.push_back(it->printer_name); | 225 printers.push_back(it->printer_name); |
(...skipping 16 matching lines...) Expand all Loading... |
238 class PrinterWatcherCUPS | 242 class PrinterWatcherCUPS |
239 : public PrintSystem::PrinterWatcher { | 243 : public PrintSystem::PrinterWatcher { |
240 public: | 244 public: |
241 PrinterWatcherCUPS(PrintSystemCUPS* print_system, | 245 PrinterWatcherCUPS(PrintSystemCUPS* print_system, |
242 const std::string& printer_name) | 246 const std::string& printer_name) |
243 : printer_name_(printer_name), | 247 : printer_name_(printer_name), |
244 delegate_(NULL), | 248 delegate_(NULL), |
245 print_system_(print_system) { | 249 print_system_(print_system) { |
246 } | 250 } |
247 | 251 |
248 ~PrinterWatcherCUPS() { | |
249 StopWatching(); | |
250 } | |
251 | |
252 // PrintSystem::PrinterWatcher implementation. | 252 // PrintSystem::PrinterWatcher implementation. |
253 virtual bool StartWatching( | 253 virtual bool StartWatching( |
254 PrintSystem::PrinterWatcher::Delegate* delegate) OVERRIDE{ | 254 PrintSystem::PrinterWatcher::Delegate* delegate) OVERRIDE{ |
255 scoped_refptr<printing::PrintBackend> print_backend( | 255 scoped_refptr<printing::PrintBackend> print_backend( |
256 printing::PrintBackend::CreateInstance(NULL)); | 256 printing::PrintBackend::CreateInstance(NULL)); |
257 child_process_logging::ScopedPrinterInfoSetter prn_info( | 257 child_process_logging::ScopedPrinterInfoSetter prn_info( |
258 print_backend->GetPrinterDriverInfo(printer_name_)); | 258 print_backend->GetPrinterDriverInfo(printer_name_)); |
259 if (delegate_ != NULL) | 259 if (delegate_ != NULL) |
260 StopWatching(); | 260 StopWatching(); |
261 delegate_ = delegate; | 261 delegate_ = delegate; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 delegate_->OnPrinterChanged(); | 313 delegate_->OnPrinterChanged(); |
314 VLOG(1) << "CP_CUPS: Printer update detected for: " << printer_name_; | 314 VLOG(1) << "CP_CUPS: Printer update detected for: " << printer_name_; |
315 } | 315 } |
316 } | 316 } |
317 MessageLoop::current()->PostDelayedTask( | 317 MessageLoop::current()->PostDelayedTask( |
318 FROM_HERE, | 318 FROM_HERE, |
319 base::Bind(&PrinterWatcherCUPS::PrinterUpdate, this), | 319 base::Bind(&PrinterWatcherCUPS::PrinterUpdate, this), |
320 print_system_->GetUpdateTimeout()); | 320 print_system_->GetUpdateTimeout()); |
321 } | 321 } |
322 | 322 |
| 323 protected: |
| 324 virtual ~PrinterWatcherCUPS() { |
| 325 StopWatching(); |
| 326 } |
| 327 |
323 private: | 328 private: |
324 std::string GetSettingsHash() { | 329 std::string GetSettingsHash() { |
325 printing::PrinterBasicInfo info; | 330 printing::PrinterBasicInfo info; |
326 if (!print_system_->GetPrinterInfo(printer_name_, &info)) | 331 if (!print_system_->GetPrinterInfo(printer_name_, &info)) |
327 return std::string(); | 332 return std::string(); |
328 | 333 |
329 printing::PrinterCapsAndDefaults caps; | 334 printing::PrinterCapsAndDefaults caps; |
330 if (!print_system_->GetPrinterCapsAndDefaults(printer_name_, &caps)) | 335 if (!print_system_->GetPrinterCapsAndDefaults(printer_name_, &caps)) |
331 return std::string(); | 336 return std::string(); |
332 | 337 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 } | 385 } |
381 | 386 |
382 static void NotifyDelegate(JobSpooler::Delegate* delegate, | 387 static void NotifyDelegate(JobSpooler::Delegate* delegate, |
383 int job_id, bool dry_run) { | 388 int job_id, bool dry_run) { |
384 if (dry_run || job_id) | 389 if (dry_run || job_id) |
385 delegate->OnJobSpoolSucceeded(job_id); | 390 delegate->OnJobSpoolSucceeded(job_id); |
386 else | 391 else |
387 delegate->OnJobSpoolFailed(); | 392 delegate->OnJobSpoolFailed(); |
388 } | 393 } |
389 | 394 |
| 395 protected: |
| 396 virtual ~JobSpoolerCUPS() {} |
| 397 |
390 private: | 398 private: |
391 scoped_refptr<PrintSystemCUPS> print_system_; | 399 scoped_refptr<PrintSystemCUPS> print_system_; |
392 | 400 |
393 DISALLOW_COPY_AND_ASSIGN(JobSpoolerCUPS); | 401 DISALLOW_COPY_AND_ASSIGN(JobSpoolerCUPS); |
394 }; | 402 }; |
395 | 403 |
396 PrintSystemCUPS::PrintSystemCUPS(const DictionaryValue* print_system_settings) | 404 PrintSystemCUPS::PrintSystemCUPS(const DictionaryValue* print_system_settings) |
397 : update_timeout_(base::TimeDelta::FromMinutes( | 405 : update_timeout_(base::TimeDelta::FromMinutes( |
398 kCheckForPrinterUpdatesMinutes)), | 406 kCheckForPrinterUpdatesMinutes)), |
399 initialized_(false), | 407 initialized_(false), |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 | 837 |
830 void PrintSystemCUPS::RunCapsCallback( | 838 void PrintSystemCUPS::RunCapsCallback( |
831 const PrinterCapsAndDefaultsCallback& callback, | 839 const PrinterCapsAndDefaultsCallback& callback, |
832 bool succeeded, | 840 bool succeeded, |
833 const std::string& printer_name, | 841 const std::string& printer_name, |
834 const printing::PrinterCapsAndDefaults& printer_info) { | 842 const printing::PrinterCapsAndDefaults& printer_info) { |
835 callback.Run(succeeded, printer_name, printer_info); | 843 callback.Run(succeeded, printer_name, printer_info); |
836 } | 844 } |
837 | 845 |
838 } // namespace cloud_print | 846 } // namespace cloud_print |
OLD | NEW |