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

Side by Side Diff: chrome/browser/android/location_settings_impl.cc

Issue 2709883005: Stubs for triggering the LSD in Clank (Closed)
Patch Set: Group location settings dialog enums into a single java_cpp_enum rule Created 3 years, 9 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 unified diff | Download patch
OLDNEW
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 #include "chrome/browser/android/location_settings_impl.h" 5 #include "chrome/browser/android/location_settings_impl.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "content/public/browser/web_contents.h" 8 #include "content/public/browser/web_contents.h"
9 #include "jni/LocationSettings_jni.h" 9 #include "jni/LocationSettings_jni.h"
10 10
11 using base::android::AttachCurrentThread; 11 using base::android::AttachCurrentThread;
12 12
13 using LocationSettingsDialogOutcomeCallback =
14 LocationSettings::LocationSettingsDialogOutcomeCallback;
15
13 LocationSettingsImpl::LocationSettingsImpl() {} 16 LocationSettingsImpl::LocationSettingsImpl() {}
14 17
15 LocationSettingsImpl::~LocationSettingsImpl() {} 18 LocationSettingsImpl::~LocationSettingsImpl() {}
16 19
17 bool LocationSettingsImpl::CanSitesRequestLocationPermission( 20 bool LocationSettingsImpl::CanSitesRequestLocationPermission(
18 content::WebContents* web_contents) { 21 content::WebContents* web_contents) {
19 JNIEnv* env = AttachCurrentThread(); 22 JNIEnv* env = AttachCurrentThread();
20 return Java_LocationSettings_canSitesRequestLocationPermission( 23 return Java_LocationSettings_canSitesRequestLocationPermission(
21 env, web_contents->GetJavaWebContents()); 24 env, web_contents->GetJavaWebContents());
22 } 25 }
26
27 bool LocationSettingsImpl::CanPromptToEnableSystemLocationSetting() {
28 JNIEnv* env = AttachCurrentThread();
29 return Java_LocationSettings_canPromptToEnableSystemLocationSetting(env);
30 }
31
32 void LocationSettingsImpl::PromptToEnableSystemLocationSetting(
33 const LocationSettingsDialogContext prompt_context,
34 content::WebContents* web_contents,
35 LocationSettingsDialogOutcomeCallback callback) {
36 JNIEnv* env = AttachCurrentThread();
37 // Transfers the ownership of the callback to the Java callback. The Java
38 // callback is guaranteed to be called unless the user never replies to the
39 // dialog, and the callback pointer will be destroyed in
40 // OnLocationSettingsDialogOutcome.
41 auto* callback_ptr =
42 new LocationSettingsDialogOutcomeCallback(std::move(callback));
43 Java_LocationSettings_promptToEnableSystemLocationSetting(
44 env, prompt_context, web_contents->GetJavaWebContents(),
45 reinterpret_cast<jlong>(callback_ptr));
46 }
47
48 static void OnLocationSettingsDialogOutcome(
49 JNIEnv* env,
50 const base::android::JavaParamRef<jclass>& jcaller,
51 jlong callback_ptr,
52 int result) {
53 auto* callback =
54 reinterpret_cast<LocationSettingsDialogOutcomeCallback*>(callback_ptr);
55 std::move(*callback).Run(static_cast<LocationSettingsDialogOutcome>(result));
56 // Destroy the callback whose ownership was transferred in
57 // PromptToEnableSystemLocationSetting.
58 delete callback;
59 }
60
61 bool LocationSettingsImpl::Register(JNIEnv* env) {
62 return RegisterNativesImpl(env);
63 }
OLDNEW
« no previous file with comments | « chrome/browser/android/location_settings_impl.h ('k') | chrome/browser/android/mock_location_settings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698