arcore_install_helper.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 COMPONENTS_WEBXR_ANDROID_ARCORE_INSTALL_HELPER_H_
  5. #define COMPONENTS_WEBXR_ANDROID_ARCORE_INSTALL_HELPER_H_
  6. #include <memory>
  7. #include "base/android/jni_android.h"
  8. #include "base/android/scoped_java_ref.h"
  9. #include "base/callback.h"
  10. #include "base/memory/weak_ptr.h"
  11. #include "components/messages/android/message_enums.h"
  12. #include "components/messages/android/message_wrapper.h"
  13. #include "content/public/browser/xr_install_helper.h"
  14. namespace webxr {
  15. // Equivalent of ArCoreApk.Availability enum.
  16. // For detailed description, please see:
  17. // https://developers.google.com/ar/reference/java/arcore/reference/com/google/ar/core/ArCoreApk.Availability
  18. // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.webxr
  19. enum class ArCoreAvailability : int {
  20. kSupportedApkTooOld = 0,
  21. kSupportedInstalled = 1,
  22. kSupportedNotInstalled = 2,
  23. kUnknownChecking = 3,
  24. kUnknownError = 4,
  25. kUnknownTimedOut = 5,
  26. kUnsupportedDeviceNotCapable = 6,
  27. };
  28. // Helper class to ensure that ArCore has been properly installed from the
  29. // store, per the ArCore Apk's installation implementation. Inherits from
  30. // content::XrInstallHelper so that it may be returned by the
  31. // XrIntegrationClient.
  32. class ArCoreInstallHelper : public content::XrInstallHelper {
  33. public:
  34. explicit ArCoreInstallHelper();
  35. ~ArCoreInstallHelper() override;
  36. ArCoreInstallHelper(const ArCoreInstallHelper&) = delete;
  37. ArCoreInstallHelper& operator=(const ArCoreInstallHelper&) = delete;
  38. // content::XrInstallHelper implementation.
  39. void EnsureInstalled(
  40. int render_process_id,
  41. int render_frame_id,
  42. base::OnceCallback<void(bool)> install_callback) override;
  43. // Called from Java end.
  44. void OnRequestInstallSupportedArCoreResult(JNIEnv* env, bool success);
  45. private:
  46. void ShowMessage(int render_process_id, int render_frame_id);
  47. void HandleMessagePrimaryAction(int render_process_id, int render_frame_id);
  48. void HandleMessageDismissed(messages::DismissReason dismiss_reason);
  49. void RunInstallFinishedCallback(bool succeeded);
  50. base::OnceCallback<void(bool)> install_finished_callback_;
  51. base::android::ScopedJavaGlobalRef<jobject> java_install_utils_;
  52. std::unique_ptr<messages::MessageWrapper> message_;
  53. // Must be last.
  54. base::WeakPtrFactory<ArCoreInstallHelper> weak_ptr_factory_{this};
  55. };
  56. } // namespace webxr
  57. #endif // COMPONENTS_WEBXR_ANDROID_ARCORE_INSTALL_HELPER_H_