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

Unified Diff: chrome/browser/extensions/api/mdns/mdns_api.cc

Issue 668983003: Enable chrome.mdns for Chrome Apps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reinstate mdns service type whitelist for extensions and fix formatting. Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/mdns/mdns_api.cc
diff --git a/chrome/browser/extensions/api/mdns/mdns_api.cc b/chrome/browser/extensions/api/mdns/mdns_api.cc
index 572ae1eec7b08e50906f96f94aeda0314b75d1c0..d27c448bca168a0a37a171f91f9abcf5deb2fde0 100644
--- a/chrome/browser/extensions/api/mdns/mdns_api.cc
+++ b/chrome/browser/extensions/api/mdns/mdns_api.cc
@@ -10,6 +10,7 @@
#include "base/profiler/scoped_profile.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/common/extensions/api/mdns.h"
+#include "extensions/browser/extension_registry.h"
namespace extensions {
@@ -22,7 +23,11 @@ const char kCastServiceType[] = "_googlecast._tcp.local";
const char kPrivetServiceType[] = "_privet._tcp.local";
const char kTestServiceType[] = "_testing._tcp.local";
-bool IsServiceTypeWhitelisted(const std::string& service_type) {
+bool IsServiceTypeWhitelisted(const std::string& service_type,
+ bool is_extension) {
+ if (!is_extension) {
+ return true;
+ }
return service_type == kCastServiceType ||
service_type == kPrivetServiceType ||
service_type == kTestServiceType;
@@ -109,21 +114,33 @@ void MDnsAPI::UpdateMDnsListeners(const EventListenerInfo& details) {
std::set<std::string> removed_service_types =
base::STLSetDifference<std::set<std::string> >(
service_types_, new_service_types);
+ service_types_ = new_service_types;
// Update the registry.
DnsSdRegistry* registry = dns_sd_registry();
+
+ 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.
+ extensions::ExtensionRegistry::Get(details.browser_context);
+ 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.
+ return;
+ }
+ 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
+ details.extension_id,
+ extensions::ExtensionRegistry::EVERYTHING);
+ if (!extension) {
+ return;
+ }
+
for (std::set<std::string>::iterator it = added_service_types.begin();
it != added_service_types.end(); ++it) {
- if (IsServiceTypeWhitelisted(*it))
+ 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
registry->RegisterDnsSdListener(*it);
}
for (std::set<std::string>::iterator it = removed_service_types.begin();
it != removed_service_types.end(); ++it) {
- if (IsServiceTypeWhitelisted(*it))
+ if (IsServiceTypeWhitelisted(*it, extension->is_extension()))
registry->UnregisterDnsSdListener(*it);
}
-
- service_types_ = new_service_types;
}
void MDnsAPI::OnDnsSdEvent(const std::string& service_type,

Powered by Google App Engine
This is Rietveld 408576698