Skip to content

Commit 569a0cc

Browse files
authored
Extend disable_bluetooth flag to content, device, and services (#8937)
The previous PR that introduced the disable_bluetooth flag only excluded the interface under third_party/blink. This change extends the exclusion to Bluetooth-related codes under content, device, and services when 'disable_bluetooth' is true. Additionally, Serial (which depends on Bluetooth) is excluded from lightweight builds as well.
1 parent 43e0866 commit 569a0cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+746
-98
lines changed

BUILD.gn

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import("//build/config/compiler/compiler.gni")
1414
import("//build/config/cronet/config.gni")
1515
import("//build/config/dcheck_always_on.gni")
1616
import("//build/config/features.gni")
17+
import("//build/config/lightweight.gni")
1718
import("//build/config/rust.gni")
1819
import("//build/config/sanitizers/sanitizers.gni")
1920
import("//build/config/ui.gni")
@@ -873,6 +874,10 @@ group("gn_all") {
873874
if (!is_android && !is_ios) {
874875
deps += [ "//components/cronet:cronet_tests" ]
875876
}
877+
878+
if (disable_bluetooth && !is_android && !is_ios) {
879+
deps -= [ "//content/browser/bluetooth/tools:bluetooth_metrics_hash" ]
880+
}
876881
}
877882

878883
if (is_chrome_for_testing) {
@@ -1350,6 +1355,12 @@ if (use_blink && !is_cronet_build) {
13501355
"//build/android/",
13511356
]
13521357
}
1358+
1359+
if (disable_bluetooth) {
1360+
data_deps -= [
1361+
"//device/bluetooth/public/mojom:fake_bluetooth_interfaces_js_data_deps",
1362+
]
1363+
}
13531364
}
13541365

13551366
_common_web_test_script = "//testing/scripts/run_isolated_script_test.py"

build/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ buildflag_header("lightweight_buildflags") {
129129
header = "lightweight_buildflags.h"
130130
flags = [
131131
"DISABLE_XR=$disable_xr",
132+
"DISABLE_BLUETOOTH=$disable_bluetooth",
132133
]
133134
}
134135

components/BUILD.gn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import("//base/debug/debug.gni")
66
import("//build/config/chrome_build.gni")
77
import("//build/config/features.gni")
8+
import("//build/config/lightweight.gni")
89
import("//build/config/ui.gni")
910
import("//components/compose/features.gni")
1011
import("//components/enterprise/buildflags/buildflags.gni")
@@ -1229,6 +1230,9 @@ if (use_blink) {
12291230
"//sandbox",
12301231
]
12311232
}
1233+
1234+
# TODO(lightweight): "device/bluetooth" can be removed. Upstream to Chromium.
1235+
deps -= [ "//device/bluetooth" ]
12321236
}
12331237

