Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(892)

Unified Diff: chrome/browser/geolocation/chrome_geolocation_permission_context_android.cc

Issue 23345004: Fix Android strict-mode violation in GeoLocation info bar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addresses comments Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/geolocation/chrome_geolocation_permission_context_android.cc
diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context_android.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context_android.cc
index afb213cf34353c11985c078dda19866207ee32e1..13574188aa283127328992081869ca0c79bc1181 100644
--- a/chrome/browser/geolocation/chrome_geolocation_permission_context_android.cc
+++ b/chrome/browser/geolocation/chrome_geolocation_permission_context_android.cc
@@ -6,6 +6,7 @@
#include "base/prefs/pref_service.h"
#include "chrome/browser/android/google_location_settings_helper.h"
+#include "chrome/browser/content_settings/permission_request_id.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/browser_thread.h"
@@ -21,23 +22,71 @@ ChromeGeolocationPermissionContextAndroid::
~ChromeGeolocationPermissionContextAndroid() {
}
-void ChromeGeolocationPermissionContextAndroid::DecidePermission(
+void ChromeGeolocationPermissionContextAndroid::ProceedDecidePermission(
const PermissionRequestID& id,
const GURL& requesting_frame,
const GURL& embedder,
base::Callback<void(bool)> callback) {
+ // Super class implementation expects everything in UI thread instead.
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ ChromeGeolocationPermissionContext::DecidePermission(
+ id, requesting_frame, embedder, callback);
+}
+void ChromeGeolocationPermissionContextAndroid::CheckMasterLocation(
+ const PermissionRequestID& id,
+ const GURL& requesting_frame,
+ const GURL& embedder,
+ base::Callback<void(bool)> callback) {
// Check to see if the feature in its entirety has been disabled.
// This must happen before other services (e.g. tabs, extensions)
// get an opportunity to allow the geolocation request.
- if (!google_location_settings_helper_->IsMasterLocationSettingEnabled()) {
- PermissionDecided(id, requesting_frame, embedder, callback, false);
- return;
+ bool enabled =
+ google_location_settings_helper_->IsMasterLocationSettingEnabled();
bulach 2014/01/15 16:22:07 I think my previous comment was that we could also
+
+ // The flow for geolocation permission on android is:
+ // - ChromeGeolocationPermissionContextAndroid::DecidePermission
+ // intercepts the flow in the UI thread, and posts task
+ // to the blocking pool to CheckMasterLocation (in order to
+ // avoid strict-mode violation).
+ // - At this point the master location permission is either:
+ // -- enabled, in which we case it proceeds the normal flow
+ // via ChromeGeolocationPermissionContext (which may create infobars, etc.).
+ // -- disabled, in which case the permission is already decided.
+ //
+ // In either case, ChromeGeolocationPermissionContext expects these
+ // in the UI thread.
+ base::Closure ui_closure;
+ if (enabled) {
+ ui_closure = base::Bind(
+ &ChromeGeolocationPermissionContextAndroid::ProceedDecidePermission,
+ base::Unretained(this), id, requesting_frame, embedder, callback);
+ } else {
+ ui_closure = base::Bind(
+ &ChromeGeolocationPermissionContextAndroid::PermissionDecided,
+ base::Unretained(this), id,
+ requesting_frame, embedder, callback, false);
}
- ChromeGeolocationPermissionContext::DecidePermission(id, requesting_frame,
- embedder, callback);
+ // This method is executed from the BlockingPool, post the result
+ // back to the UI thread.
+ content::BrowserThread::PostTask(
+ content::BrowserThread::UI, FROM_HERE, ui_closure);
+}
+
+void ChromeGeolocationPermissionContextAndroid::DecidePermission(
+ const PermissionRequestID& id,
+ const GURL& requesting_frame,
+ const GURL& embedder,
+ base::Callback<void(bool)> callback) {
+
+ // Called on the UI thread. However, do the work on a separate thread
+ // to avoid strict mode violation.
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ content::BrowserThread::PostBlockingPoolTask(FROM_HERE,
+ base::Bind(
+ &ChromeGeolocationPermissionContextAndroid::CheckMasterLocation,
+ base::Unretained(this), id, requesting_frame, embedder, callback));
}
void ChromeGeolocationPermissionContextAndroid::PermissionDecided(
@@ -46,7 +95,6 @@ void ChromeGeolocationPermissionContextAndroid::PermissionDecided(
const GURL& embedder,
base::Callback<void(bool)> callback,
bool allowed) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
// If Google Apps Location setting is turned off then we ignore
// the 'allow' website setting for this site and instead show
// the infobar to go back to the 'settings' to turn it back on.

Powered by Google App Engine
This is Rietveld 408576698