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

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: Unretained -> WeakPtr. Printjob -> PrintJob. 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 663ea7b150fa8dec728da14b687a63749d1b0cf7..90b620cd59943c7c91fc1c5d834e4182bcd7874c 100644
--- a/cloud_print/gcp20/prototype/cloud_print_requester.h
+++ b/cloud_print/gcp20/prototype/cloud_print_requester.h
@@ -5,28 +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/memory/weak_ptr.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[];
+extern const bool kFunctionVebose;
// Class for requesting CloudPrint server and parsing responses.
class CloudPrintRequester : public base::SupportsWeakPtr<CloudPrintRequester>,
- public net::URLFetcherDelegate,
- public gaia::GaiaOAuthClient::Delegate {
+ public gaia::GaiaOAuthClient::Delegate,
+ public CloudPrintRequest::Delegate {
public:
class Delegate {
public:
@@ -48,6 +49,23 @@ class CloudPrintRequester : public base::SupportsWeakPtr<CloudPrintRequester>,
// 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<cloud_print_response_parser::Job>& jobs) = 0;
+
+ // Invoked when printjob is finally downloaded and available for printing.
+ virtual void OnPrintJobDownloaded(
+ const cloud_print_response_parser::Job& job) = 0;
+
+ // Invoked when printjob is marked as done on CloudPrint server.
+ virtual void OnPrintJobDone() = 0;
};
// Creates and initializes objects.
@@ -57,20 +75,41 @@ class CloudPrintRequester : public base::SupportsWeakPtr<CloudPrintRequester>,
// 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);
+
+ // Creates chain of requests for requesting printjob.
+ void RequestPrintJob(const cloud_print_response_parser::Job& job);
- // gaia::GaiaOAuthClient::Delegate
+ // Reports server that printjob has been printed.
+ void SendPrintJobDone(const std::string& job_id);
+
+ 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;
@@ -79,26 +118,43 @@ class CloudPrintRequester : public base::SupportsWeakPtr<CloudPrintRequester>,
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<cloud_print_response_parser::Job> current_print_job_;
// Privet context getter.
scoped_refptr<CloudPrintURLRequestContextGetter> context_getter_;

Powered by Google App Engine
This is Rietveld 408576698