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

Side by Side Diff: chrome/browser/extensions/api/mdns/mdns_api.cc

Issue 238633009: cleanup: Use EventRouter instead of ExtensionSystem::Get->event_router() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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 "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_system.h"
13 12
14 namespace extensions { 13 namespace extensions {
15 14
16 namespace mdns = api::mdns; 15 namespace mdns = api::mdns;
17 16
18 namespace { 17 namespace {
19 18
20 // Whitelisted mDNS service types. 19 // Whitelisted mDNS service types.
21 const char kCastServiceType[] = "_googlecast._tcp.local"; 20 const char kCastServiceType[] = "_googlecast._tcp.local";
22 const char kPrivetServiceType[] = "_privet._tcp.local"; 21 const char kPrivetServiceType[] = "_privet._tcp.local";
23 const char kTestServiceType[] = "_testing._tcp.local"; 22 const char kTestServiceType[] = "_testing._tcp.local";
24 23
25 bool IsServiceTypeWhitelisted(const std::string& service_type) { 24 bool IsServiceTypeWhitelisted(const std::string& service_type) {
26 return service_type == kCastServiceType || 25 return service_type == kCastServiceType ||
27 service_type == kPrivetServiceType || 26 service_type == kPrivetServiceType ||
28 service_type == kTestServiceType; 27 service_type == kTestServiceType;
29 } 28 }
30 29
31 } // namespace 30 } // namespace
32 31
33 MDnsAPI::MDnsAPI(content::BrowserContext* context) : browser_context_(context) { 32 MDnsAPI::MDnsAPI(content::BrowserContext* context) : browser_context_(context) {
34 DCHECK(browser_context_); 33 DCHECK(browser_context_);
35 ExtensionSystem::Get(context)->event_router()->RegisterObserver( 34 EventRouter::Get(context)
36 this, mdns::OnServiceList::kEventName); 35 ->RegisterObserver(this, mdns::OnServiceList::kEventName);
37 } 36 }
38 37
39 MDnsAPI::~MDnsAPI() { 38 MDnsAPI::~MDnsAPI() {
40 if (dns_sd_registry_.get()) { 39 if (dns_sd_registry_.get()) {
41 dns_sd_registry_->RemoveObserver(this); 40 dns_sd_registry_->RemoveObserver(this);
42 } 41 }
43 } 42 }
44 43
45 // static 44 // static
46 MDnsAPI* MDnsAPI::Get(content::BrowserContext* context) { 45 MDnsAPI* MDnsAPI::Get(content::BrowserContext* context) {
(...skipping 30 matching lines...) Expand all
77 void MDnsAPI::OnListenerRemoved(const EventListenerInfo& details) { 76 void MDnsAPI::OnListenerRemoved(const EventListenerInfo& details) {
78 DCHECK(thread_checker_.CalledOnValidThread()); 77 DCHECK(thread_checker_.CalledOnValidThread());
79 UpdateMDnsListeners(details); 78 UpdateMDnsListeners(details);
80 } 79 }
81 80
82 void MDnsAPI::UpdateMDnsListeners(const EventListenerInfo& details) { 81 void MDnsAPI::UpdateMDnsListeners(const EventListenerInfo& details) {
83 std::set<std::string> new_service_types; 82 std::set<std::string> new_service_types;
84 83
85 // Check all listeners for service type filers. 84 // Check all listeners for service type filers.
86 const EventListenerMap::ListenerList& listeners = 85 const EventListenerMap::ListenerList& listeners =
87 extensions::ExtensionSystem::Get(browser_context_) 86 extensions::EventRouter::Get(browser_context_)
88 ->event_router()
89 ->listeners() 87 ->listeners()
90 .GetEventListenersByName(details.event_name); 88 .GetEventListenersByName(details.event_name);
91 for (EventListenerMap::ListenerList::const_iterator it = listeners.begin(); 89 for (EventListenerMap::ListenerList::const_iterator it = listeners.begin();
92 it != listeners.end(); ++it) { 90 it != listeners.end(); ++it) {
93 base::DictionaryValue* filter = ((*it)->filter.get()); 91 base::DictionaryValue* filter = ((*it)->filter.get());
94 92
95 std::string filter_value; 93 std::string filter_value;
96 filter->GetStringASCII(kEventFilterServiceTypeKey, &filter_value); 94 filter->GetStringASCII(kEventFilterServiceTypeKey, &filter_value);
97 if (filter_value.empty()) 95 if (filter_value.empty())
98 continue; 96 continue;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 scoped_ptr<base::ListValue> results = mdns::OnServiceList::Create(args); 140 scoped_ptr<base::ListValue> results = mdns::OnServiceList::Create(args);
143 scoped_ptr<Event> event( 141 scoped_ptr<Event> event(
144 new Event(mdns::OnServiceList::kEventName, results.Pass())); 142 new Event(mdns::OnServiceList::kEventName, results.Pass()));
145 event->restrict_to_browser_context = browser_context_; 143 event->restrict_to_browser_context = browser_context_;
146 event->filter_info.SetServiceType(service_type); 144 event->filter_info.SetServiceType(service_type);
147 145
148 VLOG(1) << "Broadcasting OnServiceList event: " << event.get(); 146 VLOG(1) << "Broadcasting OnServiceList event: " << event.get();
149 147
150 // TODO(justinlin): To avoid having listeners without filters getting all 148 // TODO(justinlin): To avoid having listeners without filters getting all
151 // events, modify API to have this event require filters. 149 // events, modify API to have this event require filters.
152 extensions::ExtensionSystem::Get(browser_context_) 150 extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass());
153 ->event_router()
154 ->BroadcastEvent(event.Pass());
155 } 151 }
156 152
157 } // namespace extensions 153 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698