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

Side by Side 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, 4 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "cloud_print/gcp20/prototype/cloud_print_requester.h" 13 #include "cloud_print/gcp20/prototype/cloud_print_requester.h"
14 #include "cloud_print/gcp20/prototype/cloud_print_xmpp_listener.h"
14 #include "cloud_print/gcp20/prototype/dns_sd_server.h" 15 #include "cloud_print/gcp20/prototype/dns_sd_server.h"
15 #include "cloud_print/gcp20/prototype/print_job_handler.h" 16 #include "cloud_print/gcp20/prototype/print_job_handler.h"
16 #include "cloud_print/gcp20/prototype/privet_http_server.h" 17 #include "cloud_print/gcp20/prototype/privet_http_server.h"
17 #include "cloud_print/gcp20/prototype/x_privet_token.h" 18 #include "cloud_print/gcp20/prototype/x_privet_token.h"
18 19
19 extern const base::FilePath::CharType kPrinterStatePath[]; 20 extern const base::FilePath::CharType kPrinterStatePath[];
20 21
21 // This class maintains work of DNS-SD server, HTTP server and others. 22 // This class maintains work of DNS-SD server, HTTP server and others.
22 class Printer : public base::SupportsWeakPtr<Printer>, 23 class Printer : public base::SupportsWeakPtr<Printer>,
23 public PrivetHttpServer::Delegate, 24 public PrivetHttpServer::Delegate,
24 public CloudPrintRequester::Delegate { 25 public CloudPrintRequester::Delegate,
26 public CloudPrintXmppListener::Delegate {
25 public: 27 public:
26 // Constructs uninitialized object. 28 // Constructs uninitialized object.
27 Printer(); 29 Printer();
28 30
29 // Destroys the object. 31 // Destroys the object.
30 virtual ~Printer(); 32 virtual ~Printer();
31 33
32 // Starts all servers. 34 // Starts all servers.
33 bool Start(); 35 bool Start();
34 36
35 // Returns true if printer was started. 37 // Returns true if printer was started.
36 bool IsOnline() const; 38 bool IsRunning() const;
37
38 // Method for trying to reconnecting to server.
39 void WakeUp();
40 39
41 // Stops all servers. 40 // Stops all servers.
42 void Stop(); 41 void Stop();
43 42
44 private: 43 private:
45 struct RegistrationInfo { 44 struct RegistrationInfo {
46 enum RegistrationState { 45 enum RegistrationState {
47 DEV_REG_UNREGISTERED, 46 DEV_REG_UNREGISTERED,
48 DEV_REG_REGISTRATION_STARTED, // |action=start| was called, 47 DEV_REG_REGISTRATION_STARTED, // |action=start| was called,
49 // request to CloudPrint was sent. 48 // request to CloudPrint was sent.
(...skipping 12 matching lines...) Expand all
62 CONFIRMATION_DISCARDED, 61 CONFIRMATION_DISCARDED,
63 CONFIRMATION_TIMEOUT, 62 CONFIRMATION_TIMEOUT,
64 }; 63 };
65 64
66 RegistrationInfo(); 65 RegistrationInfo();
67 ~RegistrationInfo(); 66 ~RegistrationInfo();
68 67
69 std::string user; 68 std::string user;
70 std::string refresh_token; 69 std::string refresh_token;
71 std::string device_id; 70 std::string device_id;
71 std::string xmpp_jid;
72 RegistrationState state; 72 RegistrationState state;
73 ConfirmationState confirmation_state; 73 ConfirmationState confirmation_state;
74 74
75 std::string registration_token; 75 std::string registration_token;
76 std::string complete_invite_url; 76 std::string complete_invite_url;
77 77
78 // Contains error response if |DEV_REG_REGISTRATION_ERROR| is set. 78 // Contains error response if |DEV_REG_REGISTRATION_ERROR| is set.
79 std::string error_description; 79 std::string error_description;
80 }; 80 };
81 81
(...skipping 27 matching lines...) Expand all
109 virtual void CreateInfo(PrivetHttpServer::DeviceInfo* info) OVERRIDE; 109 virtual void CreateInfo(PrivetHttpServer::DeviceInfo* info) OVERRIDE;
110 virtual bool IsRegistered() const OVERRIDE; 110 virtual bool IsRegistered() const OVERRIDE;
111 virtual bool CheckXPrivetTokenHeader(const std::string& token) const OVERRIDE; 111 virtual bool CheckXPrivetTokenHeader(const std::string& token) const OVERRIDE;
112 112
113 // CloudRequester::Delegate methods: 113 // CloudRequester::Delegate methods:
114 virtual void OnRegistrationStartResponseParsed( 114 virtual void OnRegistrationStartResponseParsed(
115 const std::string& registration_token, 115 const std::string& registration_token,
116 const std::string& complete_invite_url, 116 const std::string& complete_invite_url,
117 const std::string& device_id) OVERRIDE; 117 const std::string& device_id) OVERRIDE;
118 virtual void OnGetAuthCodeResponseParsed( 118 virtual void OnGetAuthCodeResponseParsed(
119 const std::string& refresh_token) OVERRIDE; 119 const std::string& refresh_token,
120 const std::string& access_token,
121 int access_token_expires_in_seconds) OVERRIDE;
122 virtual void OnXmppJidReceived(const std::string& xmpp_jid) OVERRIDE;
123 virtual void OnAccesstokenReceviced(const std::string& access_token,
124 int expires_in_seconds) OVERRIDE;
120 virtual void OnRegistrationError(const std::string& description) OVERRIDE; 125 virtual void OnRegistrationError(const std::string& description) OVERRIDE;
126 virtual void OnNetworkError() OVERRIDE;
121 virtual void OnServerError(const std::string& description) OVERRIDE; 127 virtual void OnServerError(const std::string& description) OVERRIDE;
122 virtual void OnNetworkError() OVERRIDE; 128 virtual void OnAuthError() OVERRIDE;
129 virtual std::string GetAccessToken() OVERRIDE;
123 virtual void OnPrintJobsAvailable( 130 virtual void OnPrintJobsAvailable(
124 const std::vector<cloud_print_response_parser::Job>& jobs) OVERRIDE; 131 const std::vector<cloud_print_response_parser::Job>& jobs) OVERRIDE;
125 virtual void OnPrintJobDownloaded( 132 virtual void OnPrintJobDownloaded(
126 const cloud_print_response_parser::Job& job) OVERRIDE; 133 const cloud_print_response_parser::Job& job) OVERRIDE;
127 virtual void OnPrintJobDone() OVERRIDE; 134 virtual void OnPrintJobDone() OVERRIDE;
128 135
136 // CloudPrintXmppListener::Delegate methods:
137 virtual void OnXmppConnected() OVERRIDE;
138 virtual void OnXmppAuthError() OVERRIDE;
139 virtual void OnXmppNetworkError() OVERRIDE;
140 virtual void OnXmppNewPrintJob(const std::string& device_id) OVERRIDE;
141 virtual void OnXmppNewLocalSettings(const std::string& device_id) OVERRIDE;
142 virtual void OnXmppDeleteNotification(const std::string& device_id) OVERRIDE;
143
144 // Method for trying to reconnecting to server on start or after network fail.
145 void TryConnect();
146
147 // Connects XMPP.
148 void ConnectXmpp();
149
150 // Method to handle pending events.
151 // Do *NOT* call this method instantly. Only with |PostOnIdle|.
152 void OnIdle();
153
154 // Method for checking printer status.
155 // (e.g. printjobs, local settings, deleted status).
156 void CheckPendingUpdates();
157
158 // Ask CloudPrint server for new local sendings.
159 void GetLocalSettings();
160
161 // Ask CloudPrint server for printjobs.
162 void FetchPrintJobs();
163
164 // Saves |access_token| and calculates time for next update.
165 void RememberAccessToken(const std::string& access_token,
166 int expires_in_seconds);
167
129 // Checks if register call is called correctly (|user| is correct, 168 // Checks if register call is called correctly (|user| is correct,
130 // error is no set etc). Returns |false| if error status is put into |status|. 169 // error is no set etc). Returns |false| if error status is put into |status|.
131 // Otherwise no error was occurred. 170 // Otherwise no error was occurred.
132 PrivetHttpServer::RegistrationErrorStatus CheckCommonRegErrors( 171 PrivetHttpServer::RegistrationErrorStatus CheckCommonRegErrors(
133 const std::string& user) const; 172 const std::string& user) const;
134 173
135 // Checks if confirmation was received. 174 // Checks if confirmation was received.
136 void WaitUserConfirmation(base::Time valid_until); 175 void WaitUserConfirmation(base::Time valid_until);
137 176
138 // Generates ProxyId for this device. 177 // Generates ProxyId for this device.
139 std::string GenerateProxyId() const; 178 std::string GenerateProxyId() const;
140 179
141 // Creates data for DNS TXT respond. 180 // Creates data for DNS TXT respond.
142 std::vector<std::string> CreateTxt() const; 181 std::vector<std::string> CreateTxt() const;
143 182
144 // Ask CloudPrint server for printjobs.
145 void FetchPrintJobs();
146
147 // Saving and loading registration info from file. 183 // Saving and loading registration info from file.
148 void SaveToFile(const base::FilePath& file_path) const; 184 void SaveToFile(const base::FilePath& file_path) const;
149 bool LoadFromFile(const base::FilePath& file_path); 185 bool LoadFromFile(const base::FilePath& file_path);
150 186
151 // Adds |WakeUp| method to the MessageLoop. 187 // Adds |OnIdle| method to the MessageLoop.
152 void PostWakeUp(); 188 void PostOnIdle();
153
154 // Adds |WakeUp| method to the MessageLoop with certain |delay|.
155 void PostDelayedWakeUp(const base::TimeDelta& delay);
156 189
157 // Converts errors. 190 // Converts errors.
158 PrivetHttpServer::RegistrationErrorStatus ConfirmationToRegistrationError( 191 PrivetHttpServer::RegistrationErrorStatus ConfirmationToRegistrationError(
159 RegistrationInfo::ConfirmationState state); 192 RegistrationInfo::ConfirmationState state);
160 193
161 std::string ConnectionStateToString(ConnectionState state) const; 194 std::string ConnectionStateToString(ConnectionState state) const;
162 195
163 // Changes state and update info in DNS server. 196 // Changes state and update info in DNS server.
164 bool ChangeState(ConnectionState new_state); 197 bool ChangeState(ConnectionState new_state);
165 198
166 RegistrationInfo reg_info_; 199 RegistrationInfo reg_info_;
167 200
168 // Contains DNS-SD server. 201 // Contains DNS-SD server.
169 DnsSdServer dns_server_; 202 DnsSdServer dns_server_;
170 203
171 // Contains Privet HTTP server. 204 // Contains Privet HTTP server.
172 PrivetHttpServer http_server_; 205 PrivetHttpServer http_server_;
173 206
174 // Connection state of device. 207 // Connection state of device.
175 ConnectionState connection_state_; 208 ConnectionState connection_state_;
176 209
177 // Contains CloudPrint client. 210 // Contains CloudPrint client.
178 scoped_ptr<CloudPrintRequester> requester_; 211 scoped_ptr<CloudPrintRequester> requester_;
179 212
213 // XMPP Listener.
214 scoped_ptr<CloudPrintXmppListener> xmpp_listener_;
215
180 XPrivetToken xtoken_; 216 XPrivetToken xtoken_;
181 217
182 scoped_ptr<PrintJobHandler> print_job_handler_; 218 scoped_ptr<PrintJobHandler> print_job_handler_;
183 219
220 // Last valid |access_token|.
221 std::string access_token_;
222 base::Time access_token_update_;
223
184 // Uses for calculating uptime. 224 // Uses for calculating uptime.
185 base::Time starttime_; 225 base::Time starttime_;
186 226
227 // Used for preventing two and more OnIdle posted in message loop.
228 bool on_idle_posted_;
229
230 // Contains |true| if Printer has to check pending local settings.
231 bool pending_local_settings_check_;
232
233 // Contains |true| if Printer has to check available printjobs.
234 bool pending_print_jobs_check_;
235
187 DISALLOW_COPY_AND_ASSIGN(Printer); 236 DISALLOW_COPY_AND_ASSIGN(Printer);
188 }; 237 };
189 238
190 #endif // GCP20_PROTOTYPE_PRINTER_H_ 239 #endif // GCP20_PROTOTYPE_PRINTER_H_
191 240
OLDNEW
« 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