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 "chrome/common/net/http_return.h" | 10 #include "chrome/common/net/http_return.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 cloud_print::PrintSystem* print_system, | 20 cloud_print::PrintSystem* print_system, |
21 Delegate* delegate) | 21 Delegate* delegate) |
22 : printer_name_(printer_name), job_id_(job_id), | 22 : printer_name_(printer_name), job_id_(job_id), |
23 local_job_id_(local_job_id), auth_token_(auth_token), | 23 local_job_id_(local_job_id), auth_token_(auth_token), |
24 cloud_print_server_url_(cloud_print_server_url), | 24 cloud_print_server_url_(cloud_print_server_url), |
25 print_system_(print_system), delegate_(delegate), stopped_(false) { | 25 print_system_(print_system), delegate_(delegate), stopped_(false) { |
26 DCHECK(delegate_); | 26 DCHECK(delegate_); |
27 } | 27 } |
28 | 28 |
| 29 JobStatusUpdater::~JobStatusUpdater() {} |
| 30 |
29 // Start checking the status of the local print job. | 31 // Start checking the status of the local print job. |
30 void JobStatusUpdater::UpdateStatus() { | 32 void JobStatusUpdater::UpdateStatus() { |
31 // It does not matter if we had already sent out an update and are waiting for | 33 // It does not matter if we had already sent out an update and are waiting for |
32 // a response. This is a new update and we will simply cancel the old request | 34 // a response. This is a new update and we will simply cancel the old request |
33 // and send a new one. | 35 // and send a new one. |
34 if (!stopped_) { | 36 if (!stopped_) { |
35 bool need_update = false; | 37 bool need_update = false; |
36 // If the job has already been completed, we just need to update the server | 38 // If the job has already been completed, we just need to update the server |
37 // with that status. The *only* reason we would come back here in that case | 39 // with that status. The *only* reason we would come back here in that case |
38 // is if our last server update attempt failed. | 40 // is if our last server update attempt failed. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 next_update_interval *= 10; | 93 next_update_interval *= 10; |
92 MessageLoop::current()->PostDelayedTask( | 94 MessageLoop::current()->PostDelayedTask( |
93 FROM_HERE, NewRunnableMethod(this, &JobStatusUpdater::UpdateStatus), | 95 FROM_HERE, NewRunnableMethod(this, &JobStatusUpdater::UpdateStatus), |
94 next_update_interval); | 96 next_update_interval); |
95 } else if (last_job_details_.status == | 97 } else if (last_job_details_.status == |
96 cloud_print::PRINT_JOB_STATUS_COMPLETED) { | 98 cloud_print::PRINT_JOB_STATUS_COMPLETED) { |
97 MessageLoop::current()->PostTask( | 99 MessageLoop::current()->PostTask( |
98 FROM_HERE, NewRunnableMethod(this, &JobStatusUpdater::Stop)); | 100 FROM_HERE, NewRunnableMethod(this, &JobStatusUpdater::Stop)); |
99 } | 101 } |
100 } | 102 } |
OLD | NEW |