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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 // NULL to OpenPrinter. | 61 // NULL to OpenPrinter. |
62 LPTSTR printer_name_to_use = NULL; | 62 LPTSTR printer_name_to_use = NULL; |
63 std::wstring printer_name_wide; | 63 std::wstring printer_name_wide; |
64 if (!printer_name.empty()) { | 64 if (!printer_name.empty()) { |
65 printer_name_wide = base::UTF8ToWide(printer_name); | 65 printer_name_wide = base::UTF8ToWide(printer_name); |
66 printer_name_to_use = const_cast<LPTSTR>(printer_name_wide.c_str()); | 66 printer_name_to_use = const_cast<LPTSTR>(printer_name_wide.c_str()); |
67 } | 67 } |
68 bool ret = false; | 68 bool ret = false; |
69 if (printer_.OpenPrinter(printer_name_to_use)) { | 69 if (printer_.OpenPrinter(printer_name_to_use)) { |
70 printer_change_.Set(FindFirstPrinterChangeNotification( | 70 printer_change_.Set(FindFirstPrinterChangeNotification( |
71 printer_, PRINTER_CHANGE_PRINTER|PRINTER_CHANGE_JOB, 0, NULL)); | 71 printer_.Get(), PRINTER_CHANGE_PRINTER|PRINTER_CHANGE_JOB, 0, NULL)); |
72 if (printer_change_.IsValid()) { | 72 if (printer_change_.IsValid()) { |
73 ret = watcher_.StartWatching(printer_change_, this); | 73 ret = watcher_.StartWatching(printer_change_.Get(), this); |
74 } | 74 } |
75 } | 75 } |
76 if (!ret) { | 76 if (!ret) { |
77 Stop(); | 77 Stop(); |
78 } | 78 } |
79 return ret; | 79 return ret; |
80 } | 80 } |
81 | 81 |
82 bool Stop() { | 82 bool Stop() { |
83 watcher_.StopWatching(); | 83 watcher_.StopWatching(); |
(...skipping 17 matching lines...) Expand all Loading... |
101 delegate_->OnPrinterAdded(); | 101 delegate_->OnPrinterAdded(); |
102 } else if (change & PRINTER_CHANGE_DELETE_PRINTER) { | 102 } else if (change & PRINTER_CHANGE_DELETE_PRINTER) { |
103 delegate_->OnPrinterDeleted(); | 103 delegate_->OnPrinterDeleted(); |
104 } else if (change & PRINTER_CHANGE_SET_PRINTER) { | 104 } else if (change & PRINTER_CHANGE_SET_PRINTER) { |
105 delegate_->OnPrinterChanged(); | 105 delegate_->OnPrinterChanged(); |
106 } | 106 } |
107 if (change & PRINTER_CHANGE_JOB) { | 107 if (change & PRINTER_CHANGE_JOB) { |
108 delegate_->OnJobChanged(); | 108 delegate_->OnJobChanged(); |
109 } | 109 } |
110 } | 110 } |
111 watcher_.StartWatching(printer_change_, this); | 111 watcher_.StartWatching(printer_change_.Get(), this); |
112 } | 112 } |
113 | 113 |
114 bool GetCurrentPrinterInfo(printing::PrinterBasicInfo* printer_info) { | 114 bool GetCurrentPrinterInfo(printing::PrinterBasicInfo* printer_info) { |
115 DCHECK(printer_info); | 115 DCHECK(printer_info); |
116 return InitBasicPrinterInfo(printer_, printer_info); | 116 return InitBasicPrinterInfo(printer_.Get(), printer_info); |
117 } | 117 } |
118 | 118 |
119 private: | 119 private: |
120 base::win::ObjectWatcher watcher_; | 120 base::win::ObjectWatcher watcher_; |
121 printing::ScopedPrinterHandle printer_; // The printer being watched | 121 printing::ScopedPrinterHandle printer_; // The printer being watched |
122 // Returned by FindFirstPrinterChangeNotifier. | 122 // Returned by FindFirstPrinterChangeNotifier. |
123 printing::ScopedPrinterChangeHandle printer_change_; | 123 printing::ScopedPrinterChangeHandle printer_change_; |
124 Delegate* delegate_; // Delegate to notify | 124 Delegate* delegate_; // Delegate to notify |
125 bool did_signal_; // DoneWaiting was called | 125 bool did_signal_; // DoneWaiting was called |
126 std::string printer_info_; // For crash reporting. | 126 std::string printer_info_; // For crash reporting. |
(...skipping 19 matching lines...) Expand all Loading... |
146 } | 146 } |
147 | 147 |
148 // PrintSystemWatcherWin::Delegate implementation. | 148 // PrintSystemWatcherWin::Delegate implementation. |
149 virtual void OnPrinterAdded() OVERRIDE { | 149 virtual void OnPrinterAdded() OVERRIDE { |
150 delegate_->OnPrinterAdded(); | 150 delegate_->OnPrinterAdded(); |
151 } | 151 } |
152 virtual void OnPrinterDeleted() OVERRIDE {} | 152 virtual void OnPrinterDeleted() OVERRIDE {} |
153 virtual void OnPrinterChanged() OVERRIDE {} | 153 virtual void OnPrinterChanged() OVERRIDE {} |
154 virtual void OnJobChanged() OVERRIDE {} | 154 virtual void OnJobChanged() OVERRIDE {} |
155 | 155 |
156 protected: | 156 protected: |
157 virtual ~PrintServerWatcherWin() {} | 157 virtual ~PrintServerWatcherWin() {} |
158 | 158 |
159 private: | 159 private: |
160 PrintSystem::PrintServerWatcher::Delegate* delegate_; | 160 PrintSystem::PrintServerWatcher::Delegate* delegate_; |
161 PrintSystemWatcherWin watcher_; | 161 PrintSystemWatcherWin watcher_; |
162 | 162 |
163 DISALLOW_COPY_AND_ASSIGN(PrintServerWatcherWin); | 163 DISALLOW_COPY_AND_ASSIGN(PrintServerWatcherWin); |
164 }; | 164 }; |
165 | 165 |
166 class PrinterWatcherWin | 166 class PrinterWatcherWin |
(...skipping 30 matching lines...) Expand all Loading... |
197 virtual void OnPrinterDeleted() OVERRIDE { | 197 virtual void OnPrinterDeleted() OVERRIDE { |
198 delegate_->OnPrinterDeleted(); | 198 delegate_->OnPrinterDeleted(); |
199 } | 199 } |
200 virtual void OnPrinterChanged() OVERRIDE { | 200 virtual void OnPrinterChanged() OVERRIDE { |
201 delegate_->OnPrinterChanged(); | 201 delegate_->OnPrinterChanged(); |
202 } | 202 } |
203 virtual void OnJobChanged() OVERRIDE { | 203 virtual void OnJobChanged() OVERRIDE { |
204 delegate_->OnJobChanged(); | 204 delegate_->OnJobChanged(); |
205 } | 205 } |
206 | 206 |
207 protected: | 207 protected: |
208 virtual ~PrinterWatcherWin() {} | 208 virtual ~PrinterWatcherWin() {} |
209 | 209 |
210 private: | 210 private: |
211 std::string printer_name_; | 211 std::string printer_name_; |
212 PrintSystem::PrinterWatcher::Delegate* delegate_; | 212 PrintSystem::PrinterWatcher::Delegate* delegate_; |
213 PrintSystemWatcherWin watcher_; | 213 PrintSystemWatcherWin watcher_; |
214 | 214 |
215 DISALLOW_COPY_AND_ASSIGN(PrinterWatcherWin); | 215 DISALLOW_COPY_AND_ASSIGN(PrinterWatcherWin); |
216 }; | 216 }; |
217 | 217 |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 crash_keys::ScopedPrinterInfo crash_key( | 745 crash_keys::ScopedPrinterInfo crash_key( |
746 print_backend_->GetPrinterDriverInfo(printer_name)); | 746 print_backend_->GetPrinterDriverInfo(printer_name)); |
747 DCHECK(job_details); | 747 DCHECK(job_details); |
748 printing::ScopedPrinterHandle printer_handle; | 748 printing::ScopedPrinterHandle printer_handle; |
749 std::wstring printer_name_wide = base::UTF8ToWide(printer_name); | 749 std::wstring printer_name_wide = base::UTF8ToWide(printer_name); |
750 printer_handle.OpenPrinter(printer_name_wide.c_str()); | 750 printer_handle.OpenPrinter(printer_name_wide.c_str()); |
751 DCHECK(printer_handle.IsValid()); | 751 DCHECK(printer_handle.IsValid()); |
752 bool ret = false; | 752 bool ret = false; |
753 if (printer_handle.IsValid()) { | 753 if (printer_handle.IsValid()) { |
754 DWORD bytes_needed = 0; | 754 DWORD bytes_needed = 0; |
755 GetJob(printer_handle, job_id, 1, NULL, 0, &bytes_needed); | 755 GetJob(printer_handle.Get(), job_id, 1, NULL, 0, &bytes_needed); |
756 DWORD last_error = GetLastError(); | 756 DWORD last_error = GetLastError(); |
757 if (ERROR_INVALID_PARAMETER != last_error) { | 757 if (ERROR_INVALID_PARAMETER != last_error) { |
758 // ERROR_INVALID_PARAMETER normally means that the job id is not valid. | 758 // ERROR_INVALID_PARAMETER normally means that the job id is not valid. |
759 DCHECK(last_error == ERROR_INSUFFICIENT_BUFFER); | 759 DCHECK(last_error == ERROR_INSUFFICIENT_BUFFER); |
760 scoped_ptr<BYTE[]> job_info_buffer(new BYTE[bytes_needed]); | 760 scoped_ptr<BYTE[]> job_info_buffer(new BYTE[bytes_needed]); |
761 if (GetJob(printer_handle, job_id, 1, job_info_buffer.get(), bytes_needed, | 761 if (GetJob(printer_handle.Get(), job_id, 1, job_info_buffer.get(), |
762 &bytes_needed)) { | 762 bytes_needed, &bytes_needed)) { |
763 JOB_INFO_1 *job_info = | 763 JOB_INFO_1 *job_info = |
764 reinterpret_cast<JOB_INFO_1 *>(job_info_buffer.get()); | 764 reinterpret_cast<JOB_INFO_1 *>(job_info_buffer.get()); |
765 if (job_info->pStatus) { | 765 if (job_info->pStatus) { |
766 base::WideToUTF8(job_info->pStatus, wcslen(job_info->pStatus), | 766 base::WideToUTF8(job_info->pStatus, wcslen(job_info->pStatus), |
767 &job_details->status_message); | 767 &job_details->status_message); |
768 } | 768 } |
769 job_details->platform_status_flags = job_info->Status; | 769 job_details->platform_status_flags = job_info->Status; |
770 if ((job_info->Status & JOB_STATUS_COMPLETE) || | 770 if ((job_info->Status & JOB_STATUS_COMPLETE) || |
771 (job_info->Status & JOB_STATUS_PRINTED)) { | 771 (job_info->Status & JOB_STATUS_PRINTED)) { |
772 job_details->status = PRINT_JOB_STATUS_COMPLETED; | 772 job_details->status = PRINT_JOB_STATUS_COMPLETED; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 } | 819 } |
820 | 820 |
821 } // namespace | 821 } // namespace |
822 | 822 |
823 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( | 823 scoped_refptr<PrintSystem> PrintSystem::CreateInstance( |
824 const base::DictionaryValue* print_system_settings) { | 824 const base::DictionaryValue* print_system_settings) { |
825 return new PrintSystemWin; | 825 return new PrintSystemWin; |
826 } | 826 } |
827 | 827 |
828 } // namespace cloud_print | 828 } // namespace cloud_print |
OLD | NEW |