diff options
author | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-17 18:07:39 +0000 |
---|---|---|
committer | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-17 18:07:39 +0000 |
commit | a5566938c4e9d644245e9bca37eeff2cdb3eb7f4 (patch) | |
tree | 9ee34bf33dfd27fb72db5582b244284ce64bf242 | |
parent | 103b2f350efa34cac47f79c743dc640efca59f72 (diff) | |
download | chromium_src-a5566938c4e9d644245e9bca37eeff2cdb3eb7f4.zip chromium_src-a5566938c4e9d644245e9bca37eeff2cdb3eb7f4.tar.gz chromium_src-a5566938c4e9d644245e9bca37eeff2cdb3eb7f4.tar.bz2 |
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
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 2dc8fa9..f9ffb43 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<PrivetHTTPResolution> 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<PrivetHTTPClient> 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 0652671..6633206 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<std::string, linked_ptr<DeviceContext> > DeviceContextMap; void OnPrivetInfoDone(DeviceContext* context, - std::string name, + const std::string& name, const base::DictionaryValue* json_value); - void OnPrivetResolved(scoped_ptr<PrivetHTTPClient> http_client); + void OnPrivetResolved(const std::string& name, + scoped_ptr<PrivetHTTPClient> http_client); scoped_ptr<PrivetHTTPAsynchronousFactory> 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 4791199..5a009cc 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<PrivetHTTPClient> 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()); |