Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / utility / local_discovery / service_discovery_message_handler.h
blob722125f9931634aacd1209378bff5cf3db203e2c
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_UTILITY_LOCAL_DISCOVERY_SERVICE_DISCOVERY_MESSAGE_HANDLER_H_
6 #define CHROME_UTILITY_LOCAL_DISCOVERY_SERVICE_DISCOVERY_MESSAGE_HANDLER_H_
8 #include <map>
9 #include <string>
11 #include "base/memory/linked_ptr.h"
12 #include "chrome/common/local_discovery/service_discovery_client.h"
13 #include "chrome/utility/utility_message_handler.h"
15 struct LocalDiscoveryMsg_SocketInfo;
17 namespace net {
18 class MDnsClient;
21 namespace base {
22 struct FileDescriptor;
23 class TaskRunner;
24 class Thread;
27 namespace tracked_objects {
28 class Location;
31 namespace local_discovery {
33 class ServiceDiscoveryClient;
35 // Handles messages related to local discovery inside utility process.
36 class ServiceDiscoveryMessageHandler : public chrome::UtilityMessageHandler {
37 public:
38 ServiceDiscoveryMessageHandler();
39 virtual ~ServiceDiscoveryMessageHandler();
41 // UtilityMessageHandler implementation.
42 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
44 static void PreSandboxStartup();
46 private:
47 typedef std::map<uint64, linked_ptr<ServiceWatcher> > ServiceWatchers;
48 typedef std::map<uint64, linked_ptr<ServiceResolver> > ServiceResolvers;
49 typedef std::map<uint64, linked_ptr<LocalDomainResolver> >
50 LocalDomainResolvers;
52 // Lazy initializes ServiceDiscoveryClient.
53 bool InitializeThread();
54 void PostTask(const tracked_objects::Location& from_here,
55 const base::Closure& task);
57 // IPC message handlers.
58 #if defined(OS_POSIX)
59 void OnSetSockets(const std::vector<LocalDiscoveryMsg_SocketInfo>& sockets);
60 #endif // OS_POSIX
61 void OnStartWatcher(uint64 id, const std::string& service_type);
62 void OnDiscoverServices(uint64 id, bool force_update);
63 void OnDestroyWatcher(uint64 id);
64 void OnResolveService(uint64 id, const std::string& service_name);
65 void OnDestroyResolver(uint64 id);
66 void OnResolveLocalDomain(uint64 id, const std::string& domain,
67 net::AddressFamily address_family);
68 void OnDestroyLocalDomainResolver(uint64 id);
70 void InitializeMdns();
71 void StartWatcher(uint64 id, const std::string& service_type);
72 void DiscoverServices(uint64 id, bool force_update);
73 void DestroyWatcher(uint64 id);
74 void ResolveService(uint64 id, const std::string& service_name);
75 void DestroyResolver(uint64 id);
76 void ResolveLocalDomain(uint64 id, const std::string& domain,
77 net::AddressFamily address_family);
78 void DestroyLocalDomainResolver(uint64 id);
80 void ShutdownLocalDiscovery();
81 void ShutdownOnIOThread();
83 // Is called by ServiceWatcher as callback.
84 void OnServiceUpdated(uint64 id,
85 ServiceWatcher::UpdateType update,
86 const std::string& name);
88 // Is called by ServiceResolver as callback.
89 void OnServiceResolved(uint64 id,
90 ServiceResolver::RequestStatus status,
91 const ServiceDescription& description);
93 // Is called by LocalDomainResolver as callback.
94 void OnLocalDomainResolved(uint64 id,
95 bool success,
96 const net::IPAddressNumber& address_ipv4,
97 const net::IPAddressNumber& address_ipv6);
99 void Send(IPC::Message* msg);
101 ServiceWatchers service_watchers_;
102 ServiceResolvers service_resolvers_;
103 LocalDomainResolvers local_domain_resolvers_;
105 scoped_ptr<net::MDnsClient> mdns_client_;
106 scoped_ptr<ServiceDiscoveryClient> service_discovery_client_;
108 scoped_refptr<base::TaskRunner> utility_task_runner_;
109 scoped_refptr<base::TaskRunner> discovery_task_runner_;
110 scoped_ptr<base::Thread> discovery_thread_;
113 } // namespace local_discovery
115 #endif // CHROME_UTILITY_LOCAL_DISCOVERY_SERVICE_DISCOVERY_MESSAGE_HANDLER_H_