Files
brave-core/browser/speedreader/speedreader_service_factory.h
T
cdesouza-chromium cbc844a561 BuildServiceInstanceFor => BuildServiceInstanceForBrowserContext (#25833)
This PR replaces the use of `BuildServiceInstanceFor` across brave, as
it has been deprecated, in favour of
`BuildServiceInstanceForBrowserContext`, which return a `unique_ptr`
rather than a naked pointer allocation.

Chromium change:
https://chromium.googlesource.com/chromium/src/+/6121e052e0373a9a0cc84a718ef73e68e3b8a628

commit 6121e052e0373a9a0cc84a718ef73e68e3b8a628
Author: Tom Sepez <tsepez@chromium.org>
Date:   Wed Dec 14 21:38:26 2022 +0000

    Rework BrowserContextKeyedServiceFactory::BuildServiceInstanceFor().

    Avoid releasing an unique_ptr<> only to re-insert the raw value back
    into a different one. Instead, maintain ownership at all times.

    This is done by overriding the form of BuildServiceInstanceFor() as declared by KeyedServiceFactory, rather than the form of declared by BrowserContextKeyedServiceFactory.

    Demonstrate one usage in page_colors_factor.cc as an example, before
    taking on the hundreds that remain.

    Bug: 1396138
2024-10-08 11:57:01 +01:00

57 lines
1.8 KiB
C++

/* Copyright (c) 2020 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef BRAVE_BROWSER_SPEEDREADER_SPEEDREADER_SERVICE_FACTORY_H_
#define BRAVE_BROWSER_SPEEDREADER_SPEEDREADER_SERVICE_FACTORY_H_
#include <memory>
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "components/keyed_service/core/keyed_service.h"
namespace content {
class BrowserContext;
}
namespace base {
template <typename T>
class NoDestructor;
} // namespace base
namespace speedreader {
class SpeedreaderService;
class SpeedreaderServiceFactory : public BrowserContextKeyedServiceFactory {
public:
static SpeedreaderServiceFactory* GetInstance();
static SpeedreaderService* GetForBrowserContext(
content::BrowserContext* browser_context);
private:
friend base::NoDestructor<SpeedreaderServiceFactory>;
SpeedreaderServiceFactory();
~SpeedreaderServiceFactory() override;
SpeedreaderServiceFactory(const SpeedreaderServiceFactory&) = delete;
SpeedreaderServiceFactory& operator=(const SpeedreaderServiceFactory&) =
delete;
// BrowserContextKeyedServiceFactory overrides:
// Speedreader works in OTR modes, but doesn't persists its pref changes
// to the parent profile. So we override this to use OTR browser contexts
// as-is.
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
std::unique_ptr<KeyedService> BuildServiceInstanceForBrowserContext(
content::BrowserContext* context) const override;
bool ServiceIsCreatedWithBrowserContext() const override;
};
} // namespace speedreader
#endif // BRAVE_BROWSER_SPEEDREADER_SPEEDREADER_SERVICE_FACTORY_H_