OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/printer_job_handler.h" | 5 #include "chrome/service/cloud_print/printer_job_handler.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/md5.h" | 9 #include "base/md5.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 job_handler_message_loop_proxy_( | 38 job_handler_message_loop_proxy_( |
39 base::MessageLoopProxy::CreateForCurrentThread()), | 39 base::MessageLoopProxy::CreateForCurrentThread()), |
40 shutting_down_(false), | 40 shutting_down_(false), |
41 server_job_available_(false), | 41 server_job_available_(false), |
42 printer_update_pending_(true), | 42 printer_update_pending_(true), |
43 printer_delete_pending_(false), | 43 printer_delete_pending_(false), |
44 task_in_progress_(false) { | 44 task_in_progress_(false) { |
45 } | 45 } |
46 | 46 |
47 bool PrinterJobHandler::Initialize() { | 47 bool PrinterJobHandler::Initialize() { |
48 if (print_system_->GetPrintBackend()->IsValidPrinter( | 48 if (print_system_->IsValidPrinter( |
49 printer_info_.printer_name)) { | 49 printer_info_.printer_name)) { |
50 printer_watcher_ = print_system_->CreatePrinterWatcher( | 50 printer_watcher_ = print_system_->CreatePrinterWatcher( |
51 printer_info_.printer_name); | 51 printer_info_.printer_name); |
52 printer_watcher_->StartWatching(this); | 52 printer_watcher_->StartWatching(this); |
53 NotifyJobAvailable(); | 53 NotifyJobAvailable(); |
54 } else { | 54 } else { |
55 // This printer does not exist any more. Delete it from the server. | 55 // This printer does not exist any more. Delete it from the server. |
56 OnPrinterDeleted(); | 56 OnPrinterDeleted(); |
57 } | 57 } |
58 return true; | 58 return true; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 VLOG(1) << "CP_PROXY: Update printer info, id: " | 138 VLOG(1) << "CP_PROXY: Update printer info, id: " |
139 << printer_info_cloud_.printer_id; | 139 << printer_info_cloud_.printer_id; |
140 // We need to update the parts of the printer info that have changed | 140 // We need to update the parts of the printer info that have changed |
141 // (could be printer name, description, status or capabilities). | 141 // (could be printer name, description, status or capabilities). |
142 printing::PrinterBasicInfo printer_info; | 142 printing::PrinterBasicInfo printer_info; |
143 printer_watcher_->GetCurrentPrinterInfo(&printer_info); | 143 printer_watcher_->GetCurrentPrinterInfo(&printer_info); |
144 printing::PrinterCapsAndDefaults printer_caps; | 144 printing::PrinterCapsAndDefaults printer_caps; |
145 std::string post_data; | 145 std::string post_data; |
146 std::string mime_boundary; | 146 std::string mime_boundary; |
147 CloudPrintHelpers::CreateMimeBoundaryForUpload(&mime_boundary); | 147 CloudPrintHelpers::CreateMimeBoundaryForUpload(&mime_boundary); |
148 if (print_system_->GetPrintBackend()->GetPrinterCapsAndDefaults( | 148 if (print_system_->GetPrinterCapsAndDefaults( |
149 printer_info.printer_name, &printer_caps)) { | 149 printer_info.printer_name, &printer_caps)) { |
150 std::string caps_hash = MD5String(printer_caps.printer_capabilities); | 150 std::string caps_hash = MD5String(printer_caps.printer_capabilities); |
151 if (caps_hash != printer_info_cloud_.caps_hash) { | 151 if (caps_hash != printer_info_cloud_.caps_hash) { |
152 // Hashes don't match, we need to upload new capabilities (the defaults | 152 // Hashes don't match, we need to upload new capabilities (the defaults |
153 // go for free along with the capabilities) | 153 // go for free along with the capabilities) |
154 printer_info_cloud_.caps_hash = caps_hash; | 154 printer_info_cloud_.caps_hash = caps_hash; |
155 CloudPrintHelpers::AddMultipartValueForUpload( | 155 CloudPrintHelpers::AddMultipartValueForUpload( |
156 kPrinterCapsValue, printer_caps.printer_capabilities, | 156 kPrinterCapsValue, printer_caps.printer_capabilities, |
157 mime_boundary, printer_caps.caps_mime_type, &post_data); | 157 mime_boundary, printer_caps.caps_mime_type, &post_data); |
158 CloudPrintHelpers::AddMultipartValueForUpload( | 158 CloudPrintHelpers::AddMultipartValueForUpload( |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 } | 575 } |
576 | 576 |
577 void PrinterJobHandler::OnJobSpoolFailed() { | 577 void PrinterJobHandler::OnJobSpoolFailed() { |
578 DCHECK(MessageLoop::current() == print_thread_.message_loop()); | 578 DCHECK(MessageLoop::current() == print_thread_.message_loop()); |
579 job_spooler_ = NULL; | 579 job_spooler_ = NULL; |
580 job_handler_message_loop_proxy_->PostTask(FROM_HERE, | 580 job_handler_message_loop_proxy_->PostTask(FROM_HERE, |
581 NewRunnableMethod(this, | 581 NewRunnableMethod(this, |
582 &PrinterJobHandler::JobFailed, | 582 &PrinterJobHandler::JobFailed, |
583 PRINT_FAILED)); | 583 PRINT_FAILED)); |
584 } | 584 } |
OLD | NEW |