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

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

Issue 20238002: GCP2.0 Device: XMPP (without pings). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@DEPS-jingle
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
« no previous file with comments | « cloud_print/gcp20/prototype/gcp20_device.gyp ('k') | cloud_print/gcp20/prototype/printer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cloud_print/gcp20/prototype/printer.h
diff --git a/cloud_print/gcp20/prototype/printer.h b/cloud_print/gcp20/prototype/printer.h
index 3f402b9859d33493e759225e9e9500924ad1e66e..7b1ba50b8aab8fd38bae4f158f6a6dee1e83a459 100644
--- a/cloud_print/gcp20/prototype/printer.h
+++ b/cloud_print/gcp20/prototype/printer.h
@@ -11,6 +11,7 @@
#include "base/files/file_path.h"
#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"
@@ -21,7 +22,8 @@ extern const base::FilePath::CharType 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();
@@ -33,10 +35,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();
@@ -69,6 +68,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;
@@ -116,16 +116,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,
+ 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.
@@ -141,18 +180,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(
@@ -177,13 +210,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);
};
« no previous file with comments | « cloud_print/gcp20/prototype/gcp20_device.gyp ('k') | cloud_print/gcp20/prototype/printer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698