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" |
(...skipping 12 matching lines...) Expand all Loading... |
23 const char kTestServiceType[] = "_testing._tcp.local"; | 23 const char kTestServiceType[] = "_testing._tcp.local"; |
24 | 24 |
25 bool IsServiceTypeWhitelisted(const std::string& service_type) { | 25 bool IsServiceTypeWhitelisted(const std::string& service_type) { |
26 return service_type == kCastServiceType || | 26 return service_type == kCastServiceType || |
27 service_type == kPrivetServiceType || | 27 service_type == kPrivetServiceType || |
28 service_type == kTestServiceType; | 28 service_type == kTestServiceType; |
29 } | 29 } |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 MDnsAPI::MDnsAPI(Profile* profile) : profile_(profile) { | 33 MDnsAPI::MDnsAPI(content::BrowserContext* context) : browser_context_(context) { |
34 DCHECK(profile_); | 34 DCHECK(browser_context_); |
35 ExtensionSystem::Get(profile)->event_router()->RegisterObserver( | 35 ExtensionSystem::Get(context)->event_router()->RegisterObserver( |
36 this, mdns::OnServiceList::kEventName); | 36 this, mdns::OnServiceList::kEventName); |
37 } | 37 } |
38 | 38 |
39 MDnsAPI::~MDnsAPI() { | 39 MDnsAPI::~MDnsAPI() { |
40 if (dns_sd_registry_.get()) { | 40 if (dns_sd_registry_.get()) { |
41 dns_sd_registry_->RemoveObserver(this); | 41 dns_sd_registry_->RemoveObserver(this); |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 // static | 45 // static |
46 MDnsAPI* MDnsAPI::Get(Profile* profile) { | 46 MDnsAPI* MDnsAPI::Get(content::BrowserContext* context) { |
47 return ProfileKeyedAPIFactory<MDnsAPI>::GetForProfile(profile); | 47 return ProfileKeyedAPIFactory<MDnsAPI>::GetForProfile(context); |
48 } | 48 } |
49 | 49 |
50 static base::LazyInstance<ProfileKeyedAPIFactory<MDnsAPI> > g_factory = | 50 static base::LazyInstance<ProfileKeyedAPIFactory<MDnsAPI> > g_factory = |
51 LAZY_INSTANCE_INITIALIZER; | 51 LAZY_INSTANCE_INITIALIZER; |
52 | 52 |
53 // static | 53 // static |
54 ProfileKeyedAPIFactory<MDnsAPI>* MDnsAPI::GetFactoryInstance() { | 54 ProfileKeyedAPIFactory<MDnsAPI>* MDnsAPI::GetFactoryInstance() { |
55 return g_factory.Pointer(); | 55 return g_factory.Pointer(); |
56 } | 56 } |
57 | 57 |
(...skipping 19 matching lines...) Expand all Loading... |
77 void MDnsAPI::OnListenerRemoved(const EventListenerInfo& details) { | 77 void MDnsAPI::OnListenerRemoved(const EventListenerInfo& details) { |
78 DCHECK(thread_checker_.CalledOnValidThread()); | 78 DCHECK(thread_checker_.CalledOnValidThread()); |
79 UpdateMDnsListeners(details); | 79 UpdateMDnsListeners(details); |
80 } | 80 } |
81 | 81 |
82 void MDnsAPI::UpdateMDnsListeners(const EventListenerInfo& details) { | 82 void MDnsAPI::UpdateMDnsListeners(const EventListenerInfo& details) { |
83 std::set<std::string> new_service_types; | 83 std::set<std::string> new_service_types; |
84 | 84 |
85 // Check all listeners for service type filers. | 85 // Check all listeners for service type filers. |
86 const EventListenerMap::ListenerList& listeners = | 86 const EventListenerMap::ListenerList& listeners = |
87 extensions::ExtensionSystem::Get(profile_)->event_router()-> | 87 extensions::ExtensionSystem::Get(browser_context_) |
88 listeners().GetEventListenersByName(details.event_name); | 88 ->event_router() |
| 89 ->listeners() |
| 90 .GetEventListenersByName(details.event_name); |
89 for (EventListenerMap::ListenerList::const_iterator it = listeners.begin(); | 91 for (EventListenerMap::ListenerList::const_iterator it = listeners.begin(); |
90 it != listeners.end(); ++it) { | 92 it != listeners.end(); ++it) { |
91 base::DictionaryValue* filter = ((*it)->filter.get()); | 93 base::DictionaryValue* filter = ((*it)->filter.get()); |
92 | 94 |
93 std::string filter_value; | 95 std::string filter_value; |
94 filter->GetStringASCII(kEventFilterServiceTypeKey, &filter_value); | 96 filter->GetStringASCII(kEventFilterServiceTypeKey, &filter_value); |
95 if (filter_value.empty()) | 97 if (filter_value.empty()) |
96 continue; | 98 continue; |
97 new_service_types.insert(filter_value); | 99 new_service_types.insert(filter_value); |
98 } | 100 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 mdns_service->service_name = (*it).service_name; | 135 mdns_service->service_name = (*it).service_name; |
134 mdns_service->service_host_port = (*it).service_host_port; | 136 mdns_service->service_host_port = (*it).service_host_port; |
135 mdns_service->ip_address = (*it).ip_address; | 137 mdns_service->ip_address = (*it).ip_address; |
136 mdns_service->service_data = (*it).service_data; | 138 mdns_service->service_data = (*it).service_data; |
137 args.push_back(mdns_service); | 139 args.push_back(mdns_service); |
138 } | 140 } |
139 | 141 |
140 scoped_ptr<base::ListValue> results = mdns::OnServiceList::Create(args); | 142 scoped_ptr<base::ListValue> results = mdns::OnServiceList::Create(args); |
141 scoped_ptr<Event> event( | 143 scoped_ptr<Event> event( |
142 new Event(mdns::OnServiceList::kEventName, results.Pass())); | 144 new Event(mdns::OnServiceList::kEventName, results.Pass())); |
143 event->restrict_to_browser_context = profile_; | 145 event->restrict_to_browser_context = browser_context_; |
144 event->filter_info.SetServiceType(service_type); | 146 event->filter_info.SetServiceType(service_type); |
145 | 147 |
146 VLOG(1) << "Broadcasting OnServiceList event: " << event.get(); | 148 VLOG(1) << "Broadcasting OnServiceList event: " << event.get(); |
147 | 149 |
148 // TODO(justinlin): To avoid having listeners without filters getting all | 150 // TODO(justinlin): To avoid having listeners without filters getting all |
149 // events, modify API to have this event require filters. | 151 // events, modify API to have this event require filters. |
150 extensions::ExtensionSystem::Get(profile_)->event_router()-> | 152 extensions::ExtensionSystem::Get(browser_context_) |
151 BroadcastEvent(event.Pass()); | 153 ->event_router() |
| 154 ->BroadcastEvent(event.Pass()); |
152 } | 155 } |
153 | 156 |
154 } // namespace extensions | 157 } // namespace extensions |
OLD | NEW |