image_annotation_service.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef SERVICES_IMAGE_ANNOTATION_IMAGE_ANNOTATION_SERVICE_H_
  5. #define SERVICES_IMAGE_ANNOTATION_IMAGE_ANNOTATION_SERVICE_H_
  6. #include <memory>
  7. #include <string>
  8. #include "base/feature_list.h"
  9. #include "base/memory/scoped_refptr.h"
  10. #include "base/metrics/field_trial_params.h"
  11. #include "mojo/public/cpp/bindings/pending_receiver.h"
  12. #include "mojo/public/cpp/bindings/receiver.h"
  13. #include "services/data_decoder/public/mojom/json_parser.mojom.h"
  14. #include "services/image_annotation/annotator.h"
  15. #include "services/image_annotation/public/mojom/image_annotation.mojom.h"
  16. #include "services/network/public/cpp/shared_url_loader_factory.h"
  17. namespace image_annotation {
  18. class ImageAnnotationService : public mojom::ImageAnnotationService {
  19. public:
  20. // Whether or not to override service parameters for experimentation.
  21. static const base::Feature kExperiment;
  22. ImageAnnotationService(
  23. mojo::PendingReceiver<mojom::ImageAnnotationService> receiver,
  24. std::string api_key,
  25. scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory,
  26. std::unique_ptr<Annotator::Client> annotator_client);
  27. ImageAnnotationService(const ImageAnnotationService&) = delete;
  28. ImageAnnotationService& operator=(const ImageAnnotationService&) = delete;
  29. ~ImageAnnotationService() override;
  30. private:
  31. // Service params:
  32. // The url of the service that fetches descriptions given image pixels.
  33. static constexpr base::FeatureParam<std::string> kPixelsServerUrl{
  34. &kExperiment, "server_url",
  35. "https://ckintersect-pa.googleapis.com/v1/intersect/pixels"};
  36. // The url of the service that returns the supported languages.
  37. static constexpr base::FeatureParam<std::string> kLangsServerUrl{
  38. &kExperiment, "langs_server_url",
  39. "https://ckintersect-pa.googleapis.com/v1/intersect/langs"};
  40. // An override Google API key. If empty, the API key with which the browser
  41. // was built (if any) will be used instead.
  42. static constexpr base::FeatureParam<std::string> kApiKey{&kExperiment,
  43. "api_key", ""};
  44. static constexpr base::FeatureParam<int> kThrottleMs{&kExperiment,
  45. "throttle_ms", 300};
  46. static constexpr base::FeatureParam<int> kBatchSize{&kExperiment,
  47. "batch_size", 10};
  48. static constexpr base::FeatureParam<double> kMinOcrConfidence{
  49. &kExperiment, "min_ocr_confidence", 0.7};
  50. // mojom::ImageAnnotationService implementation:
  51. void BindAnnotator(mojo::PendingReceiver<mojom::Annotator> receiver) override;
  52. mojo::Receiver<mojom::ImageAnnotationService> receiver_;
  53. Annotator annotator_;
  54. };
  55. } // namespace image_annotation
  56. #endif // SERVICES_IMAGE_ANNOTATION_IMAGE_ANNOTATION_SERVICE_H_