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
|
// Copyright 2021 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/safe_browsing/extension_telemetry/extension_telemetry_service_factory.h"
#include "base/no_destructor.h"
#include "chrome/browser/extensions/chrome_extension_system_factory.h"
#include "chrome/browser/extensions/extension_management.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/extension_telemetry/extension_telemetry_service.h"
#include "chrome/browser/safe_browsing/network_context_service.h"
#include "chrome/browser/safe_browsing/network_context_service_factory.h"
#include "components/enterprise/buildflags/buildflags.h"
#include "components/safe_browsing/core/common/features.h"
#include "content/public/browser/browser_context.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_prefs_factory.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_registry_factory.h"
#if BUILDFLAG(ENTERPRISE_CLOUD_CONTENT_ANALYSIS)
#include "chrome/browser/enterprise/connectors/connectors_service.h"
#include "chrome/browser/enterprise/connectors/reporting/extension_telemetry_event_router_factory.h"
#endif // BUILDFLAG(ENTERPRISE_CLOUD_CONTENT_ANALYSIS)
namespace safe_browsing {
// static
ExtensionTelemetryService* ExtensionTelemetryServiceFactory::GetForProfile(
Profile* profile) {
return static_cast<ExtensionTelemetryService*>(
GetInstance()->GetServiceForBrowserContext(profile, /* create= */ true));
}
// static
ExtensionTelemetryServiceFactory*
ExtensionTelemetryServiceFactory::GetInstance() {
static base::NoDestructor<ExtensionTelemetryServiceFactory> instance;
return instance.get();
}
ExtensionTelemetryServiceFactory::ExtensionTelemetryServiceFactory()
: ProfileKeyedServiceFactory(
// AshInternals should be 'kNone' since ExtensionTelemetryService
// should not be initialized for internal profiles on ChromeOS Ash.
"ExtensionTelemetryService",
ProfileSelections::BuildForRegularProfile()) {
DependsOn(NetworkContextServiceFactory::GetInstance());
DependsOn(extensions::ExtensionPrefsFactory::GetInstance());
DependsOn(extensions::ExtensionRegistryFactory::GetInstance());
DependsOn(extensions::ExtensionManagementFactory::GetInstance());
DependsOn(extensions::ChromeExtensionSystemFactory::GetInstance());
#if BUILDFLAG(ENTERPRISE_CLOUD_CONTENT_ANALYSIS)
DependsOn(enterprise_connectors::ConnectorsServiceFactory::GetInstance());
DependsOn(enterprise_connectors::ExtensionTelemetryEventRouterFactory::
GetInstance());
#endif // BUILDFLAG(ENTERPRISE_CLOUD_CONTENT_ANALYSIS)
}
std::unique_ptr<KeyedService>
ExtensionTelemetryServiceFactory::BuildServiceInstanceForBrowserContext(
content::BrowserContext* context) const {
NetworkContextService* network_service =
NetworkContextServiceFactory::GetForBrowserContext(context);
if (!network_service) {
return nullptr;
}
return std::make_unique<ExtensionTelemetryService>(
Profile::FromBrowserContext(context),
network_service->GetURLLoaderFactory());
}
bool ExtensionTelemetryServiceFactory::ServiceIsCreatedWithBrowserContext()
const {
return true;
}
bool ExtensionTelemetryServiceFactory::ServiceIsNULLWhileTesting() const {
return true;
}
} // namespace safe_browsing
|