| Index: cloud_print/gcp20/prototype/printer.h
|
| diff --git a/cloud_print/gcp20/prototype/printer.h b/cloud_print/gcp20/prototype/printer.h
|
| index 9dba7874a147f572469ae64e5a13e1728387a2a3..3f402b9859d33493e759225e9e9500924ad1e66e 100644
|
| --- a/cloud_print/gcp20/prototype/printer.h
|
| +++ b/cloud_print/gcp20/prototype/printer.h
|
| @@ -8,13 +8,17 @@
|
| #include <string>
|
| #include <vector>
|
|
|
| +#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/dns_sd_server.h"
|
| +#include "cloud_print/gcp20/prototype/print_job_handler.h"
|
| #include "cloud_print/gcp20/prototype/privet_http_server.h"
|
| #include "cloud_print/gcp20/prototype/x_privet_token.h"
|
|
|
| -// This class maintain work of DNS-SD server, HTTP server and others.
|
| +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 {
|
| @@ -31,6 +35,9 @@ class Printer : public base::SupportsWeakPtr<Printer>,
|
| // Returns true if printer was started.
|
| bool IsOnline() const;
|
|
|
| + // Method for trying to reconnecting to server.
|
| + void WakeUp();
|
| +
|
| // Stops all servers.
|
| void Stop();
|
|
|
| @@ -79,6 +86,13 @@ class Printer : public base::SupportsWeakPtr<Printer>,
|
| REG_ACTION_CANCEL
|
| };
|
|
|
| + enum ConnectionState {
|
| + NOT_CONFIGURED,
|
| + OFFLINE,
|
| + ONLINE,
|
| + CONNECTING
|
| + };
|
| +
|
| // PrivetHttpServer::Delegate methods:
|
| virtual PrivetHttpServer::RegistrationErrorStatus RegistrationStart(
|
| const std::string& user) OVERRIDE;
|
| @@ -104,6 +118,13 @@ class Printer : public base::SupportsWeakPtr<Printer>,
|
| 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<cloud_print_response_parser::Job>& jobs) OVERRIDE;
|
| + virtual void OnPrintJobDownloaded(
|
| + const cloud_print_response_parser::Job& job) 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|.
|
| @@ -111,23 +132,37 @@ class Printer : public base::SupportsWeakPtr<Printer>,
|
| 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 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);
|
| +
|
| // 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.
|
| @@ -136,11 +171,16 @@ class Printer : public base::SupportsWeakPtr<Printer>,
|
| // 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> print_job_handler_;
|
| +
|
| // Uses for calculating uptime.
|
| base::Time starttime_;
|
|
|
|
|