Commit fbaad662 authored by apisarev's avatar apisarev Committed by Commit bot

Store unique_ptr instead of raw poiter in extension callback map

There is callback map in extension function dispatcher, which store
pointers on callback wrappers. But it force to remember to delete
wrapper after erase from map. This may lead to memory leak.
To prevent it, raw pointer in map was replaced by unique_ptr (like in
other callback map in same class).

BUG=None
R=finnur

Review-Url: https://codereview.chromium.org/2850533002
Cr-Commit-Position: refs/heads/master@{#467932}
parent 03074588
...@@ -140,8 +140,6 @@ class ExtensionFunctionDispatcher::UIThreadResponseCallbackWrapper ...@@ -140,8 +140,6 @@ class ExtensionFunctionDispatcher::UIThreadResponseCallbackWrapper
dispatcher_->ui_thread_response_callback_wrappers_ dispatcher_->ui_thread_response_callback_wrappers_
.erase(render_frame_host); .erase(render_frame_host);
} }
delete this;
} }
ExtensionFunction::ResponseCallback CreateCallback(int request_id) { ExtensionFunction::ResponseCallback CreateCallback(int request_id) {
...@@ -370,9 +368,9 @@ void ExtensionFunctionDispatcher::Dispatch( ...@@ -370,9 +368,9 @@ void ExtensionFunctionDispatcher::Dispatch(
callback_wrapper = callback_wrapper =
new UIThreadResponseCallbackWrapper(AsWeakPtr(), render_frame_host); new UIThreadResponseCallbackWrapper(AsWeakPtr(), render_frame_host);
ui_thread_response_callback_wrappers_[render_frame_host] = ui_thread_response_callback_wrappers_[render_frame_host] =
callback_wrapper; base::WrapUnique(callback_wrapper);
} else { } else {
callback_wrapper = iter->second; callback_wrapper = iter->second.get();
} }
DispatchWithCallbackInternal( DispatchWithCallbackInternal(
params, render_frame_host, render_process_id, params, render_frame_host, render_process_id,
......
...@@ -169,7 +169,8 @@ class ExtensionFunctionDispatcher ...@@ -169,7 +169,8 @@ class ExtensionFunctionDispatcher
// This map doesn't own either the keys or the values. When a RenderFrameHost // This map doesn't own either the keys or the values. When a RenderFrameHost
// instance goes away, the corresponding entry in this map (if exists) will be // instance goes away, the corresponding entry in this map (if exists) will be
// removed. // removed.
typedef std::map<content::RenderFrameHost*, UIThreadResponseCallbackWrapper*> typedef std::map<content::RenderFrameHost*,
std::unique_ptr<UIThreadResponseCallbackWrapper>>
UIThreadResponseCallbackWrapperMap; UIThreadResponseCallbackWrapperMap;
UIThreadResponseCallbackWrapperMap ui_thread_response_callback_wrappers_; UIThreadResponseCallbackWrapperMap ui_thread_response_callback_wrappers_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment