1 // Copyright 2012 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.
5 #ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_ANDROID_H_
6 #define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_ANDROID_H_
8 // The flow for geolocation permissions on Android needs to take into account
9 // the global geolocation settings so it differs from the desktop one. It
11 // GeolocationPermissionContextAndroid::DecidePermission intercepts the flow in
12 // the UI thread, and posts a task to the blocking pool to CheckSystemLocation.
13 // CheckSystemLocation will in fact check several possible settings
14 // - The global system geolocation setting
15 // - The Google location settings on pre KK devices
16 // - An old internal Chrome setting on pre-JB MR1 devices
17 // With all that information it will decide if system location is enabled.
18 // If enabled, it proceeds with the per site flow via
19 // GeolocationPermissionContext (which will check per site permissions, create
22 // Otherwise the permission is already decided.
24 // There is a bit of thread jumping since some of the permissions (like the
25 // per site settings) are queried on the UI thread while the system level
26 // permissions are considered I/O and thus checked in the blocking thread pool.
28 #include "base/memory/scoped_ptr.h"
29 #include "base/memory/weak_ptr.h"
30 #include "chrome/browser/geolocation/geolocation_permission_context.h"
31 #include "components/content_settings/core/common/permission_request_id.h"
38 class GoogleLocationSettingsHelper
;
40 class GeolocationPermissionContextAndroid
41 : public GeolocationPermissionContext
{
43 explicit GeolocationPermissionContextAndroid(Profile
* profile
);
44 virtual ~GeolocationPermissionContextAndroid();
47 struct PermissionRequestInfo
{
48 PermissionRequestInfo();
50 PermissionRequestID id
;
51 GURL requesting_origin
;
56 // PermissionContextBase:
57 virtual void RequestPermission(
58 content::WebContents
* web_contents
,
59 const PermissionRequestID
& id
,
60 const GURL
& requesting_frame_origin
,
62 const BrowserPermissionCallback
& callback
) override
;
64 void CheckMasterLocation(content::WebContents
* web_contents
,
65 const PermissionRequestInfo
& info
,
66 const BrowserPermissionCallback
& callback
);
68 void ProceedDecidePermission(content::WebContents
* web_contents
,
69 const PermissionRequestInfo
& info
,
70 base::Callback
<void(bool)> callback
);
72 // Will perform a final check on the system location settings before
73 // granting the permission.
74 void InterceptPermissionCheck(const BrowserPermissionCallback
& callback
,
77 scoped_ptr
<GoogleLocationSettingsHelper
> google_location_settings_helper_
;
78 base::WeakPtrFactory
<GeolocationPermissionContextAndroid
> weak_factory_
;
81 void CheckSystemLocation(content::WebContents
* web_contents
,
82 const PermissionRequestInfo
& info
,
83 base::Callback
<void(bool)> callback
);
85 DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContextAndroid
);
88 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_ANDROID_H_