File: chrome_extension_system_factory.cc

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (139 lines) | stat: -rw-r--r-- 5,529 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/extensions/chrome_extension_system_factory.h"

#include "chrome/browser/extensions/blocklist_factory.h"
#include "chrome/browser/extensions/extension_management.h"
#include "chrome/browser/extensions/forced_extensions/install_stage_tracker_factory.h"
#include "chrome/browser/extensions/install_verifier_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "extensions/browser/event_router_factory.h"
#include "extensions/browser/extension_host_registry.h"
#include "extensions/browser/extension_prefs_factory.h"
#include "extensions/browser/extension_registry_factory.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extensions_browser_client.h"
#include "extensions/browser/process_manager_factory.h"
#include "extensions/browser/renderer_startup_helper.h"

#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "chrome/browser/ui/global_error/global_error_service_factory.h"
#endif

namespace extensions {

// ChromeExtensionSystemSharedFactory

// static
ChromeExtensionSystem::Shared*
ChromeExtensionSystemSharedFactory::GetForBrowserContext(
    content::BrowserContext* context) {
  return static_cast<ChromeExtensionSystem::Shared*>(
      GetInstance()->GetServiceForBrowserContext(context, true));
}

// static
ChromeExtensionSystemSharedFactory*
ChromeExtensionSystemSharedFactory::GetInstance() {
  static base::NoDestructor<ChromeExtensionSystemSharedFactory> instance;
  return instance.get();
}

ChromeExtensionSystemSharedFactory::ChromeExtensionSystemSharedFactory()
    : ProfileKeyedServiceFactory(
          "ExtensionSystemShared",
          ProfileSelections::Builder()
              .WithRegular(ProfileSelection::kRedirectedToOriginal)
              // TODO(crbug.com/40257657): Audit whether these should be
              // redirected or should have their own instance.
              .WithGuest(ProfileSelection::kRedirectedToOriginal)
              // TODO(crbug.com/41488885): Check if this service is needed for
              // Ash Internals.
              .WithAshInternals(ProfileSelection::kRedirectedToOriginal)
              .Build()) {
  DependsOn(ExtensionPrefsFactory::GetInstance());
  DependsOn(ExtensionManagementFactory::GetInstance());
  // This depends on ExtensionService, which depends on ExtensionRegistry.
  DependsOn(ExtensionRegistryFactory::GetInstance());
#if BUILDFLAG(ENABLE_EXTENSIONS)
  // GlobalErrorService is only used on Win/Mac/Linux.
  DependsOn(GlobalErrorServiceFactory::GetInstance());
#endif
  DependsOn(InstallVerifierFactory::GetInstance());
  DependsOn(ProcessManagerFactory::GetInstance());
  DependsOn(RendererStartupHelperFactory::GetInstance());
  DependsOn(BlocklistFactory::GetInstance());
  DependsOn(EventRouterFactory::GetInstance());
  // This depends on ExtensionDownloader, which depends on
  // IdentityManager for webstore authentication.
  DependsOn(IdentityManagerFactory::GetInstance());
  DependsOn(InstallStageTrackerFactory::GetInstance());
  // ExtensionService (owned by the ExtensionSystem) depends on
  // ExtensionHostRegistry.
  DependsOn(ExtensionHostRegistry::GetFactory());
}

ChromeExtensionSystemSharedFactory::~ChromeExtensionSystemSharedFactory() =
    default;

std::unique_ptr<KeyedService>
ChromeExtensionSystemSharedFactory::BuildServiceInstanceForBrowserContext(
    content::BrowserContext* context) const {
  return std::make_unique<ChromeExtensionSystem::Shared>(
      static_cast<Profile*>(context));
}

// ChromeExtensionSystemFactory

// static
ExtensionSystem* ChromeExtensionSystemFactory::GetForBrowserContext(
    content::BrowserContext* context) {
  return static_cast<ExtensionSystem*>(
      GetInstance()->GetServiceForBrowserContext(context, true));
}

// static
ChromeExtensionSystemFactory* ChromeExtensionSystemFactory::GetInstance() {
  static base::NoDestructor<ChromeExtensionSystemFactory> instance;
  return instance.get();
}

ChromeExtensionSystemFactory::ChromeExtensionSystemFactory()
    : ExtensionSystemProvider("ExtensionSystem",
                              BrowserContextDependencyManager::GetInstance()) {
  DCHECK(ExtensionsBrowserClient::Get())
      << "ChromeExtensionSystemFactory must be initialized after "
         "BrowserProcess";
  DependsOn(ChromeExtensionSystemSharedFactory::GetInstance());
}

ChromeExtensionSystemFactory::~ChromeExtensionSystemFactory() = default;

std::unique_ptr<KeyedService>
ChromeExtensionSystemFactory::BuildServiceInstanceForBrowserContext(
    content::BrowserContext* context) const {
  return std::make_unique<ChromeExtensionSystem>(
      static_cast<Profile*>(context));
}

content::BrowserContext* ChromeExtensionSystemFactory::GetBrowserContextToUse(
    content::BrowserContext* context) const {
  return ProfileSelections::Builder()
      .WithRegular(ProfileSelection::kOwnInstance)
      .WithGuest(ProfileSelection::kOwnInstance)
      // TODO(crbug.com/41488885): Check if this service is needed for
      // Ash Internals.
      .WithAshInternals(ProfileSelection::kOwnInstance)
      .Build()
      .ApplyProfileSelection(Profile::FromBrowserContext(context));
}

bool ChromeExtensionSystemFactory::ServiceIsCreatedWithBrowserContext() const {
  return true;
}

}  // namespace extensions