Commit 96d75bc5 authored by Jihwan Marc Kim's avatar Jihwan Marc Kim Committed by Commit Bot

Accessing C++ enums in Java for WebBluetooth

Currently the BluetoothChooser has C++ enums for event type.
And the BluetoothChooserDialog java code has event type too.
It would be better to define these enums in one place in C++ And
the Java code can share it without defining them again.

Bug: 994392
Change-Id: I12c8ba92219b4aa3290da6a746467d40e39de1f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2387901
Commit-Queue: Ovidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarSean Topping <seantopping@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarOvidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809458}
parent 23fc54ff
......@@ -33,6 +33,7 @@ import org.chromium.chrome.browser.omnibox.ChromeAutocompleteSchemeClassifier;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.components.location.LocationUtils;
import org.chromium.components.omnibox.OmniboxUrlEmphasizer;
import org.chromium.content_public.browser.bluetooth.BluetoothChooserEvent;
import org.chromium.ui.base.PermissionCallback;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.text.NoUnderlineClickableSpan;
......@@ -64,15 +65,6 @@ public class BluetoothChooserDialog
int DISCOVERY_IDLE = 2;
}
// Values passed to nativeOnDialogFinished:eventType, and only used in the native function.
@IntDef({DialogFinished.DENIED_PERMISSION, DialogFinished.CANCELLED, DialogFinished.SELECTED})
@Retention(RetentionPolicy.SOURCE)
@interface DialogFinished {
int DENIED_PERMISSION = 0;
int CANCELLED = 1;
int SELECTED = 2;
}
// The window that owns this dialog.
final WindowAndroid mWindowAndroid;
......@@ -253,9 +245,9 @@ public class BluetoothChooserDialog
@Override
public void onItemSelected(String id) {
if (id.isEmpty()) {
finishDialog(DialogFinished.CANCELLED, "");
finishDialog(BluetoothChooserEvent.CANCELLED, "");
} else {
finishDialog(DialogFinished.SELECTED, id);
finishDialog(BluetoothChooserEvent.SELECTED, id);
}
}
......@@ -288,7 +280,7 @@ public class BluetoothChooserDialog
&& !mWindowAndroid.canRequestPermission(Manifest.permission.ACCESS_FINE_LOCATION)) {
// Immediately close the dialog because the user has asked Chrome not to request the
// location permission.
finishDialog(DialogFinished.DENIED_PERMISSION, "");
finishDialog(BluetoothChooserEvent.DENIED_PERMISSION, "");
return false;
}
......
......@@ -35,6 +35,7 @@ import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.batch.BlankCTATabInitialStateRule;
import org.chromium.components.location.LocationUtils;
import org.chromium.components.security_state.ConnectionSecurityLevel;
import org.chromium.content_public.browser.bluetooth.BluetoothChooserEvent;
import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
......@@ -210,7 +211,7 @@ public class BluetoothChooserDialogTest {
CriteriaHelper.pollUiThread(() -> Criteria.checkThat(mFinishedEventType, Matchers.not(-1)));
Assert.assertEquals(BluetoothChooserDialog.DialogFinished.CANCELLED, mFinishedEventType);
Assert.assertEquals(BluetoothChooserEvent.CANCELLED, mFinishedEventType);
Assert.assertEquals("", mFinishedDeviceId);
}
......@@ -267,7 +268,7 @@ public class BluetoothChooserDialogTest {
selectItem(2);
Assert.assertEquals(BluetoothChooserDialog.DialogFinished.SELECTED, mFinishedEventType);
Assert.assertEquals(BluetoothChooserEvent.SELECTED, mFinishedEventType);
Assert.assertEquals("id-2", mFinishedDeviceId);
}
......
......@@ -198,14 +198,14 @@ class FakeBluetoothChooser : public content::BluetoothChooser {
// Select the first device that is added if |device_to_select_| is not
// populated.
if (!device_to_select_) {
event_handler_.Run(content::BluetoothChooser::Event::SELECTED, device_id);
event_handler_.Run(content::BluetoothChooserEvent::SELECTED, device_id);
return;
}
// Otherwise, select the added device if its device ID matches
// |device_to_select_|.
if (device_to_select_.value() == device_id) {
event_handler_.Run(content::BluetoothChooser::Event::SELECTED, device_id);
event_handler_.Run(content::BluetoothChooserEvent::SELECTED, device_id);
}
}
......
......@@ -112,14 +112,14 @@ void BluetoothChooserAndroid::OnDialogFinished(
// Values are defined in BluetoothChooserDialog as DIALOG_FINISHED constants.
switch (event_type) {
case 0:
event_handler_.Run(Event::DENIED_PERMISSION, "");
event_handler_.Run(content::BluetoothChooserEvent::DENIED_PERMISSION, "");
return;
case 1:
event_handler_.Run(Event::CANCELLED, "");
event_handler_.Run(content::BluetoothChooserEvent::CANCELLED, "");
return;
case 2:
event_handler_.Run(
Event::SELECTED,
content::BluetoothChooserEvent::SELECTED,
base::android::ConvertJavaStringToUTF8(env, device_id));
return;
}
......@@ -127,7 +127,7 @@ void BluetoothChooserAndroid::OnDialogFinished(
}
void BluetoothChooserAndroid::RestartSearch() {
event_handler_.Run(Event::RESCAN, "");
event_handler_.Run(content::BluetoothChooserEvent::RESCAN, "");
}
void BluetoothChooserAndroid::RestartSearch(JNIEnv*) {
......@@ -136,17 +136,18 @@ void BluetoothChooserAndroid::RestartSearch(JNIEnv*) {
void BluetoothChooserAndroid::ShowBluetoothOverviewLink(JNIEnv* env) {
OpenURL(chrome::kChooserBluetoothOverviewURL);
event_handler_.Run(Event::SHOW_OVERVIEW_HELP, "");
event_handler_.Run(content::BluetoothChooserEvent::SHOW_OVERVIEW_HELP, "");
}
void BluetoothChooserAndroid::ShowBluetoothAdapterOffLink(JNIEnv* env) {
OpenURL(chrome::kChooserBluetoothOverviewURL);
event_handler_.Run(Event::SHOW_ADAPTER_OFF_HELP, "");
event_handler_.Run(content::BluetoothChooserEvent::SHOW_ADAPTER_OFF_HELP, "");
}
void BluetoothChooserAndroid::ShowNeedLocationPermissionLink(JNIEnv* env) {
OpenURL(chrome::kChooserBluetoothOverviewURL);
event_handler_.Run(Event::SHOW_NEED_LOCATION_HELP, "");
event_handler_.Run(content::BluetoothChooserEvent::SHOW_NEED_LOCATION_HELP,
"");
}
void BluetoothChooserAndroid::OpenURL(const char* url) {
......
......@@ -104,7 +104,7 @@ void BluetoothChooserController::RefreshOptions() {
if (event_handler_.is_null())
return;
ClearAllDevices();
event_handler_.Run(content::BluetoothChooser::Event::RESCAN, std::string());
event_handler_.Run(content::BluetoothChooserEvent::RESCAN, std::string());
}
void BluetoothChooserController::OpenAdapterOffHelpUrl() const {
......@@ -134,7 +134,7 @@ void BluetoothChooserController::Select(const std::vector<size_t>& indices) {
return;
}
DCHECK_LT(index, devices_.size());
event_handler_.Run(content::BluetoothChooser::Event::SELECTED,
event_handler_.Run(content::BluetoothChooserEvent::SELECTED,
devices_[index].id);
}
......@@ -142,16 +142,14 @@ void BluetoothChooserController::Cancel() {
RecordInteractionWithChooser(event_handler_.is_null());
if (event_handler_.is_null())
return;
event_handler_.Run(content::BluetoothChooser::Event::CANCELLED,
std::string());
event_handler_.Run(content::BluetoothChooserEvent::CANCELLED, std::string());
}
void BluetoothChooserController::Close() {
RecordInteractionWithChooser(event_handler_.is_null());
if (event_handler_.is_null())
return;
event_handler_.Run(content::BluetoothChooser::Event::CANCELLED,
std::string());
event_handler_.Run(content::BluetoothChooserEvent::CANCELLED, std::string());
}
void BluetoothChooserController::OpenHelpCenterUrl() const {
......
......@@ -25,7 +25,7 @@ class BluetoothChooserControllerTest : public testing::Test {
}
protected:
void OnBluetoothChooserEvent(content::BluetoothChooser::Event event,
void OnBluetoothChooserEvent(content::BluetoothChooserEvent event,
const std::string& device_id) {
last_event_ = event;
last_device_id_ = device_id;
......@@ -33,7 +33,7 @@ class BluetoothChooserControllerTest : public testing::Test {
BluetoothChooserController bluetooth_chooser_controller_;
MockChooserControllerView mock_bluetooth_chooser_view_;
content::BluetoothChooser::Event last_event_;
content::BluetoothChooserEvent last_event_;
std::string last_device_id_;
private:
......@@ -326,7 +326,7 @@ TEST_F(BluetoothChooserControllerWithDevicesAddedTest, FailedToStartState) {
TEST_F(BluetoothChooserControllerWithDevicesAddedTest, RefreshOptions) {
bluetooth_chooser_controller_.RefreshOptions();
EXPECT_EQ(0u, bluetooth_chooser_controller_.NumOptions());
EXPECT_EQ(content::BluetoothChooser::Event::RESCAN, last_event_);
EXPECT_EQ(content::BluetoothChooserEvent::RESCAN, last_event_);
EXPECT_EQ(std::string(), last_device_id_);
}
......@@ -334,20 +334,20 @@ TEST_F(BluetoothChooserControllerWithDevicesAddedTest,
SelectingOneDeviceShouldCallEventHandler) {
std::vector<size_t> indices{0};
bluetooth_chooser_controller_.Select(indices);
EXPECT_EQ(content::BluetoothChooser::Event::SELECTED, last_event_);
EXPECT_EQ(content::BluetoothChooserEvent::SELECTED, last_event_);
EXPECT_EQ("id_a", last_device_id_);
}
TEST_F(BluetoothChooserControllerWithDevicesAddedTest,
CancelShouldCallEventHandler) {
bluetooth_chooser_controller_.Cancel();
EXPECT_EQ(content::BluetoothChooser::Event::CANCELLED, last_event_);
EXPECT_EQ(content::BluetoothChooserEvent::CANCELLED, last_event_);
EXPECT_EQ(std::string(), last_device_id_);
}
TEST_F(BluetoothChooserControllerWithDevicesAddedTest,
CloseShouldCallEventHandler) {
bluetooth_chooser_controller_.Close();
EXPECT_EQ(content::BluetoothChooser::Event::CANCELLED, last_event_);
EXPECT_EQ(content::BluetoothChooserEvent::CANCELLED, last_event_);
EXPECT_EQ(std::string(), last_device_id_);
}
......@@ -31,7 +31,8 @@ void CastBluetoothChooser::GrantAccess(const std::string& address) {
}
if (available_devices_.find(address) != available_devices_.end()) {
RunEventHandlerAndResetReceiver(Event::SELECTED, address);
RunEventHandlerAndResetReceiver(content::BluetoothChooserEvent::SELECTED,
address);
return;
}
approved_devices_.insert(address);
......@@ -42,7 +43,7 @@ void CastBluetoothChooser::GrantAccessToAllDevices() {
all_devices_approved_ = true;
if (!available_devices_.empty()) {
RunEventHandlerAndResetReceiver(Event::SELECTED,
RunEventHandlerAndResetReceiver(content::BluetoothChooserEvent::SELECTED,
*available_devices_.begin());
}
}
......@@ -58,14 +59,15 @@ void CastBluetoothChooser::AddOrUpdateDevice(const std::string& device_id,
// Note: |device_id| is just a canonical Bluetooth address.
if (all_devices_approved_ ||
approved_devices_.find(device_id) != approved_devices_.end()) {
RunEventHandlerAndResetReceiver(Event::SELECTED, device_id);
RunEventHandlerAndResetReceiver(content::BluetoothChooserEvent::SELECTED,
device_id);
return;
}
available_devices_.insert(device_id);
}
void CastBluetoothChooser::RunEventHandlerAndResetReceiver(
content::BluetoothChooser::Event event,
content::BluetoothChooserEvent event,
std::string address) {
DCHECK(event_handler_);
std::move(event_handler_).Run(event, std::move(address));
......@@ -77,7 +79,8 @@ void CastBluetoothChooser::OnClientConnectionError() {
// tear down the client immediately. In this case, do not run the event
// handler, as we may have not had the opportunity to select a device.
if (!all_devices_approved_ && event_handler_) {
RunEventHandlerAndResetReceiver(Event::CANCELLED, "");
RunEventHandlerAndResetReceiver(content::BluetoothChooserEvent::CANCELLED,
"");
}
}
......
......@@ -46,7 +46,7 @@ class CastBluetoothChooser : public content::BluetoothChooser,
// Runs the event_handler and resets the client receiver. After this is
// called, this class should not be used.
void RunEventHandlerAndResetReceiver(content::BluetoothChooser::Event event,
void RunEventHandlerAndResetReceiver(content::BluetoothChooserEvent event,
std::string address);
// Called when the remote connection held by |receiver_| is torn down.
......
......@@ -92,7 +92,7 @@ TEST_F(CastBluetoothChooserTest, GrantAccessBeforeDeviceAvailable) {
AddDeviceToChooser("99:88:77:66:55:44");
// Now make the approved device available. |handler| should be called.
EXPECT_CALL(handler_, Run(content::BluetoothChooser::Event::SELECTED,
EXPECT_CALL(handler_, Run(content::BluetoothChooserEvent::SELECTED,
"aa:bb:cc:dd:ee:ff"));
EXPECT_CALL(provider().connection_closed(), Run());
AddDeviceToChooser("aa:bb:cc:dd:ee:ff");
......@@ -108,7 +108,7 @@ TEST_F(CastBluetoothChooserTest, DiscoverDeviceBeforeAccessGranted) {
AddDeviceToChooser("99:88:77:66:55:44");
// Now approve one of those devices. |handler| should run.
EXPECT_CALL(handler_, Run(content::BluetoothChooser::Event::SELECTED,
EXPECT_CALL(handler_, Run(content::BluetoothChooserEvent::SELECTED,
"00:00:00:11:00:00"));
EXPECT_CALL(provider().connection_closed(), Run());
provider().client()->GrantAccess("00:00:00:11:00:00");
......@@ -122,7 +122,7 @@ TEST_F(CastBluetoothChooserTest, GrantAccessToAllDevicesBeforeDiscovery) {
task_environment_.RunUntilIdle();
// Now make the some device available. |handler| should be called.
EXPECT_CALL(handler_, Run(content::BluetoothChooser::Event::SELECTED,
EXPECT_CALL(handler_, Run(content::BluetoothChooserEvent::SELECTED,
"aa:bb:cc:dd:ee:ff"));
EXPECT_CALL(provider().connection_closed(), Run());
AddDeviceToChooser("aa:bb:cc:dd:ee:ff");
......@@ -138,7 +138,7 @@ TEST_F(CastBluetoothChooserTest, GrantAccessToAllDevicesAfterDiscovery) {
// Now grant access to all devices. |handler| should be called with one of the
// available devices.
EXPECT_CALL(handler_, Run(content::BluetoothChooser::Event::SELECTED,
EXPECT_CALL(handler_, Run(content::BluetoothChooserEvent::SELECTED,
AnyOf("11:22:33:44:55:66", "aa:bb:cc:dd:ee:ff",
"00:00:00:11:00:00")));
EXPECT_CALL(provider().connection_closed(), Run());
......@@ -160,7 +160,7 @@ TEST_F(CastBluetoothChooserTest, TearDownClientAfterAllAccessGranted) {
task_environment_.RunUntilIdle();
// As soon as a device is available, run the handler.
EXPECT_CALL(handler_, Run(content::BluetoothChooser::Event::SELECTED,
EXPECT_CALL(handler_, Run(content::BluetoothChooserEvent::SELECTED,
"aa:bb:cc:dd:ee:ff"));
AddDeviceToChooser("aa:bb:cc:dd:ee:ff");
}
......@@ -172,8 +172,8 @@ TEST_F(CastBluetoothChooserTest, TearDownClientBeforeApprovedDeviceDiscovered) {
AddDeviceToChooser("aa:bb:cc:dd:ee:ff");
// Tear the client down before any access is granted. |handler| should run,
// but with Event::CANCELLED.
EXPECT_CALL(handler_, Run(content::BluetoothChooser::Event::CANCELLED, ""));
// but with content::BluetoothChooserEvent::CANCELLED.
EXPECT_CALL(handler_, Run(content::BluetoothChooserEvent::CANCELLED, ""));
provider().reset_client();
EXPECT_FALSE(provider().client());
task_environment_.RunUntilIdle();
......
......@@ -197,25 +197,25 @@ void StopDiscoverySession(
discovery_session->Stop();
}
UMARequestDeviceOutcome OutcomeFromChooserEvent(BluetoothChooser::Event event) {
UMARequestDeviceOutcome OutcomeFromChooserEvent(BluetoothChooserEvent event) {
switch (event) {
case BluetoothChooser::Event::DENIED_PERMISSION:
case BluetoothChooserEvent::DENIED_PERMISSION:
return UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_DENIED_PERMISSION;
case BluetoothChooser::Event::CANCELLED:
case BluetoothChooserEvent::CANCELLED:
return UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_CANCELLED;
case BluetoothChooser::Event::SHOW_OVERVIEW_HELP:
case BluetoothChooserEvent::SHOW_OVERVIEW_HELP:
return UMARequestDeviceOutcome::BLUETOOTH_OVERVIEW_HELP_LINK_PRESSED;
case BluetoothChooser::Event::SHOW_ADAPTER_OFF_HELP:
case BluetoothChooserEvent::SHOW_ADAPTER_OFF_HELP:
return UMARequestDeviceOutcome::ADAPTER_OFF_HELP_LINK_PRESSED;
case BluetoothChooser::Event::SHOW_NEED_LOCATION_HELP:
case BluetoothChooserEvent::SHOW_NEED_LOCATION_HELP:
return UMARequestDeviceOutcome::NEED_LOCATION_HELP_LINK_PRESSED;
case BluetoothChooser::Event::SELECTED:
case BluetoothChooserEvent::SELECTED:
// We can't know if we are going to send a success message yet because
// the device could have vanished. This event should be histogramed
// manually after checking if the device is still around.
NOTREACHED();
return UMARequestDeviceOutcome::SUCCESS;
case BluetoothChooser::Event::RESCAN:
case BluetoothChooserEvent::RESCAN:
return UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_RESCAN;
}
NOTREACHED();
......@@ -335,7 +335,7 @@ void BluetoothDeviceChooserController::GetDevice(
if (!chooser_->CanAskForScanningPermission()) {
DVLOG(1) << "Closing immediately because Chooser cannot obtain permission.";
OnBluetoothChooserEvent(BluetoothChooser::Event::DENIED_PERMISSION,
OnBluetoothChooserEvent(BluetoothChooserEvent::DENIED_PERMISSION,
"" /* device_address */);
return;
}
......@@ -385,7 +385,7 @@ void BluetoothDeviceChooserController::AdapterPoweredChanged(bool powered) {
powered ? BluetoothChooser::AdapterPresence::POWERED_ON
: BluetoothChooser::AdapterPresence::POWERED_OFF);
if (powered) {
OnBluetoothChooserEvent(BluetoothChooser::Event::RESCAN,
OnBluetoothChooserEvent(BluetoothChooserEvent::RESCAN,
"" /* device_address */);
}
}
......@@ -495,14 +495,14 @@ void BluetoothDeviceChooserController::OnStartDiscoverySessionFailed() {
}
void BluetoothDeviceChooserController::OnBluetoothChooserEvent(
BluetoothChooser::Event event,
BluetoothChooserEvent event,
const std::string& device_address) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Shouldn't recieve an event from a closed chooser.
DCHECK(chooser_);
switch (event) {
case BluetoothChooser::Event::RESCAN:
case BluetoothChooserEvent::RESCAN:
RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event));
device_ids_.clear();
PopulateConnectedDevices();
......@@ -510,31 +510,31 @@ void BluetoothDeviceChooserController::OnBluetoothChooserEvent(
StartDeviceDiscovery();
// No need to close the chooser so we return.
return;
case BluetoothChooser::Event::DENIED_PERMISSION:
case BluetoothChooserEvent::DENIED_PERMISSION:
RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event));
PostErrorCallback(
WebBluetoothResult::CHOOSER_NOT_SHOWN_USER_DENIED_PERMISSION_TO_SCAN);
break;
case BluetoothChooser::Event::CANCELLED:
case BluetoothChooserEvent::CANCELLED:
RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event));
PostErrorCallback(WebBluetoothResult::CHOOSER_CANCELLED);
break;
case BluetoothChooser::Event::SHOW_OVERVIEW_HELP:
case BluetoothChooserEvent::SHOW_OVERVIEW_HELP:
DVLOG(1) << "Overview Help link pressed.";
RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event));
PostErrorCallback(WebBluetoothResult::CHOOSER_CANCELLED);
break;
case BluetoothChooser::Event::SHOW_ADAPTER_OFF_HELP:
case BluetoothChooserEvent::SHOW_ADAPTER_OFF_HELP:
DVLOG(1) << "Adapter Off Help link pressed.";
RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event));
PostErrorCallback(WebBluetoothResult::CHOOSER_CANCELLED);
break;
case BluetoothChooser::Event::SHOW_NEED_LOCATION_HELP:
case BluetoothChooserEvent::SHOW_NEED_LOCATION_HELP:
DVLOG(1) << "Need Location Help link pressed.";
RecordRequestDeviceOutcome(OutcomeFromChooserEvent(event));
PostErrorCallback(WebBluetoothResult::CHOOSER_CANCELLED);
break;
case BluetoothChooser::Event::SELECTED:
case BluetoothChooserEvent::SELECTED:
RecordNumOfDevices(options_->accept_all_devices, device_ids_.size());
// RecordRequestDeviceOutcome is called in the callback, because the
// device may have vanished.
......
......@@ -114,7 +114,7 @@ class CONTENT_EXPORT BluetoothDeviceChooserController final {
// Runs |error_callback_| if the chooser was cancelled or if we weren't able
// to show the chooser. Otherwise runs |success_callback_| with
// |device_address|.
void OnBluetoothChooserEvent(BluetoothChooser::Event event,
void OnBluetoothChooserEvent(BluetoothChooserEvent event,
const std::string& device_address);
// Helper function to asynchronously run success_callback_.
......
......@@ -125,6 +125,7 @@ android_library("content_java") {
":generate_sandboxed_service_srcjar",
":is_ready_to_pay_service_aidl",
"//content/browser/accessibility:content_browser_accessibility_java_enums_srcjar",
"//content/public/browser:bluetooth_chooser_event_javagen",
"//ui/touch_selection:ui_touch_handle_orientation_srcjar",
"//ui/touch_selection:ui_touch_selection_enums_srcjar",
]
......
......@@ -559,6 +559,9 @@ if (is_android) {
java_cpp_enum("contacts_picker_properties_requested_javagen") {
sources = [ "contacts_picker_properties_requested.h" ]
}
java_cpp_enum("bluetooth_chooser_event_javagen") {
sources = [ "bluetooth_chooser.h" ]
}
}
proto_library("proto") {
......
......@@ -13,41 +13,34 @@
namespace content {
// A Java counterpart will be generated for this enum.
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.content_public.browser.bluetooth
enum class BluetoothChooserEvent {
DENIED_PERMISSION,
CANCELLED,
SELECTED,
RESCAN,
SHOW_OVERVIEW_HELP,
SHOW_ADAPTER_OFF_HELP,
SHOW_NEED_LOCATION_HELP,
};
// Represents a way to ask the user to select a Bluetooth device from a list of
// options.
class CONTENT_EXPORT BluetoothChooser {
public:
enum class Event {
// Chromium can't ask for permission to scan for Bluetooth devices.
DENIED_PERMISSION,
// The user cancelled the chooser instead of selecting a device.
CANCELLED,
// The user selected device |opt_device_id|.
SELECTED,
// The user asked for a new Bluetooth discovery session to start.
RESCAN,
// Show overview page for Bluetooth.
SHOW_OVERVIEW_HELP,
// Show help page explaining why scanning failed because Bluetooth is off.
SHOW_ADAPTER_OFF_HELP,
// Show help page explaining why Chromium needs the Location permission to
// scan for Bluetooth devices. Only used on Android.
SHOW_NEED_LOCATION_HELP,
// As the dialog implementations grow more user-visible buttons and knobs,
// we'll add enumerators here to support them.
};
// Chooser implementations are constructed with an |EventHandler| and report
// user interaction with the chooser through it. |opt_device_id| is an empty
// string except for Event::SELECTED.
// string except for BluetoothChooserEvent::SELECTED.
//
// The EventHandler won't be called after the chooser object is destroyed.
//
// After the EventHandler is called with Event::CANCELLED, Event::SELECTED,
// Event::DENIED_PERMISSION or Event::SHOW_*, it won't be called again, and
// After the EventHandler is called with BluetoothChooserEvent::CANCELLED,
// BluetoothChooserEvent::SELECTED, BluetoothChooserEvent::DENIED_PERMISSION
// or BluetoothChooserEvent::SHOW_*, it won't be called again, and
// users must not call any more BluetoothChooser methods.
typedef base::RepeatingCallback<void(Event, const std::string& opt_device_id)>
typedef base::RepeatingCallback<void(BluetoothChooserEvent,
const std::string& opt_device_id)>
EventHandler;
BluetoothChooser() {}
......
......@@ -44,12 +44,12 @@ void FakeBluetoothChooser::OnRunBluetoothChooser(
void FakeBluetoothChooser::SelectPeripheral(
const std::string& peripheral_address) {
DCHECK(event_handler_);
event_handler_.Run(BluetoothChooser::Event::SELECTED, peripheral_address);
event_handler_.Run(BluetoothChooserEvent::SELECTED, peripheral_address);
}
void FakeBluetoothChooser::Cancel() {
DCHECK(event_handler_);
event_handler_.Run(BluetoothChooser::Event::CANCELLED, std::string());
event_handler_.Run(BluetoothChooserEvent::CANCELLED, std::string());
client_->OnEvent(mojom::FakeBluetoothChooserEvent::New(
mojom::ChooserEventType::CHOOSER_CLOSED, /*origin=*/base::nullopt,
/*peripheral_address=*/base::nullopt));
......@@ -57,7 +57,7 @@ void FakeBluetoothChooser::Cancel() {
void FakeBluetoothChooser::Rescan() {
DCHECK(event_handler_);
event_handler_.Run(BluetoothChooser::Event::RESCAN, std::string());
event_handler_.Run(BluetoothChooserEvent::RESCAN, std::string());
client_->OnEvent(mojom::FakeBluetoothChooserEvent::New(
mojom::ChooserEventType::DISCOVERING, /*origin=*/base::nullopt,
/*peripheral_address=*/base::nullopt));
......
......@@ -91,7 +91,7 @@ class WebTestBluetoothChooserFactory::Chooser : public BluetoothChooser {
WebTestBluetoothChooserFactory::WebTestBluetoothChooserFactory() {}
WebTestBluetoothChooserFactory::~WebTestBluetoothChooserFactory() {
SendEvent(BluetoothChooser::Event::CANCELLED, "");
SendEvent(BluetoothChooserEvent::CANCELLED, "");
}
std::unique_ptr<BluetoothChooser>
......@@ -113,7 +113,7 @@ std::vector<std::string> WebTestBluetoothChooserFactory::GetAndResetEvents() {
return result;
}
void WebTestBluetoothChooserFactory::SendEvent(BluetoothChooser::Event event,
void WebTestBluetoothChooserFactory::SendEvent(BluetoothChooserEvent event,
const std::string& device_id) {
// Copy |choosers_| to make sure event handler executions that modify
// |choosers_| don't invalidate iterators.
......
......@@ -27,7 +27,7 @@ class WebTestBluetoothChooserFactory {
std::vector<std::string> GetAndResetEvents();
void SendEvent(BluetoothChooser::Event event, const std::string& device_id);
void SendEvent(BluetoothChooserEvent event, const std::string& device_id);
private:
class Chooser;
......
......@@ -1777,13 +1777,13 @@ void WebTestControlHost::SendBluetoothManualChooserEvent(
"sendBluetoothManualChooserEvent.");
return;
}
BluetoothChooser::Event event;
BluetoothChooserEvent event;
if (event_name == "cancelled") {
event = BluetoothChooser::Event::CANCELLED;
event = BluetoothChooserEvent::CANCELLED;
} else if (event_name == "selected") {
event = BluetoothChooser::Event::SELECTED;
event = BluetoothChooserEvent::SELECTED;
} else if (event_name == "rescan") {
event = BluetoothChooser::Event::RESCAN;
event = BluetoothChooserEvent::RESCAN;
} else {
printer_->AddErrorMessage(base::StringPrintf(
"FAIL: Unexpected sendBluetoothManualChooserEvent() event name '%s'.",
......
......@@ -21,7 +21,7 @@ void WebTestFirstDeviceBluetoothChooser::SetAdapterPresence(
case AdapterPresence::POWERED_OFF:
// Without a user-visible dialog, if the adapter is off, there's no way to
// ask the user to turn it on again, so we should cancel.
event_handler_.Run(Event::CANCELLED, "");
event_handler_.Run(BluetoothChooserEvent::CANCELLED, "");
break;
case AdapterPresence::POWERED_ON:
break;
......@@ -37,7 +37,7 @@ void WebTestFirstDeviceBluetoothChooser::ShowDiscoveryState(
// device, we'll never find one, so we should cancel.
VLOG(1) << "WebTestFirstDeviceBluetoothChooser found nothing before "
"going idle.";
event_handler_.Run(Event::CANCELLED, "");
event_handler_.Run(BluetoothChooserEvent::CANCELLED, "");
break;
case DiscoveryState::DISCOVERING:
break;
......@@ -51,7 +51,7 @@ void WebTestFirstDeviceBluetoothChooser::AddOrUpdateDevice(
bool is_gatt_connected,
bool is_paired,
int signal_strength_level) {
event_handler_.Run(Event::SELECTED, device_id);
event_handler_.Run(BluetoothChooserEvent::SELECTED, device_id);
}
} // namespace content
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment