| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef GCP20_PROTOTYPE_PRINTER_H_ | 5 #ifndef GCP20_PROTOTYPE_PRINTER_H_ |
| 6 #define GCP20_PROTOTYPE_PRINTER_H_ | 6 #define GCP20_PROTOTYPE_PRINTER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/weak_ptr.h" |
| 11 #include "cloud_print/gcp20/prototype/cloud_print_requester.h" | 12 #include "cloud_print/gcp20/prototype/cloud_print_requester.h" |
| 12 #include "cloud_print/gcp20/prototype/dns_sd_server.h" | 13 #include "cloud_print/gcp20/prototype/dns_sd_server.h" |
| 13 #include "cloud_print/gcp20/prototype/privet_http_server.h" | 14 #include "cloud_print/gcp20/prototype/privet_http_server.h" |
| 14 #include "cloud_print/gcp20/prototype/x_privet_token.h" | 15 #include "cloud_print/gcp20/prototype/x_privet_token.h" |
| 15 | 16 |
| 16 // This class maintain work of DNS-SD server, HTTP server and others. | 17 // This class maintain work of DNS-SD server, HTTP server and others. |
| 17 class Printer : public PrivetHttpServer::Delegate, | 18 class Printer : public base::SupportsWeakPtr<Printer>, |
| 19 public PrivetHttpServer::Delegate, |
| 18 public CloudPrintRequester::Delegate { | 20 public CloudPrintRequester::Delegate { |
| 19 public: | 21 public: |
| 20 // Constructs uninitialized object. | 22 // Constructs uninitialized object. |
| 21 Printer(); | 23 Printer(); |
| 22 | 24 |
| 23 // Destroys the object. | 25 // Destroys the object. |
| 24 virtual ~Printer(); | 26 virtual ~Printer(); |
| 25 | 27 |
| 26 // Starts all servers. | 28 // Starts all servers. |
| 27 bool Start(); | 29 bool Start(); |
| 28 | 30 |
| 29 // Returns true if printer was started. | 31 // Returns true if printer was started. |
| 30 bool IsOnline() const; | 32 bool IsOnline() const; |
| 31 | 33 |
| 32 // Stops all servers. | 34 // Stops all servers. |
| 33 void Stop(); | 35 void Stop(); |
| 34 | 36 |
| 35 private: | 37 private: |
| 36 struct RegistrationInfo { | 38 struct RegistrationInfo { |
| 37 enum RegistrationState { | 39 enum RegistrationState { |
| 38 DEV_REG_UNREGISTERED = 0, | 40 DEV_REG_UNREGISTERED, |
| 39 DEV_REG_REGISTRATION_STARTED, | 41 DEV_REG_REGISTRATION_STARTED, // |action=start| was called, |
| 40 DEV_REG_REGISTRATION_CLAIM_TOKEN_READY, | 42 // request to CloudPrint was sent. |
| 41 DEV_REG_REGISTRATION_COMPLETING, | 43 DEV_REG_REGISTRATION_CLAIM_TOKEN_READY, // The same as previous, |
| 42 DEV_REG_REGISTRATION_ERROR, | 44 // but request reply is already |
| 45 // received. |
| 46 DEV_REG_REGISTRATION_COMPLETING, // |action=complete| was called, |
| 47 // |complete| request was sent. |
| 48 DEV_REG_REGISTRATION_ERROR, // Is set when server error was occurred. |
| 43 DEV_REG_REGISTERED, | 49 DEV_REG_REGISTERED, |
| 44 }; | 50 }; |
| 45 | 51 |
| 52 enum ConfirmationState { |
| 53 CONFIRMATION_PENDING, |
| 54 CONFIRMATION_CONFIRMED, |
| 55 CONFIRMATION_DISCARDED, |
| 56 CONFIRMATION_TIMEOUT, |
| 57 }; |
| 58 |
| 46 RegistrationInfo(); | 59 RegistrationInfo(); |
| 47 ~RegistrationInfo(); | 60 ~RegistrationInfo(); |
| 48 | 61 |
| 49 std::string user; | 62 std::string user; |
| 50 std::string refresh_token; | 63 std::string refresh_token; |
| 51 std::string device_id; | 64 std::string device_id; |
| 52 RegistrationState state; | 65 RegistrationState state; |
| 66 ConfirmationState confirmation_state; |
| 53 | 67 |
| 54 std::string registration_token; | 68 std::string registration_token; |
| 55 std::string complete_invite_url; | 69 std::string complete_invite_url; |
| 56 | 70 |
| 57 // Contains error response if |DEV_REG_REGISTRATION_ERROR| is set. | 71 // Contains error response if |DEV_REG_REGISTRATION_ERROR| is set. |
| 58 std::string error_description; | 72 std::string error_description; |
| 59 }; | 73 }; |
| 60 | 74 |
| 61 enum RegistrationAction { | 75 enum RegistrationAction { |
| 62 REG_ACTION_START, | 76 REG_ACTION_START, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 93 | 107 |
| 94 // Checks if register call is called correctly (|user| is correct, | 108 // Checks if register call is called correctly (|user| is correct, |
| 95 // error is no set etc). Returns |false| if error status is put into |status|. | 109 // error is no set etc). Returns |false| if error status is put into |status|. |
| 96 // Otherwise no error was occurred. | 110 // Otherwise no error was occurred. |
| 97 PrivetHttpServer::RegistrationErrorStatus CheckCommonRegErrors( | 111 PrivetHttpServer::RegistrationErrorStatus CheckCommonRegErrors( |
| 98 const std::string& user) const; | 112 const std::string& user) const; |
| 99 | 113 |
| 100 // Generates ProxyId for this device. | 114 // Generates ProxyId for this device. |
| 101 std::string GenerateProxyId() const; | 115 std::string GenerateProxyId() const; |
| 102 | 116 |
| 117 // Checks if confirmation was received. |
| 118 void WaitUserConfirmation(base::Time valid_until); |
| 119 |
| 103 // Creates data for DNS TXT respond. | 120 // Creates data for DNS TXT respond. |
| 104 std::vector<std::string> CreateTxt() const; | 121 std::vector<std::string> CreateTxt() const; |
| 105 | 122 |
| 106 RegistrationInfo reg_info_; | |
| 107 | |
| 108 // Saving and loading registration info from file. | 123 // Saving and loading registration info from file. |
| 109 void SaveToFile(const base::FilePath& file_path) const; | 124 void SaveToFile(const base::FilePath& file_path) const; |
| 110 bool LoadFromFile(const base::FilePath& file_path); | 125 bool LoadFromFile(const base::FilePath& file_path); |
| 111 | 126 |
| 127 // Converts errors. |
| 128 PrivetHttpServer::RegistrationErrorStatus ConfirmationToRegistrationError( |
| 129 RegistrationInfo::ConfirmationState state); |
| 130 |
| 131 RegistrationInfo reg_info_; |
| 132 |
| 112 // Contains DNS-SD server. | 133 // Contains DNS-SD server. |
| 113 DnsSdServer dns_server_; | 134 DnsSdServer dns_server_; |
| 114 | 135 |
| 115 // Contains Privet HTTP server. | 136 // Contains Privet HTTP server. |
| 116 PrivetHttpServer http_server_; | 137 PrivetHttpServer http_server_; |
| 117 | 138 |
| 118 // Contains Cloud Print client. | 139 // Contains Cloud Print client. |
| 119 scoped_ptr<CloudPrintRequester> requester_; | 140 scoped_ptr<CloudPrintRequester> requester_; |
| 120 | 141 |
| 121 XPrivetToken xtoken_; | 142 XPrivetToken xtoken_; |
| 122 | 143 |
| 123 // Uses for calculating uptime. | 144 // Uses for calculating uptime. |
| 124 base::Time starttime_; | 145 base::Time starttime_; |
| 125 | 146 |
| 126 DISALLOW_COPY_AND_ASSIGN(Printer); | 147 DISALLOW_COPY_AND_ASSIGN(Printer); |
| 127 }; | 148 }; |
| 128 | 149 |
| 129 #endif // GCP20_PROTOTYPE_PRINTER_H_ | 150 #endif // GCP20_PROTOTYPE_PRINTER_H_ |
| 130 | 151 |
| OLD | NEW |