Chromium Code Reviews| Index: cloud_print/gcp20/prototype/printer.h |
| diff --git a/cloud_print/gcp20/prototype/printer.h b/cloud_print/gcp20/prototype/printer.h |
| index e41de372d2df2002f9b1ad95757ac01471b8d104..6299ffc226a664ce5fdbecfd9eecdeb031ae45bb 100644 |
| --- a/cloud_print/gcp20/prototype/printer.h |
| +++ b/cloud_print/gcp20/prototype/printer.h |
| @@ -10,6 +10,7 @@ |
| #include "base/memory/weak_ptr.h" |
| #include "cloud_print/gcp20/prototype/cloud_print_requester.h" |
| +#include "cloud_print/gcp20/prototype/cloud_print_xmpp_listener.h" |
| #include "cloud_print/gcp20/prototype/dns_sd_server.h" |
| #include "cloud_print/gcp20/prototype/print_job_handler.h" |
| #include "cloud_print/gcp20/prototype/privet_http_server.h" |
| @@ -20,7 +21,8 @@ extern const char kPrinterStatePath[]; |
| // This class maintains work of DNS-SD server, HTTP server and others. |
| class Printer : public base::SupportsWeakPtr<Printer>, |
| public PrivetHttpServer::Delegate, |
| - public CloudPrintRequester::Delegate { |
| + public CloudPrintRequester::Delegate, |
| + public CloudPrintXmppListener::Delegate { |
| public: |
| // Constructs uninitialized object. |
| Printer(); |
| @@ -32,10 +34,7 @@ class Printer : public base::SupportsWeakPtr<Printer>, |
| bool Start(); |
| // Returns true if printer was started. |
| - bool IsOnline() const; |
| - |
| - // Method for trying to reconnecting to server. |
| - void WakeUp(); |
| + bool IsRunning() const; |
| // Stops all servers. |
| void Stop(); |
| @@ -68,6 +67,7 @@ class Printer : public base::SupportsWeakPtr<Printer>, |
| std::string user; |
| std::string refresh_token; |
| std::string device_id; |
| + std::string xmpp_jid; |
| RegistrationState state; |
| ConfirmationState confirmation_state; |
| @@ -115,16 +115,55 @@ class Printer : public base::SupportsWeakPtr<Printer>, |
| const std::string& complete_invite_url, |
| const std::string& device_id) OVERRIDE; |
| virtual void OnGetAuthCodeResponseParsed( |
| - const std::string& refresh_token) OVERRIDE; |
| + const std::string& refresh_token, |
|
gene
2013/07/25 20:36:54
nit: wrong indentation
maksymb
2013/07/25 20:54:46
Done.
|
| + const std::string& access_token, |
| + int access_token_expires_in_seconds) OVERRIDE; |
| + virtual void OnXmppJidReceived(const std::string& xmpp_jid) OVERRIDE; |
| + virtual void OnAccesstokenReceviced(const std::string& access_token, |
| + int expires_in_seconds) OVERRIDE; |
| virtual void OnRegistrationError(const std::string& description) OVERRIDE; |
| - virtual void OnServerError(const std::string& description) OVERRIDE; |
| virtual void OnNetworkError() OVERRIDE; |
| + virtual void OnServerError(const std::string& description) OVERRIDE; |
| + virtual void OnAuthError() OVERRIDE; |
| + virtual std::string GetAccessToken() OVERRIDE; |
| virtual void OnPrintJobsAvailable( |
| const std::vector<cloud_print_response_parser::Job>& jobs) OVERRIDE; |
| virtual void OnPrintJobDownloaded( |
| const cloud_print_response_parser::Job& job) OVERRIDE; |
| virtual void OnPrintJobDone() OVERRIDE; |
| + // CloudPrintXmppListener::Delegate methods: |
| + virtual void OnXmppConnected() OVERRIDE; |
| + virtual void OnXmppAuthError() OVERRIDE; |
| + virtual void OnXmppNetworkError() OVERRIDE; |
| + virtual void OnXmppNewPrintJob(const std::string& device_id) OVERRIDE; |
| + virtual void OnXmppNewLocalSettings(const std::string& device_id) OVERRIDE; |
| + virtual void OnXmppDeleteNotification(const std::string& device_id) OVERRIDE; |
| + |
| + // Method for trying to reconnecting to server on start or after network fail. |
| + void TryConnect(); |
| + |
| + // Connects XMPP. |
| + void ConnectXmpp(); |
| + |
| + // Method to handle pending events. |
| + // Do *NOT* call this method instantly. Only with |PostOnIdle|. |
| + void OnIdle(); |
| + |
| + // Method for checking printer status. |
| + // (e.g. printjobs, local settings, deleted status). |
| + void CheckPendingUpdates(); |
| + |
| + // Ask CloudPrint server for new local sendings. |
| + void GetLocalSettings(); |
| + |
| + // Ask CloudPrint server for printjobs. |
| + void FetchPrintJobs(); |
| + |
| + // Saves |access_token| and calculates time for next update. |
| + void RememberAccessToken(const std::string& access_token, |
| + int expires_in_seconds); |
| + |
| // Checks if register call is called correctly (|user| is correct, |
| // error is no set etc). Returns |false| if error status is put into |status|. |
| // Otherwise no error was occurred. |
| @@ -140,18 +179,12 @@ class Printer : public base::SupportsWeakPtr<Printer>, |
| // Creates data for DNS TXT respond. |
| std::vector<std::string> CreateTxt() const; |
| - // Ask CloudPrint server for printjobs. |
| - void FetchPrintJobs(); |
| - |
| // Saving and loading registration info from file. |
| void SaveToFile(const base::FilePath& file_path) const; |
| bool LoadFromFile(const base::FilePath& file_path); |
| - // Adds |WakeUp| method to the MessageLoop. |
| - void PostWakeUp(); |
| - |
| - // Adds |WakeUp| method to the MessageLoop with certain |delay|. |
| - void PostDelayedWakeUp(const base::TimeDelta& delay); |
| + // Adds |OnIdle| method to the MessageLoop. |
| + void PostOnIdle(); |
| // Converts errors. |
| PrivetHttpServer::RegistrationErrorStatus ConfirmationToRegistrationError( |
| @@ -176,13 +209,29 @@ class Printer : public base::SupportsWeakPtr<Printer>, |
| // Contains CloudPrint client. |
| scoped_ptr<CloudPrintRequester> requester_; |
| + // XMPP Listener. |
| + scoped_ptr<CloudPrintXmppListener> xmpp_listener_; |
| + |
| XPrivetToken xtoken_; |
| scoped_ptr<PrintJobHandler> print_job_handler_; |
| + // Last valid |access_token|. |
| + std::string access_token_; |
| + base::Time access_token_update_; |
| + |
| // Uses for calculating uptime. |
| base::Time starttime_; |
| + // Used for preventing two and more OnIdle posted in message loop. |
| + bool on_idle_posted_; |
| + |
| + // Contains |true| if Printer has to check pending local settings. |
| + bool pending_local_settings_check_; |
| + |
| + // Contains |true| if Printer has to check available printjobs. |
| + bool pending_print_jobs_check_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(Printer); |
| }; |