| Index: chrome/browser/extensions/api/mdns/mdns_service.h
|
| diff --git a/chrome/browser/extensions/api/mdns/mdns_service.h b/chrome/browser/extensions/api/mdns/mdns_service.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1421e1697ef9d7d454acb47e202dba2bb5352548
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/api/mdns/mdns_service.h
|
| @@ -0,0 +1,99 @@
|
| +// Copyright (c) 2013 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.
|
| +
|
| +#ifndef CHROME_BROWSER_EXTENSIONS_API_MDNS_MDNS_SERVICE_H_
|
| +#define CHROME_BROWSER_EXTENSIONS_API_MDNS_MDNS_SERVICE_H_
|
| +
|
| +#include <string>
|
| +
|
| +#include "base/basictypes.h"
|
| +#include "base/memory/linked_ptr.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +
|
| +#include "chrome/browser/local_discovery/service_discovery_host_client.h"
|
| +
|
| +// namespace local_discovery {
|
| +// class ServiceWatcher {
|
| +// enum UpdateType;
|
| +// }
|
| +// class ServiceDiscoveryClient;
|
| +// }
|
| +
|
| +namespace extensions {
|
| +
|
| +namespace api {
|
| +namespace mdns {
|
| +struct MDnsService;
|
| +}
|
| +}
|
| +
|
| +// Manages a watcher for a specific MDNS/DNS-SD service type and notifies
|
| +// a delegate of changes to watched services.
|
| +class MDnsService {
|
| + public:
|
| + // Delegate that is notified when a watched service is added, updated or
|
| + // removed.
|
| + class Delegate {
|
| + public:
|
| + virtual void ServiceAdded(const std::string& service_name,
|
| + const api::mdns::MDnsService& service) = 0;
|
| + virtual void ServiceUpdated(const std::string& service_name,
|
| + const api::mdns::MDnsService& service) = 0;
|
| + virtual void ServiceRemoved(const std::string& service_name) = 0;
|
| + };
|
| +
|
| + explicit MDnsService(const std::string& service_type,
|
| + MDnsService::Delegate *delegate);
|
| + ~MDnsService();
|
| +
|
| + // Starts the service watcher.
|
| + bool Start();
|
| +
|
| + // Stops the service watcher.
|
| + void Stop();
|
| +
|
| + // Requests that the service watcher issue an immediate query for services.
|
| + // force_update will first clear the service cache.
|
| + void Discover(bool force_update);
|
| +
|
| + const std::string& service_type();
|
| +
|
| + private:
|
| + typedef std::map<std::string, linked_ptr<local_discovery::ServiceResolver> >
|
| + ServiceResolverMap;
|
| +
|
| + // Invoked when the watcher notifies us of a service change.
|
| + void OnServiceUpdated(
|
| + local_discovery::ServiceWatcher::UpdateType update,
|
| + const std::string& service_name);
|
| +
|
| + void OnResolveComplete(
|
| + bool added,
|
| + local_discovery::ServiceResolver::RequestStatus status,
|
| + const local_discovery::ServiceDescription& description);
|
| +
|
| + // The service type that we are watching.
|
| + const std::string service_type_;
|
| +
|
| + // The delegate to notify of changes to services.
|
| + // TODO: I think this should be a reference.
|
| + MDnsService::Delegate * delegate_;
|
| +
|
| + // The instance of the service discovery client.
|
| + local_discovery::ServiceDiscoveryClient* service_discovery_client_;
|
| +
|
| + // The instance of the service watcher.
|
| + scoped_ptr<local_discovery::ServiceWatcher> service_watcher_;
|
| +
|
| + // True when the watcher is running.
|
| + bool running_;
|
| +
|
| + ServiceResolverMap resolvers_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(MDnsService);
|
| +};
|
| +
|
| +} // namespace extensions
|
| +
|
| +#endif // CHROME_BROWSER_EXTENSIONS_API_MDNS_MDNS_SERVICE_H_
|
|
|