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

Side by Side Diff: chrome/service/cloud_print/print_system_cups.cc

Issue 653773004: Standardize usage of virtual/override/final in chrome/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months 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
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/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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // the number of requests. 69 // the number of requests.
70 typedef std::map<std::string, printing::PrinterCapsAndDefaults> CapsMap; 70 typedef std::map<std::string, printing::PrinterCapsAndDefaults> CapsMap;
71 CapsMap caps_cache; 71 CapsMap caps_cache;
72 }; 72 };
73 73
74 class PrintSystemCUPS : public PrintSystem { 74 class PrintSystemCUPS : public PrintSystem {
75 public: 75 public:
76 explicit PrintSystemCUPS(const base::DictionaryValue* print_system_settings); 76 explicit PrintSystemCUPS(const base::DictionaryValue* print_system_settings);
77 77
78 // PrintSystem implementation. 78 // PrintSystem implementation.
79 virtual PrintSystemResult Init() override; 79 PrintSystemResult Init() override;
80 virtual PrintSystem::PrintSystemResult EnumeratePrinters( 80 PrintSystem::PrintSystemResult EnumeratePrinters(
81 printing::PrinterList* printer_list) override; 81 printing::PrinterList* printer_list) override;
82 virtual void GetPrinterCapsAndDefaults( 82 void GetPrinterCapsAndDefaults(
83 const std::string& printer_name, 83 const std::string& printer_name,
84 const PrinterCapsAndDefaultsCallback& callback) override; 84 const PrinterCapsAndDefaultsCallback& callback) override;
85 virtual bool IsValidPrinter(const std::string& printer_name) override; 85 bool IsValidPrinter(const std::string& printer_name) override;
86 virtual bool ValidatePrintTicket( 86 bool ValidatePrintTicket(const std::string& printer_name,
87 const std::string& printer_name, 87 const std::string& print_ticket_data,
88 const std::string& print_ticket_data, 88 const std::string& print_ticket_mime_type) override;
89 const std::string& print_ticket_mime_type) override; 89 bool GetJobDetails(const std::string& printer_name,
90 virtual bool GetJobDetails(const std::string& printer_name, 90 PlatformJobId job_id,
91 PlatformJobId job_id, 91 PrintJobDetails* job_details) override;
92 PrintJobDetails *job_details) override; 92 PrintSystem::PrintServerWatcher* CreatePrintServerWatcher() override;
93 virtual PrintSystem::PrintServerWatcher* CreatePrintServerWatcher() override; 93 PrintSystem::PrinterWatcher* CreatePrinterWatcher(
94 virtual PrintSystem::PrinterWatcher* CreatePrinterWatcher(
95 const std::string& printer_name) override; 94 const std::string& printer_name) override;
96 virtual PrintSystem::JobSpooler* CreateJobSpooler() override; 95 PrintSystem::JobSpooler* CreateJobSpooler() override;
97 virtual bool UseCddAndCjt() override; 96 bool UseCddAndCjt() override;
98 virtual std::string GetSupportedMimeTypes() override; 97 std::string GetSupportedMimeTypes() override;
99 98
100 // Helper functions. 99 // Helper functions.
101 PlatformJobId SpoolPrintJob(const std::string& print_ticket, 100 PlatformJobId SpoolPrintJob(const std::string& print_ticket,
102 const base::FilePath& print_data_file_path, 101 const base::FilePath& print_data_file_path,
103 const std::string& print_data_mime_type, 102 const std::string& print_data_mime_type,
104 const std::string& printer_name, 103 const std::string& printer_name,
105 const std::string& job_title, 104 const std::string& job_title,
106 const std::vector<std::string>& tags, 105 const std::vector<std::string>& tags,
107 bool* dry_run); 106 bool* dry_run);
108 bool GetPrinterInfo(const std::string& printer_name, 107 bool GetPrinterInfo(const std::string& printer_name,
(...skipping 10 matching lines...) Expand all
119 return update_timeout_; 118 return update_timeout_;
120 } 119 }
121 120
122 bool NotifyDelete() const { 121 bool NotifyDelete() const {
123 // Notify about deleted printers only when we 122 // Notify about deleted printers only when we
124 // fetched printers list without errors. 123 // fetched printers list without errors.
125 return notify_delete_ && printer_enum_succeeded_; 124 return notify_delete_ && printer_enum_succeeded_;
126 } 125 }
127 126
128 private: 127 private:
129 virtual ~PrintSystemCUPS() {} 128 ~PrintSystemCUPS() override {}
130 129
131 // Following functions are wrappers around corresponding CUPS functions. 130 // Following functions are wrappers around corresponding CUPS functions.
132 // <functions>2() are called when print server is specified, and plain 131 // <functions>2() are called when print server is specified, and plain
133 // version in another case. There is an issue specifing CUPS_HTTP_DEFAULT 132 // version in another case. There is an issue specifing CUPS_HTTP_DEFAULT
134 // in the <functions>2(), it does not work in CUPS prior to 1.4. 133 // in the <functions>2(), it does not work in CUPS prior to 1.4.
135 int GetJobs(cups_job_t** jobs, const GURL& url, 134 int GetJobs(cups_job_t** jobs, const GURL& url,
136 http_encryption_t encryption, const char* name, 135 http_encryption_t encryption, const char* name,
137 int myjobs, int whichjobs); 136 int myjobs, int whichjobs);
138 int PrintFile(const GURL& url, http_encryption_t encryption, 137 int PrintFile(const GURL& url, http_encryption_t encryption,
139 const char* name, const char* filename, 138 const char* name, const char* filename,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 172
174 class PrintServerWatcherCUPS 173 class PrintServerWatcherCUPS
175 : public PrintSystem::PrintServerWatcher { 174 : public PrintSystem::PrintServerWatcher {
176 public: 175 public:
177 explicit PrintServerWatcherCUPS(PrintSystemCUPS* print_system) 176 explicit PrintServerWatcherCUPS(PrintSystemCUPS* print_system)
178 : print_system_(print_system), 177 : print_system_(print_system),
179 delegate_(NULL) { 178 delegate_(NULL) {
180 } 179 }
181 180
182 // PrintSystem::PrintServerWatcher implementation. 181 // PrintSystem::PrintServerWatcher implementation.
183 virtual bool StartWatching( 182 bool StartWatching(
184 PrintSystem::PrintServerWatcher::Delegate* delegate) override { 183 PrintSystem::PrintServerWatcher::Delegate* delegate) override {
185 delegate_ = delegate; 184 delegate_ = delegate;
186 printers_hash_ = GetPrintersHash(); 185 printers_hash_ = GetPrintersHash();
187 base::MessageLoop::current()->PostDelayedTask( 186 base::MessageLoop::current()->PostDelayedTask(
188 FROM_HERE, 187 FROM_HERE,
189 base::Bind(&PrintServerWatcherCUPS::CheckForUpdates, this), 188 base::Bind(&PrintServerWatcherCUPS::CheckForUpdates, this),
190 print_system_->GetUpdateTimeout()); 189 print_system_->GetUpdateTimeout());
191 return true; 190 return true;
192 } 191 }
193 192
194 virtual bool StopWatching() override { 193 bool StopWatching() override {
195 delegate_ = NULL; 194 delegate_ = NULL;
196 return true; 195 return true;
197 } 196 }
198 197
199 void CheckForUpdates() { 198 void CheckForUpdates() {
200 if (delegate_ == NULL) 199 if (delegate_ == NULL)
201 return; // Orphan call. We have been stopped already. 200 return; // Orphan call. We have been stopped already.
202 VLOG(1) << "CP_CUPS: Checking for new printers"; 201 VLOG(1) << "CP_CUPS: Checking for new printers";
203 std::string new_hash = GetPrintersHash(); 202 std::string new_hash = GetPrintersHash();
204 if (printers_hash_ != new_hash) { 203 if (printers_hash_ != new_hash) {
205 printers_hash_ = new_hash; 204 printers_hash_ = new_hash;
206 delegate_->OnPrinterAdded(); 205 delegate_->OnPrinterAdded();
207 } 206 }
208 base::MessageLoop::current()->PostDelayedTask( 207 base::MessageLoop::current()->PostDelayedTask(
209 FROM_HERE, 208 FROM_HERE,
210 base::Bind(&PrintServerWatcherCUPS::CheckForUpdates, this), 209 base::Bind(&PrintServerWatcherCUPS::CheckForUpdates, this),
211 print_system_->GetUpdateTimeout()); 210 print_system_->GetUpdateTimeout());
212 } 211 }
213 212
214 protected: 213 protected:
215 virtual ~PrintServerWatcherCUPS() { 214 ~PrintServerWatcherCUPS() override { StopWatching(); }
216 StopWatching();
217 }
218 215
219 private: 216 private:
220 std::string GetPrintersHash() { 217 std::string GetPrintersHash() {
221 printing::PrinterList printer_list; 218 printing::PrinterList printer_list;
222 print_system_->EnumeratePrinters(&printer_list); 219 print_system_->EnumeratePrinters(&printer_list);
223 220
224 // Sort printer names. 221 // Sort printer names.
225 std::vector<std::string> printers; 222 std::vector<std::string> printers;
226 printing::PrinterList::iterator it; 223 printing::PrinterList::iterator it;
227 for (it = printer_list.begin(); it != printer_list.end(); ++it) 224 for (it = printer_list.begin(); it != printer_list.end(); ++it)
(...skipping 18 matching lines...) Expand all
246 : public PrintSystem::PrinterWatcher { 243 : public PrintSystem::PrinterWatcher {
247 public: 244 public:
248 PrinterWatcherCUPS(PrintSystemCUPS* print_system, 245 PrinterWatcherCUPS(PrintSystemCUPS* print_system,
249 const std::string& printer_name) 246 const std::string& printer_name)
250 : printer_name_(printer_name), 247 : printer_name_(printer_name),
251 delegate_(NULL), 248 delegate_(NULL),
252 print_system_(print_system) { 249 print_system_(print_system) {
253 } 250 }
254 251
255 // PrintSystem::PrinterWatcher implementation. 252 // PrintSystem::PrinterWatcher implementation.
256 virtual bool StartWatching( 253 bool StartWatching(PrintSystem::PrinterWatcher::Delegate* delegate) override {
257 PrintSystem::PrinterWatcher::Delegate* delegate) override{
258 scoped_refptr<printing::PrintBackend> print_backend( 254 scoped_refptr<printing::PrintBackend> print_backend(
259 printing::PrintBackend::CreateInstance(NULL)); 255 printing::PrintBackend::CreateInstance(NULL));
260 crash_keys::ScopedPrinterInfo crash_key( 256 crash_keys::ScopedPrinterInfo crash_key(
261 print_backend->GetPrinterDriverInfo(printer_name_)); 257 print_backend->GetPrinterDriverInfo(printer_name_));
262 if (delegate_ != NULL) 258 if (delegate_ != NULL)
263 StopWatching(); 259 StopWatching();
264 delegate_ = delegate; 260 delegate_ = delegate;
265 settings_hash_ = GetSettingsHash(); 261 settings_hash_ = GetSettingsHash();
266 // Schedule next job status update. 262 // Schedule next job status update.
267 base::MessageLoop::current()->PostDelayedTask( 263 base::MessageLoop::current()->PostDelayedTask(
268 FROM_HERE, 264 FROM_HERE,
269 base::Bind(&PrinterWatcherCUPS::JobStatusUpdate, this), 265 base::Bind(&PrinterWatcherCUPS::JobStatusUpdate, this),
270 base::TimeDelta::FromSeconds(kJobUpdateTimeoutSeconds)); 266 base::TimeDelta::FromSeconds(kJobUpdateTimeoutSeconds));
271 // Schedule next printer check. 267 // Schedule next printer check.
272 // TODO(gene): Randomize time for the next printer update. 268 // TODO(gene): Randomize time for the next printer update.
273 base::MessageLoop::current()->PostDelayedTask( 269 base::MessageLoop::current()->PostDelayedTask(
274 FROM_HERE, 270 FROM_HERE,
275 base::Bind(&PrinterWatcherCUPS::PrinterUpdate, this), 271 base::Bind(&PrinterWatcherCUPS::PrinterUpdate, this),
276 print_system_->GetUpdateTimeout()); 272 print_system_->GetUpdateTimeout());
277 return true; 273 return true;
278 } 274 }
279 275
280 virtual bool StopWatching() override{ 276 bool StopWatching() override {
281 delegate_ = NULL; 277 delegate_ = NULL;
282 return true; 278 return true;
283 } 279 }
284 280
285 virtual bool GetCurrentPrinterInfo( 281 bool GetCurrentPrinterInfo(
286 printing::PrinterBasicInfo* printer_info) override { 282 printing::PrinterBasicInfo* printer_info) override {
287 DCHECK(printer_info); 283 DCHECK(printer_info);
288 return print_system_->GetPrinterInfo(printer_name_, printer_info); 284 return print_system_->GetPrinterInfo(printer_name_, printer_info);
289 } 285 }
290 286
291 void JobStatusUpdate() { 287 void JobStatusUpdate() {
292 if (delegate_ == NULL) 288 if (delegate_ == NULL)
293 return; // Orphan call. We have been stopped already. 289 return; // Orphan call. We have been stopped already.
294 // For CUPS proxy, we are going to fire OnJobChanged notification 290 // For CUPS proxy, we are going to fire OnJobChanged notification
295 // periodically. Higher level will check if there are any outstanding 291 // periodically. Higher level will check if there are any outstanding
(...skipping 25 matching lines...) Expand all
321 << ", printer name: " << printer_name_; 317 << ", printer name: " << printer_name_;
322 } 318 }
323 } 319 }
324 base::MessageLoop::current()->PostDelayedTask( 320 base::MessageLoop::current()->PostDelayedTask(
325 FROM_HERE, 321 FROM_HERE,
326 base::Bind(&PrinterWatcherCUPS::PrinterUpdate, this), 322 base::Bind(&PrinterWatcherCUPS::PrinterUpdate, this),
327 print_system_->GetUpdateTimeout()); 323 print_system_->GetUpdateTimeout());
328 } 324 }
329 325
330 protected: 326 protected:
331 virtual ~PrinterWatcherCUPS() { 327 ~PrinterWatcherCUPS() override { StopWatching(); }
332 StopWatching();
333 }
334 328
335 private: 329 private:
336 std::string GetSettingsHash() { 330 std::string GetSettingsHash() {
337 printing::PrinterBasicInfo info; 331 printing::PrinterBasicInfo info;
338 if (!print_system_->GetPrinterInfo(printer_name_, &info)) 332 if (!print_system_->GetPrinterInfo(printer_name_, &info))
339 return std::string(); 333 return std::string();
340 334
341 printing::PrinterCapsAndDefaults caps; 335 printing::PrinterCapsAndDefaults caps;
342 if (!print_system_->GetPrinterCapsAndDefaults(printer_name_, &caps)) 336 if (!print_system_->GetPrinterCapsAndDefaults(printer_name_, &caps))
343 return std::string(); 337 return std::string();
(...skipping 22 matching lines...) Expand all
366 }; 360 };
367 361
368 class JobSpoolerCUPS : public PrintSystem::JobSpooler { 362 class JobSpoolerCUPS : public PrintSystem::JobSpooler {
369 public: 363 public:
370 explicit JobSpoolerCUPS(PrintSystemCUPS* print_system) 364 explicit JobSpoolerCUPS(PrintSystemCUPS* print_system)
371 : print_system_(print_system) { 365 : print_system_(print_system) {
372 DCHECK(print_system_.get()); 366 DCHECK(print_system_.get());
373 } 367 }
374 368
375 // PrintSystem::JobSpooler implementation. 369 // PrintSystem::JobSpooler implementation.
376 virtual bool Spool(const std::string& print_ticket, 370 bool Spool(const std::string& print_ticket,
377 const std::string& print_ticket_mime_type, 371 const std::string& print_ticket_mime_type,
378 const base::FilePath& print_data_file_path, 372 const base::FilePath& print_data_file_path,
379 const std::string& print_data_mime_type, 373 const std::string& print_data_mime_type,
380 const std::string& printer_name, 374 const std::string& printer_name,
381 const std::string& job_title, 375 const std::string& job_title,
382 const std::vector<std::string>& tags, 376 const std::vector<std::string>& tags,
383 JobSpooler::Delegate* delegate) override{ 377 JobSpooler::Delegate* delegate) override {
384 DCHECK(delegate); 378 DCHECK(delegate);
385 bool dry_run = false; 379 bool dry_run = false;
386 int job_id = print_system_->SpoolPrintJob( 380 int job_id = print_system_->SpoolPrintJob(
387 print_ticket, print_data_file_path, print_data_mime_type, 381 print_ticket, print_data_file_path, print_data_mime_type,
388 printer_name, job_title, tags, &dry_run); 382 printer_name, job_title, tags, &dry_run);
389 base::MessageLoop::current()->PostTask( 383 base::MessageLoop::current()->PostTask(
390 FROM_HERE, 384 FROM_HERE,
391 base::Bind(&JobSpoolerCUPS::NotifyDelegate, delegate, job_id, dry_run)); 385 base::Bind(&JobSpoolerCUPS::NotifyDelegate, delegate, job_id, dry_run));
392 return true; 386 return true;
393 } 387 }
394 388
395 static void NotifyDelegate(JobSpooler::Delegate* delegate, 389 static void NotifyDelegate(JobSpooler::Delegate* delegate,
396 int job_id, bool dry_run) { 390 int job_id, bool dry_run) {
397 if (dry_run || job_id) 391 if (dry_run || job_id)
398 delegate->OnJobSpoolSucceeded(job_id); 392 delegate->OnJobSpoolSucceeded(job_id);
399 else 393 else
400 delegate->OnJobSpoolFailed(); 394 delegate->OnJobSpoolFailed();
401 } 395 }
402 396
403 protected: 397 protected:
404 virtual ~JobSpoolerCUPS() {} 398 ~JobSpoolerCUPS() override {}
405 399
406 private: 400 private:
407 scoped_refptr<PrintSystemCUPS> print_system_; 401 scoped_refptr<PrintSystemCUPS> print_system_;
408 402
409 DISALLOW_COPY_AND_ASSIGN(JobSpoolerCUPS); 403 DISALLOW_COPY_AND_ASSIGN(JobSpoolerCUPS);
410 }; 404 };
411 405
412 PrintSystemCUPS::PrintSystemCUPS( 406 PrintSystemCUPS::PrintSystemCUPS(
413 const base::DictionaryValue* print_system_settings) 407 const base::DictionaryValue* print_system_settings)
414 : update_timeout_(base::TimeDelta::FromMinutes( 408 : update_timeout_(base::TimeDelta::FromMinutes(
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 866
873 void PrintSystemCUPS::RunCapsCallback( 867 void PrintSystemCUPS::RunCapsCallback(
874 const PrinterCapsAndDefaultsCallback& callback, 868 const PrinterCapsAndDefaultsCallback& callback,
875 bool succeeded, 869 bool succeeded,
876 const std::string& printer_name, 870 const std::string& printer_name,
877 const printing::PrinterCapsAndDefaults& printer_info) { 871 const printing::PrinterCapsAndDefaults& printer_info) {
878 callback.Run(succeeded, printer_name, printer_info); 872 callback.Run(succeeded, printer_name, printer_info);
879 } 873 }
880 874
881 } // namespace cloud_print 875 } // namespace cloud_print
OLDNEW
« no previous file with comments | « chrome/service/cloud_print/job_status_updater.h ('k') | chrome/service/cloud_print/printer_job_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698