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

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

Issue 735053002: Prefix CommandLine usage with base namespace (Part 7: cloud_print/) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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/dns_sd_server.h" 5 #include "cloud_print/gcp20/prototype/dns_sd_server.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 void DnsSdServer::UpdateMetadata(const std::vector<std::string>& metadata) { 91 void DnsSdServer::UpdateMetadata(const std::vector<std::string>& metadata) {
92 if (!IsOnline()) 92 if (!IsOnline())
93 return; 93 return;
94 94
95 metadata_ = metadata; 95 metadata_ = metadata;
96 96
97 // TODO(maksymb): If less than 20% of full TTL left before next announcement 97 // TODO(maksymb): If less than 20% of full TTL left before next announcement
98 // then send it now. 98 // then send it now.
99 99
100 uint32 current_ttl = GetCurrentTLL(); 100 uint32 current_ttl = GetCurrentTLL();
101 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoAnnouncement)) { 101 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
102 switches::kNoAnnouncement)) {
102 DnsResponseBuilder builder(current_ttl); 103 DnsResponseBuilder builder(current_ttl);
103 104
104 builder.AppendTxt(serv_params_.service_name_, current_ttl, metadata_, true); 105 builder.AppendTxt(serv_params_.service_name_, current_ttl, metadata_, true);
105 scoped_refptr<net::IOBufferWithSize> buffer(builder.Build()); 106 scoped_refptr<net::IOBufferWithSize> buffer(builder.Build());
106 107
107 DCHECK(buffer.get() != NULL); 108 DCHECK(buffer.get() != NULL);
108 109
109 socket_->SendTo(buffer.get(), buffer.get()->size(), multicast_address_, 110 socket_->SendTo(buffer.get(), buffer.get()->size(), multicast_address_,
110 base::Bind(&DoNothingAfterSendToSocket)); 111 base::Bind(&DoNothingAfterSendToSocket));
111 } 112 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 break; 177 break;
177 } 178 }
178 } 179 }
179 180
180 scoped_refptr<net::IOBufferWithSize> buffer(builder.Build()); 181 scoped_refptr<net::IOBufferWithSize> buffer(builder.Build());
181 if (buffer.get() == NULL) 182 if (buffer.get() == NULL)
182 return; // No answers. 183 return; // No answers.
183 184
184 VLOG(1) << "Current TTL for respond: " << current_ttl; 185 VLOG(1) << "Current TTL for respond: " << current_ttl;
185 186
186 bool unicast_respond = 187 bool unicast_respond = base::CommandLine::ForCurrentProcess()->HasSwitch(
187 CommandLine::ForCurrentProcess()->HasSwitch(switches::kUnicastRespond); 188 switches::kUnicastRespond);
188 socket_->SendTo(buffer.get(), buffer.get()->size(), 189 socket_->SendTo(buffer.get(), buffer.get()->size(),
189 unicast_respond ? recv_address_ : multicast_address_, 190 unicast_respond ? recv_address_ : multicast_address_,
190 base::Bind(&DoNothingAfterSendToSocket)); 191 base::Bind(&DoNothingAfterSendToSocket));
191 VLOG(1) << "Responded to " 192 VLOG(1) << "Responded to "
192 << (unicast_respond ? recv_address_ : multicast_address_).ToString(); 193 << (unicast_respond ? recv_address_ : multicast_address_).ToString();
193 } 194 }
194 195
195 void DnsSdServer::ProccessQuery(uint32 current_ttl, const DnsQueryRecord& query, 196 void DnsSdServer::ProccessQuery(uint32 current_ttl, const DnsQueryRecord& query,
196 DnsResponseBuilder* builder) const { 197 DnsResponseBuilder* builder) const {
197 std::string log; 198 std::string log;
198 bool responded = false; 199 bool responded = false;
199 switch (query.qtype) { 200 switch (query.qtype) {
200 // TODO(maksymb): Add IPv6 support. 201 // TODO(maksymb): Add IPv6 support.
201 case net::dns_protocol::kTypePTR: 202 case net::dns_protocol::kTypePTR:
202 log = "Processing PTR query"; 203 log = "Processing PTR query";
203 if (query.qname == serv_params_.service_type_ || 204 if (query.qname == serv_params_.service_type_ ||
204 query.qname == serv_params_.secondary_service_type_) { 205 query.qname == serv_params_.secondary_service_type_) {
205 builder->AppendPtr(query.qname, current_ttl, 206 builder->AppendPtr(query.qname, current_ttl,
206 serv_params_.service_name_, true); 207 serv_params_.service_name_, true);
207 208
208 if (CommandLine::ForCurrentProcess()->HasSwitch( 209 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
209 switches::kExtendedResponce)) { 210 switches::kExtendedResponce)) {
210 builder->AppendSrv(serv_params_.service_name_, current_ttl, 211 builder->AppendSrv(serv_params_.service_name_, current_ttl,
211 kSrvPriority, kSrvWeight, serv_params_.http_port_, 212 kSrvPriority, kSrvWeight, serv_params_.http_port_,
212 serv_params_.service_domain_name_, false); 213 serv_params_.service_domain_name_, false);
213 builder->AppendA(serv_params_.service_domain_name_, current_ttl, 214 builder->AppendA(serv_params_.service_domain_name_, current_ttl,
214 serv_params_.http_ipv4_, false); 215 serv_params_.http_ipv4_, false);
215 builder->AppendAAAA(serv_params_.service_domain_name_, current_ttl, 216 builder->AppendAAAA(serv_params_.service_domain_name_, current_ttl,
216 serv_params_.http_ipv6_, false); 217 serv_params_.http_ipv6_, false);
217 builder->AppendTxt(serv_params_.service_name_, current_ttl, metadata_, 218 builder->AppendTxt(serv_params_.service_name_, current_ttl, metadata_,
218 false); 219 false);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 274
274 // TODO(maksymb): Add handler for errors 275 // TODO(maksymb): Add handler for errors
275 DCHECK(rv == net::ERR_IO_PENDING); 276 DCHECK(rv == net::ERR_IO_PENDING);
276 } 277 }
277 278
278 void DnsSdServer::OnDatagramReceived() { 279 void DnsSdServer::OnDatagramReceived() {
279 DoLoop(0); 280 DoLoop(0);
280 } 281 }
281 282
282 void DnsSdServer::SendAnnouncement(uint32 ttl) { 283 void DnsSdServer::SendAnnouncement(uint32 ttl) {
283 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoAnnouncement)) { 284 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
285 switches::kNoAnnouncement)) {
284 DnsResponseBuilder builder(ttl); 286 DnsResponseBuilder builder(ttl);
285 287
286 builder.AppendPtr(serv_params_.service_type_, ttl, 288 builder.AppendPtr(serv_params_.service_type_, ttl,
287 serv_params_.service_name_, true); 289 serv_params_.service_name_, true);
288 builder.AppendPtr(serv_params_.secondary_service_type_, ttl, 290 builder.AppendPtr(serv_params_.secondary_service_type_, ttl,
289 serv_params_.service_name_, true); 291 serv_params_.service_name_, true);
290 builder.AppendSrv(serv_params_.service_name_, ttl, kSrvPriority, 292 builder.AppendSrv(serv_params_.service_name_, ttl, kSrvPriority,
291 kSrvWeight, serv_params_.http_port_, 293 kSrvWeight, serv_params_.http_port_,
292 serv_params_.service_domain_name_, true); 294 serv_params_.service_domain_name_, true);
293 builder.AppendA(serv_params_.service_domain_name_, ttl, 295 builder.AppendA(serv_params_.service_domain_name_, ttl,
(...skipping 25 matching lines...) Expand all
319 321
320 uint32 DnsSdServer::GetCurrentTLL() const { 322 uint32 DnsSdServer::GetCurrentTLL() const {
321 uint32 current_ttl = (time_until_live_ - base::Time::Now()).InSeconds(); 323 uint32 current_ttl = (time_until_live_ - base::Time::Now()).InSeconds();
322 if (time_until_live_ < base::Time::Now() || current_ttl == 0) { 324 if (time_until_live_ < base::Time::Now() || current_ttl == 0) {
323 // This should not be reachable. But still we don't need to fail. 325 // This should not be reachable. But still we don't need to fail.
324 current_ttl = 1; // Service is still alive. 326 current_ttl = 1; // Service is still alive.
325 LOG(ERROR) << "|current_ttl| was equal to zero."; 327 LOG(ERROR) << "|current_ttl| was equal to zero.";
326 } 328 }
327 return current_ttl; 329 return current_ttl;
328 } 330 }
OLDNEW
« no previous file with comments | « cloud_print/gcp20/prototype/command_line_reader.cc ('k') | cloud_print/gcp20/prototype/gcp20_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698