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 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_PUBLIC_BROWSER_BLUETOOTH_CHOOSER_H_ 6 #define CONTENT_PUBLIC_BROWSER_BLUETOOTH_CHOOSER_H_ 7 8 #include <string> 9 10 #include "base/callback.h" 11 #include "base/strings/string16.h" 12 #include "content/common/content_export.h" 13 14 namespace content { 15 16 // A Java counterpart will be generated for this enum. 17 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.content_public.browser.bluetooth 18 enum class BluetoothChooserEvent { 19 DENIED_PERMISSION, 20 CANCELLED, 21 SELECTED, 22 RESCAN, 23 SHOW_OVERVIEW_HELP, 24 SHOW_ADAPTER_OFF_HELP, 25 SHOW_NEED_LOCATION_HELP, 26 }; 27 28 // Represents a way to ask the user to select a Bluetooth device from a list of 29 // options. 30 class CONTENT_EXPORT BluetoothChooser { 31 public: 32 // Chooser implementations are constructed with an |EventHandler| and report 33 // user interaction with the chooser through it. |opt_device_id| is an empty 34 // string except for BluetoothChooserEvent::SELECTED. 35 // 36 // The EventHandler won't be called after the chooser object is destroyed. 37 // 38 // After the EventHandler is called with BluetoothChooserEvent::CANCELLED, 39 // BluetoothChooserEvent::SELECTED, BluetoothChooserEvent::DENIED_PERMISSION 40 // or BluetoothChooserEvent::SHOW_*, it won't be called again, and 41 // users must not call any more BluetoothChooser methods. 42 typedef base::RepeatingCallback<void(BluetoothChooserEvent, 43 const std::string& opt_device_id)> 44 EventHandler; 45 BluetoothChooser()46 BluetoothChooser() {} 47 virtual ~BluetoothChooser(); 48 49 // Some platforms (especially Android) require Chromium to have permission 50 // from the user before it can scan for Bluetooth devices. This function 51 // returns false if Chromium isn't even allowed to ask. It defaults to true. 52 virtual bool CanAskForScanningPermission(); 53 54 // Lets the chooser tell the user the state of the Bluetooth adapter. This 55 // defaults to POWERED_ON. 56 enum class AdapterPresence { ABSENT, POWERED_OFF, POWERED_ON }; SetAdapterPresence(AdapterPresence presence)57 virtual void SetAdapterPresence(AdapterPresence presence) {} 58 59 // Lets the chooser tell the user whether discovery is happening. This 60 // defaults to DISCOVERING. 61 enum class DiscoveryState { FAILED_TO_START, DISCOVERING, IDLE }; ShowDiscoveryState(DiscoveryState state)62 virtual void ShowDiscoveryState(DiscoveryState state) {} 63 64 // Adds a new device to the chooser or updates the information of an existing 65 // device. 66 // 67 // Sometimes when a Bluetooth device stops advertising, the |device_name| can 68 // be invalid, and in that case |should_update_name| will be set false. 69 // 70 // The range of |signal_strength_level| is -1 to 4 inclusively. 71 // -1 means that the device doesn't have RSSI which happens when the device 72 // is already connected. AddOrUpdateDevice(const std::string & device_id,bool should_update_name,const base::string16 & device_name,bool is_gatt_connected,bool is_paired,int signal_strength_level)73 virtual void AddOrUpdateDevice(const std::string& device_id, 74 bool should_update_name, 75 const base::string16& device_name, 76 bool is_gatt_connected, 77 bool is_paired, 78 int signal_strength_level) {} 79 }; 80 81 } // namespace content 82 83 #endif // CONTENT_PUBLIC_BROWSER_BLUETOOTH_CHOOSER_H_ 84