| 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/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "chrome/service/cloud_print/cloud_print_url_fetcher.h" | 14 #include "chrome/service/cloud_print/cloud_print_url_fetcher.h" |
| 15 #include "chrome/service/cloud_print/print_system.h" | 15 #include "chrome/service/cloud_print/print_system.h" |
| 16 #include "net/traffic_annotation/network_traffic_annotation.h" |
| 16 #include "net/url_request/url_request_status.h" | 17 #include "net/url_request/url_request_status.h" |
| 17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 18 | 19 |
| 19 namespace cloud_print { | 20 namespace cloud_print { |
| 20 | 21 |
| 21 // Periodically monitors the status of a local print job and updates the | 22 // Periodically monitors the status of a local print job and updates the |
| 22 // cloud print server accordingly. When the job has been completed this | 23 // cloud print server accordingly. When the job has been completed this |
| 23 // object releases the reference to itself which should cause it to | 24 // object releases the reference to itself which should cause it to |
| 24 // self-destruct. | 25 // self-destruct. |
| 25 class JobStatusUpdater : public base::RefCountedThreadSafe<JobStatusUpdater>, | 26 class JobStatusUpdater : public base::RefCountedThreadSafe<JobStatusUpdater>, |
| 26 public CloudPrintURLFetcher::Delegate { | 27 public CloudPrintURLFetcher::Delegate { |
| 27 public: | 28 public: |
| 28 class Delegate { | 29 class Delegate { |
| 29 public: | 30 public: |
| 30 virtual bool OnJobCompleted(JobStatusUpdater* updater) = 0; | 31 virtual bool OnJobCompleted(JobStatusUpdater* updater) = 0; |
| 31 virtual void OnAuthError() = 0; | 32 virtual void OnAuthError() = 0; |
| 32 | 33 |
| 33 protected: | 34 protected: |
| 34 virtual ~Delegate() {} | 35 virtual ~Delegate() {} |
| 35 }; | 36 }; |
| 36 | 37 |
| 37 JobStatusUpdater(const std::string& printer_name, | 38 JobStatusUpdater(const std::string& printer_name, |
| 38 const std::string& job_id, | 39 const std::string& job_id, |
| 39 PlatformJobId local_job_id, | 40 PlatformJobId local_job_id, |
| 40 const GURL& cloud_print_server_url, | 41 const GURL& cloud_print_server_url, |
| 41 PrintSystem* print_system, | 42 PrintSystem* print_system, |
| 42 Delegate* delegate); | 43 Delegate* delegate, |
| 44 const net::PartialNetworkTrafficAnnotationTag& |
| 45 partial_traffic_annotation); |
| 43 | 46 |
| 44 // Checks the status of the local print job and sends an update. | 47 // Checks the status of the local print job and sends an update. |
| 45 void UpdateStatus(); | 48 void UpdateStatus(); |
| 46 void Stop(); | 49 void Stop(); |
| 47 | 50 |
| 48 // CloudPrintURLFetcher::Delegate implementation. | 51 // CloudPrintURLFetcher::Delegate implementation. |
| 49 CloudPrintURLFetcher::ResponseAction HandleJSONData( | 52 CloudPrintURLFetcher::ResponseAction HandleJSONData( |
| 50 const net::URLFetcher* source, | 53 const net::URLFetcher* source, |
| 51 const GURL& url, | 54 const GURL& url, |
| 52 const base::DictionaryValue* json_data, | 55 const base::DictionaryValue* json_data, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 67 std::string job_id_; | 70 std::string job_id_; |
| 68 PlatformJobId local_job_id_; | 71 PlatformJobId local_job_id_; |
| 69 PrintJobDetails last_job_details_; | 72 PrintJobDetails last_job_details_; |
| 70 scoped_refptr<CloudPrintURLFetcher> request_; | 73 scoped_refptr<CloudPrintURLFetcher> request_; |
| 71 GURL cloud_print_server_url_; | 74 GURL cloud_print_server_url_; |
| 72 scoped_refptr<PrintSystem> print_system_; | 75 scoped_refptr<PrintSystem> print_system_; |
| 73 Delegate* delegate_; | 76 Delegate* delegate_; |
| 74 // A flag that is set to true in Stop() and will ensure the next scheduled | 77 // A flag that is set to true in Stop() and will ensure the next scheduled |
| 75 // task will do nothing. | 78 // task will do nothing. |
| 76 bool stopped_; | 79 bool stopped_; |
| 80 // Partial network traffic annotation for network requests. |
| 81 const net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation_; |
| 82 |
| 77 DISALLOW_COPY_AND_ASSIGN(JobStatusUpdater); | 83 DISALLOW_COPY_AND_ASSIGN(JobStatusUpdater); |
| 78 }; | 84 }; |
| 79 | 85 |
| 80 } // namespace cloud_print | 86 } // namespace cloud_print |
| 81 | 87 |
| 82 #endif // CHROME_SERVICE_CLOUD_PRINT_JOB_STATUS_UPDATER_H_ | 88 #endif // CHROME_SERVICE_CLOUD_PRINT_JOB_STATUS_UPDATER_H_ |
| OLD | NEW |