#include "chrome/browser/safe_browsing/extension_telemetry/extension_telemetry_service.h"
#include <sstream>
#include <vector>
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/i18n/time_formatting.h"
#include "base/json/values_util.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_tokenizer.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/threading/sequence_bound.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "chrome/browser/enterprise/browser_management/management_service_factory.h"
#include "chrome/browser/enterprise/connectors/connectors_service.h"
#include "chrome/browser/enterprise/connectors/reporting/extension_telemetry_event_router.h"
#include "chrome/browser/extensions/extension_management.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/extension_telemetry/cookies_get_all_signal_processor.h"
#include "chrome/browser/safe_browsing/extension_telemetry/cookies_get_signal_processor.h"
#include "chrome/browser/safe_browsing/extension_telemetry/declarative_net_request_action_signal_processor.h"
#include "chrome/browser/safe_browsing/extension_telemetry/declarative_net_request_signal_processor.h"
#include "chrome/browser/safe_browsing/extension_telemetry/extension_js_callstacks.h"
#include "chrome/browser/safe_browsing/extension_telemetry/extension_signal.h"
#include "chrome/browser/safe_browsing/extension_telemetry/extension_telemetry_config_manager.h"
#include "chrome/browser/safe_browsing/extension_telemetry/extension_telemetry_file_processor.h"
#include "chrome/browser/safe_browsing/extension_telemetry/extension_telemetry_persister.h"
#include "chrome/browser/safe_browsing/extension_telemetry/extension_telemetry_service_factory.h"
#include "chrome/browser/safe_browsing/extension_telemetry/extension_telemetry_uploader.h"
#include "chrome/browser/safe_browsing/extension_telemetry/potential_password_theft_signal_processor.h"
#include "chrome/browser/safe_browsing/extension_telemetry/remote_host_contacted_signal_processor.h"
#include "chrome/browser/safe_browsing/extension_telemetry/tabs_api_signal_processor.h"
#include "chrome/browser/safe_browsing/extension_telemetry/tabs_execute_script_signal_processor.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/safe_browsing/core/browser/sync/safe_browsing_primary_account_token_fetcher.h"
#include "components/safe_browsing/core/browser/sync/sync_utils.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/proto/csd.pb.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/blocklist_extension_prefs.h"
#include "extensions/browser/blocklist_state.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/path_util.h"
#include "extensions/common/file_util.h"
#include "extensions/common/mojom/manifest.mojom-shared.h"
#include "extensions/common/switches.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace safe_browsing {
namespace {
ExtensionManagement;
ManifestLocation;
RepeatedPtrField;
ExtensionInfo;
OffstoreExtensionVerdict;
constexpr char kFileDataProcessTimestampPref[] = …;
constexpr char kFileDataDictPref[] = …;
constexpr char kManifestFile[] = …;
constexpr int kNumChecksPerUploadInterval = …;
base::TimeDelta kUploadIntervalSeconds = …;
base::TimeDelta kStartupUploadCheckDelaySeconds = …;
base::TimeDelta kOffstoreFileDataCollectionIntervalSeconds = …;
base::TimeDelta kOffstoreFileDataCollectionStartupDelaySeconds = …;
base::TimeDelta kOffstoreFileDataCollectionDurationLimitSeconds = …;
void RecordWhenFileWasPersisted(bool persisted_at_write_interval) { … }
void RecordNumOffstoreExtensions(int num_extensions) { … }
void RecordCollectionDuration(base::TimeDelta duration) { … }
void RecordSignalTypeForEnterprise(ExtensionSignalType signal_type) { … }
void RecordEnterpriseReportSize(size_t size) { … }
static_assert …;
ExtensionInfo::Type GetType(extensions::Manifest::Type type) { … }
static_assert …;
ExtensionInfo::InstallLocation GetInstallLocation(ManifestLocation location) { … }
static_assert …;
ExtensionTelemetryReportRequest::ManagementAuthorityTrustworthiness
GetManagementAuthorityTrustworthiness(
policy::ManagementAuthorityTrustworthiness
management_authority_trustworthiness) { … }
ExtensionInfo::InstallationPolicy
ExtensionManagementInstallationModeToExtensionInfoInstallationPolicy(
const ExtensionManagement::InstallationMode& installation_mode) { … }
ExtensionInfo::BlocklistState BitMapBlocklistStateToExtensionInfoBlocklistState(
const extensions::BitMapBlocklistState& state) { … }
ExtensionInfo::BlocklistState GetBlocklistState(
const extensions::ExtensionId extension_id,
extensions::ExtensionPrefs* extension_prefs) { … }
ExtensionInfo::BlocklistState GetExtensionTelemetryServiceBlocklistState(
const extensions::ExtensionId extension_id,
extensions::ExtensionPrefs* extension_prefs) { … }
extensions::BlocklistState ConvertTelemetryResponseVerdictToBlocklistState(
OffstoreExtensionVerdict::OffstoreExtensionVerdictType type) { … }
extensions::ExtensionSet CollectCommandLineExtensionInfo() { … }
enterprise_connectors::ExtensionTelemetryEventRouter*
GetExtensionTelemetryEventRouter(Profile* profile) { … }
bool CollectForEnterprise(ExtensionSignalType type) { … }
}
BASE_FEATURE(…);
ExtensionTelemetryService::~ExtensionTelemetryService() = default;
ExtensionTelemetryService* ExtensionTelemetryService::Get(Profile* profile) { … }
ExtensionTelemetryService::ExtensionTelemetryService(
Profile* profile,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory)
: … { … }
void ExtensionTelemetryService::RecordSignalType(
ExtensionSignalType signal_type) { … }
void ExtensionTelemetryService::RecordSignalDiscarded(
ExtensionSignalType signal_type) { … }
void ExtensionTelemetryService::OnESBPrefChanged() { … }
void ExtensionTelemetryService::OnEnterprisePolicyChanged() { … }
void ExtensionTelemetryService::SetEnabledForESB(bool enable) { … }
void ExtensionTelemetryService::SetEnabledForEnterprise(bool enable) { … }
bool ExtensionTelemetryService::enabled() const { … }
void ExtensionTelemetryService::Shutdown() { … }
bool ExtensionTelemetryService::SignalDataPresent() const { … }
bool ExtensionTelemetryService::IsSignalEnabled(
const extensions::ExtensionId& extension_id,
ExtensionSignalType signal_type) const { … }
void ExtensionTelemetryService::AddSignal(
std::unique_ptr<ExtensionSignal> signal) { … }
void ExtensionTelemetryService::AddSignalHelper(
const ExtensionSignal& signal,
ExtensionStore& store,
SignalSubscribers& subscribers) { … }
std::unique_ptr<ExtensionTelemetryReportRequest>
ExtensionTelemetryService::CreateReportWithCommonFieldsPopulated() { … }
void ExtensionTelemetryService::CreateAndUploadReport() { … }
void ExtensionTelemetryService::CreateAndSendEnterpriseReport() { … }
void ExtensionTelemetryService::OnUploadComplete(
bool success,
const std::string& response_data) { … }
void ExtensionTelemetryService::UploadPersistedFile(std::string report) { … }
void ExtensionTelemetryService::UploadReport(
std::unique_ptr<std::string> report) { … }
void ExtensionTelemetryService::StartUploadCheck() { … }
void ExtensionTelemetryService::PersistOrUploadData() { … }
std::unique_ptr<ExtensionTelemetryReportRequest>
ExtensionTelemetryService::CreateReport() { … }
std::unique_ptr<ExtensionTelemetryReportRequest>
ExtensionTelemetryService::CreateReportForEnterprise() { … }
std::unique_ptr<SafeBrowsingTokenFetcher>
ExtensionTelemetryService::GetTokenFetcher() { … }
void ExtensionTelemetryService::DumpReportForTesting(
const ExtensionTelemetryReportRequest& report) { … }
ExtensionTelemetryService::OffstoreExtensionFileData::
OffstoreExtensionFileData() = default;
ExtensionTelemetryService::OffstoreExtensionFileData::
~OffstoreExtensionFileData() = default;
ExtensionTelemetryService::OffstoreExtensionFileData::
OffstoreExtensionFileData::OffstoreExtensionFileData(
const OffstoreExtensionFileData& src) = default;
std::optional<ExtensionTelemetryService::OffstoreExtensionFileData>
ExtensionTelemetryService::RetrieveOffstoreFileDataForReport(
const extensions::ExtensionId& extension_id) { … }
std::unique_ptr<ExtensionInfo>
ExtensionTelemetryService::GetExtensionInfoForReport(
const extensions::Extension& extension) { … }
void ExtensionTelemetryService::SetUpSignalProcessorsAndSubscribersForESB() { … }
void ExtensionTelemetryService::
SetUpSignalProcessorsAndSubscribersForEnterprise() { … }
ExtensionTelemetryService::OffstoreExtensionFileDataContext::
OffstoreExtensionFileDataContext(
const extensions::ExtensionId& extension_id,
const base::FilePath& root_dir)
: … { … }
ExtensionTelemetryService::OffstoreExtensionFileDataContext::
OffstoreExtensionFileDataContext(
const extensions::ExtensionId& extension_id,
const base::FilePath& root_dir,
const base::Time& last_processed_time)
: … { … }
bool ExtensionTelemetryService::OffstoreExtensionFileDataContext::operator<(
const OffstoreExtensionFileDataContext& other) const { … }
void ExtensionTelemetryService::SetUpOffstoreFileDataCollection() { … }
void ExtensionTelemetryService::StartOffstoreFileDataCollection() { … }
void ExtensionTelemetryService::OnCommandLineExtensionsInfoCollected(
extensions::ExtensionSet commandline_extensions) { … }
void ExtensionTelemetryService::GetOffstoreExtensionDirs() { … }
void ExtensionTelemetryService::RemoveStaleExtensionsFileDataFromPref() { … }
void ExtensionTelemetryService::CollectOffstoreFileData() { … }
void ExtensionTelemetryService::OnOffstoreFileDataCollected(
base::flat_set<OffstoreExtensionFileDataContext>::iterator context,
base::Value::Dict file_data) { … }
void ExtensionTelemetryService::StopOffstoreFileDataCollection() { … }
void ExtensionTelemetryService::ProcessOffstoreExtensionVerdicts(
const ExtensionTelemetryReportResponse& response) { … }
base::TimeDelta
ExtensionTelemetryService::GetOffstoreFileDataCollectionStartupDelaySeconds() { … }
base::TimeDelta
ExtensionTelemetryService::GetOffstoreFileDataCollectionIntervalSeconds() { … }
}