Commit 0c5f58ab authored by Charlie Harrison's avatar Charlie Harrison Committed by Commit Bot

Use unique_ptrs for ContentSettingBubbleModels

Currently, these are created with bare `new`, until they are threaded
into the ContentSettingBubbleContents, where they are wrapped into a
unique_ptr.

This CL removes the bare new creation, so ownership passing is explicit.

Bug: None
Change-Id: Ieaecab0ecaa49ae0d732acb27615b6b2e328e167
Reviewed-on: https://chromium-review.googlesource.com/c/1333871Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Charlie Harrison <csharrison@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607691}
parent 801c71c5
...@@ -1650,46 +1650,48 @@ ContentSettingFramebustBlockBubbleModel::CreateListItem(const GURL& url) { ...@@ -1650,46 +1650,48 @@ ContentSettingFramebustBlockBubbleModel::CreateListItem(const GURL& url) {
const int ContentSettingBubbleModel::kAllowButtonIndex = 0; const int ContentSettingBubbleModel::kAllowButtonIndex = 0;
// static // static
ContentSettingBubbleModel* std::unique_ptr<ContentSettingBubbleModel>
ContentSettingBubbleModel::CreateContentSettingBubbleModel( ContentSettingBubbleModel::CreateContentSettingBubbleModel(
Delegate* delegate, Delegate* delegate,
WebContents* web_contents, WebContents* web_contents,
Profile* profile, Profile* profile,
ContentSettingsType content_type) { ContentSettingsType content_type) {
if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) { if (content_type == CONTENT_SETTINGS_TYPE_COOKIES) {
return new ContentSettingCookiesBubbleModel(delegate, web_contents, return std::make_unique<ContentSettingCookiesBubbleModel>(
profile); delegate, web_contents, profile);
} }
if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) { if (content_type == CONTENT_SETTINGS_TYPE_POPUPS) {
return new ContentSettingPopupBubbleModel(delegate, web_contents, profile); return std::make_unique<ContentSettingPopupBubbleModel>(
delegate, web_contents, profile);
} }
if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) {
return new ContentSettingDomainListBubbleModel(delegate, web_contents, return std::make_unique<ContentSettingDomainListBubbleModel>(
profile, content_type); delegate, web_contents, profile, content_type);
} }
if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) { if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) {
return new ContentSettingPluginBubbleModel(delegate, web_contents, profile); return std::make_unique<ContentSettingPluginBubbleModel>(
delegate, web_contents, profile);
} }
if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) { if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT) {
return new ContentSettingMixedScriptBubbleModel(delegate, web_contents, return std::make_unique<ContentSettingMixedScriptBubbleModel>(
profile); delegate, web_contents, profile);
} }
if (content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) { if (content_type == CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS) {
ProtocolHandlerRegistry* registry = ProtocolHandlerRegistry* registry =
ProtocolHandlerRegistryFactory::GetForBrowserContext(profile); ProtocolHandlerRegistryFactory::GetForBrowserContext(profile);
return new ContentSettingRPHBubbleModel(delegate, web_contents, profile, return std::make_unique<ContentSettingRPHBubbleModel>(
registry); delegate, web_contents, profile, registry);
} }
if (content_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { if (content_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) {
return new ContentSettingMidiSysExBubbleModel(delegate, web_contents, return std::make_unique<ContentSettingMidiSysExBubbleModel>(
profile); delegate, web_contents, profile);
} }
if (content_type == CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS) { if (content_type == CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS) {
return new ContentSettingDownloadsBubbleModel(delegate, web_contents, return std::make_unique<ContentSettingDownloadsBubbleModel>(
profile); delegate, web_contents, profile);
} }
if (content_type == CONTENT_SETTINGS_TYPE_ADS) { if (content_type == CONTENT_SETTINGS_TYPE_ADS) {
return new ContentSettingSubresourceFilterBubbleModel( return std::make_unique<ContentSettingSubresourceFilterBubbleModel>(
delegate, web_contents, profile); delegate, web_contents, profile);
} }
if (content_type == CONTENT_SETTINGS_TYPE_IMAGES || if (content_type == CONTENT_SETTINGS_TYPE_IMAGES ||
...@@ -1698,8 +1700,8 @@ ContentSettingBubbleModel* ...@@ -1698,8 +1700,8 @@ ContentSettingBubbleModel*
content_type == CONTENT_SETTINGS_TYPE_SOUND || content_type == CONTENT_SETTINGS_TYPE_SOUND ||
content_type == CONTENT_SETTINGS_TYPE_CLIPBOARD_READ || content_type == CONTENT_SETTINGS_TYPE_CLIPBOARD_READ ||
content_type == CONTENT_SETTINGS_TYPE_SENSORS) { content_type == CONTENT_SETTINGS_TYPE_SENSORS) {
return new ContentSettingSingleRadioGroup(delegate, web_contents, profile, return std::make_unique<ContentSettingSingleRadioGroup>(
content_type); delegate, web_contents, profile, content_type);
} }
NOTREACHED() << "No bubble for the content type " << content_type << "."; NOTREACHED() << "No bubble for the content type " << content_type << ".";
return nullptr; return nullptr;
......
...@@ -162,8 +162,8 @@ class ContentSettingBubbleModel : public content::NotificationObserver { ...@@ -162,8 +162,8 @@ class ContentSettingBubbleModel : public content::NotificationObserver {
// bubbles fit this description. // bubbles fit this description.
// TODO(msramek): Move this to ContentSettingSimpleBubbleModel or remove // TODO(msramek): Move this to ContentSettingSimpleBubbleModel or remove
// entirely. // entirely.
static ContentSettingBubbleModel* CreateContentSettingBubbleModel( static std::unique_ptr<ContentSettingBubbleModel>
Delegate* delegate, CreateContentSettingBubbleModel(Delegate* delegate,
content::WebContents* web_contents, content::WebContents* web_contents,
Profile* profile, Profile* profile,
ContentSettingsType content_type); ContentSettingsType content_type);
......
...@@ -119,9 +119,9 @@ TEST_F(ContentSettingBubbleModelTest, Cookies) { ...@@ -119,9 +119,9 @@ TEST_F(ContentSettingBubbleModelTest, Cookies) {
content_settings->ClearNavigationRelatedContentSettings(); content_settings->ClearNavigationRelatedContentSettings();
content_settings->OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES); content_settings->OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES);
content_setting_bubble_model.reset( content_setting_bubble_model =
ContentSettingBubbleModel::CreateContentSettingBubbleModel( ContentSettingBubbleModel::CreateContentSettingBubbleModel(
NULL, web_contents(), profile(), CONTENT_SETTINGS_TYPE_COOKIES)); NULL, web_contents(), profile(), CONTENT_SETTINGS_TYPE_COOKIES);
const ContentSettingBubbleModel::BubbleContent& bubble_content_2 = const ContentSettingBubbleModel::BubbleContent& bubble_content_2 =
content_setting_bubble_model->bubble_content(); content_setting_bubble_model->bubble_content();
...@@ -791,10 +791,9 @@ TEST_F(ContentSettingBubbleModelTest, PepperBroker) { ...@@ -791,10 +791,9 @@ TEST_F(ContentSettingBubbleModelTest, PepperBroker) {
content_settings content_settings
->ClearContentSettingsExceptForNavigationRelatedSettings(); ->ClearContentSettingsExceptForNavigationRelatedSettings();
content_settings->OnContentAllowed(CONTENT_SETTINGS_TYPE_PPAPI_BROKER); content_settings->OnContentAllowed(CONTENT_SETTINGS_TYPE_PPAPI_BROKER);
content_setting_bubble_model.reset( content_setting_bubble_model =
ContentSettingBubbleModel::CreateContentSettingBubbleModel( ContentSettingBubbleModel::CreateContentSettingBubbleModel(
NULL, web_contents(), profile(), NULL, web_contents(), profile(), CONTENT_SETTINGS_TYPE_PPAPI_BROKER);
CONTENT_SETTINGS_TYPE_PPAPI_BROKER));
const ContentSettingBubbleModel::BubbleContent& bubble_content_2 = const ContentSettingBubbleModel::BubbleContent& bubble_content_2 =
content_setting_bubble_model->bubble_content(); content_setting_bubble_model->bubble_content();
......
...@@ -124,7 +124,7 @@ class ContentSettingMediaImageModel : public ContentSettingImageModel { ...@@ -124,7 +124,7 @@ class ContentSettingMediaImageModel : public ContentSettingImageModel {
bool UpdateAndGetVisibility(WebContents* web_contents) override; bool UpdateAndGetVisibility(WebContents* web_contents) override;
ContentSettingBubbleModel* CreateBubbleModelImpl( std::unique_ptr<ContentSettingBubbleModel> CreateBubbleModelImpl(
ContentSettingBubbleModel::Delegate* delegate, ContentSettingBubbleModel::Delegate* delegate,
WebContents* web_contents, WebContents* web_contents,
Profile* profile) override; Profile* profile) override;
...@@ -212,7 +212,7 @@ ContentSettingSimpleImageModel::ContentSettingSimpleImageModel( ...@@ -212,7 +212,7 @@ ContentSettingSimpleImageModel::ContentSettingSimpleImageModel(
ContentSettingsType content_type) ContentSettingsType content_type)
: ContentSettingImageModel(image_type), content_type_(content_type) {} : ContentSettingImageModel(image_type), content_type_(content_type) {}
ContentSettingBubbleModel* std::unique_ptr<ContentSettingBubbleModel>
ContentSettingSimpleImageModel::CreateBubbleModelImpl( ContentSettingSimpleImageModel::CreateBubbleModelImpl(
ContentSettingBubbleModel::Delegate* delegate, ContentSettingBubbleModel::Delegate* delegate,
WebContents* web_contents, WebContents* web_contents,
...@@ -545,13 +545,13 @@ bool ContentSettingMediaImageModel::UpdateAndGetVisibility( ...@@ -545,13 +545,13 @@ bool ContentSettingMediaImageModel::UpdateAndGetVisibility(
return true; return true;
} }
ContentSettingBubbleModel* ContentSettingMediaImageModel::CreateBubbleModelImpl( std::unique_ptr<ContentSettingBubbleModel>
ContentSettingMediaImageModel::CreateBubbleModelImpl(
ContentSettingBubbleModel::Delegate* delegate, ContentSettingBubbleModel::Delegate* delegate,
WebContents* web_contents, WebContents* web_contents,
Profile* profile) { Profile* profile) {
return new ContentSettingMediaStreamBubbleModel(delegate, return std::make_unique<ContentSettingMediaStreamBubbleModel>(
web_contents, delegate, web_contents, profile);
profile);
} }
// Blocked Framebust ----------------------------------------------------------- // Blocked Framebust -----------------------------------------------------------
...@@ -570,13 +570,13 @@ bool ContentSettingFramebustBlockImageModel::UpdateAndGetVisibility( ...@@ -570,13 +570,13 @@ bool ContentSettingFramebustBlockImageModel::UpdateAndGetVisibility(
return true; return true;
} }
ContentSettingBubbleModel* std::unique_ptr<ContentSettingBubbleModel>
ContentSettingFramebustBlockImageModel::CreateBubbleModelImpl( ContentSettingFramebustBlockImageModel::CreateBubbleModelImpl(
ContentSettingBubbleModel::Delegate* delegate, ContentSettingBubbleModel::Delegate* delegate,
WebContents* web_contents, WebContents* web_contents,
Profile* profile) { Profile* profile) {
return new ContentSettingFramebustBlockBubbleModel(delegate, web_contents, return std::make_unique<ContentSettingFramebustBlockBubbleModel>(
profile); delegate, web_contents, profile);
} }
// Sensors --------------------------------------------------------------------- // Sensors ---------------------------------------------------------------------
...@@ -636,7 +636,8 @@ ContentSettingImageModel::ContentSettingImageModel(ImageType image_type) ...@@ -636,7 +636,8 @@ ContentSettingImageModel::ContentSettingImageModel(ImageType image_type)
explanatory_string_id_(0), explanatory_string_id_(0),
image_type_(image_type) {} image_type_(image_type) {}
ContentSettingBubbleModel* ContentSettingImageModel::CreateBubbleModel( std::unique_ptr<ContentSettingBubbleModel>
ContentSettingImageModel::CreateBubbleModel(
ContentSettingBubbleModel::Delegate* delegate, ContentSettingBubbleModel::Delegate* delegate,
content::WebContents* web_contents, content::WebContents* web_contents,
Profile* profile) { Profile* profile) {
......
...@@ -70,8 +70,7 @@ class ContentSettingImageModel { ...@@ -70,8 +70,7 @@ class ContentSettingImageModel {
void Update(content::WebContents* contents); void Update(content::WebContents* contents);
// Creates the model for the bubble that will be attached to this image. // Creates the model for the bubble that will be attached to this image.
// The bubble model is owned by the caller. std::unique_ptr<ContentSettingBubbleModel> CreateBubbleModel(
ContentSettingBubbleModel* CreateBubbleModel(
ContentSettingBubbleModel::Delegate* delegate, ContentSettingBubbleModel::Delegate* delegate,
content::WebContents* web_contents, content::WebContents* web_contents,
Profile* profile); Profile* profile);
...@@ -105,7 +104,7 @@ class ContentSettingImageModel { ...@@ -105,7 +104,7 @@ class ContentSettingImageModel {
virtual bool UpdateAndGetVisibility(content::WebContents* web_contents) = 0; virtual bool UpdateAndGetVisibility(content::WebContents* web_contents) = 0;
// Internal implementation by subclasses of bubble model creation. // Internal implementation by subclasses of bubble model creation.
virtual ContentSettingBubbleModel* CreateBubbleModelImpl( virtual std::unique_ptr<ContentSettingBubbleModel> CreateBubbleModelImpl(
ContentSettingBubbleModel::Delegate* delegate, ContentSettingBubbleModel::Delegate* delegate,
content::WebContents* web_contents, content::WebContents* web_contents,
Profile* profile) = 0; Profile* profile) = 0;
...@@ -139,7 +138,7 @@ class ContentSettingSimpleImageModel : public ContentSettingImageModel { ...@@ -139,7 +138,7 @@ class ContentSettingSimpleImageModel : public ContentSettingImageModel {
ContentSettingsType content_type); ContentSettingsType content_type);
// ContentSettingImageModel implementation. // ContentSettingImageModel implementation.
ContentSettingBubbleModel* CreateBubbleModelImpl( std::unique_ptr<ContentSettingBubbleModel> CreateBubbleModelImpl(
ContentSettingBubbleModel::Delegate* delegate, ContentSettingBubbleModel::Delegate* delegate,
content::WebContents* web_contents, content::WebContents* web_contents,
Profile* profile) override; Profile* profile) override;
...@@ -158,7 +157,7 @@ class ContentSettingFramebustBlockImageModel : public ContentSettingImageModel { ...@@ -158,7 +157,7 @@ class ContentSettingFramebustBlockImageModel : public ContentSettingImageModel {
bool UpdateAndGetVisibility(content::WebContents* web_contents) override; bool UpdateAndGetVisibility(content::WebContents* web_contents) override;
ContentSettingBubbleModel* CreateBubbleModelImpl( std::unique_ptr<ContentSettingBubbleModel> CreateBubbleModelImpl(
ContentSettingBubbleModel::Delegate* delegate, ContentSettingBubbleModel::Delegate* delegate,
content::WebContents* web_contents, content::WebContents* web_contents,
Profile* profile) override; Profile* profile) override;
......
...@@ -78,9 +78,7 @@ IN_PROC_BROWSER_TEST_F(ContentSettingImageModelBrowserTest, CreateBubbleModel) { ...@@ -78,9 +78,7 @@ IN_PROC_BROWSER_TEST_F(ContentSettingImageModelBrowserTest, CreateBubbleModel) {
std::vector<std::unique_ptr<ContentSettingImageModel>> models = std::vector<std::unique_ptr<ContentSettingImageModel>> models =
ContentSettingImageModel::GenerateContentSettingImageModels(); ContentSettingImageModel::GenerateContentSettingImageModels();
for (auto& model : models) { for (auto& model : models) {
EXPECT_TRUE(base::WrapUnique( EXPECT_TRUE(model->CreateBubbleModel(nullptr, web_contents, profile));
model->CreateBubbleModel(nullptr, web_contents, profile))
.get());
EXPECT_TRUE(image_types.insert(model->image_type()).second); EXPECT_TRUE(image_types.insert(model->image_type()).second);
} }
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/ui/views/content_setting_bubble_contents.h" #include "chrome/browser/ui/views/content_setting_bubble_contents.h"
#include <utility>
#include <vector> #include <vector>
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -359,13 +360,13 @@ void ContentSettingBubbleContents::ListItemContainer::AddRowToLayout( ...@@ -359,13 +360,13 @@ void ContentSettingBubbleContents::ListItemContainer::AddRowToLayout(
// ContentSettingBubbleContents ----------------------------------------------- // ContentSettingBubbleContents -----------------------------------------------
ContentSettingBubbleContents::ContentSettingBubbleContents( ContentSettingBubbleContents::ContentSettingBubbleContents(
ContentSettingBubbleModel* content_setting_bubble_model, std::unique_ptr<ContentSettingBubbleModel> content_setting_bubble_model,
content::WebContents* web_contents, content::WebContents* web_contents,
views::View* anchor_view, views::View* anchor_view,
views::BubbleBorder::Arrow arrow) views::BubbleBorder::Arrow arrow)
: content::WebContentsObserver(web_contents), : content::WebContentsObserver(web_contents),
BubbleDialogDelegateView(anchor_view, arrow), BubbleDialogDelegateView(anchor_view, arrow),
content_setting_bubble_model_(content_setting_bubble_model), content_setting_bubble_model_(std::move(content_setting_bubble_model)),
list_item_container_(nullptr), list_item_container_(nullptr),
custom_link_(nullptr), custom_link_(nullptr),
manage_button_(nullptr), manage_button_(nullptr),
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define CHROME_BROWSER_UI_VIEWS_CONTENT_SETTING_BUBBLE_CONTENTS_H_ #define CHROME_BROWSER_UI_VIEWS_CONTENT_SETTING_BUBBLE_CONTENTS_H_
#include <map> #include <map>
#include <memory>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/macros.h" #include "base/macros.h"
...@@ -43,7 +44,7 @@ class ContentSettingBubbleContents : public content::WebContentsObserver, ...@@ -43,7 +44,7 @@ class ContentSettingBubbleContents : public content::WebContentsObserver,
public ContentSettingBubbleModel::Owner { public ContentSettingBubbleModel::Owner {
public: public:
ContentSettingBubbleContents( ContentSettingBubbleContents(
ContentSettingBubbleModel* content_setting_bubble_model, std::unique_ptr<ContentSettingBubbleModel> content_setting_bubble_model,
content::WebContents* web_contents, content::WebContents* web_contents,
views::View* anchor_view, views::View* anchor_view,
views::BubbleBorder::Arrow arrow); views::BubbleBorder::Arrow arrow);
......
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