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/job_status_updater.h" | 5 #include "chrome/service/cloud_print/job_status_updater.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/metrics/histogram.h" |
9 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "chrome/common/cloud_print/cloud_print_constants.h" | 13 #include "chrome/common/cloud_print/cloud_print_constants.h" |
13 #include "chrome/service/cloud_print/cloud_print_helpers.h" | 14 #include "chrome/service/cloud_print/cloud_print_helpers.h" |
14 #include "url/gurl.h" | 15 #include "url/gurl.h" |
15 | 16 |
16 namespace cloud_print { | 17 namespace cloud_print { |
17 | 18 |
18 JobStatusUpdater::JobStatusUpdater(const std::string& printer_name, | 19 JobStatusUpdater::JobStatusUpdater(const std::string& printer_name, |
(...skipping 21 matching lines...) Expand all Loading... |
40 if (!stopped_) { | 41 if (!stopped_) { |
41 bool need_update = false; | 42 bool need_update = false; |
42 // If the job has already been completed, we just need to update the server | 43 // If the job has already been completed, we just need to update the server |
43 // with that status. The *only* reason we would come back here in that case | 44 // with that status. The *only* reason we would come back here in that case |
44 // is if our last server update attempt failed. | 45 // is if our last server update attempt failed. |
45 if (last_job_details_.status == PRINT_JOB_STATUS_COMPLETED) { | 46 if (last_job_details_.status == PRINT_JOB_STATUS_COMPLETED) { |
46 need_update = true; | 47 need_update = true; |
47 } else { | 48 } else { |
48 PrintJobDetails details; | 49 PrintJobDetails details; |
49 if (print_system_->GetJobDetails(printer_name_, local_job_id_, | 50 if (print_system_->GetJobDetails(printer_name_, local_job_id_, |
50 &details)) { | 51 &details)) { |
51 if (details != last_job_details_) { | 52 if (details != last_job_details_) { |
52 last_job_details_ = details; | 53 last_job_details_ = details; |
53 need_update = true; | 54 need_update = true; |
54 } | 55 } |
55 } else { | 56 } else { |
56 // If GetJobDetails failed, the most likely case is that the job no | 57 // If GetJobDetails failed, the most likely case is that the job no |
57 // longer exists in the OS queue. We are going to assume it is done in | 58 // longer exists in the OS queue. We are going to assume it is done in |
58 // this case. | 59 // this case. |
59 last_job_details_.Clear(); | 60 last_job_details_.Clear(); |
60 last_job_details_.status = PRINT_JOB_STATUS_COMPLETED; | 61 last_job_details_.status = PRINT_JOB_STATUS_COMPLETED; |
61 need_update = true; | 62 need_update = true; |
62 } | 63 } |
| 64 UMA_HISTOGRAM_ENUMERATION("CloudPrint.NativeJobStatus", |
| 65 last_job_details_.status, PRINT_JOB_STATUS_MAX); |
63 } | 66 } |
64 if (need_update) { | 67 if (need_update) { |
65 request_ = CloudPrintURLFetcher::Create(); | 68 request_ = CloudPrintURLFetcher::Create(); |
66 request_->StartGetRequest( | 69 request_->StartGetRequest( |
67 CloudPrintURLFetcher::REQUEST_UPDATE_JOB, | 70 CloudPrintURLFetcher::REQUEST_UPDATE_JOB, |
68 GetUrlForJobStatusUpdate( | 71 GetUrlForJobStatusUpdate( |
69 cloud_print_server_url_, job_id_, last_job_details_), | 72 cloud_print_server_url_, job_id_, last_job_details_), |
70 this, | 73 this, |
71 kCloudPrintAPIMaxRetryCount, | 74 kCloudPrintAPIMaxRetryCount, |
72 std::string()); | 75 std::string()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 return CloudPrintURLFetcher::STOP_PROCESSING; | 107 return CloudPrintURLFetcher::STOP_PROCESSING; |
105 } | 108 } |
106 | 109 |
107 std::string JobStatusUpdater::GetAuthHeader() { | 110 std::string JobStatusUpdater::GetAuthHeader() { |
108 return GetCloudPrintAuthHeaderFromStore(); | 111 return GetCloudPrintAuthHeaderFromStore(); |
109 } | 112 } |
110 | 113 |
111 JobStatusUpdater::~JobStatusUpdater() {} | 114 JobStatusUpdater::~JobStatusUpdater() {} |
112 | 115 |
113 } // namespace cloud_print | 116 } // namespace cloud_print |
OLD | NEW |