| 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_JOB_STATUS_UPDATER_H_ | 5 #ifndef CHROME_SERVICE_CLOUD_PRINT_JOB_STATUS_UPDATER_H_ |
| 6 #define CHROME_SERVICE_CLOUD_PRINT_JOB_STATUS_UPDATER_H_ | 6 #define CHROME_SERVICE_CLOUD_PRINT_JOB_STATUS_UPDATER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "chrome/service/cloud_print/cloud_print_url_fetcher.h" | 13 #include "chrome/service/cloud_print/cloud_print_url_fetcher.h" |
| 14 #include "chrome/service/cloud_print/print_system.h" | 14 #include "chrome/service/cloud_print/print_system.h" |
| 15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 16 #include "net/url_request/url_request_status.h" | 16 #include "net/url_request/url_request_status.h" |
| 17 | 17 |
| 18 namespace cloud_print { |
| 19 |
| 18 // Periodically monitors the status of a local print job and updates the | 20 // Periodically monitors the status of a local print job and updates the |
| 19 // cloud print server accordingly. When the job has been completed this | 21 // cloud print server accordingly. When the job has been completed this |
| 20 // object releases the reference to itself which should cause it to | 22 // object releases the reference to itself which should cause it to |
| 21 // self-destruct. | 23 // self-destruct. |
| 22 class JobStatusUpdater : public base::RefCountedThreadSafe<JobStatusUpdater>, | 24 class JobStatusUpdater : public base::RefCountedThreadSafe<JobStatusUpdater>, |
| 23 public CloudPrintURLFetcherDelegate { | 25 public CloudPrintURLFetcherDelegate { |
| 24 public: | 26 public: |
| 25 class Delegate { | 27 class Delegate { |
| 26 public: | 28 public: |
| 27 virtual bool OnJobCompleted(JobStatusUpdater* updater) = 0; | 29 virtual bool OnJobCompleted(JobStatusUpdater* updater) = 0; |
| 28 virtual void OnAuthError() = 0; | 30 virtual void OnAuthError() = 0; |
| 29 | 31 |
| 30 protected: | 32 protected: |
| 31 virtual ~Delegate() {} | 33 virtual ~Delegate() {} |
| 32 }; | 34 }; |
| 33 | 35 |
| 34 JobStatusUpdater(const std::string& printer_name, | 36 JobStatusUpdater(const std::string& printer_name, |
| 35 const std::string& job_id, | 37 const std::string& job_id, |
| 36 cloud_print::PlatformJobId& local_job_id, | 38 PlatformJobId& local_job_id, |
| 37 const GURL& cloud_print_server_url, | 39 const GURL& cloud_print_server_url, |
| 38 cloud_print::PrintSystem* print_system, | 40 PrintSystem* print_system, |
| 39 Delegate* delegate); | 41 Delegate* delegate); |
| 40 | 42 |
| 41 // Checks the status of the local print job and sends an update. | 43 // Checks the status of the local print job and sends an update. |
| 42 void UpdateStatus(); | 44 void UpdateStatus(); |
| 43 void Stop(); | 45 void Stop(); |
| 44 | 46 |
| 45 // CloudPrintURLFetcher::Delegate implementation. | 47 // CloudPrintURLFetcher::Delegate implementation. |
| 46 virtual CloudPrintURLFetcher::ResponseAction HandleJSONData( | 48 virtual CloudPrintURLFetcher::ResponseAction HandleJSONData( |
| 47 const net::URLFetcher* source, | 49 const net::URLFetcher* source, |
| 48 const GURL& url, | 50 const GURL& url, |
| 49 base::DictionaryValue* json_data, | 51 base::DictionaryValue* json_data, |
| 50 bool succeeded) OVERRIDE; | 52 bool succeeded) OVERRIDE; |
| 51 virtual CloudPrintURLFetcher::ResponseAction OnRequestAuthError() OVERRIDE; | 53 virtual CloudPrintURLFetcher::ResponseAction OnRequestAuthError() OVERRIDE; |
| 52 virtual std::string GetAuthHeader() OVERRIDE; | 54 virtual std::string GetAuthHeader() OVERRIDE; |
| 53 | 55 |
| 54 private: | 56 private: |
| 55 friend class base::RefCountedThreadSafe<JobStatusUpdater>; | 57 friend class base::RefCountedThreadSafe<JobStatusUpdater>; |
| 56 virtual ~JobStatusUpdater(); | 58 virtual ~JobStatusUpdater(); |
| 57 | 59 |
| 58 std::string printer_name_; | 60 std::string printer_name_; |
| 59 std::string job_id_; | 61 std::string job_id_; |
| 60 cloud_print::PlatformJobId local_job_id_; | 62 PlatformJobId local_job_id_; |
| 61 cloud_print::PrintJobDetails last_job_details_; | 63 PrintJobDetails last_job_details_; |
| 62 scoped_refptr<CloudPrintURLFetcher> request_; | 64 scoped_refptr<CloudPrintURLFetcher> request_; |
| 63 GURL cloud_print_server_url_; | 65 GURL cloud_print_server_url_; |
| 64 scoped_refptr<cloud_print::PrintSystem> print_system_; | 66 scoped_refptr<PrintSystem> print_system_; |
| 65 Delegate* delegate_; | 67 Delegate* delegate_; |
| 66 // A flag that is set to true in Stop() and will ensure the next scheduled | 68 // A flag that is set to true in Stop() and will ensure the next scheduled |
| 67 // task will do nothing. | 69 // task will do nothing. |
| 68 bool stopped_; | 70 bool stopped_; |
| 69 DISALLOW_COPY_AND_ASSIGN(JobStatusUpdater); | 71 DISALLOW_COPY_AND_ASSIGN(JobStatusUpdater); |
| 70 }; | 72 }; |
| 71 | 73 |
| 72 // This typedef is to workaround the issue with certain versions of | 74 // This typedef is to workaround the issue with certain versions of |
| 73 // Visual Studio where it gets confused between multiple Delegate | 75 // Visual Studio where it gets confused between multiple Delegate |
| 74 // classes and gives a C2500 error. (I saw this error on the try bots - | 76 // classes and gives a C2500 error. (I saw this error on the try bots - |
| 75 // the workaround was not needed for my machine). | 77 // the workaround was not needed for my machine). |
| 76 typedef JobStatusUpdater::Delegate JobStatusUpdaterDelegate; | 78 typedef JobStatusUpdater::Delegate JobStatusUpdaterDelegate; |
| 77 | 79 |
| 80 } // namespace cloud_print |
| 81 |
| 78 #endif // CHROME_SERVICE_CLOUD_PRINT_JOB_STATUS_UPDATER_H_ | 82 #endif // CHROME_SERVICE_CLOUD_PRINT_JOB_STATUS_UPDATER_H_ |
| OLD | NEW |