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

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

Issue 22870011: chrome.mdns API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: can listen Created 7 years, 4 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
new file mode 100644
index 0000000000000000000000000000000000000000..8410baaf824943b3431c29260eecfbb9c1780627
--- /dev/null
+++ b/chrome/browser/extensions/api/mdns/mdns_api.cc
@@ -0,0 +1,69 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/api/mdns/mdns_api.h"
+
+#include <vector>
+
+#include "base/time/time.h"
+#include "chrome/browser/extensions/api/mdns/mdns_api_factory.h"
+#include "chrome/browser/extensions/event_router.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/extensions/api/mdns.h"
+#include "chrome/common/extensions/api/mdns/mdns_manifest_handler.h"
+#include "content/public/browser/browser_thread.h"
+#include "extensions/common/manifest_constants.h"
+
+using base::TimeDelta;
+using content::BrowserThread;
+
+namespace extensions {
+
+namespace mdns = api::mdns;
+
+MDnsAPI::MDnsAPI(Profile* profile) : profile_(profile) {
+ ExtensionSystem::Get(profile)->event_router()->RegisterObserver(
mark a. foltz 2013/08/23 23:27:23 DCHECK(profile_)
justinlin 2013/08/27 00:09:25 Done.
+ this, mdns::OnServiceList::kEventName);
+}
+
+MDnsAPI::~MDnsAPI() {}
+
+NsdRegistry* MDnsAPI::nsd_registry() {
+ if (!nsd_registry_.get()) {
+ nsd_registry_.reset(new extensions::NsdRegistry());
+ }
+ return nsd_registry_.get();
+}
+
+void MDnsAPI::OnListenerAdded(const EventListenerInfo& details) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
mark a. foltz 2013/08/23 23:27:23 Use base::NonThreadSafe or base::TheadChecker inst
justinlin 2013/08/27 00:09:25 Done.
+ const extensions::Extension* extension = ExtensionSystem::Get(profile_)->
+ extension_service()->GetExtensionById(details.extension_id, false);
+ MDnsInfo* info = static_cast<MDnsInfo*>(
+ extension->GetManifestData(manifest_keys::kMDnsServiceTypes));
+ NsdRegistry* nsd_registry =
+ MDnsAPIFactory::GetForProfile(profile_)->nsd_registry();
+ for (std::vector<std::string>::iterator it = info->service_types.begin();
+ it != info->service_types.end(); ++it) {
+ LOG(ERROR) << "LISTENING FOR SERVICE TYPE " << *it;
+ nsd_registry->RegisterMDnsListener(*it);
mark a. foltz 2013/08/23 23:27:23 When an extension is unloaded or disabled, do we h
justinlin 2013/08/27 00:09:25 Done.
+ }
+}
+
+void MDnsAPI::OnListenerRemoved(const EventListenerInfo& details) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ // TODO(justinlin): Unregister.
+}
+
+void MDnsAPI::OnNsdEvent(const NsdRegistry::NsdDeviceList& devices) {
+
+}
+
+void MDnsAPI::OnNsdEvent(NsdRegistry::NsdErrorCode type) {
+
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698