Chromium Code Reviews| 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" |
| 9 | 10 |
| 10 namespace content { | 11 namespace content { |
| 11 class WebContents; | 12 class WebContents; |
| 12 } | 13 } |
| 13 | 14 |
| 14 // This class determines whether Chrome can access the device's location, | 15 // This class determines whether Chrome can access the device's location, |
| 15 // i.e. whether location is enabled system-wide on the device. | 16 // i.e. whether location is enabled system-wide on the device. |
| 16 class LocationSettings { | 17 class LocationSettings { |
| 17 public: | 18 public: |
| 18 virtual ~LocationSettings() {} | 19 virtual ~LocationSettings() {} |
| 19 | 20 |
| 20 // Returns true if: | 21 // Returns true if: |
| 21 // - Location is enabled system-wide (in Android settings) | 22 // - Location is enabled system-wide (in Android settings) |
| 22 // - The necessary location permission are granted to Chrome, or if Chrome | 23 // - The necessary location permission are granted to Chrome, or if Chrome |
| 23 // still has the ability to request the permissions to be granted. | 24 // still has the ability to request the permissions to be granted. |
| 24 virtual bool CanSitesRequestLocationPermission( | 25 virtual bool CanSitesRequestLocationPermission( |
| 25 content::WebContents* web_contents) = 0; | 26 content::WebContents* web_contents) = 0; |
| 27 | |
| 28 // Returns true iff a prompt can be triggered to ask the user to turn on the | |
| 29 // system location setting on their device. | |
| 30 // In particular, returns false if the system location setting is already | |
| 31 // enabled or if some of the features required to trigger a system location | |
| 32 // setting prompt are not available. | |
| 33 virtual bool CanPromptToEnableSystemLocationSetting() = 0; | |
| 34 | |
| 35 // An enum to describe the context in which a system location setting prompt | |
| 36 // is triggered to allow the prompt UI to be customized to the given context. | |
| 37 // | |
| 38 // Keep in sync with the LocationSettingsDialogContext IntDef in | |
|
Ted C
2017/03/02 00:21:56
We have a system to generate java int constants ba
qfiard
2017/03/02 13:28:13
Done, nice!
| |
| 39 // //components/location/android/java/src/org/chromium/components/location/Loc ationUtils.java | |
| 40 enum LocationSettingsDialogContext { | |
| 41 // Default context. | |
| 42 DEFAULT = 1, | |
| 43 // Prompt triggered in the context of a search. | |
| 44 SEARCH = 2, | |
| 45 }; | |
| 46 | |
| 47 // An enum to describe the outcome of a location setting prompt triggered by | |
| 48 // PromptToEnableSystemLocationSetting(). | |
| 49 // | |
| 50 // Keep in sync with the LocationSettingsDialogOutcome IntDef in | |
| 51 // //components/location/android/java/src/org/chromium/components/location/Loc ationUtils.java | |
| 52 enum LocationSettingsDialogOutcome { | |
| 53 // The user accepted the prompt and the system location setting has been | |
| 54 // flipped to granted. | |
| 55 GRANTED = 1, | |
| 56 | |
| 57 // The user rejected the prompt and the system location setting has not been | |
| 58 // flipped. | |
| 59 DENIED = 2, | |
| 60 | |
| 61 // The prompt could not be triggered. | |
| 62 // When CanPromptToEnableSystemLocationSetting() returns true, this should | |
| 63 // only happen in exceptional circonstances, e.g. | |
| 64 // - In the case of a race condition where the system location setting is | |
| 65 // flipped elsewhere before the prompt could be triggered; | |
| 66 // - In the case where some of the features required to trigger a system | |
| 67 // location setting prompt became unavailable or unresponsive after the | |
| 68 // response from CanPromptToEnableSystemLocationSetting() was received. | |
| 69 NO_PROMPT = 3, | |
| 70 }; | |
| 71 | |
| 72 typedef base::OnceCallback<void(LocationSettingsDialogOutcome)> | |
| 73 LocationSettingsDialogOutcomeCallback; | |
| 74 | |
| 75 // Triggers a prompt to ask the user to turn on the system location setting on | |
| 76 // their device. | |
| 77 // The prompt will be triggered in the activity of the web contents. | |
| 78 virtual void PromptToEnableSystemLocationSetting( | |
|
Ted C
2017/03/02 00:21:56
I would add comments about the lifetime of this.
qfiard
2017/03/02 13:28:13
Done.
| |
| 79 const LocationSettingsDialogContext prompt_context, | |
| 80 content::WebContents* web_contents, | |
| 81 LocationSettingsDialogOutcomeCallback callback) = 0; | |
| 26 }; | 82 }; |
| 27 | 83 |
| 28 #endif // CHROME_BROWSER_ANDROID_LOCATION_SETTINGS_H_ | 84 #endif // CHROME_BROWSER_ANDROID_LOCATION_SETTINGS_H_ |
| OLD | NEW |