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/printer_job_handler.h" | 5 #include "chrome/service/cloud_print/printer_job_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/location.h" |
11 #include "base/md5.h" | 12 #include "base/md5.h" |
12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/thread_task_runner_handle.h" |
15 #include "base/values.h" | 17 #include "base/values.h" |
16 #include "chrome/common/cloud_print/cloud_print_constants.h" | 18 #include "chrome/common/cloud_print/cloud_print_constants.h" |
17 #include "chrome/common/cloud_print/cloud_print_helpers.h" | 19 #include "chrome/common/cloud_print/cloud_print_helpers.h" |
18 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
19 #include "chrome/service/cloud_print/cloud_print_service_helpers.h" | 21 #include "chrome/service/cloud_print/cloud_print_service_helpers.h" |
20 #include "chrome/service/cloud_print/job_status_updater.h" | 22 #include "chrome/service/cloud_print/job_status_updater.h" |
21 #include "net/base/mime_util.h" | 23 #include "net/base/mime_util.h" |
22 #include "net/http/http_response_headers.h" | 24 #include "net/http/http_response_headers.h" |
23 #include "net/http/http_status_code.h" | 25 #include "net/http/http_status_code.h" |
24 #include "printing/printing_utils.h" | 26 #include "printing/printing_utils.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 Delegate* delegate) | 67 Delegate* delegate) |
66 : print_system_(print_system), | 68 : print_system_(print_system), |
67 printer_info_(printer_info), | 69 printer_info_(printer_info), |
68 printer_info_cloud_(printer_info_cloud), | 70 printer_info_cloud_(printer_info_cloud), |
69 cloud_print_server_url_(cloud_print_server_url), | 71 cloud_print_server_url_(cloud_print_server_url), |
70 delegate_(delegate), | 72 delegate_(delegate), |
71 local_job_id_(-1), | 73 local_job_id_(-1), |
72 next_json_data_handler_(NULL), | 74 next_json_data_handler_(NULL), |
73 next_data_handler_(NULL), | 75 next_data_handler_(NULL), |
74 print_thread_("Chrome_CloudPrintJobPrintThread"), | 76 print_thread_("Chrome_CloudPrintJobPrintThread"), |
75 job_handler_message_loop_proxy_( | 77 job_handler_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
76 base::MessageLoopProxy::current()), | |
77 shutting_down_(false), | 78 shutting_down_(false), |
78 job_check_pending_(false), | 79 job_check_pending_(false), |
79 printer_update_pending_(true), | 80 printer_update_pending_(true), |
80 task_in_progress_(false), | 81 task_in_progress_(false), |
81 weak_ptr_factory_(this) { | 82 weak_ptr_factory_(this) { |
82 } | 83 } |
83 | 84 |
84 bool PrinterJobHandler::Initialize() { | 85 bool PrinterJobHandler::Initialize() { |
85 if (!print_system_->IsValidPrinter(printer_info_.printer_name)) | 86 if (!print_system_->IsValidPrinter(printer_info_.printer_name)) |
86 return false; | 87 return false; |
(...skipping 12 matching lines...) Expand all Loading... |
99 void PrinterJobHandler::CheckForJobs(const std::string& reason) { | 100 void PrinterJobHandler::CheckForJobs(const std::string& reason) { |
100 VLOG(1) << "CP_CONNECTOR: Checking for jobs" | 101 VLOG(1) << "CP_CONNECTOR: Checking for jobs" |
101 << ", printer id: " << printer_info_cloud_.printer_id | 102 << ", printer id: " << printer_info_cloud_.printer_id |
102 << ", reason: " << reason | 103 << ", reason: " << reason |
103 << ", task in progress: " << task_in_progress_; | 104 << ", task in progress: " << task_in_progress_; |
104 UMA_HISTOGRAM_ENUMERATION("CloudPrint.JobHandlerEvent", | 105 UMA_HISTOGRAM_ENUMERATION("CloudPrint.JobHandlerEvent", |
105 JOB_HANDLER_CHECK_FOR_JOBS, JOB_HANDLER_MAX); | 106 JOB_HANDLER_CHECK_FOR_JOBS, JOB_HANDLER_MAX); |
106 job_fetch_reason_ = reason; | 107 job_fetch_reason_ = reason; |
107 job_check_pending_ = true; | 108 job_check_pending_ = true; |
108 if (!task_in_progress_) { | 109 if (!task_in_progress_) { |
109 base::MessageLoop::current()->PostTask( | 110 base::ThreadTaskRunnerHandle::Get()->PostTask( |
110 FROM_HERE, base::Bind(&PrinterJobHandler::Start, this)); | 111 FROM_HERE, base::Bind(&PrinterJobHandler::Start, this)); |
111 } | 112 } |
112 } | 113 } |
113 | 114 |
114 void PrinterJobHandler::Shutdown() { | 115 void PrinterJobHandler::Shutdown() { |
115 VLOG(1) << "CP_CONNECTOR: Shutting down printer job handler" | 116 VLOG(1) << "CP_CONNECTOR: Shutting down printer job handler" |
116 << ", printer id: " << printer_info_cloud_.printer_id; | 117 << ", printer id: " << printer_info_cloud_.printer_id; |
117 Reset(); | 118 Reset(); |
118 shutting_down_ = true; | 119 shutting_down_ = true; |
119 while (!job_status_updater_list_.empty()) { | 120 while (!job_status_updater_list_.empty()) { |
120 // Calling Stop() will cause the OnJobCompleted to be called which will | 121 // Calling Stop() will cause the OnJobCompleted to be called which will |
121 // remove the updater object from the list. | 122 // remove the updater object from the list. |
122 job_status_updater_list_.front()->Stop(); | 123 job_status_updater_list_.front()->Stop(); |
123 } | 124 } |
124 } | 125 } |
125 | 126 |
126 // CloudPrintURLFetcher::Delegate implementation. | 127 // CloudPrintURLFetcher::Delegate implementation. |
127 CloudPrintURLFetcher::ResponseAction PrinterJobHandler::HandleRawResponse( | 128 CloudPrintURLFetcher::ResponseAction PrinterJobHandler::HandleRawResponse( |
128 const net::URLFetcher* source, | 129 const net::URLFetcher* source, |
129 const GURL& url, | 130 const GURL& url, |
130 const net::URLRequestStatus& status, | 131 const net::URLRequestStatus& status, |
131 int response_code, | 132 int response_code, |
132 const net::ResponseCookies& cookies, | 133 const net::ResponseCookies& cookies, |
133 const std::string& data) { | 134 const std::string& data) { |
134 // 415 (Unsupported media type) error while fetching data from the server | 135 // 415 (Unsupported media type) error while fetching data from the server |
135 // means data conversion error. Stop fetching process and mark job as error. | 136 // means data conversion error. Stop fetching process and mark job as error. |
136 if (next_data_handler_ == (&PrinterJobHandler::HandlePrintDataResponse) && | 137 if (next_data_handler_ == (&PrinterJobHandler::HandlePrintDataResponse) && |
137 response_code == net::HTTP_UNSUPPORTED_MEDIA_TYPE) { | 138 response_code == net::HTTP_UNSUPPORTED_MEDIA_TYPE) { |
138 VLOG(1) << "CP_CONNECTOR: Job failed (unsupported media type)"; | 139 VLOG(1) << "CP_CONNECTOR: Job failed (unsupported media type)"; |
139 base::MessageLoop::current()->PostTask( | 140 base::ThreadTaskRunnerHandle::Get()->PostTask( |
140 FROM_HERE, | 141 FROM_HERE, |
141 base::Bind(&PrinterJobHandler::JobFailed, this, JOB_DOWNLOAD_FAILED)); | 142 base::Bind(&PrinterJobHandler::JobFailed, this, JOB_DOWNLOAD_FAILED)); |
142 return CloudPrintURLFetcher::STOP_PROCESSING; | 143 return CloudPrintURLFetcher::STOP_PROCESSING; |
143 } | 144 } |
144 return CloudPrintURLFetcher::CONTINUE_PROCESSING; | 145 return CloudPrintURLFetcher::CONTINUE_PROCESSING; |
145 } | 146 } |
146 | 147 |
147 CloudPrintURLFetcher::ResponseAction PrinterJobHandler::HandleRawData( | 148 CloudPrintURLFetcher::ResponseAction PrinterJobHandler::HandleRawData( |
148 const net::URLFetcher* source, | 149 const net::URLFetcher* source, |
149 const GURL& url, | 150 const GURL& url, |
(...skipping 10 matching lines...) Expand all Loading... |
160 bool succeeded) { | 161 bool succeeded) { |
161 DCHECK(next_json_data_handler_); | 162 DCHECK(next_json_data_handler_); |
162 return (this->*next_json_data_handler_)(source, url, json_data, succeeded); | 163 return (this->*next_json_data_handler_)(source, url, json_data, succeeded); |
163 } | 164 } |
164 | 165 |
165 // Mark the job fetch as failed and check if other jobs can be printed | 166 // Mark the job fetch as failed and check if other jobs can be printed |
166 void PrinterJobHandler::OnRequestGiveUp() { | 167 void PrinterJobHandler::OnRequestGiveUp() { |
167 if (job_queue_handler_.JobFetchFailed(job_details_.job_id_)) { | 168 if (job_queue_handler_.JobFetchFailed(job_details_.job_id_)) { |
168 VLOG(1) << "CP_CONNECTOR: Job failed to load (scheduling retry)"; | 169 VLOG(1) << "CP_CONNECTOR: Job failed to load (scheduling retry)"; |
169 CheckForJobs(kJobFetchReasonFailure); | 170 CheckForJobs(kJobFetchReasonFailure); |
170 base::MessageLoop::current()->PostTask( | 171 base::ThreadTaskRunnerHandle::Get()->PostTask( |
171 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); | 172 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); |
172 } else { | 173 } else { |
173 VLOG(1) << "CP_CONNECTOR: Job failed (giving up after " << | 174 VLOG(1) << "CP_CONNECTOR: Job failed (giving up after " << |
174 kNumRetriesBeforeAbandonJob << " retries)"; | 175 kNumRetriesBeforeAbandonJob << " retries)"; |
175 base::MessageLoop::current()->PostTask( | 176 base::ThreadTaskRunnerHandle::Get()->PostTask( |
176 FROM_HERE, | 177 FROM_HERE, |
177 base::Bind(&PrinterJobHandler::JobFailed, this, JOB_DOWNLOAD_FAILED)); | 178 base::Bind(&PrinterJobHandler::JobFailed, this, JOB_DOWNLOAD_FAILED)); |
178 } | 179 } |
179 } | 180 } |
180 | 181 |
181 CloudPrintURLFetcher::ResponseAction PrinterJobHandler::OnRequestAuthError() { | 182 CloudPrintURLFetcher::ResponseAction PrinterJobHandler::OnRequestAuthError() { |
182 // We got an Auth error and have no idea how long it will take to refresh | 183 // We got an Auth error and have no idea how long it will take to refresh |
183 // auth information (may take forever). We'll drop current request and | 184 // auth information (may take forever). We'll drop current request and |
184 // propagate this error to the upper level. After auth issues will be | 185 // propagate this error to the upper level. After auth issues will be |
185 // resolved, GCP connector will restart. | 186 // resolved, GCP connector will restart. |
(...skipping 20 matching lines...) Expand all Loading... |
206 if (index->get() == updater) { | 207 if (index->get() == updater) { |
207 job_status_updater_list_.erase(index); | 208 job_status_updater_list_.erase(index); |
208 ret = true; | 209 ret = true; |
209 break; | 210 break; |
210 } | 211 } |
211 } | 212 } |
212 return ret; | 213 return ret; |
213 } | 214 } |
214 | 215 |
215 void PrinterJobHandler::OnAuthError() { | 216 void PrinterJobHandler::OnAuthError() { |
216 base::MessageLoop::current()->PostTask( | 217 base::ThreadTaskRunnerHandle::Get()->PostTask( |
217 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); | 218 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); |
218 if (delegate_) | 219 if (delegate_) |
219 delegate_->OnAuthError(); | 220 delegate_->OnAuthError(); |
220 } | 221 } |
221 | 222 |
222 void PrinterJobHandler::OnPrinterDeleted() { | 223 void PrinterJobHandler::OnPrinterDeleted() { |
223 if (delegate_) | 224 if (delegate_) |
224 delegate_->OnPrinterDeleted(printer_info_cloud_.printer_id); | 225 delegate_->OnPrinterDeleted(printer_info_cloud_.printer_id); |
225 } | 226 } |
226 | 227 |
227 void PrinterJobHandler::OnPrinterChanged() { | 228 void PrinterJobHandler::OnPrinterChanged() { |
228 printer_update_pending_ = true; | 229 printer_update_pending_ = true; |
229 if (!task_in_progress_) { | 230 if (!task_in_progress_) { |
230 base::MessageLoop::current()->PostTask( | 231 base::ThreadTaskRunnerHandle::Get()->PostTask( |
231 FROM_HERE, base::Bind(&PrinterJobHandler::Start, this)); | 232 FROM_HERE, base::Bind(&PrinterJobHandler::Start, this)); |
232 } | 233 } |
233 } | 234 } |
234 | 235 |
235 void PrinterJobHandler::OnJobChanged() { | 236 void PrinterJobHandler::OnJobChanged() { |
236 // Some job on the printer changed. Loop through all our JobStatusUpdaters | 237 // Some job on the printer changed. Loop through all our JobStatusUpdaters |
237 // and have them check for updates. | 238 // and have them check for updates. |
238 for (JobStatusUpdaterList::iterator index = job_status_updater_list_.begin(); | 239 for (JobStatusUpdaterList::iterator index = job_status_updater_list_.begin(); |
239 index != job_status_updater_list_.end(); index++) { | 240 index != job_status_updater_list_.end(); index++) { |
240 base::MessageLoop::current()->PostTask( | 241 base::ThreadTaskRunnerHandle::Get()->PostTask( |
241 FROM_HERE, base::Bind(&JobStatusUpdater::UpdateStatus, index->get())); | 242 FROM_HERE, base::Bind(&JobStatusUpdater::UpdateStatus, index->get())); |
242 } | 243 } |
243 } | 244 } |
244 | 245 |
245 void PrinterJobHandler::OnJobSpoolSucceeded(const PlatformJobId& job_id) { | 246 void PrinterJobHandler::OnJobSpoolSucceeded(const PlatformJobId& job_id) { |
246 DCHECK(base::MessageLoop::current() == print_thread_.message_loop()); | 247 DCHECK(base::MessageLoop::current() == print_thread_.message_loop()); |
247 job_spooler_->AddRef(); | 248 job_spooler_->AddRef(); |
248 print_thread_.message_loop()->ReleaseSoon(FROM_HERE, job_spooler_.get()); | 249 print_thread_.message_loop()->ReleaseSoon(FROM_HERE, job_spooler_.get()); |
249 job_spooler_ = NULL; | 250 job_spooler_ = NULL; |
250 job_handler_message_loop_proxy_->PostTask( | 251 job_handler_task_runner_->PostTask( |
251 FROM_HERE, base::Bind(&PrinterJobHandler::JobSpooled, this, job_id)); | 252 FROM_HERE, base::Bind(&PrinterJobHandler::JobSpooled, this, job_id)); |
252 } | 253 } |
253 | 254 |
254 void PrinterJobHandler::OnJobSpoolFailed() { | 255 void PrinterJobHandler::OnJobSpoolFailed() { |
255 DCHECK(base::MessageLoop::current() == print_thread_.message_loop()); | 256 DCHECK(base::MessageLoop::current() == print_thread_.message_loop()); |
256 job_spooler_->AddRef(); | 257 job_spooler_->AddRef(); |
257 print_thread_.message_loop()->ReleaseSoon(FROM_HERE, job_spooler_.get()); | 258 print_thread_.message_loop()->ReleaseSoon(FROM_HERE, job_spooler_.get()); |
258 job_spooler_ = NULL; | 259 job_spooler_ = NULL; |
259 VLOG(1) << "CP_CONNECTOR: Job failed (spool failed)"; | 260 VLOG(1) << "CP_CONNECTOR: Job failed (spool failed)"; |
260 job_handler_message_loop_proxy_->PostTask( | 261 job_handler_task_runner_->PostTask( |
261 FROM_HERE, base::Bind(&PrinterJobHandler::JobFailed, this, JOB_FAILED)); | 262 FROM_HERE, base::Bind(&PrinterJobHandler::JobFailed, this, JOB_FAILED)); |
262 } | 263 } |
263 | 264 |
264 // static | 265 // static |
265 void PrinterJobHandler::ReportsStats() { | 266 void PrinterJobHandler::ReportsStats() { |
266 base::subtle::Atomic32 started = | 267 base::subtle::Atomic32 started = |
267 base::subtle::NoBarrier_AtomicExchange(&g_total_jobs_started, 0); | 268 base::subtle::NoBarrier_AtomicExchange(&g_total_jobs_started, 0); |
268 base::subtle::Atomic32 done = | 269 base::subtle::Atomic32 done = |
269 base::subtle::NoBarrier_AtomicExchange(&g_total_jobs_done, 0); | 270 base::subtle::NoBarrier_AtomicExchange(&g_total_jobs_done, 0); |
270 UMA_HISTOGRAM_COUNTS_100("CloudPrint.JobsStartedPerInterval", started); | 271 UMA_HISTOGRAM_COUNTS_100("CloudPrint.JobsStartedPerInterval", started); |
(...skipping 10 matching lines...) Expand all Loading... |
281 PrinterJobHandler::HandlePrinterUpdateResponse( | 282 PrinterJobHandler::HandlePrinterUpdateResponse( |
282 const net::URLFetcher* source, | 283 const net::URLFetcher* source, |
283 const GURL& url, | 284 const GURL& url, |
284 base::DictionaryValue* json_data, | 285 base::DictionaryValue* json_data, |
285 bool succeeded) { | 286 bool succeeded) { |
286 VLOG(1) << "CP_CONNECTOR: Handling printer update response" | 287 VLOG(1) << "CP_CONNECTOR: Handling printer update response" |
287 << ", printer id: " << printer_info_cloud_.printer_id; | 288 << ", printer id: " << printer_info_cloud_.printer_id; |
288 // We are done here. Go to the Stop state | 289 // We are done here. Go to the Stop state |
289 VLOG(1) << "CP_CONNECTOR: Stopping printer job handler" | 290 VLOG(1) << "CP_CONNECTOR: Stopping printer job handler" |
290 << ", printer id: " << printer_info_cloud_.printer_id; | 291 << ", printer id: " << printer_info_cloud_.printer_id; |
291 base::MessageLoop::current()->PostTask( | 292 base::ThreadTaskRunnerHandle::Get()->PostTask( |
292 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); | 293 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); |
293 return CloudPrintURLFetcher::STOP_PROCESSING; | 294 return CloudPrintURLFetcher::STOP_PROCESSING; |
294 } | 295 } |
295 | 296 |
296 CloudPrintURLFetcher::ResponseAction | 297 CloudPrintURLFetcher::ResponseAction |
297 PrinterJobHandler::HandleJobMetadataResponse( | 298 PrinterJobHandler::HandleJobMetadataResponse( |
298 const net::URLFetcher* source, | 299 const net::URLFetcher* source, |
299 const GURL& url, | 300 const GURL& url, |
300 base::DictionaryValue* json_data, | 301 base::DictionaryValue* json_data, |
301 bool succeeded) { | 302 bool succeeded) { |
(...skipping 20 matching lines...) Expand all Loading... |
322 job_fetch_reason_), | 323 job_fetch_reason_), |
323 this, kJobDataMaxRetryCount, std::string()); | 324 this, kJobDataMaxRetryCount, std::string()); |
324 } else { | 325 } else { |
325 request_->StartGetRequest( | 326 request_->StartGetRequest( |
326 CloudPrintURLFetcher::REQUEST_TICKET, | 327 CloudPrintURLFetcher::REQUEST_TICKET, |
327 GURL(job_details_.print_ticket_url_), this, kJobDataMaxRetryCount, | 328 GURL(job_details_.print_ticket_url_), this, kJobDataMaxRetryCount, |
328 std::string()); | 329 std::string()); |
329 } | 330 } |
330 } else { | 331 } else { |
331 job_available = false; | 332 job_available = false; |
332 base::MessageLoop::current()->PostDelayedTask( | 333 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
333 FROM_HERE, | 334 FROM_HERE, |
334 base::Bind(&PrinterJobHandler::RunScheduledJobCheck, this), | 335 base::Bind(&PrinterJobHandler::RunScheduledJobCheck, this), |
335 jobs[0].time_remaining_); | 336 jobs[0].time_remaining_); |
336 } | 337 } |
337 } | 338 } |
338 } | 339 } |
339 | 340 |
340 if (!job_available) { | 341 if (!job_available) { |
341 // If no jobs are available, go to the Stop state. | 342 // If no jobs are available, go to the Stop state. |
342 VLOG(1) << "CP_CONNECTOR: Stopping printer job handler" | 343 VLOG(1) << "CP_CONNECTOR: Stopping printer job handler" |
343 << ", printer id: " << printer_info_cloud_.printer_id; | 344 << ", printer id: " << printer_info_cloud_.printer_id; |
344 base::MessageLoop::current()->PostTask( | 345 base::ThreadTaskRunnerHandle::Get()->PostTask( |
345 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); | 346 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); |
346 } | 347 } |
347 return CloudPrintURLFetcher::STOP_PROCESSING; | 348 return CloudPrintURLFetcher::STOP_PROCESSING; |
348 } | 349 } |
349 | 350 |
350 CloudPrintURLFetcher::ResponseAction | 351 CloudPrintURLFetcher::ResponseAction |
351 PrinterJobHandler::HandlePrintTicketResponse(const net::URLFetcher* source, | 352 PrinterJobHandler::HandlePrintTicketResponse(const net::URLFetcher* source, |
352 const GURL& url, | 353 const GURL& url, |
353 const std::string& data) { | 354 const std::string& data) { |
354 VLOG(1) << "CP_CONNECTOR: Handling print ticket response" | 355 VLOG(1) << "CP_CONNECTOR: Handling print ticket response" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 return CloudPrintURLFetcher::STOP_PROCESSING; | 397 return CloudPrintURLFetcher::STOP_PROCESSING; |
397 } | 398 } |
398 } | 399 } |
399 UMA_HISTOGRAM_ENUMERATION("CloudPrint.JobHandlerEvent", | 400 UMA_HISTOGRAM_ENUMERATION("CloudPrint.JobHandlerEvent", |
400 JOB_HANDLER_INVALID_DATA, JOB_HANDLER_MAX); | 401 JOB_HANDLER_INVALID_DATA, JOB_HANDLER_MAX); |
401 | 402 |
402 // If we are here, then there was an error in saving the print data, bail out | 403 // If we are here, then there was an error in saving the print data, bail out |
403 // here. | 404 // here. |
404 VLOG(1) << "CP_CONNECTOR: Error saving print data" | 405 VLOG(1) << "CP_CONNECTOR: Error saving print data" |
405 << ", printer id: " << printer_info_cloud_.printer_id; | 406 << ", printer id: " << printer_info_cloud_.printer_id; |
406 base::MessageLoop::current()->PostTask( | 407 base::ThreadTaskRunnerHandle::Get()->PostTask( |
407 FROM_HERE, base::Bind(&PrinterJobHandler::JobFailed, this, | 408 FROM_HERE, |
408 JOB_DOWNLOAD_FAILED)); | 409 base::Bind(&PrinterJobHandler::JobFailed, this, JOB_DOWNLOAD_FAILED)); |
409 return CloudPrintURLFetcher::STOP_PROCESSING; | 410 return CloudPrintURLFetcher::STOP_PROCESSING; |
410 } | 411 } |
411 | 412 |
412 CloudPrintURLFetcher::ResponseAction | 413 CloudPrintURLFetcher::ResponseAction |
413 PrinterJobHandler::HandleInProgressStatusUpdateResponse( | 414 PrinterJobHandler::HandleInProgressStatusUpdateResponse( |
414 const net::URLFetcher* source, | 415 const net::URLFetcher* source, |
415 const GURL& url, | 416 const GURL& url, |
416 base::DictionaryValue* json_data, | 417 base::DictionaryValue* json_data, |
417 bool succeeded) { | 418 bool succeeded) { |
418 VLOG(1) << "CP_CONNECTOR: Handling success status update response" | 419 VLOG(1) << "CP_CONNECTOR: Handling success status update response" |
419 << ", printer id: " << printer_info_cloud_.printer_id; | 420 << ", printer id: " << printer_info_cloud_.printer_id; |
420 base::MessageLoop::current()->PostTask( | 421 base::ThreadTaskRunnerHandle::Get()->PostTask( |
421 FROM_HERE, base::Bind(&PrinterJobHandler::StartPrinting, this)); | 422 FROM_HERE, base::Bind(&PrinterJobHandler::StartPrinting, this)); |
422 return CloudPrintURLFetcher::STOP_PROCESSING; | 423 return CloudPrintURLFetcher::STOP_PROCESSING; |
423 } | 424 } |
424 | 425 |
425 CloudPrintURLFetcher::ResponseAction | 426 CloudPrintURLFetcher::ResponseAction |
426 PrinterJobHandler::HandleFailureStatusUpdateResponse( | 427 PrinterJobHandler::HandleFailureStatusUpdateResponse( |
427 const net::URLFetcher* source, | 428 const net::URLFetcher* source, |
428 const GURL& url, | 429 const GURL& url, |
429 base::DictionaryValue* json_data, | 430 base::DictionaryValue* json_data, |
430 bool succeeded) { | 431 bool succeeded) { |
431 VLOG(1) << "CP_CONNECTOR: Handling failure status update response" | 432 VLOG(1) << "CP_CONNECTOR: Handling failure status update response" |
432 << ", printer id: " << printer_info_cloud_.printer_id; | 433 << ", printer id: " << printer_info_cloud_.printer_id; |
433 base::MessageLoop::current()->PostTask( | 434 base::ThreadTaskRunnerHandle::Get()->PostTask( |
434 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); | 435 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); |
435 return CloudPrintURLFetcher::STOP_PROCESSING; | 436 return CloudPrintURLFetcher::STOP_PROCESSING; |
436 } | 437 } |
437 | 438 |
438 void PrinterJobHandler::Start() { | 439 void PrinterJobHandler::Start() { |
439 VLOG(1) << "CP_CONNECTOR: Starting printer job handler" | 440 VLOG(1) << "CP_CONNECTOR: Starting printer job handler" |
440 << ", printer id: " << printer_info_cloud_.printer_id | 441 << ", printer id: " << printer_info_cloud_.printer_id |
441 << ", task in progress: " << task_in_progress_; | 442 << ", task in progress: " << task_in_progress_; |
442 UMA_HISTOGRAM_ENUMERATION("CloudPrint.JobHandlerEvent", | 443 UMA_HISTOGRAM_ENUMERATION("CloudPrint.JobHandlerEvent", |
443 JOB_HANDLER_START, JOB_HANDLER_MAX); | 444 JOB_HANDLER_START, JOB_HANDLER_MAX); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 493 |
493 void PrinterJobHandler::Stop() { | 494 void PrinterJobHandler::Stop() { |
494 VLOG(1) << "CP_CONNECTOR: Stopping printer job handler" | 495 VLOG(1) << "CP_CONNECTOR: Stopping printer job handler" |
495 << ", printer id: " << printer_info_cloud_.printer_id; | 496 << ", printer id: " << printer_info_cloud_.printer_id; |
496 task_in_progress_ = false; | 497 task_in_progress_ = false; |
497 VLOG(1) << "CP_CONNECTOR: Changed task in progress" | 498 VLOG(1) << "CP_CONNECTOR: Changed task in progress" |
498 << ", printer id: " << printer_info_cloud_.printer_id | 499 << ", printer id: " << printer_info_cloud_.printer_id |
499 << ", task in progress: " << task_in_progress_; | 500 << ", task in progress: " << task_in_progress_; |
500 Reset(); | 501 Reset(); |
501 if (HavePendingTasks()) { | 502 if (HavePendingTasks()) { |
502 base::MessageLoop::current()->PostTask( | 503 base::ThreadTaskRunnerHandle::Get()->PostTask( |
503 FROM_HERE, base::Bind(&PrinterJobHandler::Start, this)); | 504 FROM_HERE, base::Bind(&PrinterJobHandler::Start, this)); |
504 } | 505 } |
505 } | 506 } |
506 | 507 |
507 void PrinterJobHandler::StartPrinting() { | 508 void PrinterJobHandler::StartPrinting() { |
508 VLOG(1) << "CP_CONNECTOR: Starting printing" | 509 VLOG(1) << "CP_CONNECTOR: Starting printing" |
509 << ", printer id: " << printer_info_cloud_.printer_id; | 510 << ", printer id: " << printer_info_cloud_.printer_id; |
510 UMA_HISTOGRAM_ENUMERATION("CloudPrint.JobHandlerEvent", | 511 UMA_HISTOGRAM_ENUMERATION("CloudPrint.JobHandlerEvent", |
511 JOB_HANDLER_SET_START_PRINTING, JOB_HANDLER_MAX); | 512 JOB_HANDLER_SET_START_PRINTING, JOB_HANDLER_MAX); |
512 // We are done with the request object for now. | 513 // We are done with the request object for now. |
513 request_ = NULL; | 514 request_ = NULL; |
514 if (!shutting_down_) { | 515 if (!shutting_down_) { |
515 #if defined(OS_WIN) | 516 #if defined(OS_WIN) |
516 print_thread_.init_com_with_mta(true); | 517 print_thread_.init_com_with_mta(true); |
517 #endif | 518 #endif |
518 if (!print_thread_.Start()) { | 519 if (!print_thread_.Start()) { |
519 VLOG(1) << "CP_CONNECTOR: Failed to start print thread" | 520 VLOG(1) << "CP_CONNECTOR: Failed to start print thread" |
520 << ", printer id: " << printer_info_cloud_.printer_id; | 521 << ", printer id: " << printer_info_cloud_.printer_id; |
521 JobFailed(JOB_FAILED); | 522 JobFailed(JOB_FAILED); |
522 } else { | 523 } else { |
523 print_thread_.message_loop()->PostTask( | 524 print_thread_.task_runner()->PostTask( |
524 FROM_HERE, base::Bind(&PrinterJobHandler::DoPrint, this, job_details_, | 525 FROM_HERE, base::Bind(&PrinterJobHandler::DoPrint, this, job_details_, |
525 printer_info_.printer_name)); | 526 printer_info_.printer_name)); |
526 } | 527 } |
527 } | 528 } |
528 } | 529 } |
529 | 530 |
530 void PrinterJobHandler::Reset() { | 531 void PrinterJobHandler::Reset() { |
531 job_details_.Clear(); | 532 job_details_.Clear(); |
532 request_ = NULL; | 533 request_ = NULL; |
533 print_thread_.Stop(); | 534 print_thread_.Stop(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 local_job_id_ = local_job_id; | 613 local_job_id_ = local_job_id; |
613 print_thread_.Stop(); | 614 print_thread_.Stop(); |
614 | 615 |
615 // The print job has been spooled locally. We now need to create an object | 616 // The print job has been spooled locally. We now need to create an object |
616 // that monitors the status of the job and updates the server. | 617 // that monitors the status of the job and updates the server. |
617 scoped_refptr<JobStatusUpdater> job_status_updater( | 618 scoped_refptr<JobStatusUpdater> job_status_updater( |
618 new JobStatusUpdater(printer_info_.printer_name, job_details_.job_id_, | 619 new JobStatusUpdater(printer_info_.printer_name, job_details_.job_id_, |
619 local_job_id_, cloud_print_server_url_, | 620 local_job_id_, cloud_print_server_url_, |
620 print_system_.get(), this)); | 621 print_system_.get(), this)); |
621 job_status_updater_list_.push_back(job_status_updater); | 622 job_status_updater_list_.push_back(job_status_updater); |
622 base::MessageLoop::current()->PostTask( | 623 base::ThreadTaskRunnerHandle::Get()->PostTask( |
623 FROM_HERE, | 624 FROM_HERE, |
624 base::Bind(&JobStatusUpdater::UpdateStatus, job_status_updater.get())); | 625 base::Bind(&JobStatusUpdater::UpdateStatus, job_status_updater.get())); |
625 | 626 |
626 CheckForJobs(kJobFetchReasonQueryMore); | 627 CheckForJobs(kJobFetchReasonQueryMore); |
627 | 628 |
628 VLOG(1) << "CP_CONNECTOR: Stopping printer job handler" | 629 VLOG(1) << "CP_CONNECTOR: Stopping printer job handler" |
629 << ", printer id: " << printer_info_cloud_.printer_id; | 630 << ", printer id: " << printer_info_cloud_.printer_id; |
630 base::MessageLoop::current()->PostTask( | 631 base::ThreadTaskRunnerHandle::Get()->PostTask( |
631 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); | 632 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); |
632 } | 633 } |
633 | 634 |
634 bool PrinterJobHandler::UpdatePrinterInfo() { | 635 bool PrinterJobHandler::UpdatePrinterInfo() { |
635 if (!printer_watcher_.get()) { | 636 if (!printer_watcher_.get()) { |
636 LOG(ERROR) << "CP_CONNECTOR: Printer watcher is missing." | 637 LOG(ERROR) << "CP_CONNECTOR: Printer watcher is missing." |
637 << " Check printer server url for printer id: " | 638 << " Check printer server url for printer id: " |
638 << printer_info_cloud_.printer_id; | 639 << printer_info_cloud_.printer_id; |
639 return false; | 640 return false; |
640 } | 641 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 cloud_print_server_url_, printer_info_cloud_.printer_id), | 768 cloud_print_server_url_, printer_info_cloud_.printer_id), |
768 this, | 769 this, |
769 kCloudPrintAPIMaxRetryCount, | 770 kCloudPrintAPIMaxRetryCount, |
770 mime_type, | 771 mime_type, |
771 post_data, | 772 post_data, |
772 std::string()); | 773 std::string()); |
773 } else { | 774 } else { |
774 // We are done here. Go to the Stop state | 775 // We are done here. Go to the Stop state |
775 VLOG(1) << "CP_CONNECTOR: Stopping printer job handler" | 776 VLOG(1) << "CP_CONNECTOR: Stopping printer job handler" |
776 << ", printer name: " << printer_name; | 777 << ", printer name: " << printer_name; |
777 base::MessageLoop::current()->PostTask( | 778 base::ThreadTaskRunnerHandle::Get()->PostTask( |
778 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); | 779 FROM_HERE, base::Bind(&PrinterJobHandler::Stop, this)); |
779 } | 780 } |
780 } | 781 } |
781 | 782 |
782 // The following methods are called on |print_thread_|. It is not safe to | 783 // The following methods are called on |print_thread_|. It is not safe to |
783 // access any members other than |job_handler_message_loop_proxy_|, | 784 // access any members other than |job_handler_task_runner_|, |
784 // |job_spooler_| and |print_system_|. | 785 // |job_spooler_| and |print_system_|. |
785 void PrinterJobHandler::DoPrint(const JobDetails& job_details, | 786 void PrinterJobHandler::DoPrint(const JobDetails& job_details, |
786 const std::string& printer_name) { | 787 const std::string& printer_name) { |
787 job_spooler_ = print_system_->CreateJobSpooler(); | 788 job_spooler_ = print_system_->CreateJobSpooler(); |
788 UMA_HISTOGRAM_LONG_TIMES("CloudPrint.PrepareTime", | 789 UMA_HISTOGRAM_LONG_TIMES("CloudPrint.PrepareTime", |
789 base::Time::Now() - job_start_time_); | 790 base::Time::Now() - job_start_time_); |
790 DCHECK(job_spooler_.get()); | 791 DCHECK(job_spooler_.get()); |
791 if (!job_spooler_.get()) | 792 if (!job_spooler_.get()) |
792 return; | 793 return; |
793 base::string16 document_name = printing::SimplifyDocumentTitle( | 794 base::string16 document_name = printing::SimplifyDocumentTitle( |
(...skipping 11 matching lines...) Expand all Loading... |
805 job_details.print_data_mime_type_, | 806 job_details.print_data_mime_type_, |
806 printer_name, | 807 printer_name, |
807 base::UTF16ToUTF8(document_name), | 808 base::UTF16ToUTF8(document_name), |
808 job_details.tags_, | 809 job_details.tags_, |
809 this)) { | 810 this)) { |
810 OnJobSpoolFailed(); | 811 OnJobSpoolFailed(); |
811 } | 812 } |
812 } | 813 } |
813 | 814 |
814 } // namespace cloud_print | 815 } // namespace cloud_print |
OLD | NEW |