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 #include "chrome/browser/extensions/api/mdns/mdns_api.h" | 5 #include "chrome/browser/extensions/api/mdns/mdns_api.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/common/extensions/api/mdns.h" | 11 #include "chrome/common/extensions/api/mdns.h" |
12 #include "extensions/browser/extension_registry.h" | 12 #include "extensions/browser/extension_registry.h" |
13 | 13 |
14 namespace extensions { | 14 namespace extensions { |
15 | 15 |
16 namespace mdns = api::mdns; | 16 namespace mdns = api::mdns; |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // Whitelisted mDNS service types. | 20 // Whitelisted mDNS service types. |
21 const char kCastServiceType[] = "_googlecast._tcp.local"; | 21 const char kCastServiceType[] = "_googlecast._tcp.local"; |
22 const char kPrivetServiceType[] = "_privet._tcp.local"; | 22 const char kPrivetServiceType[] = "_privet._tcp.local"; |
23 const char kTestServiceType[] = "_testing._tcp.local"; | 23 const char kTestServiceType[] = "_testing._tcp.local"; |
24 | 24 |
25 // Maximum number of services that may be included in an onServiceList event | |
26 // as arguments. | |
27 const uint8 kMaxServicesPerOnServiceListEvent = 64; | |
not at google - send to devlin
2015/03/30 17:08:50
You can, and should, declare this constant in the
Red Daly
2015/03/31 19:23:50
I didn't find great support for constants in the I
| |
28 | |
25 bool IsServiceTypeWhitelisted(const std::string& service_type) { | 29 bool IsServiceTypeWhitelisted(const std::string& service_type) { |
26 return service_type == kCastServiceType || | 30 return service_type == kCastServiceType || |
27 service_type == kPrivetServiceType || | 31 service_type == kPrivetServiceType || |
28 service_type == kTestServiceType; | 32 service_type == kTestServiceType; |
29 } | 33 } |
30 | 34 |
31 } // namespace | 35 } // namespace |
32 | 36 |
33 MDnsAPI::MDnsAPI(content::BrowserContext* context) : browser_context_(context) { | 37 MDnsAPI::MDnsAPI(content::BrowserContext* context) : browser_context_(context) { |
34 DCHECK(browser_context_); | 38 DCHECK(browser_context_); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 } | 136 } |
133 service_types_ = new_service_types; | 137 service_types_ = new_service_types; |
134 } | 138 } |
135 | 139 |
136 void MDnsAPI::OnDnsSdEvent(const std::string& service_type, | 140 void MDnsAPI::OnDnsSdEvent(const std::string& service_type, |
137 const DnsSdRegistry::DnsSdServiceList& services) { | 141 const DnsSdRegistry::DnsSdServiceList& services) { |
138 DCHECK(thread_checker_.CalledOnValidThread()); | 142 DCHECK(thread_checker_.CalledOnValidThread()); |
139 | 143 |
140 std::vector<linked_ptr<mdns::MDnsService> > args; | 144 std::vector<linked_ptr<mdns::MDnsService> > args; |
141 for (DnsSdRegistry::DnsSdServiceList::const_iterator it = services.begin(); | 145 for (DnsSdRegistry::DnsSdServiceList::const_iterator it = services.begin(); |
142 it != services.end(); ++it) { | 146 it != services.end() && args.size() < kMaxServicesPerOnServiceListEvent; |
not at google - send to devlin
2015/03/30 17:08:50
It would be nice to warn the developer somehow if
mark a. foltz
2015/03/30 17:57:22
That would depend on the number of devices adverti
Red Daly
2015/03/31 19:23:50
I added a VLOG(1) message, which will help a devel
not at google - send to devlin
2015/04/01 20:25:58
JS console output is worth doing insofar as VLOG o
Red Daly
2015/04/02 22:25:21
I modified this to do JS console output but didn't
| |
147 ++it) { | |
143 linked_ptr<mdns::MDnsService> mdns_service = | 148 linked_ptr<mdns::MDnsService> mdns_service = |
144 make_linked_ptr(new mdns::MDnsService); | 149 make_linked_ptr(new mdns::MDnsService); |
145 mdns_service->service_name = (*it).service_name; | 150 mdns_service->service_name = (*it).service_name; |
146 mdns_service->service_host_port = (*it).service_host_port; | 151 mdns_service->service_host_port = (*it).service_host_port; |
147 mdns_service->ip_address = (*it).ip_address; | 152 mdns_service->ip_address = (*it).ip_address; |
148 mdns_service->service_data = (*it).service_data; | 153 mdns_service->service_data = (*it).service_data; |
149 args.push_back(mdns_service); | 154 args.push_back(mdns_service); |
150 } | 155 } |
151 | 156 |
152 scoped_ptr<base::ListValue> results = mdns::OnServiceList::Create(args); | 157 scoped_ptr<base::ListValue> results = mdns::OnServiceList::Create(args); |
153 scoped_ptr<Event> event( | 158 scoped_ptr<Event> event( |
154 new Event(mdns::OnServiceList::kEventName, results.Pass())); | 159 new Event(mdns::OnServiceList::kEventName, results.Pass())); |
155 event->restrict_to_browser_context = browser_context_; | 160 event->restrict_to_browser_context = browser_context_; |
156 event->filter_info.SetServiceType(service_type); | 161 event->filter_info.SetServiceType(service_type); |
157 | 162 |
158 // TODO(justinlin): To avoid having listeners without filters getting all | 163 // TODO(justinlin): To avoid having listeners without filters getting all |
159 // events, modify API to have this event require filters. | 164 // events, modify API to have this event require filters. |
160 // TODO(reddaly): If event isn't on whitelist, ensure it does not get | 165 // TODO(reddaly): If event isn't on whitelist, ensure it does not get |
161 // broadcast to extensions. | 166 // broadcast to extensions. |
162 extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); | 167 extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); |
163 } | 168 } |
164 | 169 |
165 } // namespace extensions | 170 } // namespace extensions |
OLD | NEW |