12341238
test("components_perftests") {

components/permissions/BUILD.gn

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Use of this source code is governed by a BSD-style license that can be
33
# found in the LICENSE file.
44

5+
import("//build/config/lightweight.gni")
56
import("//components/guest_view/buildflags/buildflags.gni")
67
import("//device/vr/buildflags/buildflags.gni")
78
import("//services/device/public/cpp/geolocation/buildflags.gni")
@@ -235,6 +236,33 @@ source_set("permissions") {
235236
public_deps = [ ":permissions_common" ]
236237

237238
configs += [ "//build/config/compiler:wexit_time_destructors" ]
239+
240+
if (disable_bluetooth) {
241+
sources -= [
242+
"bluetooth_delegate_impl.cc",
243+
"bluetooth_delegate_impl.h",
244+
"contexts/bluetooth_chooser_context.cc",
245+
"contexts/bluetooth_chooser_context.h",
246+
]
247+
248+
if (!is_android) {
249+
sources -= [
250+
"bluetooth_chooser_controller.cc",
251+
"bluetooth_chooser_controller.h",
252+
"bluetooth_chooser_desktop.cc",
253+
"bluetooth_chooser_desktop.h",
254+
"bluetooth_scanning_prompt_controller.cc",
255+
"bluetooth_scanning_prompt_controller.h",
256+
"bluetooth_scanning_prompt_desktop.cc",
257+
"bluetooth_scanning_prompt_desktop.h",
258+
]
259+
}
260+
261+
deps -= [
262+
"//device/bluetooth",
263+
"//device/bluetooth/public/cpp",
264+
]
265+
}
238266
}
239267

240268
source_set("test_support") {

content/app/BUILD.gn

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import("//build/config/apple/mobile_config.gni")
66
import("//build/config/chrome_build.gni")
77
import("//build/config/features.gni")
8+
import("//build/config/lightweight.gni")
89
import("//ppapi/buildflags/buildflags.gni")
910
import("//third_party/tflite/features.gni")
1011

@@ -51,6 +52,12 @@ if (is_win) {
5152
"//ui/events",
5253
"//ui/shell_dialogs",
5354
]
55+
56+
if (disable_bluetooth) {
57+
content_app_deps -= [
58+
"//device/bluetooth",
59+
]
60+
}
5461
}
5562

5663
if (is_ios && target_platform != "tvos") {

content/browser/BUILD.gn

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import("//base/allocator/partition_allocator/partition_alloc.gni")
66
import("//build/buildflag_header.gni")
77
import("//build/config/compiler/pgo/pgo.gni")
88
import("//build/config/features.gni")
9+
import("//build/config/lightweight.gni")
910
import("//build/config/linux/pangocairo/pangocairo.gni")
1011
import("//build/config/ozone.gni")
1112
import("//build/config/ui.gni")
@@ -3709,6 +3710,51 @@ source_set("browser") {
37093710
if (is_chromeos) {
37103711
deps += [ "//ash/constants:constants" ]
37113712
}
3713+
3714+
if (disable_bluetooth) {
3715+
sources -= [
3716+
"bluetooth/advertisement_client.cc",
3717+
"bluetooth/advertisement_client.h",
3718+
"bluetooth/bluetooth_adapter_factory_wrapper.cc",
3719+
"bluetooth/bluetooth_adapter_factory_wrapper.h",
3720+
"bluetooth/bluetooth_allowed_devices.cc",
3721+
"bluetooth/bluetooth_allowed_devices.h",
3722+
"bluetooth/bluetooth_allowed_devices_map.cc",
3723+
"bluetooth/bluetooth_allowed_devices_map.h",
3724+
"bluetooth/bluetooth_blocklist.cc",
3725+
"bluetooth/bluetooth_blocklist.h",
3726+
"bluetooth/bluetooth_device_chooser_controller.cc",
3727+
"bluetooth/bluetooth_device_chooser_controller.h",
3728+
"bluetooth/bluetooth_device_scanning_prompt_controller.cc",
3729+
"bluetooth/bluetooth_device_scanning_prompt_controller.h",
3730+
"bluetooth/bluetooth_metrics.cc",
3731+
"bluetooth/bluetooth_metrics.h",
3732+
"bluetooth/bluetooth_util.cc",
3733+
"bluetooth/bluetooth_util.h",
3734+
"bluetooth/frame_connected_bluetooth_devices.cc",
3735+
"bluetooth/frame_connected_bluetooth_devices.h",
3736+
"bluetooth/web_bluetooth_pairing_manager.h",
3737+
"bluetooth/web_bluetooth_pairing_manager_delegate.h",
3738+
"bluetooth/web_bluetooth_pairing_manager_impl.cc",
3739+
"bluetooth/web_bluetooth_pairing_manager_impl.h",
3740+
"bluetooth/web_bluetooth_service_impl.cc",
3741+
"bluetooth/web_bluetooth_service_impl.h",
3742+
"serial/serial_service.cc",
3743+
"serial/serial_service.h",
3744+
]
3745+
3746+
deps -= [
3747+
"//device/bluetooth",
3748+
"//device/bluetooth/public/cpp",
3749+
]
3750+
3751+
if (!is_android) {
3752+
sources -= [
3753+
"webid/digital_credentials/cross_device_transaction_impl.cc",
3754+
"webid/digital_credentials/cross_device_transaction_impl.h",
3755+
]
3756+
}
3757+
}
37123758
}
37133759

37143760
if (is_android) {

content/browser/browser_interface_binders.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "base/task/thread_pool.h"
1616
#include "build/branding_buildflags.h"
1717
#include "build/build_config.h"
18+
#include "build/lightweight_buildflags.h"
1819
#include "cc/base/switches.h"
1920
#include "components/language_detection/content/common/language_detection.mojom.h"
2021
#include "components/optimization_guide/public/mojom/model_broker.mojom.h"
@@ -23,7 +24,9 @@
2324
#include "content/browser/attribution_reporting/attribution_internals_ui.h"
2425
#include "content/browser/background_fetch/background_fetch_service_impl.h"
2526
#include "content/browser/bad_message.h"
27+
#if !BUILDFLAG(DISABLE_BLUETOOTH)
2628
#include "content/browser/bluetooth/web_bluetooth_service_impl.h"
29+
#endif
2730
#include "content/browser/browser_context_impl.h"
2831
#include "content/browser/browser_main_loop.h"
2932
#include "content/browser/browsing_topics/browsing_topics_document_host.h"
@@ -137,7 +140,9 @@
137140
#include "third_party/blink/public/mojom/background_sync/background_sync.mojom.h"
138141
#include "third_party/blink/public/mojom/blob/blob_url_store.mojom.h"
139142
#include "third_party/blink/public/mojom/blob/file_backed_blob_factory.mojom.h"
143+
#if !BUILDFLAG(DISABLE_BLUETOOTH)
140144
#include "third_party/blink/public/mojom/bluetooth/web_bluetooth.mojom.h"
145+
#endif
141146
#include "third_party/blink/public/mojom/buckets/bucket_manager_host.mojom.h"
142147
#include "third_party/blink/public/mojom/cache_storage/cache_storage.mojom.h"
143148
#include "third_party/blink/public/mojom/choosers/color_chooser.mojom.h"
@@ -181,7 +186,10 @@
181186
#include "third_party/blink/public/mojom/push_messaging/push_messaging.mojom.h"
182187
#include "third_party/blink/public/mojom/quota/quota_manager_host.mojom.h"
183188
#include "third_party/blink/public/mojom/sensor/web_sensor_provider.mojom.h"
189+
// Serial depends on Bluetooth
190+
#if !BUILDFLAG(DISABLE_BLUETOOTH)
184191
#include "third_party/blink/public/mojom/serial/serial.mojom.h"
192+
#endif
185193
#include "third_party/blink/public/mojom/sms/webotp_service.mojom.h"
186194
#include "third_party/blink/public/mojom/speculation_rules/speculation_rules.mojom.h"
187195
#include "third_party/blink/public/mojom/speech/speech_synthesis.mojom.h"
@@ -941,8 +949,10 @@ void PopulateFrameBinders(RenderFrameHostImpl* host, mojo::BinderMap* map) {
941949
&BindWebNNContextProviderForRenderFrame, base::Unretained(host)));
942950
}
943951

952+
#if !BUILDFLAG(DISABLE_BLUETOOTH)
944953
map->Add<blink::mojom::WebBluetoothService>(base::BindRepeating(
945954
&WebBluetoothServiceImpl::BindIfAllowed, base::Unretained(host)));
955+
#endif
946956

947957
map->Add<blink::mojom::PushMessaging>(base::BindRepeating(
948958
&RenderFrameHostImpl::GetPushMessaging, base::Unretained(host)));
@@ -1099,8 +1109,11 @@ void PopulateFrameBinders(RenderFrameHostImpl* host, mojo::BinderMap* map) {
10991109
base::Unretained(host)));
11001110
#endif // BUILDFLAG(IS_ANDROID)
11011111

