#include "chrome/browser/companion/visual_query/visual_query_classifier_host.h"
#include <optional>
#include <string_view>
#include "base/base64.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros_local.h"
#include "base/task/thread_pool.h"
#include "chrome/browser/companion/core/companion_metrics_logger.h"
#include "chrome/browser/companion/visual_query/visual_query_suggestions_service.h"
#include "content/public/browser/render_frame_host.h"
#include "mojo/public/cpp/base/proto_wrapper.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/encode/SkJpegEncoder.h"
#include "ui/gfx/image/buffer_w_stream.h"
#include "ui/gfx/image/image_skia.h"
#include "url/gurl.h"
namespace companion::visual_query {
namespace {
void RecordStatusChange(InitStatus status) { … }
std::optional<std::string> Base64EncodeBitmap(const SkBitmap& bitmap) { … }
void CloseModelFile(base::File model_file) { … }
VisualSuggestionsMetrics GenerateMetrics(const ClassificationStats& stats) { … }
}
VisualQueryClassifierHost::VisualQueryClassifierHost(
VisualQuerySuggestionsService* visual_query_service)
: … { … }
VisualQueryClassifierHost::~VisualQueryClassifierHost() = default;
void VisualQueryClassifierHost::HandleClassification(
std::vector<mojom::VisualQuerySuggestionPtr> results,
mojom::ClassificationStatsPtr classification_stats) { … }
void VisualQueryClassifierHost::StartClassification(
content::RenderFrameHost* render_frame_host,
const GURL& validated_url,
ResultCallback callback) { … }
void VisualQueryClassifierHost::StartClassificationWithModel(
mojo::AssociatedRemote<mojom::VisualSuggestionsRequestHandler> visual_query,
base::File model,
std::optional<mojo_base::ProtoWrapper> wrapped_config) { … }
void VisualQueryClassifierHost::CancelClassification(const GURL& visible_url) { … }
std::optional<VisualSuggestionsResults>
VisualQueryClassifierHost::GetVisualResult(const GURL& url) { … }
}