image_annotation_service.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #include "services/image_annotation/image_annotation_service.h"
  5. #include <utility>
  6. #include "base/bind.h"
  7. #include "base/metrics/field_trial_params.h"
  8. #include "base/time/time.h"
  9. #include "url/gurl.h"
  10. namespace image_annotation {
  11. // static
  12. const base::Feature ImageAnnotationService::kExperiment{
  13. "ImageAnnotationServiceExperimental", base::FEATURE_DISABLED_BY_DEFAULT};
  14. constexpr base::FeatureParam<std::string>
  15. ImageAnnotationService::kPixelsServerUrl;
  16. constexpr base::FeatureParam<std::string>
  17. ImageAnnotationService::kLangsServerUrl;
  18. constexpr base::FeatureParam<std::string> ImageAnnotationService::kApiKey;
  19. constexpr base::FeatureParam<int> ImageAnnotationService::kThrottleMs;
  20. constexpr base::FeatureParam<int> ImageAnnotationService::kBatchSize;
  21. constexpr base::FeatureParam<double> ImageAnnotationService::kMinOcrConfidence;
  22. ImageAnnotationService::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. : receiver_(this, std::move(receiver)),
  28. annotator_(GURL(kPixelsServerUrl.Get()),
  29. GURL(kLangsServerUrl.Get()),
  30. kApiKey.Get().empty() ? std::move(api_key) : kApiKey.Get(),
  31. base::Milliseconds(kThrottleMs.Get()),
  32. kBatchSize.Get(),
  33. kMinOcrConfidence.Get(),
  34. shared_url_loader_factory,
  35. std::move(annotator_client)) {}
  36. ImageAnnotationService::~ImageAnnotationService() = default;
  37. void ImageAnnotationService::BindAnnotator(
  38. mojo::PendingReceiver<mojom::Annotator> receiver) {
  39. annotator_.BindReceiver(std::move(receiver));
  40. }
  41. } // namespace image_annotation