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 "base/profiler/scoped_profile.h" | 10 #include "base/profiler/scoped_profile.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
12 #include "chrome/common/extensions/api/mdns.h" | 12 #include "chrome/common/extensions/api/mdns.h" |
13 #include "extensions/browser/extension_registry.h" | |
13 | 14 |
14 namespace extensions { | 15 namespace extensions { |
15 | 16 |
16 namespace mdns = api::mdns; | 17 namespace mdns = api::mdns; |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 // Whitelisted mDNS service types. | 21 // Whitelisted mDNS service types. |
21 const char kCastServiceType[] = "_googlecast._tcp.local"; | 22 const char kCastServiceType[] = "_googlecast._tcp.local"; |
22 const char kPrivetServiceType[] = "_privet._tcp.local"; | 23 const char kPrivetServiceType[] = "_privet._tcp.local"; |
23 const char kTestServiceType[] = "_testing._tcp.local"; | 24 const char kTestServiceType[] = "_testing._tcp.local"; |
24 | 25 |
25 bool IsServiceTypeWhitelisted(const std::string& service_type) { | 26 bool IsServiceTypeWhitelisted(const std::string& service_type, |
27 bool is_extension) { | |
28 if (!is_extension) { | |
29 return true; | |
30 } | |
26 return service_type == kCastServiceType || | 31 return service_type == kCastServiceType || |
27 service_type == kPrivetServiceType || | 32 service_type == kPrivetServiceType || |
28 service_type == kTestServiceType; | 33 service_type == kTestServiceType; |
29 } | 34 } |
30 | 35 |
31 } // namespace | 36 } // namespace |
32 | 37 |
33 MDnsAPI::MDnsAPI(content::BrowserContext* context) : browser_context_(context) { | 38 MDnsAPI::MDnsAPI(content::BrowserContext* context) : browser_context_(context) { |
34 DCHECK(browser_context_); | 39 DCHECK(browser_context_); |
35 EventRouter::Get(context) | 40 EventRouter::Get(context) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 new_service_types.insert(filter_value); | 107 new_service_types.insert(filter_value); |
103 } | 108 } |
104 | 109 |
105 // Find all the added and removed service types since last update. | 110 // Find all the added and removed service types since last update. |
106 std::set<std::string> added_service_types = | 111 std::set<std::string> added_service_types = |
107 base::STLSetDifference<std::set<std::string> >( | 112 base::STLSetDifference<std::set<std::string> >( |
108 new_service_types, service_types_); | 113 new_service_types, service_types_); |
109 std::set<std::string> removed_service_types = | 114 std::set<std::string> removed_service_types = |
110 base::STLSetDifference<std::set<std::string> >( | 115 base::STLSetDifference<std::set<std::string> >( |
111 service_types_, new_service_types); | 116 service_types_, new_service_types); |
117 service_types_ = new_service_types; | |
112 | 118 |
113 // Update the registry. | 119 // Update the registry. |
114 DnsSdRegistry* registry = dns_sd_registry(); | 120 DnsSdRegistry* registry = dns_sd_registry(); |
121 | |
122 const extensions::ExtensionRegistry* ext_registry = | |
not at google - send to devlin
2014/11/17 23:22:15
This file is in the extensions namespace, no exten
Red Daly
2014/11/19 21:31:50
Done.
| |
123 extensions::ExtensionRegistry::Get(details.browser_context); | |
124 if (!ext_registry) { | |
not at google - send to devlin
2014/11/17 23:22:15
There should always be an ExtensionRegistry, since
Red Daly
2014/11/19 21:31:50
Done.
| |
125 return; | |
126 } | |
127 const extensions::Extension* extension = ext_registry->GetExtensionById( | |
not at google - send to devlin
2014/11/17 23:22:15
Why do you want all extensions, rather than just t
Red Daly
2014/11/19 21:31:50
I assumed the extension is enabled if UpdateMDnsLi
Red Daly
2015/01/26 21:55:33
I checked and this assumption was incorrect: This
| |
128 details.extension_id, | |
129 extensions::ExtensionRegistry::EVERYTHING); | |
130 if (!extension) { | |
131 return; | |
132 } | |
133 | |
115 for (std::set<std::string>::iterator it = added_service_types.begin(); | 134 for (std::set<std::string>::iterator it = added_service_types.begin(); |
116 it != added_service_types.end(); ++it) { | 135 it != added_service_types.end(); ++it) { |
117 if (IsServiceTypeWhitelisted(*it)) | 136 if (IsServiceTypeWhitelisted(*it, extension->is_extension())) |
not at google - send to devlin
2014/11/17 23:22:15
I don't understand what the fact that an Extension
Red Daly
2014/11/19 21:31:50
This change is in response to Mark's earlier comme
| |
118 registry->RegisterDnsSdListener(*it); | 137 registry->RegisterDnsSdListener(*it); |
119 } | 138 } |
120 for (std::set<std::string>::iterator it = removed_service_types.begin(); | 139 for (std::set<std::string>::iterator it = removed_service_types.begin(); |
121 it != removed_service_types.end(); ++it) { | 140 it != removed_service_types.end(); ++it) { |
122 if (IsServiceTypeWhitelisted(*it)) | 141 if (IsServiceTypeWhitelisted(*it, extension->is_extension())) |
123 registry->UnregisterDnsSdListener(*it); | 142 registry->UnregisterDnsSdListener(*it); |
124 } | 143 } |
125 | |
126 service_types_ = new_service_types; | |
127 } | 144 } |
128 | 145 |
129 void MDnsAPI::OnDnsSdEvent(const std::string& service_type, | 146 void MDnsAPI::OnDnsSdEvent(const std::string& service_type, |
130 const DnsSdRegistry::DnsSdServiceList& services) { | 147 const DnsSdRegistry::DnsSdServiceList& services) { |
131 DCHECK(thread_checker_.CalledOnValidThread()); | 148 DCHECK(thread_checker_.CalledOnValidThread()); |
132 | 149 |
133 std::vector<linked_ptr<mdns::MDnsService> > args; | 150 std::vector<linked_ptr<mdns::MDnsService> > args; |
134 for (DnsSdRegistry::DnsSdServiceList::const_iterator it = services.begin(); | 151 for (DnsSdRegistry::DnsSdServiceList::const_iterator it = services.begin(); |
135 it != services.end(); ++it) { | 152 it != services.end(); ++it) { |
136 linked_ptr<mdns::MDnsService> mdns_service = | 153 linked_ptr<mdns::MDnsService> mdns_service = |
(...skipping 12 matching lines...) Expand all Loading... | |
149 event->filter_info.SetServiceType(service_type); | 166 event->filter_info.SetServiceType(service_type); |
150 | 167 |
151 VLOG(1) << "Broadcasting OnServiceList event: " << event.get(); | 168 VLOG(1) << "Broadcasting OnServiceList event: " << event.get(); |
152 | 169 |
153 // TODO(justinlin): To avoid having listeners without filters getting all | 170 // TODO(justinlin): To avoid having listeners without filters getting all |
154 // events, modify API to have this event require filters. | 171 // events, modify API to have this event require filters. |
155 extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); | 172 extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); |
156 } | 173 } |
157 | 174 |
158 } // namespace extensions | 175 } // namespace extensions |
OLD | NEW |