companion_app_parser.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2022 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 ASH_QUICK_PAIR_COMPANION_APP_COMPANION_APP_PARSER_H_
  5. #define ASH_QUICK_PAIR_COMPANION_APP_COMPANION_APP_PARSER_H_
  6. #include "base/callback_forward.h"
  7. #include "base/memory/weak_ptr.h"
  8. #include "third_party/abseil-cpp/absl/types/optional.h"
  9. namespace ash {
  10. namespace quick_pair {
  11. struct Device;
  12. class DeviceMetadata;
  13. // CompanionAppParser finds the name of a device's companion app
  14. // Call GetAppPackageName to use
  15. class CompanionAppParser {
  16. public:
  17. CompanionAppParser();
  18. CompanionAppParser(const CompanionAppParser&) = delete;
  19. CompanionAppParser& operator=(const CompanionAppParser&) = delete;
  20. ~CompanionAppParser();
  21. // Finds the name of the given device's companion app
  22. // The optional string in the callback will be null if an error
  23. // occurs or if no companion app for this device was found
  24. void GetAppPackageName(scoped_refptr<Device> device,
  25. base::OnceCallback<void(absl::optional<std::string>)>
  26. on_companion_app_parsed);
  27. private:
  28. void OnDeviceMetadataRetrieved(
  29. scoped_refptr<Device> device,
  30. base::OnceCallback<void(absl::optional<std::string>)> callback,
  31. DeviceMetadata* device_metadata,
  32. bool retryable_err);
  33. absl::optional<std::string> GetCompanionAppExtra(
  34. const std::string& intent_as_string);
  35. base::WeakPtrFactory<CompanionAppParser> weak_pointer_factory_{this};
  36. };
  37. } // namespace quick_pair
  38. } // namespace ash
  39. #endif // ASH_QUICK_PAIR_COMPANION_APP_COMPANION_APP_PARSER_H_