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

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

Issue 2876703002: [mDns] Move dns_sd_registry from extension/api/mdns to media/router/discovery/mdns (Closed)
Patch Set: rebase with master Created 3 years, 7 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 <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 18 matching lines...) Expand all
29 const char kTestServiceType[] = "_testing._tcp.local"; 29 const char kTestServiceType[] = "_testing._tcp.local";
30 30
31 bool IsServiceTypeWhitelisted(const std::string& service_type) { 31 bool IsServiceTypeWhitelisted(const std::string& service_type) {
32 return service_type == kCastServiceType || 32 return service_type == kCastServiceType ||
33 service_type == kPrivetServiceType || 33 service_type == kPrivetServiceType ||
34 service_type == kTestServiceType; 34 service_type == kTestServiceType;
35 } 35 }
36 36
37 } // namespace 37 } // namespace
38 38
39 using DnsSdRegistry = media_router::DnsSdRegistry;
40
39 MDnsAPI::MDnsAPI(content::BrowserContext* context) : browser_context_(context) { 41 MDnsAPI::MDnsAPI(content::BrowserContext* context) : browser_context_(context) {
40 DCHECK(browser_context_); 42 DCHECK(browser_context_);
41 extensions::EventRouter* event_router = EventRouter::Get(context); 43 extensions::EventRouter* event_router = EventRouter::Get(context);
42 DCHECK(event_router); 44 DCHECK(event_router);
43 event_router->RegisterObserver(this, mdns::OnServiceList::kEventName); 45 event_router->RegisterObserver(this, mdns::OnServiceList::kEventName);
44 } 46 }
45 47
46 MDnsAPI::~MDnsAPI() { 48 MDnsAPI::~MDnsAPI() {
47 if (dns_sd_registry_.get()) { 49 if (dns_sd_registry_.get()) {
48 dns_sd_registry_->RemoveObserver(this); 50 dns_sd_registry_->RemoveObserver(this);
(...skipping 23 matching lines...) Expand all
72 74
73 void MDnsAPI::ForceDiscovery() { 75 void MDnsAPI::ForceDiscovery() {
74 DCHECK(thread_checker_.CalledOnValidThread()); 76 DCHECK(thread_checker_.CalledOnValidThread());
75 DnsSdRegistry* registry = dns_sd_registry(); 77 DnsSdRegistry* registry = dns_sd_registry();
76 return registry->ForceDiscovery(); 78 return registry->ForceDiscovery();
77 } 79 }
78 80
79 DnsSdRegistry* MDnsAPI::dns_sd_registry() { 81 DnsSdRegistry* MDnsAPI::dns_sd_registry() {
80 DCHECK(thread_checker_.CalledOnValidThread()); 82 DCHECK(thread_checker_.CalledOnValidThread());
81 if (!dns_sd_registry_.get()) { 83 if (!dns_sd_registry_.get()) {
82 dns_sd_registry_.reset(new extensions::DnsSdRegistry()); 84 dns_sd_registry_.reset(new media_router::DnsSdRegistry());
83 dns_sd_registry_->AddObserver(this); 85 dns_sd_registry_->AddObserver(this);
84 } 86 }
85 return dns_sd_registry_.get(); 87 return dns_sd_registry_.get();
86 } 88 }
87 89
88 void MDnsAPI::OnListenerAdded(const EventListenerInfo& details) { 90 void MDnsAPI::OnListenerAdded(const EventListenerInfo& details) {
89 DCHECK(thread_checker_.CalledOnValidThread()); 91 DCHECK(thread_checker_.CalledOnValidThread());
90 UpdateMDnsListeners(); 92 UpdateMDnsListeners();
91 } 93 }
92 94
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 141 }
140 } 142 }
141 prev_service_counts_.swap(current_service_counts); 143 prev_service_counts_.swap(current_service_counts);
142 } 144 }
143 145
144 void MDnsAPI::OnDnsSdEvent(const std::string& service_type, 146 void MDnsAPI::OnDnsSdEvent(const std::string& service_type,
145 const DnsSdRegistry::DnsSdServiceList& services) { 147 const DnsSdRegistry::DnsSdServiceList& services) {
146 DCHECK(thread_checker_.CalledOnValidThread()); 148 DCHECK(thread_checker_.CalledOnValidThread());
147 149
148 std::vector<mdns::MDnsService> args; 150 std::vector<mdns::MDnsService> args;
149 for (const DnsSdService& service : services) { 151 for (const auto& service : services) {
150 if (static_cast<int>(args.size()) == 152 if (static_cast<int>(args.size()) ==
151 api::mdns::MAX_SERVICE_INSTANCES_PER_EVENT) { 153 api::mdns::MAX_SERVICE_INSTANCES_PER_EVENT) {
152 // TODO(reddaly): This is not the most meaningful way of notifying the 154 // TODO(reddaly): This is not the most meaningful way of notifying the
153 // application that something bad happened. It will go to the user's 155 // application that something bad happened. It will go to the user's
154 // console (which most users don't look at)and the developer will be none 156 // console (which most users don't look at)and the developer will be none
155 // the wiser. Instead, changing the event to pass the number of 157 // the wiser. Instead, changing the event to pass the number of
156 // discovered instances would allow the caller to know when the list is 158 // discovered instances would allow the caller to know when the list is
157 // truncated and tell the user something meaningful in the extension/app. 159 // truncated and tell the user something meaningful in the extension/app.
158 WriteToConsole(service_type, 160 WriteToConsole(service_type,
159 content::CONSOLE_MESSAGE_LEVEL_WARNING, 161 content::CONSOLE_MESSAGE_LEVEL_WARNING,
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 AsyncApiFunction::ResponseAction MdnsForceDiscoveryFunction::Run() { 269 AsyncApiFunction::ResponseAction MdnsForceDiscoveryFunction::Run() {
268 MDnsAPI* api = MDnsAPI::Get(browser_context()); 270 MDnsAPI* api = MDnsAPI::Get(browser_context());
269 if (!api) { 271 if (!api) {
270 return RespondNow(Error("Unknown error.")); 272 return RespondNow(Error("Unknown error."));
271 } 273 }
272 api->ForceDiscovery(); 274 api->ForceDiscovery();
273 return RespondNow(NoArguments()); 275 return RespondNow(NoArguments());
274 } 276 }
275 277
276 } // namespace extensions 278 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/mdns/mdns_api.h ('k') | chrome/browser/extensions/api/mdns/mdns_api_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698