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

Unified Diff: cloud_print/gcp20/prototype/cloud_print_requester.h

Issue 19866002: GCP2.0 Device: Receiving printjobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@confirmation
Patch Set: Created 7 years, 5 months 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 side-by-side diff with in-line comments
Download patch
Index: cloud_print/gcp20/prototype/cloud_print_requester.h
diff --git a/cloud_print/gcp20/prototype/cloud_print_requester.h b/cloud_print/gcp20/prototype/cloud_print_requester.h
index 70f6d83d1fa666a0d7aad8ae4196a2c3ac3e916b..add818b7eb48f0d32ab110428067f3305d361b4a 100644
--- a/cloud_print/gcp20/prototype/cloud_print_requester.h
+++ b/cloud_print/gcp20/prototype/cloud_print_requester.h
@@ -5,25 +5,29 @@
#ifndef CLOUD_PRINT_GCP20_PROTOTYPE_CLOUD_REQUESTER_H_
#define CLOUD_PRINT_GCP20_PROTOTYPE_CLOUD_REQUESTER_H_
-#include <map>
#include <string>
+#include <vector>
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/values.h"
+#include "cloud_print/gcp20/prototype/cloud_print_request.h"
+#include "cloud_print/gcp20/prototype/cloud_print_response_parser.h"
#include "google_apis/gaia/gaia_oauth_client.h"
-#include "net/url_request/url_fetcher.h"
-#include "net/url_request/url_fetcher_delegate.h"
-#include "net/url_request/url_request_context_getter.h"
typedef base::Callback<void(const std::string&)> ParserCallback;
class CloudPrintURLRequestContextGetter;
+class GURL;
extern const char kCloudPrintUrl[];
+using cloud_print_response_parser::Printjob;
Vitaly Buka (NO REVIEWS) 2013/07/22 03:57:31 Don't use using like that http://google-styleguid
maksymb 2013/07/22 22:56:53 Done.
+
+extern const bool kFunctionVebose;
+
// Class for requesting CloudPrint server and parsing responses.
-class CloudPrintRequester : public net::URLFetcherDelegate,
+class CloudPrintRequester : public CloudPrintRequest::Delegate,
public gaia::GaiaOAuthClient::Delegate {
public:
class Delegate {
@@ -46,6 +50,22 @@ class CloudPrintRequester : public net::URLFetcherDelegate,
// Invoked when server respond with |"success" = false| or we cannot parse
// response.
virtual void OnRegistrationError(const std::string& description) = 0;
+
+ // Invoked when network connection cannot be established.
+ virtual void OnNetworkError() = 0;
+
+ // Invoked when server error is received or cannot parse json response.
+ virtual void OnServerError(const std::string& description) = 0;
+
+ // Invoked when fetch response was received.
+ virtual void OnPrintjobsAvailable(
+ const std::vector<Printjob>& printjobs) = 0;
Vitaly Buka (NO REVIEWS) 2013/07/22 03:57:31 OnPrintJobAvailable
maksymb 2013/07/22 22:56:53 Done.
+
+ // Invoked when printjob is finally downloaded and available for printing.
+ virtual void OnPrintjobDownloaded(const Printjob& printjob) = 0;
Vitaly Buka (NO REVIEWS) 2013/07/22 03:57:31 Job
Vitaly Buka (NO REVIEWS) 2013/07/22 03:57:31 PrintJob
maksymb 2013/07/22 22:56:53 Done.
maksymb 2013/07/22 22:56:53 Done.
+
+ // Invoked when printjob is marked as done on CloudPrint server.
+ virtual void OnPrintjobDone() = 0;
};
// Creates and initializes objects.
@@ -55,20 +75,41 @@ class CloudPrintRequester : public net::URLFetcherDelegate,
// Destroys the object.
virtual ~CloudPrintRequester();
+ // Returns |true| if either |gaia| or |request| is awaiting for response.
+ bool IsBusy() const;
+
// Creates query to server for starting registration.
- bool StartRegistration(const std::string& proxy_id,
+ void StartRegistration(const std::string& proxy_id,
const std::string& device_name,
- const std::string& user,
- const std::string& cdd);
+ const std::string& user, const std::string& cdd);
// Creates request for completing registration and receiving refresh token.
- bool CompleteRegistration();
+ void CompleteRegistration();
- private:
- // net::URLFetcherDelegate
- virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
+ // Creates request for fetching printjobs.
+ void FetchPrintjobs(const std::string& refresh_token,
+ const std::string& device_id);
+
+ // Creates request for updating accesstoken.
+ // TODO(maksymb): Handle expiration of accesstoken.
+ void UpdateAccesstoken(const std::string& refresh_token);
- // gaia::GaiaOAuthClient::Delegate
+ // Creates chain of requests for requesting prinjob.
+ void RequestPrintjob(const Printjob& printjob);
Vitaly Buka (NO REVIEWS) 2013/07/22 03:57:31 print_job
maksymb 2013/07/22 22:56:53 Done.
+
+ // Reports server that prinjob has been printed.
+ void SendPrintjobDone(const std::string& jobid);
Vitaly Buka (NO REVIEWS) 2013/07/22 03:57:31 job_id
maksymb 2013/07/22 22:56:53 Done.
+
+ private:
+ //
+ virtual void OnFetchComplete() OVERRIDE;
+ virtual void OnFetchError(const std::string& server_api,
+ int server_code, int server_http_code) OVERRIDE;
+ virtual void OnFetchTimeoutReached() OVERRIDE;
+ virtual std::string access_token() OVERRIDE;
+ virtual scoped_refptr<net::URLRequestContextGetter> context_getter() OVERRIDE;
+
+ // gaia::GaiaOAuthClient::Delegate methods:
virtual void OnGetTokensResponse(const std::string& refresh_token,
const std::string& access_token,
int expires_in_seconds) OVERRIDE;
@@ -77,26 +118,43 @@ class CloudPrintRequester : public net::URLFetcherDelegate,
virtual void OnOAuthError() OVERRIDE;
virtual void OnNetworkError(int response_code) OVERRIDE;
- // Creates request with given |url| and |method|. When response is received
- // callback is called.
- // TODO(maksymb): Add timeout control for request.
- bool CreateRequest(const GURL& url,
- net::URLFetcher::RequestType method,
- const ParserCallback& callback) WARN_UNUSED_RESULT;
+ // Creates GET request.
+ scoped_ptr<CloudPrintRequest> CreateGet(const GURL& url);
+
+ // Creates POST request.
+ scoped_ptr<CloudPrintRequest> CreatePost(
+ const GURL& url,
+ const CloudPrintRequest::DataForUpload& data);
// Parses register-start server response.
- void ParseRegisterStartResponse(const std::string& response);
+ void ParseRegisterStart(const std::string& response);
// Parses register-complete server response. Initializes gaia (OAuth client)
// and receives refresh token.
- void ParseRegisterCompleteResponse(const std::string& response);
+ void ParseRegisterComplete(const std::string& response);
+
+ // Parses fetch printjobs server response.
+ void ParseFetch(const std::string& response);
+
+ // Invoked after receiving printjob ticket.
+ void ParseGetPrintjobTicket(const std::string& response);
+
+ // Invoked after receiving printjob file.
+ void ParseGetPrintjobData(const std::string& response);
+
+ // Invoked after marking printjob as DONE.
+ void ParsePrintjobDone(const std::string& response);
+
+ // Invoked after marking printjob as IN_PROGRESS.
+ void ParsePrintjobInProgress(const std::string& response);
- // Fetcher contains |NULL| if no server response is awaiting. Otherwise wait
- // until URLFetchComplete will be called and close connection.
- scoped_ptr<net::URLFetcher> fetcher_;
+ // |request| contains |NULL| if no server response is awaiting. Otherwise wait
+ // until callback will be called will be called and close connection.
+ scoped_ptr<CloudPrintRequest> request_;
- // Callback for parsing server response.
- ParserCallback parse_response_callback_;
+ // Contains information about current printjob. Information is filled by
+ // CloudPrint server responses.
+ scoped_ptr<Printjob> current_printjob_;
// Privet context getter.
scoped_refptr<CloudPrintURLRequestContextGetter> context_getter_;

Powered by Google App Engine
This is Rietveld 408576698