subresource_filter_profile_context_factory.cc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "weblayer/browser/subresource_filter_profile_context_factory.h"
  5. #include "base/no_destructor.h"
  6. #include "components/keyed_service/content/browser_context_dependency_manager.h"
  7. #include "components/keyed_service/core/keyed_service.h"
  8. #include "components/subresource_filter/content/browser/subresource_filter_profile_context.h"
  9. #include "weblayer/browser/host_content_settings_map_factory.h"
  10. namespace weblayer {
  11. // static
  12. subresource_filter::SubresourceFilterProfileContext*
  13. SubresourceFilterProfileContextFactory::GetForBrowserContext(
  14. content::BrowserContext* browser_context) {
  15. return static_cast<subresource_filter::SubresourceFilterProfileContext*>(
  16. GetInstance()->GetServiceForBrowserContext(browser_context,
  17. true /* create */));
  18. }
  19. // static
  20. SubresourceFilterProfileContextFactory*
  21. SubresourceFilterProfileContextFactory::GetInstance() {
  22. static base::NoDestructor<SubresourceFilterProfileContextFactory> factory;
  23. return factory.get();
  24. }
  25. SubresourceFilterProfileContextFactory::SubresourceFilterProfileContextFactory()
  26. : BrowserContextKeyedServiceFactory(
  27. "SubresourceFilterProfileContext",
  28. BrowserContextDependencyManager::GetInstance()) {
  29. DependsOn(HostContentSettingsMapFactory::GetInstance());
  30. }
  31. KeyedService* SubresourceFilterProfileContextFactory::BuildServiceInstanceFor(
  32. content::BrowserContext* context) const {
  33. auto* subresource_filter_profile_context =
  34. new subresource_filter::SubresourceFilterProfileContext(
  35. HostContentSettingsMapFactory::GetForBrowserContext(context));
  36. return subresource_filter_profile_context;
  37. }
  38. content::BrowserContext*
  39. SubresourceFilterProfileContextFactory::GetBrowserContextToUse(
  40. content::BrowserContext* context) const {
  41. return context;
  42. }
  43. } // namespace weblayer