| 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 #ifndef CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_HANDLER_H_ | 5 #ifndef CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_HANDLER_H_ |
| 6 #define CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_HANDLER_H_ | 6 #define CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_HANDLER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 std::string printer_id; | 86 std::string printer_id; |
| 87 std::string caps_hash; | 87 std::string caps_hash; |
| 88 std::string tags_hash; | 88 std::string tags_hash; |
| 89 int current_xmpp_timeout; | 89 int current_xmpp_timeout; |
| 90 int pending_xmpp_timeout; | 90 int pending_xmpp_timeout; |
| 91 | 91 |
| 92 PrinterInfoFromCloud(); | 92 PrinterInfoFromCloud(); |
| 93 PrinterInfoFromCloud(const PrinterInfoFromCloud& other); | 93 PrinterInfoFromCloud(const PrinterInfoFromCloud& other); |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 // Begin public interface | 96 static void ReportsStats(); |
| 97 |
| 97 PrinterJobHandler(const printing::PrinterBasicInfo& printer_info, | 98 PrinterJobHandler(const printing::PrinterBasicInfo& printer_info, |
| 98 const PrinterInfoFromCloud& printer_info_from_server, | 99 const PrinterInfoFromCloud& printer_info_from_server, |
| 99 const GURL& cloud_print_server_url, | 100 const GURL& cloud_print_server_url, |
| 100 PrintSystem* print_system, | 101 PrintSystem* print_system, |
| 101 Delegate* delegate); | 102 Delegate* delegate); |
| 102 | 103 |
| 103 bool Initialize(); | 104 bool Initialize(); |
| 104 | 105 |
| 105 std::string GetPrinterName() const; | 106 std::string GetPrinterName() const; |
| 106 | 107 |
| 107 // Requests a job check. |reason| is the reason for fetching the job. Used | 108 // Requests a job check. |reason| is the reason for fetching the job. Used |
| 108 // for logging and diagnostc purposes. | 109 // for logging and diagnostc purposes. |
| 109 void CheckForJobs(const std::string& reason); | 110 void CheckForJobs(const std::string& reason); |
| 110 | 111 |
| 111 // Shutdown everything (the process is exiting). | 112 // Shutdown everything (the process is exiting). |
| 112 void Shutdown(); | 113 void Shutdown(); |
| 113 | 114 |
| 114 base::TimeTicks last_job_fetch_time() const { return last_job_fetch_time_; } | 115 base::TimeTicks last_job_fetch_time() const { return last_job_fetch_time_; } |
| 115 // End public interface | |
| 116 | |
| 117 // Begin Delegate implementations | |
| 118 | 116 |
| 119 // CloudPrintURLFetcher::Delegate implementation. | 117 // CloudPrintURLFetcher::Delegate implementation. |
| 120 CloudPrintURLFetcher::ResponseAction HandleRawResponse( | 118 CloudPrintURLFetcher::ResponseAction HandleRawResponse( |
| 121 const net::URLFetcher* source, | 119 const net::URLFetcher* source, |
| 122 const GURL& url, | 120 const GURL& url, |
| 123 const net::URLRequestStatus& status, | 121 const net::URLRequestStatus& status, |
| 124 int response_code, | 122 int response_code, |
| 125 const net::ResponseCookies& cookies, | 123 const net::ResponseCookies& cookies, |
| 126 const std::string& data) override; | 124 const std::string& data) override; |
| 127 CloudPrintURLFetcher::ResponseAction HandleRawData( | 125 CloudPrintURLFetcher::ResponseAction HandleRawData( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 140 // JobStatusUpdater::Delegate implementation | 138 // JobStatusUpdater::Delegate implementation |
| 141 bool OnJobCompleted(JobStatusUpdater* updater) override; | 139 bool OnJobCompleted(JobStatusUpdater* updater) override; |
| 142 void OnAuthError() override; | 140 void OnAuthError() override; |
| 143 | 141 |
| 144 // PrinterWatcherDelegate implementation | 142 // PrinterWatcherDelegate implementation |
| 145 void OnPrinterDeleted() override; | 143 void OnPrinterDeleted() override; |
| 146 void OnPrinterChanged() override; | 144 void OnPrinterChanged() override; |
| 147 void OnJobChanged() override; | 145 void OnJobChanged() override; |
| 148 | 146 |
| 149 // JobSpoolerDelegate implementation. | 147 // JobSpoolerDelegate implementation. |
| 150 // Called on print_thread_. | 148 // Called on |print_thread_|. |
| 151 void OnJobSpoolSucceeded(const PlatformJobId& job_id) override; | 149 void OnJobSpoolSucceeded(const PlatformJobId& job_id) override; |
| 152 void OnJobSpoolFailed() override; | 150 void OnJobSpoolFailed() override; |
| 153 | 151 |
| 154 // End Delegate implementations | |
| 155 | |
| 156 static void ReportsStats(); | |
| 157 | |
| 158 private: | 152 private: |
| 159 friend class base::RefCountedThreadSafe<PrinterJobHandler>; | 153 friend class base::RefCountedThreadSafe<PrinterJobHandler>; |
| 160 | 154 |
| 161 enum PrintJobError { | 155 enum PrintJobError { |
| 162 JOB_SUCCESS, | 156 JOB_SUCCESS, |
| 163 JOB_DOWNLOAD_FAILED, | 157 JOB_DOWNLOAD_FAILED, |
| 164 JOB_VALIDATE_TICKET_FAILED, | 158 JOB_VALIDATE_TICKET_FAILED, |
| 165 JOB_FAILED, | 159 JOB_FAILED, |
| 166 JOB_MAX, | 160 JOB_MAX, |
| 167 }; | 161 }; |
| 168 | 162 |
| 169 // Prototype for a JSON data handler. | 163 // Prototype for a JSON data handler. |
| 170 typedef CloudPrintURLFetcher::ResponseAction | 164 typedef CloudPrintURLFetcher::ResponseAction |
| 171 (PrinterJobHandler::*JSONDataHandler)(const net::URLFetcher* source, | 165 (PrinterJobHandler::*JSONDataHandler)(const net::URLFetcher* source, |
| 172 const GURL& url, | 166 const GURL& url, |
| 173 base::DictionaryValue* json_data, | 167 base::DictionaryValue* json_data, |
| 174 bool succeeded); | 168 bool succeeded); |
| 175 // Prototype for a data handler. | 169 // Prototype for a data handler. |
| 176 typedef CloudPrintURLFetcher::ResponseAction | 170 typedef CloudPrintURLFetcher::ResponseAction ( |
| 177 (PrinterJobHandler::*DataHandler)(const net::URLFetcher* source, | 171 PrinterJobHandler::*DataHandler)(const net::URLFetcher* source, |
| 178 const GURL& url, | 172 const GURL& url, |
| 179 const std::string& data); | 173 const std::string& data); |
| 180 | 174 |
| 181 ~PrinterJobHandler() override; | 175 ~PrinterJobHandler() override; |
| 182 | 176 |
| 183 // Begin request handlers for each state in the state machine | 177 // Begin request handlers for each state in the state machine |
| 184 CloudPrintURLFetcher::ResponseAction HandlePrinterUpdateResponse( | 178 CloudPrintURLFetcher::ResponseAction HandlePrinterUpdateResponse( |
| 185 const net::URLFetcher* source, | 179 const net::URLFetcher* source, |
| 186 const GURL& url, | 180 const GURL& url, |
| 187 base::DictionaryValue* json_data, | 181 base::DictionaryValue* json_data, |
| 188 bool succeeded); | 182 bool succeeded); |
| 189 | 183 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 233 |
| 240 void JobFailed(PrintJobError error); | 234 void JobFailed(PrintJobError error); |
| 241 void JobSpooled(PlatformJobId local_job_id); | 235 void JobSpooled(PlatformJobId local_job_id); |
| 242 // Returns false if printer info is up to date and no updating is needed. | 236 // Returns false if printer info is up to date and no updating is needed. |
| 243 bool UpdatePrinterInfo(); | 237 bool UpdatePrinterInfo(); |
| 244 bool HavePendingTasks(); | 238 bool HavePendingTasks(); |
| 245 void ValidatePrintTicketFailed(); | 239 void ValidatePrintTicketFailed(); |
| 246 | 240 |
| 247 // Callback that asynchronously receives printer caps and defaults. | 241 // Callback that asynchronously receives printer caps and defaults. |
| 248 void OnReceivePrinterCaps( | 242 void OnReceivePrinterCaps( |
| 249 bool succeeded, | 243 bool succeeded, |
| 250 const std::string& printer_name, | 244 const std::string& printer_name, |
| 251 const printing::PrinterCapsAndDefaults& caps_and_defaults); | 245 const printing::PrinterCapsAndDefaults& caps_and_defaults); |
| 252 | 246 |
| 253 // Called on print_thread_. | 247 // Called on |print_thread_|. It is not safe to access any members other than |
| 248 // |job_handler_task_runner_|, |job_spooler_| and |print_system_|. |
| 254 void DoPrint(const JobDetails& job_details, | 249 void DoPrint(const JobDetails& job_details, |
| 255 const std::string& printer_name); | 250 const std::string& printer_name); |
| 256 | 251 |
| 252 bool CurrentlyOnPrintThread() const; |
| 253 |
| 257 scoped_refptr<CloudPrintURLFetcher> request_; | 254 scoped_refptr<CloudPrintURLFetcher> request_; |
| 258 scoped_refptr<PrintSystem> print_system_; | 255 scoped_refptr<PrintSystem> print_system_; |
| 259 printing::PrinterBasicInfo printer_info_; | 256 printing::PrinterBasicInfo printer_info_; |
| 260 PrinterInfoFromCloud printer_info_cloud_; | 257 PrinterInfoFromCloud printer_info_cloud_; |
| 261 GURL cloud_print_server_url_; | 258 GURL cloud_print_server_url_; |
| 262 std::string print_data_url_; | 259 std::string print_data_url_; |
| 263 JobDetails job_details_; | 260 JobDetails job_details_; |
| 264 Delegate* delegate_; | 261 Delegate* const delegate_; |
| 262 |
| 265 // Once the job has been spooled to the local spooler, this specifies the | 263 // Once the job has been spooled to the local spooler, this specifies the |
| 266 // job id of the job on the local spooler. | 264 // job id of the job on the local spooler. |
| 267 PlatformJobId local_job_id_; | 265 PlatformJobId local_job_id_; |
| 268 | 266 |
| 269 // The next response handler can either be a JSONDataHandler or a | 267 // The next response handler can either be a JSONDataHandler or a |
| 270 // DataHandler (depending on the current request being made). | 268 // DataHandler (depending on the current request being made). |
| 271 JSONDataHandler next_json_data_handler_; | 269 JSONDataHandler next_json_data_handler_; |
| 272 DataHandler next_data_handler_; | 270 DataHandler next_data_handler_; |
| 273 // The thread on which the actual print operation happens | 271 // The thread on which the actual print operation happens |
| 274 base::Thread print_thread_; | 272 base::Thread print_thread_; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 310 |
| 313 // This typedef is to workaround the issue with certain versions of | 311 // This typedef is to workaround the issue with certain versions of |
| 314 // Visual Studio where it gets confused between multiple Delegate | 312 // Visual Studio where it gets confused between multiple Delegate |
| 315 // classes and gives a C2500 error. (I saw this error on the try bots - | 313 // classes and gives a C2500 error. (I saw this error on the try bots - |
| 316 // the workaround was not needed for my machine). | 314 // the workaround was not needed for my machine). |
| 317 typedef PrinterJobHandler::Delegate PrinterJobHandlerDelegate; | 315 typedef PrinterJobHandler::Delegate PrinterJobHandlerDelegate; |
| 318 | 316 |
| 319 } // namespace cloud_print | 317 } // namespace cloud_print |
| 320 | 318 |
| 321 #endif // CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_HANDLER_H_ | 319 #endif // CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_HANDLER_H_ |
| OLD | NEW |