| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_ANDROID_LOCATION_SETTINGS_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_LOCATION_SETTINGS_H_ |
| 6 #define CHROME_BROWSER_ANDROID_LOCATION_SETTINGS_H_ | 6 #define CHROME_BROWSER_ANDROID_LOCATION_SETTINGS_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" |
| 8 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "components/location/android/location_settings_dialog_context.h" |
| 11 #include "components/location/android/location_settings_dialog_outcome.h" |
| 9 | 12 |
| 10 namespace content { | 13 namespace content { |
| 11 class WebContents; | 14 class WebContents; |
| 12 } | 15 } |
| 13 | 16 |
| 14 // This class determines whether Chrome can access the device's location, | 17 // This class determines whether Chrome can access the device's location, |
| 15 // i.e. whether location is enabled system-wide on the device. | 18 // i.e. whether location is enabled system-wide on the device. |
| 16 class LocationSettings { | 19 class LocationSettings { |
| 17 public: | 20 public: |
| 18 virtual ~LocationSettings() {} | 21 virtual ~LocationSettings() {} |
| 19 | 22 |
| 20 // Returns true if: | 23 // Returns true if: |
| 21 // - Location is enabled system-wide (in Android settings) | 24 // - Location is enabled system-wide (in Android settings) |
| 22 // - The necessary location permission are granted to Chrome, or if Chrome | 25 // - The necessary location permission are granted to Chrome, or if Chrome |
| 23 // still has the ability to request the permissions to be granted. | 26 // still has the ability to request the permissions to be granted. |
| 24 virtual bool CanSitesRequestLocationPermission( | 27 virtual bool CanSitesRequestLocationPermission( |
| 25 content::WebContents* web_contents) = 0; | 28 content::WebContents* web_contents) = 0; |
| 29 |
| 30 // Returns true iff a prompt can be triggered to ask the user to turn on the |
| 31 // system location setting on their device. |
| 32 // In particular, returns false if the system location setting is already |
| 33 // enabled or if some of the features required to trigger a system location |
| 34 // setting prompt are not available. |
| 35 virtual bool CanPromptToEnableSystemLocationSetting() = 0; |
| 36 |
| 37 typedef base::OnceCallback<void(LocationSettingsDialogOutcome)> |
| 38 LocationSettingsDialogOutcomeCallback; |
| 39 |
| 40 // Triggers a prompt to ask the user to turn on the system location setting on |
| 41 // their device, and returns the outcome of the prompt via a callback. |
| 42 // |
| 43 // The prompt will be triggered in the activity of the web contents. |
| 44 // |
| 45 // The callback is guaranteed to be called unless the user never replies to |
| 46 // the prompt dialog, which in practice happens very infrequently since the |
| 47 // dialog is modal. |
| 48 // |
| 49 // The callback may be invoked a long time after this method has returned. |
| 50 // If you need to access in the callback an object that is not owned by the |
| 51 // callback, you should ensure that the object has not been destroyed before |
| 52 // accessing it to prevent crashes, e.g. by using weak pointer semantics. |
| 53 virtual void PromptToEnableSystemLocationSetting( |
| 54 const LocationSettingsDialogContext prompt_context, |
| 55 content::WebContents* web_contents, |
| 56 LocationSettingsDialogOutcomeCallback callback) = 0; |
| 26 }; | 57 }; |
| 27 | 58 |
| 28 #endif // CHROME_BROWSER_ANDROID_LOCATION_SETTINGS_H_ | 59 #endif // CHROME_BROWSER_ANDROID_LOCATION_SETTINGS_H_ |
| OLD | NEW |