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 // Represents a way to ask the user to select a Bluetooth device from a list of 17 // options. 18 class CONTENT_EXPORT BluetoothChooser { 19 public: 20 enum class Event { 21 // Chromium can't ask for permission to scan for Bluetooth devices. 22 DENIED_PERMISSION, 23 // The user cancelled the chooser instead of selecting a device. 24 CANCELLED, 25 // The user selected device |opt_device_id|. 26 SELECTED, 27 // The user asked for a new Bluetooth discovery session to start. 28 RESCAN, 29 // Show overview page for Bluetooth. 30 SHOW_OVERVIEW_HELP, 31 // Show help page explaining why scanning failed because Bluetooth is off. 32 SHOW_ADAPTER_OFF_HELP, 33 // Show help page explaining why Chromium needs the Location permission to 34 // scan for Bluetooth devices. Only used on Android. 35 SHOW_NEED_LOCATION_HELP, 36 37 // As the dialog implementations grow more user-visible buttons and knobs, 38 // we'll add enumerators here to support them. 39 }; 40 41 // Chooser implementations are constructed with an |EventHandler| and report 42 // user interaction with the chooser through it. |opt_device_id| is an empty 43 // string except for Event::SELECTED. 44 // 45 // The EventHandler won't be called after the chooser object is destroyed. 46 // 47 // After the EventHandler is called with Event::CANCELLED, Event::SELECTED, 48 // Event::DENIED_PERMISSION or Event::SHOW_*, it won't be called again, and 49 // users must not call any more BluetoothChooser methods. 50 typedef base::RepeatingCallback<void(Event, const std::string& opt_device_id)> 51 EventHandler; 52 BluetoothChooser()53 BluetoothChooser() {} 54 virtual ~BluetoothChooser(); 55 56 // Some platforms (especially Android) require Chromium to have permission 57 // from the user before it can scan for Bluetooth devices. This function 58 // returns false if Chromium isn't even allowed to ask. It defaults to true. 59 virtual bool CanAskForScanningPermission(); 60 61 // Lets the chooser tell the user the state of the Bluetooth adapter. This 62 // defaults to POWERED_ON. 63 enum class AdapterPresence { ABSENT, POWERED_OFF, POWERED_ON }; SetAdapterPresence(AdapterPresence presence)64 virtual void SetAdapterPresence(AdapterPresence presence) {} 65 66 // Lets the chooser tell the user whether discovery is happening. This 67 // defaults to DISCOVERING. 68 enum class DiscoveryState { FAILED_TO_START, DISCOVERING, IDLE }; ShowDiscoveryState(DiscoveryState state)69 virtual void ShowDiscoveryState(DiscoveryState state) {} 70 71 // Adds a new device to the chooser or updates the information of an existing 72 // device. 73 // 74 // Sometimes when a Bluetooth device stops advertising, the |device_name| can 75 // be invalid, and in that case |should_update_name| will be set false. 76 // 77 // The range of |signal_strength_level| is -1 to 4 inclusively. 78 // -1 means that the device doesn't have RSSI which happens when the device 79 // 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)80 virtual void AddOrUpdateDevice(const std::string& device_id, 81 bool should_update_name, 82 const base::string16& device_name, 83 bool is_gatt_connected, 84 bool is_paired, 85 int signal_strength_level) {} 86 }; 87 88 } // namespace content 89 90 #endif // CONTENT_PUBLIC_BROWSER_BLUETOOTH_CHOOSER_H_ 91