Update CrOS OOBE throbber to MD throbber; delete old asset
[chromium-blink-merge.git] / chrome / utility / local_discovery / service_discovery_message_handler.h
blobb79681a8b794b817abace9e4371eb689f295b286
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 UtilityMessageHandler {
37 public:
38 ServiceDiscoveryMessageHandler();
39 ~ServiceDiscoveryMessageHandler() override;
41 // UtilityMessageHandler implementation.
42 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 OnSetActivelyRefreshServices(uint64 id, bool actively_refresh_services);
64 void OnDestroyWatcher(uint64 id);
65 void OnResolveService(uint64 id, const std::string& service_name);
66 void OnDestroyResolver(uint64 id);
67 void OnResolveLocalDomain(uint64 id, const std::string& domain,
68 net::AddressFamily address_family);
69 void OnDestroyLocalDomainResolver(uint64 id);
71 void InitializeMdns();
72 void StartWatcher(uint64 id, const std::string& service_type);
73 void DiscoverServices(uint64 id, bool force_update);
74 void SetActivelyRefreshServices(uint64 id, bool actively_refresh_services);
75 void DestroyWatcher(uint64 id);
76 void ResolveService(uint64 id, const std::string& service_name);
77 void DestroyResolver(uint64 id);
78 void ResolveLocalDomain(uint64 id, const std::string& domain,
79 net::AddressFamily address_family);
80 void DestroyLocalDomainResolver(uint64 id);
82 void ShutdownLocalDiscovery();
83 void ShutdownOnIOThread();
85 // Is called by ServiceWatcher as callback.
86 void OnServiceUpdated(uint64 id,
87 ServiceWatcher::UpdateType update,
88 const std::string& name);
90 // Is called by ServiceResolver as callback.
91 void OnServiceResolved(uint64 id,
92 ServiceResolver::RequestStatus status,
93 const ServiceDescription& description);
95 // Is called by LocalDomainResolver as callback.
96 void OnLocalDomainResolved(uint64 id,
97 bool success,
98 const net::IPAddressNumber& address_ipv4,
99 const net::IPAddressNumber& address_ipv6);
101 void Send(IPC::Message* msg);
103 ServiceWatchers service_watchers_;
104 ServiceResolvers service_resolvers_;
105 LocalDomainResolvers local_domain_resolvers_;
107 scoped_ptr<net::MDnsClient> mdns_client_;
108 scoped_ptr<ServiceDiscoveryClient> service_discovery_client_;
110 scoped_refptr<base::TaskRunner> utility_task_runner_;
111 scoped_refptr<base::TaskRunner> discovery_task_runner_;
112 scoped_ptr<base::Thread> discovery_thread_;
115 } // namespace local_discovery
117 #endif // CHROME_UTILITY_LOCAL_DISCOVERY_SERVICE_DISCOVERY_MESSAGE_HANDLER_H_