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 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 virtual void OnRegistrationError(const std::string& description) OVERRIDE; | 125 virtual void OnRegistrationError(const std::string& description) OVERRIDE; |
126 virtual void OnNetworkError() OVERRIDE; | 126 virtual void OnNetworkError() OVERRIDE; |
127 virtual void OnServerError(const std::string& description) OVERRIDE; | 127 virtual void OnServerError(const std::string& description) OVERRIDE; |
128 virtual void OnAuthError() OVERRIDE; | 128 virtual void OnAuthError() OVERRIDE; |
129 virtual std::string GetAccessToken() OVERRIDE; | 129 virtual std::string GetAccessToken() OVERRIDE; |
130 virtual void OnPrintJobsAvailable( | 130 virtual void OnPrintJobsAvailable( |
131 const std::vector<cloud_print_response_parser::Job>& jobs) OVERRIDE; | 131 const std::vector<cloud_print_response_parser::Job>& jobs) OVERRIDE; |
132 virtual void OnPrintJobDownloaded( | 132 virtual void OnPrintJobDownloaded( |
133 const cloud_print_response_parser::Job& job) OVERRIDE; | 133 const cloud_print_response_parser::Job& job) OVERRIDE; |
134 virtual void OnPrintJobDone() OVERRIDE; | 134 virtual void OnPrintJobDone() OVERRIDE; |
| 135 virtual void OnLocalSettingsReceived( |
| 136 LocalSettings::State state, |
| 137 const LocalSettings& settings) OVERRIDE; |
| 138 virtual void OnLocalSettingsUpdated() OVERRIDE; |
135 | 139 |
136 // CloudPrintXmppListener::Delegate methods: | 140 // CloudPrintXmppListener::Delegate methods: |
137 virtual void OnXmppConnected() OVERRIDE; | 141 virtual void OnXmppConnected() OVERRIDE; |
138 virtual void OnXmppAuthError() OVERRIDE; | 142 virtual void OnXmppAuthError() OVERRIDE; |
139 virtual void OnXmppNetworkError() OVERRIDE; | 143 virtual void OnXmppNetworkError() OVERRIDE; |
140 virtual void OnXmppNewPrintJob(const std::string& device_id) OVERRIDE; | 144 virtual void OnXmppNewPrintJob(const std::string& device_id) OVERRIDE; |
141 virtual void OnXmppNewLocalSettings(const std::string& device_id) OVERRIDE; | 145 virtual void OnXmppNewLocalSettings(const std::string& device_id) OVERRIDE; |
142 virtual void OnXmppDeleteNotification(const std::string& device_id) OVERRIDE; | 146 virtual void OnXmppDeleteNotification(const std::string& device_id) OVERRIDE; |
143 | 147 |
144 // Method for trying to reconnecting to server on start or after network fail. | 148 // Method for trying to reconnecting to server on start or after network fail. |
145 void TryConnect(); | 149 void TryConnect(); |
146 | 150 |
147 // Connects XMPP. | 151 // Connects XMPP. |
148 void ConnectXmpp(); | 152 void ConnectXmpp(); |
149 | 153 |
150 // Method to handle pending events. | 154 // Method to handle pending events. |
151 // Do *NOT* call this method instantly. Only with |PostOnIdle|. | 155 // Do *NOT* call this method instantly. Only with |PostOnIdle|. |
152 void OnIdle(); | 156 void OnIdle(); |
153 | 157 |
154 // Method for checking printer status. | 158 // Ask Cloud Print server for printjobs. |
155 // (e.g. printjobs, local settings, deleted status). | 159 void FetchPrintJobs(); |
156 void CheckPendingUpdates(); | |
157 | 160 |
158 // Ask CloudPrint server for new local sendings. | 161 // Ask Cloud Print server for new local sendings. |
159 void GetLocalSettings(); | 162 void GetLocalSettings(); |
160 | 163 |
161 // Ask CloudPrint server for printjobs. | 164 // Applies new local settings to printer. |
162 void FetchPrintJobs(); | 165 void ApplyLocalSettings(const LocalSettings& settings); |
| 166 |
| 167 // Used for erasing all printer info. |
| 168 void OnPrinterDeleted(); |
163 | 169 |
164 // Saves |access_token| and calculates time for next update. | 170 // Saves |access_token| and calculates time for next update. |
165 void RememberAccessToken(const std::string& access_token, | 171 void RememberAccessToken(const std::string& access_token, |
166 int expires_in_seconds); | 172 int expires_in_seconds); |
167 | 173 |
168 // Sets registration state to error and adds description. | 174 // Sets registration state to error and adds description. |
169 void SetRegistrationError(const std::string& description); | 175 void SetRegistrationError(const std::string& description); |
170 | 176 |
171 // Checks if register call is called correctly (|user| is correct, | 177 // Checks if register call is called correctly (|user| is correct, |
172 // error is no set etc). Returns |false| if error status is put into |status|. | 178 // error is no set etc). Returns |false| if error status is put into |status|. |
(...skipping 19 matching lines...) Expand all Loading... |
192 | 198 |
193 // Registration timeout. | 199 // Registration timeout. |
194 void CheckRegistrationExpiration(); | 200 void CheckRegistrationExpiration(); |
195 | 201 |
196 // Delays expiration after user action. | 202 // Delays expiration after user action. |
197 void UpdateRegistrationExpiration(); | 203 void UpdateRegistrationExpiration(); |
198 | 204 |
199 // Deletes registration expiration at all. | 205 // Deletes registration expiration at all. |
200 void InvalidateRegistrationExpiration(); | 206 void InvalidateRegistrationExpiration(); |
201 | 207 |
| 208 // Methods to start HTTP and DNS-SD servers. Return |true| if servers |
| 209 // were started. |
| 210 bool StartHttpServer(); |
| 211 bool StartDnsServer(); |
| 212 |
202 // Converts errors. | 213 // Converts errors. |
203 PrivetHttpServer::RegistrationErrorStatus ConfirmationToRegistrationError( | 214 PrivetHttpServer::RegistrationErrorStatus ConfirmationToRegistrationError( |
204 RegistrationInfo::ConfirmationState state); | 215 RegistrationInfo::ConfirmationState state); |
205 | 216 |
206 std::string ConnectionStateToString(ConnectionState state) const; | 217 std::string ConnectionStateToString(ConnectionState state) const; |
207 | 218 |
208 // Changes state to OFFLINE and posts TryReconnect. | 219 // Changes state to OFFLINE and posts TryReconnect. |
209 // For registration reconnect is instant every time. | 220 // For registration reconnect is instant every time. |
210 void FallOffline(bool instant_reconnect); | 221 void FallOffline(bool instant_reconnect); |
211 | 222 |
212 // Changes state and update info in DNS server. Returns |true| if state | 223 // Changes state and update info in DNS server. Returns |true| if state |
213 // was changed (otherwise state was the same). | 224 // was changed (otherwise state was the same). |
214 bool ChangeState(ConnectionState new_state); | 225 bool ChangeState(ConnectionState new_state); |
215 | 226 |
| 227 // TODO(maksymb): Encapsulate reg_info, local_settings and other state |
| 228 // member variables to struct. |
| 229 |
216 RegistrationInfo reg_info_; | 230 RegistrationInfo reg_info_; |
217 | 231 |
| 232 LocalSettings local_settings_; |
| 233 |
218 // Contains DNS-SD server. | 234 // Contains DNS-SD server. |
219 DnsSdServer dns_server_; | 235 DnsSdServer dns_server_; |
220 | 236 |
221 // Contains Privet HTTP server. | 237 // Contains Privet HTTP server. |
222 PrivetHttpServer http_server_; | 238 PrivetHttpServer http_server_; |
223 | 239 |
224 // Connection state of device. | 240 // Connection state of device. |
225 ConnectionState connection_state_; | 241 ConnectionState connection_state_; |
226 | 242 |
227 // Contains CloudPrint client. | 243 // Contains CloudPrint client. |
(...skipping 18 matching lines...) Expand all Loading... |
246 | 262 |
247 // Used for preventing two and more OnIdle posted in message loop. | 263 // Used for preventing two and more OnIdle posted in message loop. |
248 bool on_idle_posted_; | 264 bool on_idle_posted_; |
249 | 265 |
250 // Contains |true| if Printer has to check pending local settings. | 266 // Contains |true| if Printer has to check pending local settings. |
251 bool pending_local_settings_check_; | 267 bool pending_local_settings_check_; |
252 | 268 |
253 // Contains |true| if Printer has to check available printjobs. | 269 // Contains |true| if Printer has to check available printjobs. |
254 bool pending_print_jobs_check_; | 270 bool pending_print_jobs_check_; |
255 | 271 |
| 272 // Contains |true| if Printer has to be deleted. |
| 273 bool pending_deletion_; |
| 274 |
256 DISALLOW_COPY_AND_ASSIGN(Printer); | 275 DISALLOW_COPY_AND_ASSIGN(Printer); |
257 }; | 276 }; |
258 | 277 |
259 #endif // GCP20_PROTOTYPE_PRINTER_H_ | 278 #endif // GCP20_PROTOTYPE_PRINTER_H_ |
260 | 279 |
OLD | NEW |