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

Side by Side Diff: cloud_print/gcp20/prototype/printer.cc

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 unified diff | Download patch
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 #include "cloud_print/gcp20/prototype/printer.h" 5 #include "cloud_print/gcp20/prototype/printer.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h"
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/file_util.h" 13 #include "base/file_util.h"
13 #include "base/guid.h" 14 #include "base/guid.h"
14 #include "base/json/json_reader.h" 15 #include "base/json/json_reader.h"
15 #include "base/json/json_writer.h" 16 #include "base/json/json_writer.h"
16 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/stringprintf.h"
17 #include "cloud_print/gcp20/prototype/command_line_reader.h" 19 #include "cloud_print/gcp20/prototype/command_line_reader.h"
18 #include "cloud_print/gcp20/prototype/service_parameters.h" 20 #include "cloud_print/gcp20/prototype/service_parameters.h"
19 #include "cloud_print/gcp20/prototype/special_io.h" 21 #include "cloud_print/gcp20/prototype/special_io.h"
20 #include "net/base/net_util.h" 22 #include "net/base/net_util.h"
21 #include "net/base/url_util.h" 23 #include "net/base/url_util.h"
22 24
23 const base::FilePath::CharType kPrinterStatePath[] = 25 const base::FilePath::CharType kPrinterStatePath[] =
24 FILE_PATH_LITERAL("printer_state.json"); 26 FILE_PATH_LITERAL("printer_state.json");
25 27
26 namespace { 28 namespace {
27 29
28 const char kServiceType[] = "_privet._tcp.local"; 30 const char kServiceType[] = "_privet._tcp.local";
29 const char kServiceNamePrefix[] = "first_gcp20_device"; 31 const char kServiceNamePrefix[] = "first_gcp20_device";
30 const char kServiceDomainName[] = "my-privet-device.local"; 32 const char kServiceDomainName[] = "my-privet-device.local";
31 33
32 const char kPrinterName[] = "Google GCP2.0 Prototype"; 34 const char kPrinterName[] = "Google GCP2.0 Prototype";
33 const char kPrinterDescription[] = "Printer emulator"; 35 const char kPrinterDescription[] = "Printer emulator";
34 36
35 const char kUserConfirmationTitle[] = "Confirm registration: type 'y' if you " 37 const char kUserConfirmationTitle[] = "Confirm registration: type 'y' if you "
36 "agree and any other to discard\n"; 38 "agree and any other to discard\n";
37 const uint kUserConfirmationTimeout = 30; // in seconds 39 const uint kUserConfirmationTimeout = 30; // in seconds
38 40
41 const uint32 kReconnectTimeout = 5; // in seconds
42 const uint32 kPrintJobsTimeout = 10; // in seconds
43
39 const char kCdd[] = 44 const char kCdd[] =
40 "{\n" 45 "{\n"
41 " 'version': '1.0',\n" 46 " 'version': '1.0',\n"
42 " 'printer': {\n" 47 " 'printer': {\n"
43 " 'vendor_capability': [\n" 48 " 'vendor_capability': [\n"
44 " {\n" 49 " {\n"
45 " 'id': 'psk:MediaType',\n" 50 " 'id': 'psk:MediaType',\n"
46 " 'display_name': 'Media Type',\n" 51 " 'display_name': 'Media Type',\n"
47 " 'type': 'SELECT',\n" 52 " 'type': 'SELECT',\n"
48 " 'select_cap': {\n" 53 " 'select_cap': {\n"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 LOG(INFO) << net::IPAddressToString(iter->address); 90 LOG(INFO) << net::IPAddressToString(iter->address);
86 return iter->address; 91 return iter->address;
87 } 92 }
88 } 93 }
89 94
90 return net::IPAddressNumber(); 95 return net::IPAddressNumber();
91 } 96 }
92 97
93 } // namespace 98 } // namespace
94 99
100 using cloud_print_response_parser::Job;
101
95 Printer::RegistrationInfo::RegistrationInfo() 102 Printer::RegistrationInfo::RegistrationInfo()
96 : state(DEV_REG_UNREGISTERED), 103 : state(DEV_REG_UNREGISTERED),
97 confirmation_state(CONFIRMATION_PENDING) { 104 confirmation_state(CONFIRMATION_PENDING) {
98 } 105 }
99 106
100 Printer::RegistrationInfo::~RegistrationInfo() { 107 Printer::RegistrationInfo::~RegistrationInfo() {
101 } 108 }
102 109
103 Printer::Printer() : http_server_(this) { 110 Printer::Printer() : http_server_(this), connection_state_(OFFLINE) {
104 } 111 }
105 112
106 Printer::~Printer() { 113 Printer::~Printer() {
107 Stop(); 114 Stop();
108 } 115 }
109 116
110 bool Printer::Start() { 117 bool Printer::Start() {
111 if (IsOnline()) 118 if (IsOnline())
112 return true; 119 return true;
113 120
(...skipping 26 matching lines...) Expand all
140 147
141 // Creating Cloud Requester. 148 // Creating Cloud Requester.
142 requester_.reset( 149 requester_.reset(
143 new CloudPrintRequester( 150 new CloudPrintRequester(
144 base::MessageLoop::current()->message_loop_proxy(), 151 base::MessageLoop::current()->message_loop_proxy(),
145 this)); 152 this));
146 153
147 xtoken_ = XPrivetToken(); 154 xtoken_ = XPrivetToken();
148 starttime_ = base::Time::Now(); 155 starttime_ = base::Time::Now();
149 156
157 print_job_handler_.reset(new PrintJobHandler);
158 connection_state_ = CONNECTING;
159 if (IsRegistered())
160 WakeUp();
gene 2013/07/23 09:36:23 remove if() and just call WakeUp() ??? since WakeU
maksymb 2013/07/23 19:02:37 Done.
161
150 return true; 162 return true;
151 } 163 }
152 164
153 bool Printer::IsOnline() const { 165 bool Printer::IsOnline() const {
154 return requester_; 166 return requester_;
155 } 167 }
156 168
169 void Printer::WakeUp() {
170 VLOG(3) << "Function: " << __FUNCTION__;
171
172 if (!IsRegistered())
173 return;
174
175 FetchPrintJobs();
176 }
177
157 void Printer::Stop() { 178 void Printer::Stop() {
158 dns_server_.Shutdown(); 179 dns_server_.Shutdown();
159 http_server_.Shutdown(); 180 http_server_.Shutdown();
160 requester_.reset(); 181 requester_.reset();
182 print_job_handler_.reset();
161 } 183 }
162 184
163 PrivetHttpServer::RegistrationErrorStatus Printer::RegistrationStart( 185 PrivetHttpServer::RegistrationErrorStatus Printer::RegistrationStart(
164 const std::string& user) { 186 const std::string& user) {
165 PrivetHttpServer::RegistrationErrorStatus status = CheckCommonRegErrors(user); 187 PrivetHttpServer::RegistrationErrorStatus status = CheckCommonRegErrors(user);
166 if (status != PrivetHttpServer::REG_ERROR_OK) 188 if (status != PrivetHttpServer::REG_ERROR_OK)
167 return status; 189 return status;
168 190
169 if (reg_info_.state != RegistrationInfo::DEV_REG_UNREGISTERED) 191 if (reg_info_.state != RegistrationInfo::DEV_REG_UNREGISTERED)
170 return PrivetHttpServer::REG_ERROR_INVALID_ACTION; 192 return PrivetHttpServer::REG_ERROR_INVALID_ACTION;
171 193
172 reg_info_ = RegistrationInfo(); 194 reg_info_ = RegistrationInfo();
173 reg_info_.user = user; 195 reg_info_.user = user;
174 reg_info_.state = RegistrationInfo::DEV_REG_REGISTRATION_STARTED; 196 reg_info_.state = RegistrationInfo::DEV_REG_REGISTRATION_STARTED;
175 197
176 printf(kUserConfirmationTitle); 198 printf(kUserConfirmationTitle);
177 base::Time valid_until = base::Time::Now() + 199 base::Time valid_until = base::Time::Now() +
178 base::TimeDelta::FromSeconds(kUserConfirmationTimeout); 200 base::TimeDelta::FromSeconds(kUserConfirmationTimeout);
179 base::MessageLoop::current()->PostTask( 201 base::MessageLoop::current()->PostTask(
180 FROM_HERE, 202 FROM_HERE,
181 base::Bind(&Printer::WaitUserConfirmation, AsWeakPtr(), valid_until)); 203 base::Bind(&Printer::WaitUserConfirmation, AsWeakPtr(), valid_until));
182 204
183 requester_->StartRegistration(GenerateProxyId(), kPrinterName, user, kCdd); 205 requester_->StartRegistration(GenerateProxyId(), kPrinterName, user, kCdd);
184 206
185 return PrivetHttpServer::REG_ERROR_OK; 207 return PrivetHttpServer::REG_ERROR_OK;
186 } 208 }
187 209
188 bool Printer::CheckXPrivetTokenHeader(const std::string& token) const {
189 return xtoken_.CheckValidXToken(token);
190 }
191
192 bool Printer::IsRegistered() const {
193 return reg_info_.state == RegistrationInfo::DEV_REG_REGISTERED;
194 }
195
196 PrivetHttpServer::RegistrationErrorStatus Printer::RegistrationGetClaimToken( 210 PrivetHttpServer::RegistrationErrorStatus Printer::RegistrationGetClaimToken(
197 const std::string& user, 211 const std::string& user,
198 std::string* token, 212 std::string* token,
199 std::string* claim_url) { 213 std::string* claim_url) {
200 PrivetHttpServer::RegistrationErrorStatus status = CheckCommonRegErrors(user); 214 PrivetHttpServer::RegistrationErrorStatus status = CheckCommonRegErrors(user);
201 if (status != PrivetHttpServer::REG_ERROR_OK) 215 if (status != PrivetHttpServer::REG_ERROR_OK)
202 return status; 216 return status;
203 217
204 // Check if |action=start| was called, but |action=complete| wasn't. 218 // Check if |action=start| was called, but |action=complete| wasn't.
205 if (reg_info_.state != RegistrationInfo::DEV_REG_REGISTRATION_STARTED && 219 if (reg_info_.state != RegistrationInfo::DEV_REG_REGISTRATION_STARTED &&
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 void Printer::CreateInfo(PrivetHttpServer::DeviceInfo* info) { 291 void Printer::CreateInfo(PrivetHttpServer::DeviceInfo* info) {
278 // TODO(maksymb): Replace "text" with constants. 292 // TODO(maksymb): Replace "text" with constants.
279 293
280 *info = PrivetHttpServer::DeviceInfo(); 294 *info = PrivetHttpServer::DeviceInfo();
281 info->version = "1.0"; 295 info->version = "1.0";
282 info->name = kPrinterName; 296 info->name = kPrinterName;
283 info->description = kPrinterDescription; 297 info->description = kPrinterDescription;
284 info->url = kCloudPrintUrl; 298 info->url = kCloudPrintUrl;
285 info->id = reg_info_.device_id; 299 info->id = reg_info_.device_id;
286 info->device_state = "idle"; 300 info->device_state = "idle";
287 info->connection_state = "offline"; 301 info->connection_state = ConnectionStateToString(connection_state_);
288 info->manufacturer = "Google"; 302 info->manufacturer = "Google";
289 info->model = "Prototype"; 303 info->model = "Prototype";
290 info->serial_number = "2.3.5.7.13.17.19.31.61.89.107.127.521.607.1279.2203"; 304 info->serial_number = "2.3.5.7.13.17.19.31.61.89.107.127.521.607.1279.2203";
291 info->firmware = "3.7.31.127.8191.131071.524287.2147483647"; 305 info->firmware = "3.7.31.127.8191.131071.524287.2147483647";
292 info->uptime = static_cast<int>((base::Time::Now() - starttime_).InSeconds()); 306 info->uptime = static_cast<int>((base::Time::Now() - starttime_).InSeconds());
293 307
294 info->x_privet_token = xtoken_.GenerateXToken(); 308 info->x_privet_token = xtoken_.GenerateXToken();
295 309
296 if (reg_info_.state == RegistrationInfo::DEV_REG_UNREGISTERED) 310 if (reg_info_.state == RegistrationInfo::DEV_REG_UNREGISTERED)
297 info->api.push_back("/privet/register"); 311 info->api.push_back("/privet/register");
298 312
299 info->type.push_back("printer"); 313 info->type.push_back("printer");
300 } 314 }
301 315
316 bool Printer::IsRegistered() const {
317 return reg_info_.state == RegistrationInfo::DEV_REG_REGISTERED;
318 }
319
320 bool Printer::CheckXPrivetTokenHeader(const std::string& token) const {
321 return xtoken_.CheckValidXToken(token);
322 }
323
302 void Printer::OnRegistrationStartResponseParsed( 324 void Printer::OnRegistrationStartResponseParsed(
303 const std::string& registration_token, 325 const std::string& registration_token,
304 const std::string& complete_invite_url, 326 const std::string& complete_invite_url,
305 const std::string& device_id) { 327 const std::string& device_id) {
306 reg_info_.state = RegistrationInfo::DEV_REG_REGISTRATION_CLAIM_TOKEN_READY; 328 reg_info_.state = RegistrationInfo::DEV_REG_REGISTRATION_CLAIM_TOKEN_READY;
307 reg_info_.device_id = device_id; 329 reg_info_.device_id = device_id;
308 reg_info_.registration_token = registration_token; 330 reg_info_.registration_token = registration_token;
309 reg_info_.complete_invite_url = complete_invite_url; 331 reg_info_.complete_invite_url = complete_invite_url;
310 } 332 }
311 333
312 void Printer::OnGetAuthCodeResponseParsed(const std::string& refresh_token) { 334 void Printer::OnGetAuthCodeResponseParsed(const std::string& refresh_token) {
313 reg_info_.state = RegistrationInfo::DEV_REG_REGISTERED; 335 reg_info_.state = RegistrationInfo::DEV_REG_REGISTERED;
314 reg_info_.refresh_token = refresh_token; 336 reg_info_.refresh_token = refresh_token;
315 SaveToFile(kPrinterStatePath); 337 SaveToFile(kPrinterStatePath);
338 FetchPrintJobs();
316 } 339 }
317 340
318 void Printer::OnRegistrationError(const std::string& description) { 341 void Printer::OnRegistrationError(const std::string& description) {
319 LOG(ERROR) << "server_error: " << description; 342 LOG(ERROR) << "server_error: " << description;
320 343
321 // TODO(maksymb): Implement waiting after error and timeout of registration. 344 // TODO(maksymb): Implement waiting after error and timeout of registration.
322 reg_info_.state = RegistrationInfo::DEV_REG_REGISTRATION_ERROR; 345 reg_info_.state = RegistrationInfo::DEV_REG_REGISTRATION_ERROR;
323 reg_info_.error_description = description; 346 reg_info_.error_description = description;
324 } 347 }
325 348
349 void Printer::OnServerError(const std::string& description) {
350 VLOG(3) << "Function: " << __FUNCTION__;
351 LOG(ERROR) << "Server error: " << description;
352
353 PostDelayedWakeUp(base::TimeDelta::FromSeconds(kReconnectTimeout));
354 }
355
356 void Printer::OnNetworkError() {
357 VLOG(3) << "Function: " << __FUNCTION__;
358 ChangeState(OFFLINE);
359 PostDelayedWakeUp(base::TimeDelta::FromSeconds(kReconnectTimeout));
360 }
361
362 void Printer::OnPrintJobsAvailable(const std::vector<Job>& jobs) {
363 VLOG(3) << "Function: " << __FUNCTION__;
364 ChangeState(ONLINE);
365
366 LOG(INFO) << "Available printjobs: " << jobs.size();
367
368 if (jobs.empty()) {
369 PostDelayedWakeUp(base::TimeDelta::FromSeconds(kPrintJobsTimeout));
370 return;
371 }
372
373 // TODO(maksymb): After finishing XMPP add 'Printjobs available' flag.
374 LOG(INFO) << "Downloading first printjob.";
375 requester_->RequestPrintJob(jobs[0]);
376 return;
377 }
378
379 void Printer::OnPrintJobDownloaded(const Job& job) {
380 VLOG(3) << "Function: " << __FUNCTION__;
381 print_job_handler_->SavePrintJob(
382 job.file,
383 job.ticket,
384 base::StringPrintf("%s.%s", job.create_time.c_str(), job.job_id.c_str()),
385 job.title);
386 requester_->SendPrintJobDone(job.job_id);
387 }
388
389 void Printer::OnPrintJobDone() {
390 VLOG(3) << "Function: " << __FUNCTION__;
391 // TODO(maksymb): Replace PostTask with with XMPP notifications.
392 PostWakeUp();
393 }
394
326 PrivetHttpServer::RegistrationErrorStatus Printer::CheckCommonRegErrors( 395 PrivetHttpServer::RegistrationErrorStatus Printer::CheckCommonRegErrors(
327 const std::string& user) const { 396 const std::string& user) const {
328 DCHECK(!IsRegistered()); 397 DCHECK(!IsRegistered());
329 398
330 if (reg_info_.state != RegistrationInfo::DEV_REG_UNREGISTERED && 399 if (reg_info_.state != RegistrationInfo::DEV_REG_UNREGISTERED &&
331 user != reg_info_.user) { 400 user != reg_info_.user) {
332 return PrivetHttpServer::REG_ERROR_DEVICE_BUSY; 401 return PrivetHttpServer::REG_ERROR_DEVICE_BUSY;
333 } 402 }
334 403
335 if (reg_info_.state == RegistrationInfo::DEV_REG_REGISTRATION_ERROR) 404 if (reg_info_.state == RegistrationInfo::DEV_REG_REGISTRATION_ERROR)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 } 437 }
369 438
370 std::vector<std::string> Printer::CreateTxt() const { 439 std::vector<std::string> Printer::CreateTxt() const {
371 std::vector<std::string> txt; 440 std::vector<std::string> txt;
372 txt.push_back("txtvers=1"); 441 txt.push_back("txtvers=1");
373 txt.push_back("ty=" + std::string(kPrinterName)); 442 txt.push_back("ty=" + std::string(kPrinterName));
374 txt.push_back("note=" + std::string(kPrinterDescription)); 443 txt.push_back("note=" + std::string(kPrinterDescription));
375 txt.push_back("url=" + std::string(kCloudPrintUrl)); 444 txt.push_back("url=" + std::string(kCloudPrintUrl));
376 txt.push_back("type=printer"); 445 txt.push_back("type=printer");
377 txt.push_back("id=" + reg_info_.device_id); 446 txt.push_back("id=" + reg_info_.device_id);
378 txt.push_back("cs=offline"); 447 txt.push_back("cs=" + ConnectionStateToString(connection_state_));
379 448
380 return txt; 449 return txt;
381 } 450 }
382 451
452 void Printer::FetchPrintJobs() {
453 VLOG(3) << "Function: " << __FUNCTION__;
454
455 if (!IsRegistered())
456 return;
457
458 if (requester_->IsBusy()) {
459 PostDelayedWakeUp(base::TimeDelta::FromSeconds(kReconnectTimeout));
460 } else {
461 requester_->FetchPrintJobs(reg_info_.refresh_token, reg_info_.device_id);
462 }
463 }
464
383 void Printer::SaveToFile(const std::string& filename) const { 465 void Printer::SaveToFile(const std::string& filename) const {
384 base::DictionaryValue json; 466 base::DictionaryValue json;
385 // TODO(maksymb): Get rid of in-place constants. 467 // TODO(maksymb): Get rid of in-place constants.
386 if (IsRegistered()) { 468 if (IsRegistered()) {
387 json.SetBoolean("registered", true); 469 json.SetBoolean("registered", true);
388 json.SetString("user", reg_info_.user); 470 json.SetString("user", reg_info_.user);
389 json.SetString("device_id", reg_info_.device_id); 471 json.SetString("device_id", reg_info_.device_id);
390 json.SetString("refresh_token", reg_info_.refresh_token); 472 json.SetString("refresh_token", reg_info_.refresh_token);
391 } else { 473 } else {
392 json.SetBoolean("registered", false); 474 json.SetBoolean("registered", false);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 536
455 reg_info_ = RegistrationInfo(); 537 reg_info_ = RegistrationInfo();
456 reg_info_.state = RegistrationInfo::DEV_REG_REGISTERED; 538 reg_info_.state = RegistrationInfo::DEV_REG_REGISTERED;
457 reg_info_.user = user; 539 reg_info_.user = user;
458 reg_info_.device_id = device_id; 540 reg_info_.device_id = device_id;
459 reg_info_.refresh_token = refresh_token; 541 reg_info_.refresh_token = refresh_token;
460 542
461 return true; 543 return true;
462 } 544 }
463 545
546 void Printer::PostWakeUp() {
547 VLOG(3) << "Function: " << __FUNCTION__;
548 base::MessageLoop::current()->PostTask(
549 FROM_HERE,
550 base::Bind(&Printer::WakeUp, AsWeakPtr()));
551 }
552
553 void Printer::PostDelayedWakeUp(const base::TimeDelta& delay) {
554 VLOG(3) << "Function: " << __FUNCTION__;
555 base::MessageLoop::current()->PostDelayedTask(
556 FROM_HERE,
557 base::Bind(&Printer::WakeUp, AsWeakPtr()),
558 delay);
559 }
560
464 PrivetHttpServer::RegistrationErrorStatus 561 PrivetHttpServer::RegistrationErrorStatus
465 Printer::ConfirmationToRegistrationError( 562 Printer::ConfirmationToRegistrationError(
466 RegistrationInfo::ConfirmationState state) { 563 RegistrationInfo::ConfirmationState state) {
467 switch (state) { 564 switch (state) {
468 case RegistrationInfo::CONFIRMATION_PENDING: 565 case RegistrationInfo::CONFIRMATION_PENDING:
469 return PrivetHttpServer::REG_ERROR_PENDING_USER_ACTION; 566 return PrivetHttpServer::REG_ERROR_PENDING_USER_ACTION;
470 case RegistrationInfo::CONFIRMATION_DISCARDED: 567 case RegistrationInfo::CONFIRMATION_DISCARDED:
471 return PrivetHttpServer::REG_ERROR_USER_CANCEL; 568 return PrivetHttpServer::REG_ERROR_USER_CANCEL;
472 case RegistrationInfo::CONFIRMATION_CONFIRMED: 569 case RegistrationInfo::CONFIRMATION_CONFIRMED:
473 NOTREACHED(); 570 NOTREACHED();
474 return PrivetHttpServer::REG_ERROR_OK; 571 return PrivetHttpServer::REG_ERROR_OK;
475 case RegistrationInfo::CONFIRMATION_TIMEOUT: 572 case RegistrationInfo::CONFIRMATION_TIMEOUT:
476 return PrivetHttpServer::REG_ERROR_CONFIRMATION_TIMEOUT; 573 return PrivetHttpServer::REG_ERROR_CONFIRMATION_TIMEOUT;
477 default: 574 default:
478 NOTREACHED(); 575 NOTREACHED();
479 return PrivetHttpServer::REG_ERROR_OK; 576 return PrivetHttpServer::REG_ERROR_OK;
480 } 577 }
481 } 578 }
482 579
580 std::string Printer::ConnectionStateToString(ConnectionState state) const {
581 if (state == OFFLINE)
gene 2013/07/23 09:36:23 switch() { case } here??
maksymb 2013/07/23 19:02:37 Done.
582 return "offline";
583 if (state == ONLINE)
584 return "online";
585 if (state == CONNECTING)
586 return "connecting";
587 if (state == NOT_CONFIGURED)
588 return "not-configured";
589
590 NOTREACHED();
591 return "";
592 }
593
594 bool Printer::ChangeState(ConnectionState new_state) {
595 if (connection_state_ == new_state)
596 return false;
597
598 VLOG(1) << "Printer is now " << ConnectionStateToString(new_state);
599 connection_state_ = new_state;
600 dns_server_.UpdateMetadata(CreateTxt());
601 return true;
602 }
603
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698