From a5566938c4e9d644245e9bca37eeff2cdb3eb7f4 Mon Sep 17 00:00:00 2001 From: "vitalybuka@chromium.org" Date: Tue, 17 Jun 2014 18:07:39 +0000 Subject: [PATCH] Don't crash on device resolution failure. If resolution failed, callback receives empty pointer. BUG=385392 Review URL: https://codereview.chromium.org/333243007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277808 0039d316-1c4b-4281-b951-d872f2087c98 --- .../local_discovery/privet_local_printer_lister.cc | 16 +++++++++------- .../local_discovery/privet_local_printer_lister.h | 5 +++-- chrome/browser/local_discovery/privet_notifications.cc | 5 +++++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/chrome/browser/local_discovery/privet_local_printer_lister.cc b/chrome/browser/local_discovery/privet_local_printer_lister.cc index 2dc8fa9b6bd2..f9ffb43709fc 100644 --- a/chrome/browser/local_discovery/privet_local_printer_lister.cc +++ b/chrome/browser/local_discovery/privet_local_printer_lister.cc @@ -13,11 +13,7 @@ namespace local_discovery { struct PrivetLocalPrinterLister::DeviceContext { - public: - DeviceContext() { - } - - ~DeviceContext() { + DeviceContext() : has_local_printing(false) { } scoped_ptr privet_resolution; @@ -71,7 +67,7 @@ void PrivetLocalPrinterLister::DeviceChanged( name, description.address, base::Bind(&PrivetLocalPrinterLister::OnPrivetResolved, - base::Unretained(this))); + base::Unretained(this), name)); device_contexts_[name] = context; context->privet_resolution->Start(); @@ -84,7 +80,13 @@ void PrivetLocalPrinterLister::DeviceCacheFlushed() { } void PrivetLocalPrinterLister::OnPrivetResolved( + const std::string& name, scoped_ptr http_client) { + if (!http_client) { + // Remove device if we can't resolve it. + device_contexts_.erase(name); + return; + } DeviceContextMap::iterator i = device_contexts_.find(http_client->GetName()); DCHECK(i != device_contexts_.end()); @@ -99,7 +101,7 @@ void PrivetLocalPrinterLister::OnPrivetResolved( void PrivetLocalPrinterLister::OnPrivetInfoDone( DeviceContext* context, - std::string name, + const std::string& name, const base::DictionaryValue* json_value) { bool has_local_printing = false; const base::ListValue* api_list = NULL; diff --git a/chrome/browser/local_discovery/privet_local_printer_lister.h b/chrome/browser/local_discovery/privet_local_printer_lister.h index 0652671bc772..663320669b27 100644 --- a/chrome/browser/local_discovery/privet_local_printer_lister.h +++ b/chrome/browser/local_discovery/privet_local_printer_lister.h @@ -57,10 +57,11 @@ class PrivetLocalPrinterLister : PrivetDeviceLister::Delegate { typedef std::map > DeviceContextMap; void OnPrivetInfoDone(DeviceContext* context, - std::string name, + const std::string& name, const base::DictionaryValue* json_value); - void OnPrivetResolved(scoped_ptr http_client); + void OnPrivetResolved(const std::string& name, + scoped_ptr http_client); scoped_ptr privet_http_factory_; DeviceContextMap device_contexts_; diff --git a/chrome/browser/local_discovery/privet_notifications.cc b/chrome/browser/local_discovery/privet_notifications.cc index 4791199430d1..5a009cc0b0a6 100644 --- a/chrome/browser/local_discovery/privet_notifications.cc +++ b/chrome/browser/local_discovery/privet_notifications.cc @@ -117,6 +117,11 @@ void PrivetNotificationsListener::DeviceChanged( void PrivetNotificationsListener::CreateInfoOperation( scoped_ptr http_client) { + if (!http_client) { + // Do nothing if resolution fails. + return; + } + std::string name = http_client->GetName(); DeviceContextMap::iterator device_iter = devices_seen_.find(name); DCHECK(device_iter != devices_seen_.end()); -- 2.11.4.GIT