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

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

Issue 1040773002: Limit number of service instances passed to onServiceList listeners. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change mdns.maxServiceInstancesPerEvent to mdns.MAX_SERVICE_INSTANCES_PER_EVENT, use StringPrintf Created 5 years, 9 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 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 2a7c41d210931d1540e61b8cb89fe402a203e1e8..d0cb7b6a71e1d55ffc54386ed78340449977c71c 100644
--- a/chrome/browser/extensions/api/mdns/mdns_api.cc
+++ b/chrome/browser/extensions/api/mdns/mdns_api.cc
@@ -9,7 +9,11 @@
#include "base/lazy_instance.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/common/extensions/api/mdns.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/render_view_host.h"
+#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_registry.h"
+#include "extensions/common/extension_messages.h"
namespace extensions {
@@ -140,6 +144,17 @@ void MDnsAPI::OnDnsSdEvent(const std::string& service_type,
std::vector<linked_ptr<mdns::MDnsService> > args;
for (DnsSdRegistry::DnsSdServiceList::const_iterator it = services.begin();
it != services.end(); ++it) {
+ if (static_cast<long>(args.size()) ==
+ api::mdns::MAX_SERVICE_INSTANCES_PER_EVENT) {
+ std::string msg(base::StringPrintf(
+ "Truncating service instances in onServiceList event to max: %d",
+ api::mdns::MAX_SERVICE_INSTANCES_PER_EVENT));
+ WriteToConsole(service_type,
+ content::CONSOLE_MESSAGE_LEVEL_WARNING,
+ msg);
+ VLOG(logging::LOG_WARNING) << msg;
+ break;
+ }
linked_ptr<mdns::MDnsService> mdns_service =
make_linked_ptr(new mdns::MDnsService);
mdns_service->service_name = (*it).service_name;
@@ -162,4 +177,53 @@ void MDnsAPI::OnDnsSdEvent(const std::string& service_type,
extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass());
}
+void MDnsAPI::WriteToConsole(const std::string& service_type,
+ content::ConsoleMessageLevel level,
+ const std::string& message) {
+ std::set<std::string> extension_ids;
+
+ // Check all listeners for service type filters.
not at google - send to devlin 2015/04/03 20:36:00 Much of this code does look very similar to what's
Red Daly 2015/04/03 21:12:22 Done.
+ for (const auto& listener :
+ extensions::EventRouter::Get(browser_context_)->listeners()
+ .GetEventListenersByName(mdns::OnServiceList::kEventName)) {
+ base::DictionaryValue* filter = (listener->filter());
+
+ std::string filter_value;
+ filter->GetStringASCII(kEventFilterServiceTypeKey, &filter_value);
+ if (filter_value.empty())
+ continue;
+
+ const Extension* extension = ExtensionRegistry::Get(browser_context_)->
+ enabled_extensions().GetByID(listener->extension_id());
+ // Don't listen for services associated only with disabled extensions.
+ if (!extension)
+ continue;
+
+ // Platform apps may query for all services; other types of extensions are
+ // restricted to a whitelist.
+ if (!extension->is_platform_app() &&
+ !IsServiceTypeWhitelisted(filter_value))
+ continue;
+
+ extension_ids.insert(listener->extension_id());
+ }
+
+ // Log to the consoles of the background pages of relevant listeners.
+ for (const std::string& extension_id : extension_ids) {
+ extensions::ExtensionHost* host =
+ extensions::ProcessManager::Get(browser_context_)
+ ->GetBackgroundHostForExtension(extension_id);
+ if (!host)
+ continue;
+ content::RenderProcessHost* rph = host->render_process_host();
+ content::RenderViewHost* rvh = host->render_view_host();
+ if (!rvh || !rph)
+ continue;
+ rph->Send(new ExtensionMsg_AddMessageToConsole(
+ rvh->GetRoutingID(),
not at google - send to devlin 2015/04/03 20:35:59 You should be able to send directly to the RenderV
Red Daly 2015/04/03 21:12:22 Done.
+ level,
+ message));
+ }
+}
+
} // namespace extensions
« 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