location_settings.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2015 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_LOCATION_ANDROID_LOCATION_SETTINGS_H_
  5. #define COMPONENTS_LOCATION_ANDROID_LOCATION_SETTINGS_H_
  6. #include "base/callback.h"
  7. #include "components/location/android/location_settings_dialog_context.h"
  8. #include "components/location/android/location_settings_dialog_outcome.h"
  9. namespace ui {
  10. class WindowAndroid;
  11. }
  12. // This class determines whether Chrome can access the device's location,
  13. // i.e. whether location is enabled system-wide on the device.
  14. class LocationSettings {
  15. public:
  16. virtual ~LocationSettings() = default;
  17. // Returns true if Chrome has location permission.
  18. virtual bool HasAndroidLocationPermission() = 0;
  19. // Returns true if Chrome can prompt to get location permission.
  20. virtual bool CanPromptForAndroidLocationPermission(
  21. ui::WindowAndroid* window) = 0;
  22. // Returns true if the system location is enabled.
  23. virtual bool IsSystemLocationSettingEnabled() = 0;
  24. // Returns true iff a prompt can be triggered to ask the user to turn on the
  25. // system location setting on their device.
  26. // In particular, returns false if the system location setting is already
  27. // enabled or if some of the features required to trigger a system location
  28. // setting prompt are not available.
  29. virtual bool CanPromptToEnableSystemLocationSetting() = 0;
  30. typedef base::OnceCallback<void(LocationSettingsDialogOutcome)>
  31. LocationSettingsDialogOutcomeCallback;
  32. // Triggers a prompt to ask the user to turn on the system location setting on
  33. // their device, and returns the outcome of the prompt via a callback.
  34. //
  35. // The prompt will be triggered in the activity of the web contents.
  36. //
  37. // The callback is guaranteed to be called unless the user never replies to
  38. // the prompt dialog, which in practice happens very infrequently since the
  39. // dialog is modal.
  40. //
  41. // The callback may be invoked a long time after this method has returned.
  42. // If you need to access in the callback an object that is not owned by the
  43. // callback, you should ensure that the object has not been destroyed before
  44. // accessing it to prevent crashes, e.g. by using weak pointer semantics.
  45. virtual void PromptToEnableSystemLocationSetting(
  46. const LocationSettingsDialogContext prompt_context,
  47. ui::WindowAndroid* window,
  48. LocationSettingsDialogOutcomeCallback callback) = 0;
  49. };
  50. #endif // COMPONENTS_LOCATION_ANDROID_LOCATION_SETTINGS_H_