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/job_status_updater.h" | 5 #include "chrome/service/cloud_print/job_status_updater.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/service/cloud_print/cloud_print_consts.h" | 11 #include "chrome/service/cloud_print/cloud_print_consts.h" |
12 #include "chrome/service/cloud_print/cloud_print_helpers.h" | 12 #include "chrome/service/cloud_print/cloud_print_helpers.h" |
13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
14 | 14 |
15 JobStatusUpdater::JobStatusUpdater(const std::string& printer_name, | 15 JobStatusUpdater::JobStatusUpdater(const std::string& printer_name, |
16 const std::string& job_id, | 16 const std::string& job_id, |
17 cloud_print::PlatformJobId& local_job_id, | 17 cloud_print::PlatformJobId& local_job_id, |
18 const std::string& auth_token, | 18 const std::string& auth_token, |
19 const GURL& cloud_print_server_url, | 19 const GURL& cloud_print_server_url, |
20 Delegate* delegate) | 20 cloud_print::PrintSystem* print_system, |
| 21 Delegate* delegate) |
21 : printer_name_(printer_name), job_id_(job_id), | 22 : printer_name_(printer_name), job_id_(job_id), |
22 local_job_id_(local_job_id), auth_token_(auth_token), | 23 local_job_id_(local_job_id), auth_token_(auth_token), |
23 cloud_print_server_url_(cloud_print_server_url), | 24 cloud_print_server_url_(cloud_print_server_url), |
24 delegate_(delegate), stopped_(false) { | 25 print_system_(print_system), delegate_(delegate), stopped_(false) { |
25 DCHECK(delegate_); | 26 DCHECK(delegate_); |
26 } | 27 } |
27 | 28 |
28 // Start checking the status of the local print job. | 29 // Start checking the status of the local print job. |
29 void JobStatusUpdater::UpdateStatus() { | 30 void JobStatusUpdater::UpdateStatus() { |
30 // It does not matter if we had already sent out an update and are waiting for | 31 // It does not matter if we had already sent out an update and are waiting for |
31 // a response. This is a new update and we will simply cancel the old request | 32 // a response. This is a new update and we will simply cancel the old request |
32 // and send a new one. | 33 // and send a new one. |
33 if (!stopped_) { | 34 if (!stopped_) { |
34 bool need_update = false; | 35 bool need_update = false; |
35 // If the job has already been completed, we just need to update the server | 36 // If the job has already been completed, we just need to update the server |
36 // with that status. The *only* reason we would come back here in that case | 37 // with that status. The *only* reason we would come back here in that case |
37 // is if our last server update attempt failed. | 38 // is if our last server update attempt failed. |
38 if (last_job_details_.status == cloud_print::PRINT_JOB_STATUS_COMPLETED) { | 39 if (last_job_details_.status == cloud_print::PRINT_JOB_STATUS_COMPLETED) { |
39 need_update = true; | 40 need_update = true; |
40 } else { | 41 } else { |
41 cloud_print::PrintJobDetails details; | 42 cloud_print::PrintJobDetails details; |
42 if (cloud_print::GetJobDetails(printer_name_, local_job_id_, &details)) { | 43 if (print_system_->GetJobDetails(printer_name_, local_job_id_, |
| 44 &details)) { |
43 if (details != last_job_details_) { | 45 if (details != last_job_details_) { |
44 last_job_details_ = details; | 46 last_job_details_ = details; |
45 need_update = true; | 47 need_update = true; |
46 } | 48 } |
47 } else { | 49 } else { |
48 // If GetJobDetails failed, the most likely case is that the job no | 50 // If GetJobDetails failed, the most likely case is that the job no |
49 // longer exists in the OS queue. We are going to assume it is done in | 51 // longer exists in the OS queue. We are going to assume it is done in |
50 // this case. | 52 // this case. |
51 last_job_details_.Clear(); | 53 last_job_details_.Clear(); |
52 last_job_details_.status = cloud_print::PRINT_JOB_STATUS_COMPLETED; | 54 last_job_details_.status = cloud_print::PRINT_JOB_STATUS_COMPLETED; |
(...skipping 30 matching lines...) Expand all Loading... |
83 MessageLoop::current()->PostDelayedTask( | 85 MessageLoop::current()->PostDelayedTask( |
84 FROM_HERE, NewRunnableMethod(this, &JobStatusUpdater::UpdateStatus), | 86 FROM_HERE, NewRunnableMethod(this, &JobStatusUpdater::UpdateStatus), |
85 next_update_interval); | 87 next_update_interval); |
86 } else if (last_job_details_.status == | 88 } else if (last_job_details_.status == |
87 cloud_print::PRINT_JOB_STATUS_COMPLETED) { | 89 cloud_print::PRINT_JOB_STATUS_COMPLETED) { |
88 MessageLoop::current()->PostTask( | 90 MessageLoop::current()->PostTask( |
89 FROM_HERE, NewRunnableMethod(this, &JobStatusUpdater::Stop)); | 91 FROM_HERE, NewRunnableMethod(this, &JobStatusUpdater::Stop)); |
90 } | 92 } |
91 } | 93 } |
92 | 94 |
OLD | NEW |