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

Side by Side Diff: content/browser/bluetooth/bluetooth_device_chooser_controller.h

Issue 2059543002: bluetooth: Move FactoryWrapper to device and expose a function for testing in chooser controller (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@my-origin
Patch Set: Remove code from client interface Created 4 years, 5 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DEVICE_CHOOSER_CONTROLLER_H_ 5 #ifndef CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DEVICE_CHOOSER_CONTROLLER_H_
6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DEVICE_CHOOSER_CONTROLLER_H_ 6 #define CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DEVICE_CHOOSER_CONTROLLER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "base/timer/timer.h" 12 #include "base/timer/timer.h"
13 #include "content/common/content_export.h"
13 #include "content/public/browser/bluetooth_chooser.h" 14 #include "content/public/browser/bluetooth_chooser.h"
14 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj om.h" 15 #include "third_party/WebKit/public/platform/modules/bluetooth/web_bluetooth.moj om.h"
15 16
16 namespace device { 17 namespace device {
17 class BluetoothAdapter; 18 class BluetoothAdapter;
18 class BluetoothDevice; 19 class BluetoothDevice;
19 class BluetoothDiscoveryFilter; 20 class BluetoothDiscoveryFilter;
20 class BluetoothDiscoverySession; 21 class BluetoothDiscoverySession;
21 } 22 }
22 23
23 namespace content { 24 namespace content {
24 25
25 class RenderFrameHost; 26 class RenderFrameHost;
26 class WebContents; 27 class WebContents;
27 class WebBluetoothServiceImpl; 28 class WebBluetoothServiceImpl;
28 29
29 // Class that interacts with a chooser and starts a bluetooth discovery session. 30 // Class that interacts with a chooser and starts a bluetooth discovery session.
30 // This class needs to be re-instantiated for each call to GetDevice(). Calling 31 // This class needs to be re-instantiated for each call to GetDevice(). Calling
31 // GetDevice() twice for the same instance will DCHECK. 32 // GetDevice() twice for the same instance will DCHECK.
32 class BluetoothDeviceChooserController final { 33 class CONTENT_EXPORT BluetoothDeviceChooserController final {
33 public: 34 public:
34 typedef base::Callback<void(blink::mojom::WebBluetoothRequestDeviceOptionsPtr, 35 typedef base::Callback<void(blink::mojom::WebBluetoothRequestDeviceOptionsPtr,
35 const std::string& device_address)> 36 const std::string& device_address)>
36 SuccessCallback; 37 SuccessCallback;
37 typedef base::Callback<void(blink::mojom::WebBluetoothError error)> 38 typedef base::Callback<void(blink::mojom::WebBluetoothError error)>
38 ErrorCallback; 39 ErrorCallback;
39 40
40 // |web_bluetooth_service_| service that owns this class. 41 // |web_bluetooth_service_| service that owns this class.
41 // |render_frame_host| should be the RenderFrameHost that owns the 42 // |render_frame_host| should be the RenderFrameHost that owns the
42 // |web_bluetooth_service_|. 43 // |web_bluetooth_service_|.
43 // |adapter| should be the adapter used to scan for Bluetooth devices. 44 // |adapter| should be the adapter used to scan for Bluetooth devices.
44 // |scan_duration| is how long will a discovery session be active.
45 BluetoothDeviceChooserController( 45 BluetoothDeviceChooserController(
46 WebBluetoothServiceImpl* web_bluetooth_service_, 46 WebBluetoothServiceImpl* web_bluetooth_service_,
47 RenderFrameHost* render_frame_host, 47 RenderFrameHost* render_frame_host,
48 device::BluetoothAdapter* adapter, 48 device::BluetoothAdapter* adapter);
49 base::TimeDelta scan_duration);
50 ~BluetoothDeviceChooserController(); 49 ~BluetoothDeviceChooserController();
51 50
52 // This function performs the following checks before starting a discovery 51 // This function performs the following checks before starting a discovery
53 // session: 52 // session:
54 // - Validates filters in |request_device_options|. 53 // - Validates filters in |request_device_options|.
55 // - Removes any blacklisted UUIDs from 54 // - Removes any blacklisted UUIDs from
56 // |request_device_options.optinal_services|. 55 // |request_device_options.optinal_services|.
57 // - Checks if the request came from a cross-origin iframe. 56 // - Checks if the request came from a cross-origin iframe.
58 // - Checks if the request came from a unique origin. 57 // - Checks if the request came from a unique origin.
59 // - Checks if the adapter is present. 58 // - Checks if the adapter is present.
(...skipping 12 matching lines...) Expand all
72 const ErrorCallback& error_callback); 71 const ErrorCallback& error_callback);
73 72
74 // Adds a device to the chooser. Should only be called after GetDevice and 73 // Adds a device to the chooser. Should only be called after GetDevice and
75 // before either of the callbacks are run. 74 // before either of the callbacks are run.
76 void AddFilteredDevice(const device::BluetoothDevice& device); 75 void AddFilteredDevice(const device::BluetoothDevice& device);
77 76
78 // Stops the current discovery session and notifies the chooser 77 // Stops the current discovery session and notifies the chooser
79 // that the adapter changed states. 78 // that the adapter changed states.
80 void AdapterPoweredChanged(bool powered); 79 void AdapterPoweredChanged(bool powered);
81 80
81 // After this method is called any new instance of
82 // BluetoothDeviceChooserController will have a scan duration of 0.
83 static void SetTestScanDurationForTesting();
84
82 private: 85 private:
83 // Populates the chooser with the devices that are already in the adapter. 86 // Populates the chooser with the devices that are already in the adapter.
84 void PopulateFoundDevices(); 87 void PopulateFoundDevices();
85 88
86 // Notifies the chooser that discovery is starting and starts a discovery 89 // Notifies the chooser that discovery is starting and starts a discovery
87 // session. 90 // session.
88 void StartDeviceDiscovery(); 91 void StartDeviceDiscovery();
89 92
90 // Stops the discovery session and notifies the chooser. 93 // Stops the discovery session and notifies the chooser.
91 void StopDeviceDiscovery(); 94 void StopDeviceDiscovery();
92 95
93 // StartDiscoverySessionWithFilter callbacks: 96 // StartDiscoverySessionWithFilter callbacks:
94 void OnStartDiscoverySessionSuccess( 97 void OnStartDiscoverySessionSuccess(
95 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session); 98 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session);
96 void OnStartDiscoverySessionFailed(); 99 void OnStartDiscoverySessionFailed();
97 100
98 // BluetoothChooser::EventHandler: 101 // BluetoothChooser::EventHandler:
99 // Runs error_callback_ if the chooser was cancelled or if we weren't able 102 // Runs error_callback_ if the chooser was cancelled or if we weren't able
100 // to show the chooser. Otherwise runs success_callback_ with 103 // to show the chooser. Otherwise runs success_callback_ with
101 // |device_address|. 104 // |device_address|.
102 void OnBluetoothChooserEvent(BluetoothChooser::Event event, 105 void OnBluetoothChooserEvent(BluetoothChooser::Event event,
103 const std::string& device_address); 106 const std::string& device_address);
104 107
105 // Helper function to asynchronously run success_callback_. 108 // Helper function to asynchronously run success_callback_.
106 void PostSuccessCallback(const std::string& device_address); 109 void PostSuccessCallback(const std::string& device_address);
107 // Helper function to asynchronously run error_callback_. 110 // Helper function to asynchronously run error_callback_.
108 void PostErrorCallback(blink::mojom::WebBluetoothError error); 111 void PostErrorCallback(blink::mojom::WebBluetoothError error);
109 112
113 // If true all new instances of this class will have a scan duration of 0.
114 static bool use_test_scan_duration_;
115
110 // The adapter used to get existing devices and start a discovery session. 116 // The adapter used to get existing devices and start a discovery session.
111 device::BluetoothAdapter* adapter_; 117 device::BluetoothAdapter* adapter_;
112 // The WebBluetoothServiceImpl that owns this instance. 118 // The WebBluetoothServiceImpl that owns this instance.
113 WebBluetoothServiceImpl* web_bluetooth_service_; 119 WebBluetoothServiceImpl* web_bluetooth_service_;
114 // The RenderFrameHost that owns web_bluetooth_service_. 120 // The RenderFrameHost that owns web_bluetooth_service_.
115 RenderFrameHost* render_frame_host_; 121 RenderFrameHost* render_frame_host_;
116 // The WebContents that owns render_frame_host_. 122 // The WebContents that owns render_frame_host_.
117 WebContents* web_contents_; 123 WebContents* web_contents_;
118 124
119 // Contains the filters and optional services used when scanning. 125 // Contains the filters and optional services used when scanning.
(...skipping 19 matching lines...) Expand all
139 // Weak pointer factory for generating 'this' pointers that might live longer 145 // Weak pointer factory for generating 'this' pointers that might live longer
140 // than we do. 146 // than we do.
141 // Note: This should remain the last member so it'll be destroyed and 147 // Note: This should remain the last member so it'll be destroyed and
142 // invalidate its weak pointers before any other members are destroyed. 148 // invalidate its weak pointers before any other members are destroyed.
143 base::WeakPtrFactory<BluetoothDeviceChooserController> weak_ptr_factory_; 149 base::WeakPtrFactory<BluetoothDeviceChooserController> weak_ptr_factory_;
144 }; 150 };
145 151
146 } // namespace content 152 } // namespace content
147 153
148 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DEVICE_CHOOSER_CONTROLLER_H_ 154 #endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_DEVICE_CHOOSER_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698