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

Unified Diff: cloud_print/gcp20/prototype/printer.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/printer.h
diff --git a/cloud_print/gcp20/prototype/printer.h b/cloud_print/gcp20/prototype/printer.h
index c225d80f85375a51f4ca0f72f9e677bf78d5dc37..0326621e08a2403a9a9b4135ed347834943fc7aa 100644
--- a/cloud_print/gcp20/prototype/printer.h
+++ b/cloud_print/gcp20/prototype/printer.h
@@ -10,14 +10,16 @@
#include "cloud_print/gcp20/prototype/cloud_print_requester.h"
#include "cloud_print/gcp20/prototype/dns_sd_server.h"
+#include "cloud_print/gcp20/prototype/printjob_handler.h"
#include "cloud_print/gcp20/prototype/privet_http_server.h"
#include "cloud_print/gcp20/prototype/x_privet_token.h"
extern const char kPrinterStatePath[];
-// This class maintain work of DNS-SD server, HTTP server and others.
+// This class maintains work of DNS-SD server, HTTP server and others.
class Printer : public PrivetHttpServer::Delegate,
- public CloudPrintRequester::Delegate {
+ public CloudPrintRequester::Delegate,
+ public base::SupportsWeakPtr<Printer> {
public:
// Constructs uninitialized object.
Printer();
@@ -31,6 +33,9 @@ class Printer : public PrivetHttpServer::Delegate,
// Returns true if printer was started.
bool IsOnline() const;
+ // Method for trying to reconnecting to server.
+ void WakeUp();
+
// Stops all servers.
void Stop();
@@ -74,6 +79,12 @@ class Printer : public PrivetHttpServer::Delegate,
REG_ACTION_COMPLETE,
REG_ACTION_CANCEL
};
+ enum ConnectionState {
+ NOT_CONFIGURED,
+ OFFLINE,
+ ONLINE,
+ CONNECTING
+ };
// PrivetHttpServer::Delegate methods:
virtual PrivetHttpServer::RegistrationErrorStatus RegistrationStart(
@@ -100,6 +111,12 @@ class Printer : public PrivetHttpServer::Delegate,
virtual void OnGetAuthCodeResponseParsed(
const std::string& refresh_token) OVERRIDE;
virtual void OnRegistrationError(const std::string& description) OVERRIDE;
+ virtual void OnServerError(const std::string& description) OVERRIDE;
+ virtual void OnNetworkError() OVERRIDE;
+ virtual void OnPrintjobsAvailable(
+ const std::vector<Printjob>& printjobs) OVERRIDE;
+ virtual void OnPrintjobDownloaded(const Printjob& printjob) OVERRIDE;
+ virtual void OnPrintjobDone() OVERRIDE;
// Checks if register call is called correctly (|user| is correct,
// error is no set etc). Returns |false| if error status is put into |status|.
@@ -107,23 +124,37 @@ class Printer : public PrivetHttpServer::Delegate,
PrivetHttpServer::RegistrationErrorStatus CheckCommonRegErrors(
const std::string& user) const;
- // Generates ProxyId for this device.
- std::string GenerateProxyId() const;
-
// Checks if confirmation was received.
void WaitUserConfirmation(base::Time valid_until);
+ // Generates ProxyId for this device.
+ std::string GenerateProxyId() const;
+
// 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 std::string& filename) const;
bool LoadFromFile(const std::string& filename);
+ // Adds |WakeUp| method to the MessageLoop.
+ void PostWakeUp();
+
+ // Adds |WakeUp| method to the MessageLoop with certain |delay|.
+ void PostDelayedWakeUp(const base::TimeDelta& delay);
+
// Converts errors.
PrivetHttpServer::RegistrationErrorStatus ConfirmationToRegistrationError(
RegistrationInfo::ConfirmationState state);
+ std::string ConnectionStateToString(ConnectionState state) const;
+
+ // Changes state and update info in DNS server.
+ bool ChangeState(ConnectionState new_state);
+
RegistrationInfo reg_info_;
// Contains DNS-SD server.
@@ -132,11 +163,16 @@ class Printer : public PrivetHttpServer::Delegate,
// Contains Privet HTTP server.
PrivetHttpServer http_server_;
- // Contains Cloud Print client.
+ // Connection state of device.
+ ConnectionState connection_state_;
+
+ // Contains CloudPrint client.
scoped_ptr<CloudPrintRequester> requester_;
XPrivetToken xtoken_;
+ scoped_ptr<PrintjobHandler> printjob_handler_;
+
// Uses for calculating uptime.
base::Time starttime_;

Powered by Google App Engine
This is Rietveld 408576698