chromium/components/safe_browsing/content/browser/client_side_phishing_model.cc

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/safe_browsing/content/browser/client_side_phishing_model.h"

#include <stdint.h>

#include <memory>
#include <optional>

#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/memory/read_only_shared_memory_region.h"
#include "base/memory/shared_memory_mapping.h"
#include "base/memory/singleton.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/task/thread_pool.h"
#include "build/build_config.h"
#include "components/optimization_guide/core/optimization_guide_model_provider.h"
#include "components/optimization_guide/core/optimization_guide_util.h"
#include "components/optimization_guide/proto/client_side_phishing_model_metadata.pb.h"
#include "components/optimization_guide/proto/models.pb.h"
#include "components/safe_browsing/core/common/fbs/client_model_generated.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/proto/client_model.pb.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"

namespace safe_browsing {

namespace {

// Command-line flag that can be used to override the current CSD model. Must be
// provided with an absolute path.
const char kOverrideCsdModelFlag[] =;

void ReturnModelOverrideFailure(
    base::OnceCallback<void(std::pair<std::string, base::File>)> callback) {}

void ReadOverridenModel(
    base::FilePath path,
    base::OnceCallback<void(std::pair<std::string, base::File>)> callback) {}

base::File LoadImageEmbeddingModelFile(const base::FilePath& model_file_path) {}

// Load the model file at the provided file path.
std::pair<std::string, base::File> LoadModelAndVisualTfLiteFile(
    const base::FilePath& model_file_path,
    base::flat_set<base::FilePath> additional_files) {}

// Close the provided model file.
void CloseModelFile(base::File model_file) {}

void RecordImageEmbeddingModelUpdateSuccess(bool success) {}

}  // namespace

// --- ClientSidePhishingModel methods ---

ClientSidePhishingModel::ClientSidePhishingModel(
    optimization_guide::OptimizationGuideModelProvider* opt_guide,
    const scoped_refptr<base::SequencedTaskRunner>& background_task_runner)
    :{}

void ClientSidePhishingModel::OnModelUpdated(
    optimization_guide::proto::OptimizationTarget optimization_target,
    base::optional_ref<const optimization_guide::ModelInfo> model_info) {}

void ClientSidePhishingModel::SubscribeToImageEmbedderOptimizationGuide() {}

bool ClientSidePhishingModel::IsSubscribedToImageEmbeddingModelUpdates() {}

void ClientSidePhishingModel::OnModelAndVisualTfLiteFileLoaded(
    std::optional<optimization_guide::proto::Any> model_metadata,
    std::pair<std::string, base::File> model_and_tflite) {}

void ClientSidePhishingModel::OnImageEmbeddingModelLoaded(
    std::optional<optimization_guide::proto::Any> model_metadata,
    base::File image_embedding_model) {}

bool ClientSidePhishingModel::IsModelMetadataImageEmbeddingVersionMatching() {}

int ClientSidePhishingModel::GetTriggerModelVersion() {}

ClientSidePhishingModel::~ClientSidePhishingModel() {}

base::CallbackListSubscription ClientSidePhishingModel::RegisterCallback(
    base::RepeatingCallback<void()> callback) {}

bool ClientSidePhishingModel::IsEnabled() const {}

// static
bool ClientSidePhishingModel::VerifyCSDFlatBufferIndicesAndFields(
    const flat::ClientSideModel* model) {}

const base::flat_map<std::string, TfLiteModelMetadata::Threshold>&
ClientSidePhishingModel::GetVisualTfLiteModelThresholds() const {}

const base::File& ClientSidePhishingModel::GetVisualTfLiteModel() const {}

const base::File& ClientSidePhishingModel::GetImageEmbeddingModel() const {}

bool ClientSidePhishingModel::HasImageEmbeddingModel() {}

CSDModelType ClientSidePhishingModel::GetModelType() const {}

base::ReadOnlySharedMemoryRegion
ClientSidePhishingModel::GetModelSharedMemoryRegion() const {}

void ClientSidePhishingModel::SetModelStringForTesting(
    const std::string& model_str,
    base::File visual_tflite_model) {}

void ClientSidePhishingModel::NotifyCallbacksOnUI() {}

void ClientSidePhishingModel::SetVisualTfLiteModelForTesting(base::File file) {}

void ClientSidePhishingModel::SetModelTypeForTesting(CSDModelType model_type) {}

void ClientSidePhishingModel::ClearMappedRegionForTesting() {}

void* ClientSidePhishingModel::GetFlatBufferMemoryAddressForTesting() {}

// This function is used for testing in client_side_phishing_model_unittest
void ClientSidePhishingModel::MaybeOverrideModel() {}

// This function is used for testing in client_side_phishing_model_unittest
void ClientSidePhishingModel::OnGetOverridenModelData(
    CSDModelType model_type,
    std::pair<std::string, base::File> model_and_tflite) {}

// For browser unit testing in client_side_detection_service_browsertest
void ClientSidePhishingModel::SetModelAndVisualTfLiteForTesting(
    const base::FilePath& model_file_path,
    const base::FilePath& visual_tf_lite_model_path) {}

}  // namespace safe_browsing