[QuickStart] Add TargetDeviceBootstrapController, integrate with oobe
Add TargetDeviceBootstrapController with a preliminary implementation
and unit tests. This class is owned by OOBE, and the interface in this
CL should eventually be replaced once the OOBE team decides how best to
integrate with the frontend.
The goal of this CL is to set everything up so that once
FastPairAdvertiser is finished, we should be advertising over Bluetooth
whenever the Quick Start screen is visible.
Bug: b/234655072
Test: chromeos_unittest --gtest_filter='TargetDeviceBootstrap*'
Change-Id: I0a46ddc78963f581b494cfa97545893ca1bb06a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3708200
Commit-Queue: Curt Clemens <cclem@google.com>
Reviewed-by: Roman Sorokin <rsorokin@chromium.org>
Reviewed-by: Michael Hansen <hansenmichael@google.com>
Cr-Commit-Position: refs/heads/main@{#1017906}
diff --git a/chrome/browser/ash/login/screens/quick_start_screen.cc b/chrome/browser/ash/login/screens/quick_start_screen.cc
index 0c051b3..1efbc2794 100644
--- a/chrome/browser/ash/login/screens/quick_start_screen.cc
+++ b/chrome/browser/ash/login/screens/quick_start_screen.cc
@@ -11,6 +11,7 @@
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/time/time.h"
#include "chrome/browser/ui/webui/chromeos/login/quick_start_screen_handler.h"
+#include "chromeos/ash/components/oobe_quick_start/target_device_bootstrap_controller.h"
#include "chromeos/ash/components/oobe_quick_start/verification_shapes.h"
namespace ash {
@@ -26,6 +27,9 @@
QuickStartScreen::QuickStartScreen(base::WeakPtr<TView> view,
const ScreenExitCallback& exit_callback)
: BaseScreen(QuickStartView::kScreenId, OobeScreenPriority::DEFAULT),
+ bootstrap_controller_(
+ std::make_unique<
+ ash::quick_start::TargetDeviceBootstrapController>()),
view_(std::move(view)),
exit_callback_(exit_callback) {}
@@ -40,6 +44,8 @@
return;
view_->Show();
+ bootstrap_controller_->StartAdvertising();
+
base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&QuickStartScreen::SendRandomFiguresForTesting, // IN-TEST
@@ -47,7 +53,9 @@
base::Seconds(1));
}
-void QuickStartScreen::HideImpl() {}
+void QuickStartScreen::HideImpl() {
+ bootstrap_controller_->StopAdvertising();
+}
void QuickStartScreen::OnUserAction(const base::Value::List& args) {
SendRandomFiguresForTesting(); // IN-TEST
diff --git a/chrome/browser/ash/login/screens/quick_start_screen.h b/chrome/browser/ash/login/screens/quick_start_screen.h
index af04639..c85c85a3f 100644
--- a/chrome/browser/ash/login/screens/quick_start_screen.h
+++ b/chrome/browser/ash/login/screens/quick_start_screen.h
@@ -14,6 +14,10 @@
namespace ash {
+namespace quick_start {
+class TargetDeviceBootstrapController;
+}
+
class QuickStartScreen : public BaseScreen {
public:
using TView = QuickStartView;
@@ -41,6 +45,9 @@
void SendRandomFiguresForTesting() const;
+ std::unique_ptr<ash::quick_start::TargetDeviceBootstrapController>
+ bootstrap_controller_;
+
base::WeakPtr<TView> view_;
ScreenExitCallback exit_callback_;
};
diff --git a/chromeos/ash/components/oobe_quick_start/BUILD.gn b/chromeos/ash/components/oobe_quick_start/BUILD.gn
index d1ee1e6..f9d8cbd6 100644
--- a/chromeos/ash/components/oobe_quick_start/BUILD.gn
+++ b/chromeos/ash/components/oobe_quick_start/BUILD.gn
@@ -12,6 +12,8 @@
"//base",
]
sources = [
+ "target_device_bootstrap_controller.cc",
+ "target_device_bootstrap_controller.h",
"verification_shapes.cc",
"verification_shapes.h",
]
@@ -26,5 +28,8 @@
"//base",
"//base/test:test_support",
]
- sources = [ "verification_shapes_unittest.cc" ]
+ sources = [
+ "target_device_bootstrap_controller_unittest.cc",
+ "verification_shapes_unittest.cc",
+ ]
}
diff --git a/chromeos/ash/components/oobe_quick_start/connectivity/BUILD.gn b/chromeos/ash/components/oobe_quick_start/connectivity/BUILD.gn
index 6a791b5..9462e6d 100644
--- a/chromeos/ash/components/oobe_quick_start/connectivity/BUILD.gn
+++ b/chromeos/ash/components/oobe_quick_start/connectivity/BUILD.gn
@@ -28,7 +28,8 @@
public_deps = [ ":connectivity" ]
deps = [ "//base" ]
sources = [
- # Add fakes/mocks here.
+ "fake_target_device_connection_broker.cc",
+ "fake_target_device_connection_broker.h",
]
}
diff --git a/chromeos/ash/components/oobe_quick_start/connectivity/fake_target_device_connection_broker.cc b/chromeos/ash/components/oobe_quick_start/connectivity/fake_target_device_connection_broker.cc
new file mode 100644
index 0000000..bfbe2edb
--- /dev/null
+++ b/chromeos/ash/components/oobe_quick_start/connectivity/fake_target_device_connection_broker.cc
@@ -0,0 +1,43 @@
+// Copyright 2022 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/ash/components/oobe_quick_start/connectivity/fake_target_device_connection_broker.h"
+
+namespace ash::quick_start {
+
+FakeTargetDeviceConnectionBroker::Factory::Factory() = default;
+
+FakeTargetDeviceConnectionBroker::Factory::~Factory() = default;
+
+std::unique_ptr<TargetDeviceConnectionBroker>
+FakeTargetDeviceConnectionBroker::Factory::CreateInstance() {
+ auto connection_broker = std::make_unique<FakeTargetDeviceConnectionBroker>();
+ instances_.push_back(connection_broker.get());
+ return std::move(connection_broker);
+}
+
+FakeTargetDeviceConnectionBroker::FakeTargetDeviceConnectionBroker() = default;
+
+FakeTargetDeviceConnectionBroker::~FakeTargetDeviceConnectionBroker() = default;
+
+TargetDeviceConnectionBroker::FeatureSupportStatus
+FakeTargetDeviceConnectionBroker::GetFeatureSupportStatus() const {
+ return feature_support_status_;
+}
+
+void FakeTargetDeviceConnectionBroker::StartAdvertising(
+ ConnectionLifecycleListener* listener,
+ ResultCallback on_start_advertising_callback) {
+ ++num_start_advertising_calls_;
+ connection_lifecycle_listener_ = listener;
+ on_start_advertising_callback_ = std::move(on_start_advertising_callback);
+}
+
+void FakeTargetDeviceConnectionBroker::StopAdvertising(
+ ResultCallback on_stop_advertising_callback) {
+ ++num_stop_advertising_calls_;
+ on_stop_advertising_callback_ = std::move(on_stop_advertising_callback);
+}
+
+} // namespace ash::quick_start
diff --git a/chromeos/ash/components/oobe_quick_start/connectivity/fake_target_device_connection_broker.h b/chromeos/ash/components/oobe_quick_start/connectivity/fake_target_device_connection_broker.h
new file mode 100644
index 0000000..396837e
--- /dev/null
+++ b/chromeos/ash/components/oobe_quick_start/connectivity/fake_target_device_connection_broker.h
@@ -0,0 +1,85 @@
+// Copyright 2022 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_ASH_COMPONENTS_OOBE_QUICK_START_CONNECTIVITY_FAKE_TARGET_DEVICE_CONNECTION_BROKER_H_
+#define CHROMEOS_ASH_COMPONENTS_OOBE_QUICK_START_CONNECTIVITY_FAKE_TARGET_DEVICE_CONNECTION_BROKER_H_
+
+#include <memory>
+#include <vector>
+
+#include "chromeos/ash/components/oobe_quick_start/connectivity/target_device_connection_broker.h"
+#include "chromeos/ash/components/oobe_quick_start/connectivity/target_device_connection_broker_factory.h"
+
+namespace ash::quick_start {
+
+class FakeTargetDeviceConnectionBroker : public TargetDeviceConnectionBroker {
+ public:
+ class Factory : public TargetDeviceConnectionBrokerFactory {
+ public:
+ Factory();
+ Factory(Factory&) = delete;
+ Factory& operator=(Factory&) = delete;
+ ~Factory() override;
+
+ // Returns all FakeTargetDeviceConnectionBroker instances created by
+ // CreateInstance().
+ const std::vector<FakeTargetDeviceConnectionBroker*>& instances() {
+ return instances_;
+ }
+
+ private:
+ std::unique_ptr<TargetDeviceConnectionBroker> CreateInstance() override;
+
+ std::vector<FakeTargetDeviceConnectionBroker*> instances_;
+ };
+
+ FakeTargetDeviceConnectionBroker();
+ FakeTargetDeviceConnectionBroker(FakeTargetDeviceConnectionBroker&) = delete;
+ FakeTargetDeviceConnectionBroker& operator=(
+ FakeTargetDeviceConnectionBroker&) = delete;
+ ~FakeTargetDeviceConnectionBroker() override;
+
+ // TargetDeviceConnectionBroker:
+ FeatureSupportStatus GetFeatureSupportStatus() const override;
+ void StartAdvertising(ConnectionLifecycleListener* listener,
+ ResultCallback on_start_advertising_callback) override;
+ void StopAdvertising(ResultCallback on_stop_advertising_callback) override;
+
+ void set_feature_support_status(FeatureSupportStatus feature_support_status) {
+ feature_support_status_ = feature_support_status;
+ }
+
+ size_t num_start_advertising_calls() const {
+ return num_start_advertising_calls_;
+ }
+
+ size_t num_stop_advertising_calls() const {
+ return num_stop_advertising_calls_;
+ }
+
+ ConnectionLifecycleListener* connection_lifecycle_listener() const {
+ return connection_lifecycle_listener_;
+ }
+
+ ResultCallback on_start_advertising_callback() {
+ return std::move(on_start_advertising_callback_);
+ }
+
+ ResultCallback on_stop_advertising_callback() {
+ return std::move(on_stop_advertising_callback_);
+ }
+
+ private:
+ size_t num_start_advertising_calls_ = 0;
+ size_t num_stop_advertising_calls_ = 0;
+ FeatureSupportStatus feature_support_status_ =
+ FeatureSupportStatus::kSupported;
+ ConnectionLifecycleListener* connection_lifecycle_listener_ = nullptr;
+ ResultCallback on_start_advertising_callback_;
+ ResultCallback on_stop_advertising_callback_;
+};
+
+} // namespace ash::quick_start
+
+#endif // CHROMEOS_ASH_COMPONENTS_OOBE_QUICK_START_CONNECTIVITY_FAKE_TARGET_DEVICE_CONNECTION_BROKER_H_
diff --git a/chromeos/ash/components/oobe_quick_start/connectivity/target_device_connection_broker_factory.cc b/chromeos/ash/components/oobe_quick_start/connectivity/target_device_connection_broker_factory.cc
index 1c08e284..331d132e 100644
--- a/chromeos/ash/components/oobe_quick_start/connectivity/target_device_connection_broker_factory.cc
+++ b/chromeos/ash/components/oobe_quick_start/connectivity/target_device_connection_broker_factory.cc
@@ -28,4 +28,10 @@
TargetDeviceConnectionBrokerFactory*
TargetDeviceConnectionBrokerFactory::test_factory_ = nullptr;
+TargetDeviceConnectionBrokerFactory::TargetDeviceConnectionBrokerFactory() =
+ default;
+
+TargetDeviceConnectionBrokerFactory::~TargetDeviceConnectionBrokerFactory() =
+ default;
+
} // namespace ash::quick_start
diff --git a/chromeos/ash/components/oobe_quick_start/connectivity/target_device_connection_broker_factory.h b/chromeos/ash/components/oobe_quick_start/connectivity/target_device_connection_broker_factory.h
index 98f8cc0..94f45cf 100644
--- a/chromeos/ash/components/oobe_quick_start/connectivity/target_device_connection_broker_factory.h
+++ b/chromeos/ash/components/oobe_quick_start/connectivity/target_device_connection_broker_factory.h
@@ -20,8 +20,14 @@
static void SetFactoryForTesting(
TargetDeviceConnectionBrokerFactory* test_factory);
+ TargetDeviceConnectionBrokerFactory();
+ TargetDeviceConnectionBrokerFactory(TargetDeviceConnectionBrokerFactory&) =
+ delete;
+ TargetDeviceConnectionBrokerFactory& operator=(
+ TargetDeviceConnectionBrokerFactory&) = delete;
+ virtual ~TargetDeviceConnectionBrokerFactory();
+
protected:
- virtual ~TargetDeviceConnectionBrokerFactory() = default;
virtual std::unique_ptr<TargetDeviceConnectionBroker> CreateInstance() = 0;
private:
diff --git a/chromeos/ash/components/oobe_quick_start/target_device_bootstrap_controller.cc b/chromeos/ash/components/oobe_quick_start/target_device_bootstrap_controller.cc
new file mode 100644
index 0000000..4975444
--- /dev/null
+++ b/chromeos/ash/components/oobe_quick_start/target_device_bootstrap_controller.cc
@@ -0,0 +1,30 @@
+// Copyright 2022 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/ash/components/oobe_quick_start/target_device_bootstrap_controller.h"
+
+#include "base/callback_helpers.h"
+#include "chromeos/ash/components/oobe_quick_start/connectivity/target_device_connection_broker_factory.h"
+
+namespace ash::quick_start {
+
+TargetDeviceBootstrapController::TargetDeviceBootstrapController() {
+ connection_broker_ = TargetDeviceConnectionBrokerFactory::Create();
+}
+
+TargetDeviceBootstrapController::~TargetDeviceBootstrapController() = default;
+
+void TargetDeviceBootstrapController::StartAdvertising() {
+ DCHECK(connection_broker_->GetFeatureSupportStatus() ==
+ TargetDeviceConnectionBroker::FeatureSupportStatus::kSupported);
+ // TODO: Handle result callback
+ connection_broker_->StartAdvertising(this, base::DoNothing());
+}
+
+void TargetDeviceBootstrapController::StopAdvertising() {
+ // TODO: Handle result callback
+ connection_broker_->StopAdvertising(base::DoNothing());
+}
+
+} // namespace ash::quick_start
diff --git a/chromeos/ash/components/oobe_quick_start/target_device_bootstrap_controller.h b/chromeos/ash/components/oobe_quick_start/target_device_bootstrap_controller.h
new file mode 100644
index 0000000..0ce7133a
--- /dev/null
+++ b/chromeos/ash/components/oobe_quick_start/target_device_bootstrap_controller.h
@@ -0,0 +1,38 @@
+// Copyright 2022 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_ASH_COMPONENTS_OOBE_QUICK_START_TARGET_DEVICE_BOOTSTRAP_CONTROLLER_H_
+#define CHROMEOS_ASH_COMPONENTS_OOBE_QUICK_START_TARGET_DEVICE_BOOTSTRAP_CONTROLLER_H_
+
+#include <memory>
+
+#include "base/memory/weak_ptr.h"
+#include "chromeos/ash/components/oobe_quick_start/connectivity/target_device_connection_broker.h"
+
+namespace ash::quick_start {
+
+class TargetDeviceConnectionBroker;
+
+class TargetDeviceBootstrapController
+ : public TargetDeviceConnectionBroker::ConnectionLifecycleListener {
+ public:
+ TargetDeviceBootstrapController();
+ TargetDeviceBootstrapController(TargetDeviceBootstrapController&) = delete;
+ TargetDeviceBootstrapController& operator=(TargetDeviceBootstrapController&) =
+ delete;
+ ~TargetDeviceBootstrapController();
+
+ // TODO: Finalize api for frontend.
+ void StartAdvertising();
+ void StopAdvertising();
+
+ private:
+ std::unique_ptr<TargetDeviceConnectionBroker> connection_broker_;
+
+ base::WeakPtrFactory<TargetDeviceBootstrapController> weak_ptr_factory_{this};
+};
+
+} // namespace ash::quick_start
+
+#endif // CHROMEOS_ASH_COMPONENTS_OOBE_QUICK_START_TARGET_DEVICE_BOOTSTRAP_CONTROLLER_H_
diff --git a/chromeos/ash/components/oobe_quick_start/target_device_bootstrap_controller_unittest.cc b/chromeos/ash/components/oobe_quick_start/target_device_bootstrap_controller_unittest.cc
new file mode 100644
index 0000000..185e6d03
--- /dev/null
+++ b/chromeos/ash/components/oobe_quick_start/target_device_bootstrap_controller_unittest.cc
@@ -0,0 +1,61 @@
+// Copyright 2022 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/ash/components/oobe_quick_start/target_device_bootstrap_controller.h"
+
+#include "chromeos/ash/components/oobe_quick_start/connectivity/fake_target_device_connection_broker.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+using TargetDeviceBootstrapController =
+ ash::quick_start::TargetDeviceBootstrapController;
+using TargetDeviceConnectionBroker =
+ ash::quick_start::TargetDeviceConnectionBroker;
+using FakeTargetDeviceConnectionBroker =
+ ash::quick_start::FakeTargetDeviceConnectionBroker;
+using TargetDeviceConnectionBrokerFactory =
+ ash::quick_start::TargetDeviceConnectionBrokerFactory;
+
+} // namespace
+
+class TargetDeviceBootstrapControllerTest : public testing::Test {
+ public:
+ TargetDeviceBootstrapControllerTest() = default;
+ TargetDeviceBootstrapControllerTest(TargetDeviceBootstrapControllerTest&) =
+ delete;
+ TargetDeviceBootstrapControllerTest& operator=(
+ TargetDeviceBootstrapControllerTest&) = delete;
+ ~TargetDeviceBootstrapControllerTest() override = default;
+
+ void SetUp() override { CreateBootstrapController(); }
+
+ void CreateBootstrapController() {
+ TargetDeviceConnectionBrokerFactory::SetFactoryForTesting(
+ &connection_broker_factory_);
+
+ bootstrap_controller_ = std::make_unique<TargetDeviceBootstrapController>();
+ }
+
+ FakeTargetDeviceConnectionBroker* connection_broker() {
+ EXPECT_EQ(1u, connection_broker_factory_.instances().size());
+ return connection_broker_factory_.instances().back();
+ }
+
+ protected:
+ FakeTargetDeviceConnectionBroker::Factory connection_broker_factory_;
+ std::unique_ptr<TargetDeviceBootstrapController> bootstrap_controller_;
+};
+
+TEST_F(TargetDeviceBootstrapControllerTest, StartAdvertising) {
+ bootstrap_controller_->StartAdvertising();
+ EXPECT_EQ(1u, connection_broker()->num_start_advertising_calls());
+ EXPECT_EQ(bootstrap_controller_.get(),
+ connection_broker()->connection_lifecycle_listener());
+}
+
+TEST_F(TargetDeviceBootstrapControllerTest, StopAdvertising) {
+ bootstrap_controller_->StopAdvertising();
+ EXPECT_EQ(1u, connection_broker()->num_stop_advertising_calls());
+}