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

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

Issue 21916003: GCP2.0 Device: XMPP pings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@xmpp
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
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/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/guid.h" 14 #include "base/guid.h"
15 #include "base/json/json_reader.h" 15 #include "base/json/json_reader.h"
16 #include "base/json/json_writer.h" 16 #include "base/json/json_writer.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "cloud_print/gcp20/prototype/command_line_reader.h" 19 #include "cloud_print/gcp20/prototype/command_line_reader.h"
20 #include "cloud_print/gcp20/prototype/service_parameters.h" 20 #include "cloud_print/gcp20/prototype/service_parameters.h"
21 #include "cloud_print/gcp20/prototype/special_io.h" 21 #include "cloud_print/gcp20/prototype/special_io.h"
22 #include "net/base/net_util.h" 22 #include "net/base/net_util.h"
23 #include "net/base/url_util.h" 23 #include "net/base/url_util.h"
24 24
25 const char kPrinterStatePathDefault[] = "printer_state.json"; 25 const char kPrinterStatePathDefault[] = "printer_state.json";
26 26
27 namespace { 27 namespace {
28 28
29 const uint16 kHttpPortDefault = 10101; 29 const uint16 kHttpPortDefault = 10101;
30 const uint32 kTtlDefault = 60*60; 30 const uint32 kTtlDefault = 60*60; // in seconds
31 const int kXmppPingIntervalDefault = 5*60; // in seconds
31 32
32 const char kServiceType[] = "_privet._tcp.local"; 33 const char kServiceType[] = "_privet._tcp.local";
33 const char kServiceNamePrefixDefault[] = "first_gcp20_device"; 34 const char kServiceNamePrefixDefault[] = "first_gcp20_device";
34 const char kServiceDomainNameDefault[] = "my-privet-device.local"; 35 const char kServiceDomainNameDefault[] = "my-privet-device.local";
35 36
36 const char kPrinterName[] = "Google GCP2.0 Prototype"; 37 const char kPrinterName[] = "Google GCP2.0 Prototype";
37 const char kPrinterDescription[] = "Printer emulator"; 38 const char kPrinterDescription[] = "Printer emulator";
38 39
39 const char kUserConfirmationTitle[] = "Confirm registration: type 'y' if you " 40 const char kUserConfirmationTitle[] = "Confirm registration: type 'y' if you "
40 "agree and any other to discard\n"; 41 "agree and any other to discard\n";
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 176
176 void Printer::Stop() { 177 void Printer::Stop() {
177 dns_server_.Shutdown(); 178 dns_server_.Shutdown();
178 http_server_.Shutdown(); 179 http_server_.Shutdown();
179 requester_.reset(); 180 requester_.reset();
180 print_job_handler_.reset(); 181 print_job_handler_.reset();
181 xmpp_listener_.reset(); 182 xmpp_listener_.reset();
182 } 183 }
183 184
184 void Printer::OnAuthError() { 185 void Printer::OnAuthError() {
186 LOG(ERROR) << "Auth error occurred";
185 access_token_update_ = base::Time::Now(); 187 access_token_update_ = base::Time::Now();
186 ChangeState(OFFLINE); 188 ChangeState(OFFLINE);
187 // TODO(maksymb): Implement *instant* updating of access_token. 189 // TODO(maksymb): Implement *instant* updating of access_token.
188 } 190 }
189 191
190 std::string Printer::GetAccessToken() { 192 std::string Printer::GetAccessToken() {
191 return access_token_; 193 return access_token_;
192 } 194 }
193 195
194 PrivetHttpServer::RegistrationErrorStatus Printer::RegistrationStart( 196 PrivetHttpServer::RegistrationErrorStatus Printer::RegistrationStart(
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 ConnectXmpp(); 471 ConnectXmpp();
470 } 472 }
471 } else { 473 } else {
472 // TODO(maksymb): Ping google.com to check connection state. 474 // TODO(maksymb): Ping google.com to check connection state.
473 ChangeState(ONLINE); 475 ChangeState(ONLINE);
474 } 476 }
475 } 477 }
476 478
477 void Printer::ConnectXmpp() { 479 void Printer::ConnectXmpp() {
478 xmpp_listener_.reset( 480 xmpp_listener_.reset(
479 new CloudPrintXmppListener(reg_info_.xmpp_jid, GetTaskRunner(), this)); 481 new CloudPrintXmppListener(reg_info_.xmpp_jid, kXmppPingIntervalDefault,
482 GetTaskRunner(), this));
480 xmpp_listener_->Connect(access_token_); 483 xmpp_listener_->Connect(access_token_);
481 } 484 }
482 485
483 void Printer::OnIdle() { 486 void Printer::OnIdle() {
484 DCHECK(IsRegistered()); 487 DCHECK(IsRegistered());
485 DCHECK(on_idle_posted_) << "Instant call is not allowed"; 488 DCHECK(on_idle_posted_) << "Instant call is not allowed";
486 on_idle_posted_ = false; 489 on_idle_posted_ = false;
487 490
488 if (connection_state_ != ONLINE) 491 if (connection_state_ != ONLINE)
489 return; 492 return;
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 case NOT_CONFIGURED: 789 case NOT_CONFIGURED:
787 break; 790 break;
788 791
789 default: 792 default:
790 NOTREACHED(); 793 NOTREACHED();
791 } 794 }
792 795
793 return true; 796 return true;
794 } 797 }
795 798
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698