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

Side by Side Diff: chrome/browser/local_discovery/service_discovery_client_mac.mm

Issue 2445343005: Work around a macOS 10.12 bug involving objects with weak delegates (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « no previous file | 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_client_mac.h" 5 #include "chrome/browser/local_discovery/service_discovery_client_mac.h"
6 6
7 #import <arpa/inet.h> 7 #import <arpa/inet.h>
8 #import <Foundation/Foundation.h> 8 #import <Foundation/Foundation.h>
9 #import <net/if_dl.h> 9 #import <net/if_dl.h>
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 : service_type_(service_type), 179 : service_type_(service_type),
180 callback_(callback), 180 callback_(callback),
181 callback_runner_(base::ThreadTaskRunnerHandle::Get()), 181 callback_runner_(base::ThreadTaskRunnerHandle::Get()),
182 service_discovery_runner_(service_discovery_runner), 182 service_discovery_runner_(service_discovery_runner),
183 weak_factory_(this) { 183 weak_factory_(this) {
184 } 184 }
185 185
186 ServiceWatcherImplMac::NetServiceBrowserContainer:: 186 ServiceWatcherImplMac::NetServiceBrowserContainer::
187 ~NetServiceBrowserContainer() { 187 ~NetServiceBrowserContainer() {
188 DCHECK(IsOnServiceDiscoveryThread()); 188 DCHECK(IsOnServiceDiscoveryThread());
189
190 // Work around a 10.12 bug: NSNetServiceBrowser doesn't lose interest in its
191 // weak delegate during deallocation, so a subsequently-deallocated delegate
192 // attempts to clear the pointer to itself in an NSNetServiceBrowser that's
193 // already gone.
194 // https://crbug.com/657495, https://openradar.appspot.com/28943305
195 [browser_ setDelegate:nil];
189 } 196 }
190 197
191 void ServiceWatcherImplMac::NetServiceBrowserContainer::Start() { 198 void ServiceWatcherImplMac::NetServiceBrowserContainer::Start() {
192 service_discovery_runner_->PostTask( 199 service_discovery_runner_->PostTask(
193 FROM_HERE, 200 FROM_HERE,
194 base::Bind(&NetServiceBrowserContainer::StartOnDiscoveryThread, 201 base::Bind(&NetServiceBrowserContainer::StartOnDiscoveryThread,
195 weak_factory_.GetWeakPtr())); 202 weak_factory_.GetWeakPtr()));
196 } 203 }
197 204
198 void ServiceWatcherImplMac::NetServiceBrowserContainer::DiscoverNewServices() { 205 void ServiceWatcherImplMac::NetServiceBrowserContainer::DiscoverNewServices() {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 scoped_refptr<base::SingleThreadTaskRunner> service_discovery_runner) 299 scoped_refptr<base::SingleThreadTaskRunner> service_discovery_runner)
293 : service_name_(service_name), 300 : service_name_(service_name),
294 callback_(callback), 301 callback_(callback),
295 callback_runner_(base::ThreadTaskRunnerHandle::Get()), 302 callback_runner_(base::ThreadTaskRunnerHandle::Get()),
296 service_discovery_runner_(service_discovery_runner), 303 service_discovery_runner_(service_discovery_runner),
297 weak_factory_(this) { 304 weak_factory_(this) {
298 } 305 }
299 306
300 ServiceResolverImplMac::NetServiceContainer::~NetServiceContainer() { 307 ServiceResolverImplMac::NetServiceContainer::~NetServiceContainer() {
301 DCHECK(IsOnServiceDiscoveryThread()); 308 DCHECK(IsOnServiceDiscoveryThread());
309
310 // Work around a 10.12 bug: NSNetService doesn't lose interest in its weak
311 // delegate during deallocation, so a subsequently-deallocated delegate
312 // attempts to clear the pointer to itself in an NSNetService that's already
313 // gone.
314 // https://crbug.com/657495, https://openradar.appspot.com/28943305
315 [service_ setDelegate:nil];
302 } 316 }
303 317
304 void ServiceResolverImplMac::NetServiceContainer::StartResolving() { 318 void ServiceResolverImplMac::NetServiceContainer::StartResolving() {
305 service_discovery_runner_->PostTask( 319 service_discovery_runner_->PostTask(
306 FROM_HERE, 320 FROM_HERE,
307 base::Bind(&NetServiceContainer::StartResolvingOnDiscoveryThread, 321 base::Bind(&NetServiceContainer::StartResolvingOnDiscoveryThread,
308 weak_factory_.GetWeakPtr())); 322 weak_factory_.GetWeakPtr()));
309 } 323 }
310 324
311 void ServiceResolverImplMac::NetServiceContainer::DeleteSoon() { 325 void ServiceResolverImplMac::NetServiceContainer::DeleteSoon() {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 container_->OnResolveUpdate(local_discovery::ServiceResolver::STATUS_SUCCESS); 501 container_->OnResolveUpdate(local_discovery::ServiceResolver::STATUS_SUCCESS);
488 } 502 }
489 503
490 - (void)netService:(NSNetService*)sender 504 - (void)netService:(NSNetService*)sender
491 didNotResolve:(NSDictionary*)errorDict { 505 didNotResolve:(NSDictionary*)errorDict {
492 container_->OnResolveUpdate( 506 container_->OnResolveUpdate(
493 local_discovery::ServiceResolver::STATUS_REQUEST_TIMEOUT); 507 local_discovery::ServiceResolver::STATUS_REQUEST_TIMEOUT);
494 } 508 }
495 509
496 @end 510 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698