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

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

Issue 23709010: Replace OnIPAddressChanged with OnNetworkChanged. (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
« no previous file with comments | « chrome/browser/local_discovery/service_discovery_host_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/local_discovery/service_discovery_host_client.h" 5 #include "chrome/browser/local_discovery/service_discovery_host_client.h"
6 6
7 #if defined(OS_POSIX) 7 #if defined(OS_POSIX)
8 #include "base/file_descriptor_posix.h" 8 #include "base/file_descriptor_posix.h"
9 #endif // OS_POSIX 9 #endif // OS_POSIX
10 10
11 #include "chrome/common/local_discovery/local_discovery_messages.h" 11 #include "chrome/common/local_discovery/local_discovery_messages.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/utility_process_host.h" 13 #include "content/public/browser/utility_process_host.h"
14 #include "net/socket/socket_descriptor.h" 14 #include "net/socket/socket_descriptor.h"
15 15
16 namespace local_discovery { 16 namespace local_discovery {
17 17
18 namespace {
19
20 void LogInterfaces() {
21 net::NetworkInterfaceList list;
22 net::GetNetworkList(&list);
23 std::string log;
24 for (net::NetworkInterfaceList::iterator it = list.begin(); it != list.end();
25 ++it) {
26 log += " " + net::IPAddressToString(it->address);
27 }
28 VLOG(1) << "Local addresses:" << log;
29 }
30
31 } // namespace
32
18 using content::BrowserThread; 33 using content::BrowserThread;
19 using content::UtilityProcessHost; 34 using content::UtilityProcessHost;
20 35
21 class ServiceDiscoveryHostClient::ServiceWatcherProxy : public ServiceWatcher { 36 class ServiceDiscoveryHostClient::ServiceWatcherProxy : public ServiceWatcher {
22 public: 37 public:
23 ServiceWatcherProxy(ServiceDiscoveryHostClient* host, 38 ServiceWatcherProxy(ServiceDiscoveryHostClient* host,
24 const std::string& service_type, 39 const std::string& service_type,
25 const ServiceWatcher::UpdatedCallback& callback) 40 const ServiceWatcher::UpdatedCallback& callback)
26 : host_(host), 41 : host_(host),
27 service_type_(service_type), 42 service_type_(service_type),
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 224 }
210 225
211 void ServiceDiscoveryHostClient::UnregisterLocalDomainResolverCallback( 226 void ServiceDiscoveryHostClient::UnregisterLocalDomainResolverCallback(
212 uint64 id) { 227 uint64 id) {
213 DCHECK(CalledOnValidThread()); 228 DCHECK(CalledOnValidThread());
214 domain_resolver_callbacks_.erase(id); 229 domain_resolver_callbacks_.erase(id);
215 } 230 }
216 231
217 void ServiceDiscoveryHostClient::Start() { 232 void ServiceDiscoveryHostClient::Start() {
218 DCHECK(CalledOnValidThread()); 233 DCHECK(CalledOnValidThread());
219 net::NetworkChangeNotifier::AddIPAddressObserver(this); 234 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
220 io_runner_->PostTask( 235 io_runner_->PostTask(
221 FROM_HERE, 236 FROM_HERE,
222 base::Bind(&ServiceDiscoveryHostClient::StartOnIOThread, this)); 237 base::Bind(&ServiceDiscoveryHostClient::StartOnIOThread, this));
223 } 238 }
224 239
225 void ServiceDiscoveryHostClient::Shutdown() { 240 void ServiceDiscoveryHostClient::Shutdown() {
226 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); 241 net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this);
227 DCHECK(CalledOnValidThread()); 242 DCHECK(CalledOnValidThread());
228 io_runner_->PostTask( 243 io_runner_->PostTask(
229 FROM_HERE, 244 FROM_HERE,
230 base::Bind(&ServiceDiscoveryHostClient::ShutdownOnIOThread, this)); 245 base::Bind(&ServiceDiscoveryHostClient::ShutdownOnIOThread, this));
231 } 246 }
232 247
233 void ServiceDiscoveryHostClient::StartOnIOThread() { 248 void ServiceDiscoveryHostClient::StartOnIOThread() {
234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
235 utility_host_ = UtilityProcessHost::Create( 250 utility_host_ = UtilityProcessHost::Create(
236 this, base::MessageLoopProxy::current().get())->AsWeakPtr(); 251 this, base::MessageLoopProxy::current().get())->AsWeakPtr();
(...skipping 20 matching lines...) Expand all
257 } 272 }
258 273
259 void ServiceDiscoveryHostClient::ShutdownOnIOThread() { 274 void ServiceDiscoveryHostClient::ShutdownOnIOThread() {
260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
261 if (utility_host_) { 276 if (utility_host_) {
262 utility_host_->Send(new LocalDiscoveryMsg_ShutdownLocalDiscovery); 277 utility_host_->Send(new LocalDiscoveryMsg_ShutdownLocalDiscovery);
263 utility_host_->EndBatchMode(); 278 utility_host_->EndBatchMode();
264 } 279 }
265 } 280 }
266 281
282 void ServiceDiscoveryHostClient::Restart() {
283 DCHECK(CalledOnValidThread());
284
285 VLOG(1) << "ServiceDiscoveryHostClient::Restart";
286 LogInterfaces();
287
288 io_runner_->PostTask(
289 FROM_HERE,
290 base::Bind(&ServiceDiscoveryHostClient::RestartOnIOThread, this));
291
292 WatcherCallbacks service_watcher_callbacks;
293 service_watcher_callbacks_.swap(service_watcher_callbacks);
294
295 for (WatcherCallbacks::iterator i = service_watcher_callbacks.begin();
296 i != service_watcher_callbacks.end(); i++) {
297 if (!i->second.is_null()) {
298 i->second.Run(ServiceWatcher::UPDATE_INVALIDATED, "");
299 }
300 }
301 }
302
267 void ServiceDiscoveryHostClient::RestartOnIOThread() { 303 void ServiceDiscoveryHostClient::RestartOnIOThread() {
268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
269 305
270 ShutdownOnIOThread(); 306 ShutdownOnIOThread();
271 StartOnIOThread(); 307 StartOnIOThread();
272 } 308 }
273 309
274 void ServiceDiscoveryHostClient::Send(IPC::Message* msg) { 310 void ServiceDiscoveryHostClient::Send(IPC::Message* msg) {
275 DCHECK(CalledOnValidThread()); 311 DCHECK(CalledOnValidThread());
276 io_runner_->PostTask( 312 io_runner_->PostTask(
277 FROM_HERE, 313 FROM_HERE,
278 base::Bind(&ServiceDiscoveryHostClient::SendOnIOThread, this, msg)); 314 base::Bind(&ServiceDiscoveryHostClient::SendOnIOThread, this, msg));
279 } 315 }
280 316
281 void ServiceDiscoveryHostClient::SendOnIOThread(IPC::Message* msg) { 317 void ServiceDiscoveryHostClient::SendOnIOThread(IPC::Message* msg) {
282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
283 if (utility_host_) 319 if (utility_host_)
284 utility_host_->Send(msg); 320 utility_host_->Send(msg);
285 } 321 }
286 322
287 void ServiceDiscoveryHostClient::OnIPAddressChanged() { 323 void ServiceDiscoveryHostClient::OnNetworkChanged(
288 io_runner_->PostTask( 324 net::NetworkChangeNotifier::ConnectionType type) {
325 VLOG(1) << "ServiceDiscoveryHostClient::OnNetworkChanged";
326 LogInterfaces();
327 callback_runner_->PostDelayedTask(
289 FROM_HERE, 328 FROM_HERE,
290 base::Bind(&ServiceDiscoveryHostClient::RestartOnIOThread, this)); 329 base::Bind(&ServiceDiscoveryHostClient::Restart, this),
291 330 base::TimeDelta::FromSeconds(10));
292 WatcherCallbacks service_watcher_callbacks;
293 service_watcher_callbacks_.swap(service_watcher_callbacks);
294
295 for (WatcherCallbacks::iterator i = service_watcher_callbacks.begin();
296 i != service_watcher_callbacks.end(); i++) {
297 if (!i->second.is_null()) {
298 i->second.Run(ServiceWatcher::UPDATE_INVALIDATED, "");
299 }
300 }
301 } 331 }
302 332
303 bool ServiceDiscoveryHostClient::OnMessageReceived( 333 bool ServiceDiscoveryHostClient::OnMessageReceived(
304 const IPC::Message& message) { 334 const IPC::Message& message) {
305 bool handled = true; 335 bool handled = true;
306 IPC_BEGIN_MESSAGE_MAP(ServiceDiscoveryHostClient, message) 336 IPC_BEGIN_MESSAGE_MAP(ServiceDiscoveryHostClient, message)
307 IPC_MESSAGE_HANDLER(LocalDiscoveryHostMsg_WatcherCallback, 337 IPC_MESSAGE_HANDLER(LocalDiscoveryHostMsg_WatcherCallback,
308 OnWatcherCallback) 338 OnWatcherCallback)
309 IPC_MESSAGE_HANDLER(LocalDiscoveryHostMsg_ResolverCallback, 339 IPC_MESSAGE_HANDLER(LocalDiscoveryHostMsg_ResolverCallback,
310 OnResolverCallback) 340 OnResolverCallback)
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 void ServiceDiscoveryHostClientFactory::ReleaseClientInternal() { 448 void ServiceDiscoveryHostClientFactory::ReleaseClientInternal() {
419 DCHECK(CalledOnValidThread()); 449 DCHECK(CalledOnValidThread());
420 references_--; 450 references_--;
421 if (references_ == 0) { 451 if (references_ == 0) {
422 instance_->Shutdown(); 452 instance_->Shutdown();
423 instance_ = NULL; 453 instance_ = NULL;
424 } 454 }
425 } 455 }
426 456
427 } // namespace local_discovery 457 } // namespace local_discovery
OLDNEW
« no previous file with comments | « chrome/browser/local_discovery/service_discovery_host_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698