#ifndef CHROME_UTILITY_LOCAL_DISCOVERY_SERVICE_DISCOVERY_MESSAGE_HANDLER_H_
#define CHROME_UTILITY_LOCAL_DISCOVERY_SERVICE_DISCOVERY_MESSAGE_HANDLER_H_
#include <map>
#include <string>
#include "base/memory/linked_ptr.h"
#include "chrome/common/local_discovery/service_discovery_client.h"
#include "chrome/utility/utility_message_handler.h"
struct LocalDiscoveryMsg_SocketInfo;
namespace net {
class MDnsClient;
}
namespace base {
struct FileDescriptor;
class TaskRunner;
class Thread;
}
namespace tracked_objects {
class Location;
}
namespace local_discovery {
class ServiceDiscoveryClient;
class ServiceDiscoveryMessageHandler : public chrome::UtilityMessageHandler {
public:
ServiceDiscoveryMessageHandler();
virtual ~ServiceDiscoveryMessageHandler();
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
static void PreSandboxStartup();
private:
typedef std::map<uint64, linked_ptr<ServiceWatcher> > ServiceWatchers;
typedef std::map<uint64, linked_ptr<ServiceResolver> > ServiceResolvers;
typedef std::map<uint64, linked_ptr<LocalDomainResolver> >
LocalDomainResolvers;
bool InitializeThread();
void PostTask(const tracked_objects::Location& from_here,
const base::Closure& task);
#if defined(OS_POSIX)
void OnSetSockets(const std::vector<LocalDiscoveryMsg_SocketInfo>& sockets);
#endif
void OnStartWatcher(uint64 id, const std::string& service_type);
void OnDiscoverServices(uint64 id, bool force_update);
void OnSetActivelyRefreshServices(uint64 id, bool actively_refresh_services);
void OnDestroyWatcher(uint64 id);
void OnResolveService(uint64 id, const std::string& service_name);
void OnDestroyResolver(uint64 id);
void OnResolveLocalDomain(uint64 id, const std::string& domain,
net::AddressFamily address_family);
void OnDestroyLocalDomainResolver(uint64 id);
void InitializeMdns();
void StartWatcher(uint64 id, const std::string& service_type);
void DiscoverServices(uint64 id, bool force_update);
void SetActivelyRefreshServices(uint64 id, bool actively_refresh_services);
void DestroyWatcher(uint64 id);
void ResolveService(uint64 id, const std::string& service_name);
void DestroyResolver(uint64 id);
void ResolveLocalDomain(uint64 id, const std::string& domain,
net::AddressFamily address_family);
void DestroyLocalDomainResolver(uint64 id);
void ShutdownLocalDiscovery();
void ShutdownOnIOThread();
void OnServiceUpdated(uint64 id,
ServiceWatcher::UpdateType update,
const std::string& name);
void OnServiceResolved(uint64 id,
ServiceResolver::RequestStatus status,
const ServiceDescription& description);
void OnLocalDomainResolved(uint64 id,
bool success,
const net::IPAddressNumber& address_ipv4,
const net::IPAddressNumber& address_ipv6);
void Send(IPC::Message* msg);
ServiceWatchers service_watchers_;
ServiceResolvers service_resolvers_;
LocalDomainResolvers local_domain_resolvers_;
scoped_ptr<net::MDnsClient> mdns_client_;
scoped_ptr<ServiceDiscoveryClient> service_discovery_client_;
scoped_refptr<base::TaskRunner> utility_task_runner_;
scoped_refptr<base::TaskRunner> discovery_task_runner_;
scoped_ptr<base::Thread> discovery_thread_;
};
}
#endif