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

Side by Side Diff: chrome/browser/local_discovery/service_discovery_host_client.h

Issue 23851008: Added cache flush on network change to ServiceDiscoveryHostClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_HOST_CLIENT_H_ 5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_HOST_CLIENT_H_
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_HOST_CLIENT_H_ 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_HOST_CLIENT_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/memory/singleton.h" 11 #include "base/memory/singleton.h"
12 #include "base/threading/non_thread_safe.h" 12 #include "base/threading/non_thread_safe.h"
13 #include "chrome/common/local_discovery/service_discovery_client.h" 13 #include "chrome/common/local_discovery/service_discovery_client.h"
14 #include "content/public/browser/utility_process_host_client.h" 14 #include "content/public/browser/utility_process_host_client.h"
15 #include "net/base/network_change_notifier.h"
15 16
16 namespace base { 17 namespace base {
17 class TaskRunner; 18 class TaskRunner;
18 } 19 }
19 20
20 namespace content { 21 namespace content {
21 class UtilityProcessHost; 22 class UtilityProcessHost;
22 } 23 }
23 24
24 namespace local_discovery { 25 namespace local_discovery {
25 26
26 // Implementation of ServiceDiscoveryClient that delegates all functionality to 27 // Implementation of ServiceDiscoveryClient that delegates all functionality to
27 // utility process. 28 // utility process.
28 class ServiceDiscoveryHostClient : public base::NonThreadSafe, 29 class ServiceDiscoveryHostClient
29 public ServiceDiscoveryClient, 30 : public base::NonThreadSafe,
30 public content::UtilityProcessHostClient { 31 public ServiceDiscoveryClient,
32 public content::UtilityProcessHostClient,
33 public net::NetworkChangeNotifier::IPAddressObserver {
31 public: 34 public:
32 ServiceDiscoveryHostClient(); 35 ServiceDiscoveryHostClient();
33 36
34 // Starts utility process with ServiceDiscoveryClient. 37 // Starts utility process with ServiceDiscoveryClient.
35 void Start(); 38 void Start();
36 39
37 // Shutdowns utility process. 40 // Shutdowns utility process.
38 void Shutdown(); 41 void Shutdown();
39 42
40 // ServiceDiscoveryClient implementation. 43 // ServiceDiscoveryClient implementation.
41 virtual scoped_ptr<ServiceWatcher> CreateServiceWatcher( 44 virtual scoped_ptr<ServiceWatcher> CreateServiceWatcher(
42 const std::string& service_type, 45 const std::string& service_type,
43 const ServiceWatcher::UpdatedCallback& callback) OVERRIDE; 46 const ServiceWatcher::UpdatedCallback& callback) OVERRIDE;
44 virtual scoped_ptr<ServiceResolver> CreateServiceResolver( 47 virtual scoped_ptr<ServiceResolver> CreateServiceResolver(
45 const std::string& service_name, 48 const std::string& service_name,
46 const ServiceResolver::ResolveCompleteCallback& callback) OVERRIDE; 49 const ServiceResolver::ResolveCompleteCallback& callback) OVERRIDE;
47 virtual scoped_ptr<LocalDomainResolver> CreateLocalDomainResolver( 50 virtual scoped_ptr<LocalDomainResolver> CreateLocalDomainResolver(
48 const std::string& domain, 51 const std::string& domain,
49 net::AddressFamily address_family, 52 net::AddressFamily address_family,
50 const LocalDomainResolver::IPAddressCallback& callback) OVERRIDE; 53 const LocalDomainResolver::IPAddressCallback& callback) OVERRIDE;
51 54
52 // UtilityProcessHostClient implementation. 55 // UtilityProcessHostClient implementation.
53 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 56 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
54 57
58 // net::NetworkChangeNotifier::IPAddressObserver implementation.
59 virtual void OnIPAddressChanged() OVERRIDE;
60
55 protected: 61 protected:
56 virtual ~ServiceDiscoveryHostClient(); 62 virtual ~ServiceDiscoveryHostClient();
57 63
58 private: 64 private:
59 class ServiceWatcherProxy; 65 class ServiceWatcherProxy;
60 class ServiceResolverProxy; 66 class ServiceResolverProxy;
61 class LocalDomainResolverProxy; 67 class LocalDomainResolverProxy;
62 68
63 typedef std::map<uint64, ServiceWatcher::UpdatedCallback> WatcherCallbacks; 69 typedef std::map<uint64, ServiceWatcherProxy*> WatcherProxies;
64 typedef std::map<uint64, ServiceResolver::ResolveCompleteCallback> 70 typedef std::map<uint64, ServiceResolverProxy*>
Vitaly Buka (NO REVIEWS) 2013/09/06 04:59:27 fits one line
65 ResolverCallbacks; 71 ResolverProxies;
66 typedef std::map<uint64, LocalDomainResolver::IPAddressCallback> 72 typedef std::map<uint64, LocalDomainResolverProxy*>
Vitaly Buka (NO REVIEWS) 2013/09/06 04:59:27 maybe fits one line
67 DomainResolverCallbacks; 73 DomainResolverProxies;
68 74
69 void StartOnIOThread(); 75 void StartOnIOThread();
70 void ShutdownOnIOThread(); 76 void ShutdownOnIOThread();
77 void RestartOnIOThread();
78
79 void StartUtilityProcess();
80 void ShutdownUtilityProcess();
71 81
72 void Send(IPC::Message* msg); 82 void Send(IPC::Message* msg);
73 void SendOnIOThread(IPC::Message* msg); 83 void SendOnIOThread(IPC::Message* msg);
74 84
75 uint64 RegisterWatcherCallback( 85 uint64 RegisterWatcherProxy(
76 const ServiceWatcher::UpdatedCallback& callback); 86 ServiceWatcherProxy* proxy);
77 uint64 RegisterResolverCallback( 87 uint64 RegisterResolverProxy(
Vitaly Buka (NO REVIEWS) 2013/09/06 04:59:27 same
78 const ServiceResolver::ResolveCompleteCallback& callback); 88 ServiceResolverProxy* proxy);
79 uint64 RegisterLocalDomainResolverCallback( 89 uint64 RegisterLocalDomainResolverProxy(
80 const LocalDomainResolver::IPAddressCallback& callback); 90 LocalDomainResolverProxy* proxy);
81 91
82 void UnregisterWatcherCallback(uint64 id); 92 void UnregisterWatcherProxy(uint64 id);
83 void UnregisterResolverCallback(uint64 id); 93 void UnregisterResolverProxy(uint64 id);
84 void UnregisterLocalDomainResolverCallback(uint64 id); 94 void UnregisterLocalDomainResolverProxy(uint64 id);
85 95
86 // IPC Message handlers. 96 // IPC Message handlers.
87 void OnWatcherCallback(uint64 id, 97 void OnWatcherCallback(uint64 id,
88 ServiceWatcher::UpdateType update, 98 ServiceWatcher::UpdateType update,
89 const std::string& service_name); 99 const std::string& service_name);
90 void OnResolverCallback(uint64 id, 100 void OnResolverCallback(uint64 id,
91 ServiceResolver::RequestStatus status, 101 ServiceResolver::RequestStatus status,
92 const ServiceDescription& description); 102 const ServiceDescription& description);
93 void OnLocalDomainResolverCallback(uint64 id, 103 void OnLocalDomainResolverCallback(uint64 id,
94 bool success, 104 bool success,
95 const net::IPAddressNumber& address_ipv4, 105 const net::IPAddressNumber& address_ipv4,
96 const net::IPAddressNumber& address_ipv6); 106 const net::IPAddressNumber& address_ipv6);
97 107
98 108
99 // Runs watcher callback on owning thread. 109 // Runs watcher callback on owning thread.
100 void RunWatcherCallback(uint64 id, 110 void RunWatcherCallback(uint64 id,
101 ServiceWatcher::UpdateType update, 111 ServiceWatcher::UpdateType update,
102 const std::string& service_name); 112 const std::string& service_name);
103 // Runs resolver callback on owning thread. 113 // Runs resolver callback on owning thread.
104 void RunResolverCallback(uint64 id, 114 void RunResolverCallback(uint64 id,
105 ServiceResolver::RequestStatus status, 115 ServiceResolver::RequestStatus status,
106 const ServiceDescription& description); 116 const ServiceDescription& description);
107 // Runs local domain resolver callback on owning thread. 117 // Runs local domain resolver callback on owning thread.
108 void RunLocalDomainResolverCallback(uint64 id, 118 void RunLocalDomainResolverCallback(uint64 id,
109 bool success, 119 bool success,
110 const net::IPAddressNumber& address_ipv4, 120 const net::IPAddressNumber& address_ipv4,
111 const net::IPAddressNumber& address_ipv6); 121 const net::IPAddressNumber& address_ipv6);
112 122
113
114 base::WeakPtr<content::UtilityProcessHost> utility_host_; 123 base::WeakPtr<content::UtilityProcessHost> utility_host_;
115 124
116 // Incrementing counter to assign ID to watchers and resolvers. 125 // Incrementing counter to assign ID to watchers and resolvers.
117 uint64 current_id_; 126 uint64 current_id_;
118 WatcherCallbacks service_watcher_callbacks_; 127 WatcherProxies service_watcher_proxies_;
119 ResolverCallbacks service_resolver_callbacks_; 128 ResolverProxies service_resolver_proxies_;
120 DomainResolverCallbacks domain_resolver_callbacks_; 129 DomainResolverProxies domain_resolver_proxies_;
121 scoped_refptr<base::TaskRunner> callback_runner_; 130 scoped_refptr<base::TaskRunner> callback_runner_;
122 131
123 DISALLOW_COPY_AND_ASSIGN(ServiceDiscoveryHostClient); 132 DISALLOW_COPY_AND_ASSIGN(ServiceDiscoveryHostClient);
124 }; 133 };
125 134
126 class ServiceDiscoveryHostClientFactory : public base::NonThreadSafe { 135 class ServiceDiscoveryHostClientFactory : public base::NonThreadSafe {
127 public: 136 public:
128 ServiceDiscoveryHostClientFactory(); 137 ServiceDiscoveryHostClientFactory();
129 ~ServiceDiscoveryHostClientFactory(); 138 ~ServiceDiscoveryHostClientFactory();
130 139
131 static ServiceDiscoveryHostClient* GetClient(); 140 static ServiceDiscoveryHostClient* GetClient();
132 static void ReleaseClient(); 141 static void ReleaseClient();
133 142
134 private: 143 private:
135 friend class Singleton<ServiceDiscoveryHostClientFactory>; 144 friend class Singleton<ServiceDiscoveryHostClientFactory>;
136 145
137 static ServiceDiscoveryHostClientFactory* GetInstance(); 146 static ServiceDiscoveryHostClientFactory* GetInstance();
138 147
139 ServiceDiscoveryHostClient* GetClientInternal(); 148 ServiceDiscoveryHostClient* GetClientInternal();
140 void ReleaseClientInternal(); 149 void ReleaseClientInternal();
141 150
142 scoped_refptr<ServiceDiscoveryHostClient> instance_; 151 scoped_refptr<ServiceDiscoveryHostClient> instance_;
143 int references_; 152 int references_;
144 }; 153 };
145 154
146 } // namespace local_discovery 155 } // namespace local_discovery
147 156
148 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_HOST_CLIENT_H_ 157 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_SERVICE_DISCOVERY_HOST_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698