1112+
// Serial depends on Bluetooth
1113+
#if !BUILDFLAG(DISABLE_BLUETOOTH)
11021114
map->Add<blink::mojom::SerialService>(base::BindRepeating(
11031115
&RenderFrameHostImpl::BindSerialService, base::Unretained(host)));
1116+
#endif
11041117

11051118
#if BUILDFLAG(IS_CHROMEOS)
11061119
map->Add<blink::mojom::SmartCardService>(base::BindRepeating(
@@ -1395,8 +1408,11 @@ void PopulateDedicatedWorkerBinders(DedicatedWorkerHost* host,
13951408
base::Unretained(host)));
13961409
map->Add<blink::mojom::ReportingServiceProxy>(base::BindRepeating(
13971410
&CreateReportingServiceProxyForDedicatedWorker, base::Unretained(host)));
1411+
// Serial depends on Bluetooth
1412+
#if !BUILDFLAG(DISABLE_BLUETOOTH)
13981413
map->Add<blink::mojom::SerialService>(base::BindRepeating(
13991414
&DedicatedWorkerHost::BindSerialService, base::Unretained(host)));
1415+
#endif
14001416
#if !BUILDFLAG(IS_ANDROID)
14011417
map->Add<blink::mojom::HidService>(base::BindRepeating(
14021418
&DedicatedWorkerHost::BindHidService, base::Unretained(host)));

content/browser/renderer_host/render_frame_host_impl.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "base/types/optional_util.h"
5959
#include "base/uuid.h"
6060
#include "build/build_config.h"
61+
#include "build/lightweight_buildflags.h"
6162
#include "components/download/public/common/download_url_parameters.h"
6263
#include "components/input/input_router.h"
6364
#include "components/input/timeout_monitor.h"
@@ -67,7 +68,8 @@
6768
#include "content/browser/accessibility/render_accessibility_host.h"
6869
#include "content/browser/bad_message.h"
6970
#include "content/browser/blob_storage/file_backed_blob_factory_frame_impl.h"
70-
#include "content/browser/bluetooth/web_bluetooth_service_impl.h"
71+
// TODO(lightweight): Upstream to Chromium.
72+
//#include "content/browser/bluetooth/web_bluetooth_service_impl.h"
7173
#include "content/browser/broadcast_channel/broadcast_channel_provider.h"
7274
#include "content/browser/broadcast_channel/broadcast_channel_service.h"
7375
#include "content/browser/browser_main_loop.h"
@@ -152,7 +154,10 @@
152154
#include "content/browser/renderer_host/view_transition_opt_in_state.h"
153155
#include "content/browser/scoped_active_url.h"
154156
#include "content/browser/security/coop/cross_origin_opener_policy_reporter.h"
157+
// Disable serial when bluetooth is disabled.
158+
#if !BUILDFLAG(DISABLE_BLUETOOTH)
155159
#include "content/browser/serial/serial_service.h"
160+
#endif
156161
#include "content/browser/service_worker/service_worker_client.h"
157162
#include "content/browser/site_info.h"
158163
#include "content/browser/sms/webotp_service.h"
@@ -14073,6 +14078,8 @@ void RenderFrameHostImpl::BindNFCReceiver(
1407314078
}
1407414079
#endif
1407514080

14081+
// Serial depends on Bluetooth
14082+
#if !BUILDFLAG(DISABLE_BLUETOOTH)
1407614083
void RenderFrameHostImpl::BindSerialService(
1407714084
mojo::PendingReceiver<blink::mojom::SerialService> receiver) {
1407814085
if (!IsFeatureEnabled(network::mojom::PermissionsPolicyFeature::kSerial)) {
@@ -14100,6 +14107,7 @@ void RenderFrameHostImpl::BindSerialService(
1410014107

1410114108
SerialService::GetOrCreateForCurrentDocument(this)->Bind(std::move(receiver));
1410214109
}
14110+
#endif
1410314111

1410414112
#if !BUILDFLAG(IS_ANDROID)
1410514113
void RenderFrameHostImpl::GetHidService(

content/browser/renderer_host/render_frame_host_impl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "base/unguessable_token.h"
4545
#include "base/uuid.h"
4646
#include "build/build_config.h"
47+
#include "build/lightweight_buildflags.h"
4748
#include "content/browser/bad_message.h"
4849
#include "content/browser/browser_interface_broker_impl.h"
4950
#include "content/browser/buckets/bucket_context.h"
@@ -174,7 +175,10 @@
174175
#include "third_party/blink/public/mojom/render_accessibility.mojom.h"
175176
#include "third_party/blink/public/mojom/security_context/insecure_request_policy.mojom-forward.h"
176177
#include "third_party/blink/public/mojom/sensor/web_sensor_provider.mojom-forward.h"
178+
// Serial depends on Bluetooth
179+
#if !BUILDFLAG(DISABLE_BLUETOOTH)
177180
#include "third_party/blink/public/mojom/serial/serial.mojom-forward.h"
181+
#endif
178182
#include "third_party/blink/public/mojom/sms/webotp_service.mojom-forward.h"
179183
#include "third_party/blink/public/mojom/speech/speech_synthesis.mojom-forward.h"
180184
#include "third_party/blink/public/mojom/webaudio/audio_context_manager.mojom-forward.h"
@@ -2089,8 +2093,11 @@ class CONTENT_EXPORT RenderFrameHostImpl
20892093
void GetHidService(mojo::PendingReceiver<blink::mojom::HidService> receiver);
20902094
#endif
20912095

2096+
// Serial depends on Bluetooth
2097+
#if !BUILDFLAG(DISABLE_BLUETOOTH)
20922098
void BindSerialService(
20932099
mojo::PendingReceiver<blink::mojom::SerialService> receiver);
2100+
#endif
20942101

20952102
#if BUILDFLAG(IS_CHROMEOS)
20962103
void GetSmartCardService(

content/browser/storage_partition_impl.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "base/threading/sequence_local_storage_slot.h"
3939
#include "base/types/optional_util.h"
4040
#include "build/build_config.h"
41+
#include "build/lightweight_buildflags.h"
4142
#include "components/attribution_reporting/features.h"
4243
#include "components/leveldb_proto/public/proto_database_provider.h"
4344
#include "components/services/storage/privileged/cpp/bucket_client_info.h"
@@ -56,7 +57,9 @@
5657
#include "content/browser/background_fetch/background_fetch_context.h"
5758
#include "content/browser/blob_storage/blob_registry_wrapper.h"
5859
#include "content/browser/blob_storage/chrome_blob_storage_context.h"
60+
#if !BUILDFLAG(DISABLE_BLUETOOTH)
5961
#include "content/browser/bluetooth/bluetooth_allowed_devices_map.h"
62+
#endif
6063
#include "content/browser/broadcast_channel/broadcast_channel_service.h"
6164
#include "content/browser/browsing_data/clear_site_data_handler.h"
6265
#include "content/browser/browsing_data/storage_partition_code_cache_data_remover.h"
@@ -1418,8 +1421,10 @@ void StoragePartitionImpl::Initialize(
14181421

14191422
broadcast_channel_service_ = std::make_unique<BroadcastChannelService>();
14201423

1424+
#if !BUILDFLAG(DISABLE_BLUETOOTH)
14211425
bluetooth_allowed_devices_map_ =
14221426
std::make_unique<BluetoothAllowedDevicesMap>();
1427+
#endif
14231428

14241429
// Must be initialized before the
14251430
// `shared_url_loader_factory_for_browser_process_`. Cookie deprecation
@@ -1774,11 +1779,13 @@ BroadcastChannelService* StoragePartitionImpl::GetBroadcastChannelService() {
17741779
return broadcast_channel_service_.get();
17751780
}
17761781

1782+
#if !BUILDFLAG(DISABLE_BLUETOOTH)
17771783
BluetoothAllowedDevicesMap*
17781784
StoragePartitionImpl::GetBluetoothAllowedDevicesMap() {
17791785
DCHECK(initialized_);
17801786
return bluetooth_allowed_devices_map_.get();
17811787
}
1788+
#endif
17821789

17831790
BlobRegistryWrapper* StoragePartitionImpl::GetBlobRegistry() {
17841791
DCHECK(initialized_);
@@ -3339,8 +3346,10 @@ void StoragePartitionImpl::ResetURLLoaderFactories() {
33393346
}
33403347

33413348
void StoragePartitionImpl::ClearBluetoothAllowedDevicesMapForTesting() {
3349+
#if !BUILDFLAG(DISABLE_BLUETOOTH)
33423350
DCHECK(initialized_);
33433351
bluetooth_allowed_devices_map_->Clear();
3352+
#endif
33443353
}
33453354

33463355
void StoragePartitionImpl::AddObserver(DataRemovalObserver* observer) {

0 commit comments

Comments
 (0)