diff options
author | vabr <vabr@chromium.org> | 2015-11-18 07:46:04 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-18 15:47:05 +0000 |
commit | de2bfe79ad4380f685910a7bf33cba15d3442603 (patch) | |
tree | 479d37c5f6f97c6e46547302f4f453dda380ca2d /components/autofill | |
parent | 1c6c5dc9911b507ac286b25d8bcfe454357ea0bd (diff) | |
download | chromium_src-de2bfe79ad4380f685910a7bf33cba15d3442603.zip chromium_src-de2bfe79ad4380f685910a7bf33cba15d3442603.tar.gz chromium_src-de2bfe79ad4380f685910a7bf33cba15d3442603.tar.bz2 |
Switch ContentAutofillDriverFactory and ContentPasswordManagerDriverFactory to map<scoped_ptr>
Both the factories keep a map from RFH to drivers. This map should be a std::map of scoped_ptr instances.
BUG=557627
Review URL: https://codereview.chromium.org/1454063003
Cr-Commit-Position: refs/heads/master@{#360334}
Diffstat (limited to 'components/autofill')
-rw-r--r-- | components/autofill/content/browser/content_autofill_driver_factory.cc | 36 | ||||
-rw-r--r-- | components/autofill/content/browser/content_autofill_driver_factory.h | 6 |
2 files changed, 18 insertions, 24 deletions
diff --git a/components/autofill/content/browser/content_autofill_driver_factory.cc b/components/autofill/content/browser/content_autofill_driver_factory.cc index cf43a91..f8b1f80 100644 --- a/components/autofill/content/browser/content_autofill_driver_factory.cc +++ b/components/autofill/content/browser/content_autofill_driver_factory.cc @@ -52,20 +52,18 @@ ContentAutofillDriverFactory::ContentAutofillDriverFactory( app_locale_(app_locale), enable_download_manager_(enable_download_manager) { content::RenderFrameHost* main_frame = web_contents->GetMainFrame(); - if (main_frame->IsRenderFrameLive()) - CreateDriverForFrame(main_frame); + if (main_frame->IsRenderFrameLive()) { + frame_driver_map_[main_frame] = make_scoped_ptr(new ContentAutofillDriver( + main_frame, client_, app_locale_, enable_download_manager_)); + } } -ContentAutofillDriverFactory::~ContentAutofillDriverFactory() { - STLDeleteContainerPairSecondPointers(frame_driver_map_.begin(), - frame_driver_map_.end()); - frame_driver_map_.clear(); -} +ContentAutofillDriverFactory::~ContentAutofillDriverFactory() {} ContentAutofillDriver* ContentAutofillDriverFactory::DriverForFrame( content::RenderFrameHost* render_frame_host) { auto mapping = frame_driver_map_.find(render_frame_host); - return mapping == frame_driver_map_.end() ? nullptr : mapping->second; + return mapping == frame_driver_map_.end() ? nullptr : mapping->second.get(); } bool ContentAutofillDriverFactory::OnMessageReceived( @@ -76,22 +74,25 @@ bool ContentAutofillDriverFactory::OnMessageReceived( void ContentAutofillDriverFactory::RenderFrameCreated( content::RenderFrameHost* render_frame_host) { - // RenderFrameCreated is called more than once for the main frame. - if (!frame_driver_map_[render_frame_host]) - CreateDriverForFrame(render_frame_host); + auto insertion_result = + frame_driver_map_.insert(std::make_pair(render_frame_host, nullptr)); + // This is called twice for the main frame. + if (insertion_result.second) { // This was the first time. + insertion_result.first->second = make_scoped_ptr(new ContentAutofillDriver( + render_frame_host, client_, app_locale_, enable_download_manager_)); + } } void ContentAutofillDriverFactory::RenderFrameDeleted( content::RenderFrameHost* render_frame_host) { - delete frame_driver_map_[render_frame_host]; frame_driver_map_.erase(render_frame_host); } void ContentAutofillDriverFactory::DidNavigateAnyFrame( - content::RenderFrameHost* rfh, + content::RenderFrameHost* render_frame_host, const content::LoadCommittedDetails& details, const content::FrameNavigateParams& params) { - frame_driver_map_[rfh]->DidNavigateFrame(details, params); + frame_driver_map_[render_frame_host]->DidNavigateFrame(details, params); } void ContentAutofillDriverFactory::NavigationEntryCommitted( @@ -103,11 +104,4 @@ void ContentAutofillDriverFactory::WasHidden() { client_->HideAutofillPopup(); } -void ContentAutofillDriverFactory::CreateDriverForFrame( - content::RenderFrameHost* render_frame_host) { - DCHECK(!frame_driver_map_[render_frame_host]); - frame_driver_map_[render_frame_host] = new ContentAutofillDriver( - render_frame_host, client_, app_locale_, enable_download_manager_); -} - } // namespace autofill diff --git a/components/autofill/content/browser/content_autofill_driver_factory.h b/components/autofill/content/browser/content_autofill_driver_factory.h index c0b1aa1..12d36d6 100644 --- a/components/autofill/content/browser/content_autofill_driver_factory.h +++ b/components/autofill/content/browser/content_autofill_driver_factory.h @@ -5,6 +5,7 @@ #ifndef COMPONENTS_AUTOFILL_CONTENT_BROWSER_CONTENT_AUTOFILL_DRIVER_FACTORY_H_ #define COMPONENTS_AUTOFILL_CONTENT_BROWSER_CONTENT_AUTOFILL_DRIVER_FACTORY_H_ +#include <map> #include <string> #include "base/memory/scoped_ptr.h" @@ -68,13 +69,12 @@ class ContentAutofillDriverFactory : public content::WebContentsObserver, ~ContentAutofillDriverFactory() override; private: - void CreateDriverForFrame(content::RenderFrameHost* render_frame_host); - AutofillClient* client_; std::string app_locale_; AutofillManager::AutofillDownloadManagerState enable_download_manager_; - std::map<content::RenderFrameHost*, ContentAutofillDriver*> frame_driver_map_; + std::map<content::RenderFrameHost*, scoped_ptr<ContentAutofillDriver>> + frame_driver_map_; }; } // namespace autofill |