public_ip_address_geolocation_provider.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2017 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/device/geolocation/public_ip_address_geolocation_provider.h"
  5. #include "base/bind.h"
  6. #include "services/device/geolocation/public_ip_address_geolocator.h"
  7. #include "services/network/public/cpp/shared_url_loader_factory.h"
  8. namespace device {
  9. PublicIpAddressGeolocationProvider::PublicIpAddressGeolocationProvider(
  10. scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
  11. network::NetworkConnectionTracker* network_connection_tracker,
  12. const std::string& api_key) {
  13. // Bind sequence_checker_ to the initialization sequence.
  14. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  15. public_ip_address_location_notifier_ =
  16. std::make_unique<PublicIpAddressLocationNotifier>(
  17. std::move(url_loader_factory), network_connection_tracker, api_key);
  18. }
  19. PublicIpAddressGeolocationProvider::~PublicIpAddressGeolocationProvider() {}
  20. void PublicIpAddressGeolocationProvider::Bind(
  21. mojo::PendingReceiver<mojom::PublicIpAddressGeolocationProvider> receiver) {
  22. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  23. DCHECK(public_ip_address_location_notifier_);
  24. provider_receiver_set_.Add(this, std::move(receiver));
  25. }
  26. void PublicIpAddressGeolocationProvider::CreateGeolocation(
  27. const net::MutablePartialNetworkTrafficAnnotationTag& tag,
  28. mojo::PendingReceiver<mojom::Geolocation> receiver) {
  29. DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  30. DCHECK(public_ip_address_location_notifier_);
  31. geolocation_receiver_set_.Add(
  32. std::make_unique<PublicIpAddressGeolocator>(
  33. static_cast<net::PartialNetworkTrafficAnnotationTag>(tag),
  34. public_ip_address_location_notifier_.get(),
  35. base::BindRepeating(
  36. &mojo::UniqueReceiverSet<mojom::Geolocation>::ReportBadMessage,
  37. base::Unretained(&geolocation_receiver_set_))),
  38. std::move(receiver));
  39. }
  40. } // namespace device