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