Commit 7facefc7 authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

Don't use a raw new for ProtocolHandlerRegistry::Delegate

Bug: 1021600
Change-Id: I8501d63d719194685281e27d85342e807e3794cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1895897
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: default avatarMartin Šrámek <msramek@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713261}
parent 7f74e1d2
......@@ -518,7 +518,7 @@ std::unique_ptr<KeyedService> BuildProtocolHandlerRegistry(
content::BrowserContext* context) {
Profile* profile = Profile::FromBrowserContext(context);
return std::make_unique<ProtocolHandlerRegistry>(
profile, new FakeProtocolHandlerRegistryDelegate());
profile, std::make_unique<FakeProtocolHandlerRegistryDelegate>());
}
class ClearDomainReliabilityTester {
......
......@@ -4,6 +4,8 @@
#include "chrome/browser/browsing_data/counters/site_settings_counter.h"
#include <memory>
#include "base/bind.h"
#include "base/containers/flat_set.h"
#include "base/test/simple_test_clock.h"
......@@ -81,7 +83,7 @@ class SiteSettingsCounterTest : public testing::Test {
zoom_map_ = nullptr;
#endif
handler_registry_ = std::make_unique<ProtocolHandlerRegistry>(
profile(), new TestProtocolHandlerRegistryDelegate());
profile(), std::make_unique<TestProtocolHandlerRegistryDelegate>());
counter_ = std::make_unique<SiteSettingsCounter>(
map(), zoom_map(), handler_registry(), profile_->GetPrefs());
......
......@@ -6,7 +6,6 @@
#include <stddef.h>
#include <memory>
#include <utility>
#include "base/bind.h"
......@@ -120,9 +119,9 @@ void ProtocolHandlerRegistry::Delegate::CheckDefaultClientWithOS(
ProtocolHandlerRegistry::ProtocolHandlerRegistry(
content::BrowserContext* context,
Delegate* delegate)
std::unique_ptr<Delegate> delegate)
: context_(context),
delegate_(delegate),
delegate_(std::move(delegate)),
enabled_(true),
is_loading_(false),
is_loaded_(false) {}
......
......@@ -62,8 +62,9 @@ class ProtocolHandlerRegistry : public KeyedService {
virtual void OnProtocolHandlerRegistryChanged() = 0;
};
// Creates a new instance. Assumes ownership of |delegate|.
ProtocolHandlerRegistry(content::BrowserContext* context, Delegate* delegate);
// Creates a new instance.
ProtocolHandlerRegistry(content::BrowserContext* context,
std::unique_ptr<Delegate> delegate);
~ProtocolHandlerRegistry() override;
void AddObserver(Observer* observer);
......
......@@ -4,6 +4,8 @@
#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
#include <memory>
#include "base/memory/singleton.h"
#include "build/build_config.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
......@@ -55,7 +57,7 @@ bool ProtocolHandlerRegistryFactory::ServiceIsNULLWhileTesting() const {
KeyedService* ProtocolHandlerRegistryFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
ProtocolHandlerRegistry* registry = new ProtocolHandlerRegistry(
context, new ProtocolHandlerRegistry::Delegate());
context, std::make_unique<ProtocolHandlerRegistry::Delegate>());
#if defined(OS_CHROMEOS)
// If installing defaults, they must be installed prior calling
......
......@@ -213,8 +213,10 @@ class ProtocolHandlerRegistryTest : public testing::Test {
// Returns a new registry, initializing it if |initialize| is true.
// Caller assumes ownership for the object
void SetUpRegistry(bool initialize) {
delegate_ = new FakeDelegate();
registry_.reset(new ProtocolHandlerRegistry(profile(), delegate()));
auto delegate = std::make_unique<FakeDelegate>();
delegate_ = delegate.get();
registry_.reset(
new ProtocolHandlerRegistry(profile(), std::move(delegate)));
if (initialize) registry_->InitProtocolSettings();
}
......
......@@ -869,7 +869,7 @@ class FakeDelegate : public ProtocolHandlerRegistry::Delegate {
};
TEST_F(ContentSettingBubbleModelTest, RPHAllow) {
ProtocolHandlerRegistry registry(profile(), new FakeDelegate());
ProtocolHandlerRegistry registry(profile(), std::make_unique<FakeDelegate>());
registry.InitProtocolSettings();
const GURL page_url("http://toplevel.example/");
......@@ -934,7 +934,7 @@ TEST_F(ContentSettingBubbleModelTest, RPHAllow) {
}
TEST_F(ContentSettingBubbleModelTest, RPHDefaultDone) {
ProtocolHandlerRegistry registry(profile(), new FakeDelegate());
ProtocolHandlerRegistry registry(profile(), std::make_unique<FakeDelegate>());
registry.InitProtocolSettings();
const GURL page_url("http://toplevel.example/");
......
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