diff options
author | robertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-13 18:30:18 +0000 |
---|---|---|
committer | robertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-13 18:30:18 +0000 |
commit | 038ca2215c278f9cc2642e71347229676c9367ae (patch) | |
tree | 23d1c09824e18078a9b5d95714042af65811e39c | |
parent | bd48735a97d0863c5ac560c76887ca48a4fe13b6 (diff) | |
download | chromium_src-038ca2215c278f9cc2642e71347229676c9367ae.zip chromium_src-038ca2215c278f9cc2642e71347229676c9367ae.tar.gz chromium_src-038ca2215c278f9cc2642e71347229676c9367ae.tar.bz2 |
Correcting a possible race between adding and removing automation resource message filters.
Review URL: http://codereview.chromium.org/165395
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23331 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/automation/automation_resource_message_filter.cc | 29 | ||||
-rw-r--r-- | chrome/browser/automation/automation_resource_message_filter.h | 5 |
2 files changed, 25 insertions, 9 deletions
diff --git a/chrome/browser/automation/automation_resource_message_filter.cc b/chrome/browser/automation/automation_resource_message_filter.cc index 46ee1e8..8404403 100644 --- a/chrome/browser/automation/automation_resource_message_filter.cc +++ b/chrome/browser/automation/automation_resource_message_filter.cc @@ -133,17 +133,32 @@ void AutomationResourceMessageFilter::UnRegisterRenderView( void AutomationResourceMessageFilter::RegisterRenderViewInIOThread( int renderer_pid, int renderer_id, int tab_handle, AutomationResourceMessageFilter* filter) { - DCHECK(filtered_render_views_.find(RendererId(renderer_pid, renderer_id)) == - filtered_render_views_.end()); - filtered_render_views_[RendererId(renderer_pid, renderer_id)] = - AutomationDetails(tab_handle, filter); + RenderViewMap::iterator automation_details_iter( + filtered_render_views_.find(RendererId(renderer_pid, renderer_id))); + if (automation_details_iter != filtered_render_views_.end()) { + DCHECK(automation_details_iter->second.ref_count > 0); + automation_details_iter->second.ref_count++; + } else { + filtered_render_views_[RendererId(renderer_pid, renderer_id)] = + AutomationDetails(tab_handle, filter); + } } void AutomationResourceMessageFilter::UnRegisterRenderViewInIOThread( int renderer_pid, int renderer_id) { - DCHECK(filtered_render_views_.find(RendererId(renderer_pid, renderer_id)) != - filtered_render_views_.end()); - filtered_render_views_.erase(RendererId(renderer_pid, renderer_id)); + RenderViewMap::iterator automation_details_iter( + filtered_render_views_.find(RendererId(renderer_pid, renderer_id))); + + if (automation_details_iter == filtered_render_views_.end()) { + NOTREACHED(); + return; + } + + automation_details_iter->second.ref_count--; + + if (automation_details_iter->second.ref_count <= 0) { + filtered_render_views_.erase(RendererId(renderer_pid, renderer_id)); + } } bool AutomationResourceMessageFilter::LookupRegisteredRenderView( diff --git a/chrome/browser/automation/automation_resource_message_filter.h b/chrome/browser/automation/automation_resource_message_filter.h index ebd6464..dd802e6 100644 --- a/chrome/browser/automation/automation_resource_message_filter.h +++ b/chrome/browser/automation/automation_resource_message_filter.h @@ -25,12 +25,13 @@ class AutomationResourceMessageFilter public: // Information needed to send IPCs through automation. struct AutomationDetails { - AutomationDetails() : tab_handle(0) {} + AutomationDetails() : tab_handle(0), ref_count(1) {} AutomationDetails(int tab, AutomationResourceMessageFilter* flt) - : tab_handle(tab), filter(flt) { + : tab_handle(tab), ref_count(1), filter(flt) { } int tab_handle; + int ref_count; scoped_refptr<AutomationResourceMessageFilter> filter; }; |