blob: e12c1136253c89505575e0aacdca5c6d846bb12d [file] [log] [blame]
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "services/image_annotation/image_annotation_utils.h"
#include "services/image_annotation/public/mojom/image_annotation.mojom.h"
namespace image_annotation {
// Implementation details exposed only for testing. May change without warning.
namespace metrics_internal {
// TODO( separate out client / annotation types when we have
// more use cases for the service.
constexpr char kCacheHit[] = "ImageAnnotationService.AccessibilityV1.CacheHit";
constexpr char kJsonParseSuccess[] =
constexpr char kPixelFetchSuccess[] =
constexpr char kAnnotationConfidence[] =
constexpr char kAnnotationEmpty[] =
constexpr char kAnnotationStatus[] =
constexpr char kDescType[] = "ImageAnnotationService.AccessibilityV1.DescType";
constexpr char kDescFailure[] =
constexpr char kEngineKnown[] =
constexpr char kServerNetError[] =
constexpr char kServerHttpResponseCode[] =
constexpr char kServerLatency[] =
constexpr char kImageRequestIncludesDesc[] =
constexpr char kServerRequestSize[] =
constexpr char kServerResponseSize[] =
constexpr char kSourcePixelCount[] =
constexpr char kEncodedJpegSize[] =
constexpr char kClientResult[] =
} // namespace metrics_internal
// An enum for reporting the end result of an image annotation request.
// Logged in metrics - do not reuse or reassign values.
enum class ClientResult {
kUnknown = 0,
kSucceeded = 1,
kCanceled = 2,
kFailed = 3,
kShutdown = 4,
kMaxValue = kShutdown,
// Report whether or not annotations for an image were already stored in the
// service cache.
void ReportCacheHit(bool cache_hit);
// Report whether or not JSON returned by the image annotation service was
// successfully parsed or not.
void ReportJsonParseSuccess(bool success);
// Report whether or not pixel data is successfully fetched from a client.
void ReportPixelFetchSuccess(bool success);
// Report metadata for a successful OCR annotation.
void ReportOcrAnnotation(double confidence, bool empty);
// Report metadata for a successful description annotation.
void ReportDescAnnotation(mojom::AnnotationType type, double score, bool empty);
// Report an unsuccessful description response.
void ReportDescFailure(DescFailureReason reason);
// Report the net error from the image annotation server request. This will be
// populated even if e.g. the server URL is incorrect.
void ReportServerNetError(int code);
// Report a HTTP response code from the image annotation server.
void ReportServerResponseCode(int code);
// Report the length of time taken for a response to be returned from the
// server.
void ReportServerLatency(base::TimeDelta latency);
// Report whether or not a request for image annotation includes parameters for
// the description engine; requests for images that violate the description
// engine policy (e.g. are too small) will not.
void ReportImageRequestIncludesDesc(bool includes_desc);
// Report the size of the request sent to the image annotation server.
void ReportServerRequestSizeKB(size_t size_kb);
// Report the size of the response returned by the image annotation server.
void ReportServerResponseSizeBytes(size_t size_bytes);
// Report the status code attached to the OCR engine response.
void ReportOcrStatus(int status);
// Report the status code attached to the description engine response.
void ReportDescStatus(int status);
// Report whether or not each engine is recognised as either OCR or description.
void ReportEngineKnown(bool known);
// Report the number of source (i.e. pre-scaling) pixels in an image sent to the
// image annotation service.
void ReportSourcePixelCount(size_t pixel_count);
// Report the size of a single encoded image to be sent to the image annotation
// service.
void ReportEncodedJpegSize(size_t size_kb);
// Report the result of the image annotation request for a client.
void ReportClientResult(ClientResult result);
} // namespace image_annotation