Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: chrome/service/cloud_print/job_status_updater.h

Issue 4165013: Re-landing issue 4202006 (http://codereview.chromium.org/4202006/show) which ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #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 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/ref_counted.h" 11 #include "base/ref_counted.h"
12 #include "base/scoped_ptr.h" 12 #include "base/scoped_ptr.h"
13 #include "base/thread.h" 13 #include "base/thread.h"
14 #include "chrome/service/cloud_print/cloud_print_url_fetcher.h"
14 #include "chrome/service/cloud_print/print_system.h" 15 #include "chrome/service/cloud_print/print_system.h"
15 #include "chrome/common/net/url_fetcher.h"
16 #include "googleurl/src/gurl.h" 16 #include "googleurl/src/gurl.h"
17 #include "net/url_request/url_request_status.h" 17 #include "net/url_request/url_request_status.h"
18 18
19 // Periodically monitors the status of a local print job and updates the 19 // Periodically monitors the status of a local print job and updates the
20 // cloud print server accordingly. When the job has been completed this 20 // cloud print server accordingly. When the job has been completed this
21 // object releases the reference to itself which should cause it to 21 // object releases the reference to itself which should cause it to
22 // self-destruct. 22 // self-destruct.
23 class JobStatusUpdater : public base::RefCountedThreadSafe<JobStatusUpdater>, 23 class JobStatusUpdater : public base::RefCountedThreadSafe<JobStatusUpdater>,
24 public URLFetcher::Delegate { 24 public CloudPrintURLFetcherDelegate {
25 public: 25 public:
26 class Delegate { 26 class Delegate {
27 public: 27 public:
28 virtual bool OnJobCompleted(JobStatusUpdater* updater) = 0; 28 virtual bool OnJobCompleted(JobStatusUpdater* updater) = 0;
29 virtual void OnAuthError() = 0; 29 virtual void OnAuthError() = 0;
30 30
31 protected: 31 protected:
32 virtual ~Delegate() {} 32 virtual ~Delegate() {}
33 }; 33 };
34 34
35 JobStatusUpdater(const std::string& printer_name, 35 JobStatusUpdater(const std::string& printer_name,
36 const std::string& job_id, 36 const std::string& job_id,
37 cloud_print::PlatformJobId& local_job_id, 37 cloud_print::PlatformJobId& local_job_id,
38 const std::string& auth_token, 38 const std::string& auth_token,
39 const GURL& cloud_print_server_url, 39 const GURL& cloud_print_server_url,
40 cloud_print::PrintSystem* print_system, 40 cloud_print::PrintSystem* print_system,
41 Delegate* delegate); 41 Delegate* delegate);
42 virtual ~JobStatusUpdater(); 42 virtual ~JobStatusUpdater();
43 43
44 // Checks the status of the local print job and sends an update. 44 // Checks the status of the local print job and sends an update.
45 void UpdateStatus(); 45 void UpdateStatus();
46 void Stop(); 46 void Stop();
47 47
48 // URLFetcher::Delegate implementation. 48 // CloudPrintURLFetcher::Delegate implementation.
49 virtual void OnURLFetchComplete(const URLFetcher* source, const GURL& url, 49 virtual CloudPrintURLFetcher::ResponseAction HandleJSONData(
50 const URLRequestStatus& status, 50 const URLFetcher* source,
51 int response_code, 51 const GURL& url,
52 const ResponseCookies& cookies, 52 DictionaryValue* json_data,
53 const std::string& data); 53 bool succeeded);
54 virtual void OnRequestAuthError();
54 55
55 private: 56 private:
56 std::string printer_name_; 57 std::string printer_name_;
57 std::string job_id_; 58 std::string job_id_;
58 cloud_print::PlatformJobId local_job_id_; 59 cloud_print::PlatformJobId local_job_id_;
59 cloud_print::PrintJobDetails last_job_details_; 60 cloud_print::PrintJobDetails last_job_details_;
60 scoped_ptr<URLFetcher> request_; 61 scoped_refptr<CloudPrintURLFetcher> request_;
61 std::string auth_token_; 62 std::string auth_token_;
62 GURL cloud_print_server_url_; 63 GURL cloud_print_server_url_;
63 scoped_refptr<cloud_print::PrintSystem> print_system_; 64 scoped_refptr<cloud_print::PrintSystem> print_system_;
64 Delegate* delegate_; 65 Delegate* delegate_;
65 // A flag that is set to true in Stop() and will ensure the next scheduled 66 // A flag that is set to true in Stop() and will ensure the next scheduled
66 // task will do nothing. 67 // task will do nothing.
67 bool stopped_; 68 bool stopped_;
68 DISALLOW_COPY_AND_ASSIGN(JobStatusUpdater); 69 DISALLOW_COPY_AND_ASSIGN(JobStatusUpdater);
69 }; 70 };
70 71
71 // This typedef is to workaround the issue with certain versions of 72 // This typedef is to workaround the issue with certain versions of
72 // Visual Studio where it gets confused between multiple Delegate 73 // Visual Studio where it gets confused between multiple Delegate
73 // classes and gives a C2500 error. (I saw this error on the try bots - 74 // classes and gives a C2500 error. (I saw this error on the try bots -
74 // the workaround was not needed for my machine). 75 // the workaround was not needed for my machine).
75 typedef JobStatusUpdater::Delegate JobStatusUpdaterDelegate; 76 typedef JobStatusUpdater::Delegate JobStatusUpdaterDelegate;
76 77
77 #endif // CHROME_SERVICE_CLOUD_PRINT_JOB_STATUS_UPDATER_H_ 78 #endif // CHROME_SERVICE_CLOUD_PRINT_JOB_STATUS_UPDATER_H_
OLDNEW
« no previous file with comments | « chrome/service/cloud_print/cloud_print_url_fetcher_unittest.cc ('k') | chrome/service/cloud_print/job_status_updater.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698