Define skeleton for new isolated web app install command.
Bug: 1333966
Change-Id: I2e0de41f3edbcb6fd19e3b437a55096d928d0030
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3706701
Auto-Submit: Dmitrii Kuragin <kuragin@chromium.org>
Commit-Queue: Dmitrii Kuragin <kuragin@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Reviewed-by: Daniel Murphy <dmurph@chromium.org>
Reviewed-by: Robbie McElrath <rmcelrath@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1015511}
diff --git a/chrome/browser/web_applications/BUILD.gn b/chrome/browser/web_applications/BUILD.gn
index a33a9e34..17a61cb 100644
--- a/chrome/browser/web_applications/BUILD.gn
+++ b/chrome/browser/web_applications/BUILD.gn
@@ -18,6 +18,8 @@
"commands/install_from_info_command.h",
"commands/install_from_sync_command.cc",
"commands/install_from_sync_command.h",
+ "commands/install_isolated_app_command.cc",
+ "commands/install_isolated_app_command.h",
"commands/install_web_app_with_params_command.cc",
"commands/install_web_app_with_params_command.h",
"commands/run_on_os_login_command.cc",
@@ -480,6 +482,7 @@
sources = [
"commands/clear_browsing_data_command_unittest.cc",
"commands/install_from_sync_command_unittest.cc",
+ "commands/install_isolated_app_command_unittest.cc",
"commands/run_on_os_login_command_unittest.cc",
"daily_metrics_helper_unittest.cc",
"external_install_options_unittest.cc",
diff --git a/chrome/browser/web_applications/commands/install_isolated_app_command.cc b/chrome/browser/web_applications/commands/install_isolated_app_command.cc
new file mode 100644
index 0000000..9ac02768
--- /dev/null
+++ b/chrome/browser/web_applications/commands/install_isolated_app_command.cc
@@ -0,0 +1,39 @@
+// 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 <utility>
+
+#include "chrome/browser/web_applications/commands/install_isolated_app_command.h"
+
+#include "base/callback_helpers.h"
+#include "base/containers/flat_set.h"
+#include "base/values.h"
+#include "chrome/browser/web_applications/commands/web_app_command.h"
+
+namespace web_app {
+
+InstallIsolatedAppCommand::InstallIsolatedAppCommand(base::StringPiece url)
+ : WebAppCommand(WebAppCommandLock::CreateForAppAndWebContentsLock(
+ base::flat_set<AppId>{"some random app id"})) {
+ weak_this_ = weak_factory_.GetWeakPtr();
+}
+
+InstallIsolatedAppCommand::~InstallIsolatedAppCommand() = default;
+
+void InstallIsolatedAppCommand::Start() {
+ SignalCompletionAndSelfDestruct(CommandResult::kSuccess, base::DoNothing());
+}
+
+void InstallIsolatedAppCommand::OnSyncSourceRemoved() {
+ SignalCompletionAndSelfDestruct(CommandResult::kSuccess, base::DoNothing());
+}
+
+void InstallIsolatedAppCommand::OnShutdown() {
+ SignalCompletionAndSelfDestruct(CommandResult::kSuccess, base::DoNothing());
+}
+
+base::Value InstallIsolatedAppCommand::ToDebugValue() const {
+ return base::Value{};
+}
+} // namespace web_app
diff --git a/chrome/browser/web_applications/commands/install_isolated_app_command.h b/chrome/browser/web_applications/commands/install_isolated_app_command.h
new file mode 100644
index 0000000..8761178
--- /dev/null
+++ b/chrome/browser/web_applications/commands/install_isolated_app_command.h
@@ -0,0 +1,33 @@
+// 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 CHROME_BROWSER_WEB_APPLICATIONS_COMMANDS_INSTALL_ISOLATED_APP_COMMAND_H_
+#define CHROME_BROWSER_WEB_APPLICATIONS_COMMANDS_INSTALL_ISOLATED_APP_COMMAND_H_
+
+#include "base/memory/weak_ptr.h"
+#include "base/strings/string_piece_forward.h"
+#include "base/values.h"
+#include "chrome/browser/web_applications/commands/web_app_command.h"
+
+namespace web_app {
+
+class InstallIsolatedAppCommand : public WebAppCommand {
+ public:
+ explicit InstallIsolatedAppCommand(base::StringPiece application_url);
+ ~InstallIsolatedAppCommand() override;
+
+ base::Value ToDebugValue() const override;
+
+ void Start() override;
+ void OnSyncSourceRemoved() override;
+ void OnShutdown() override;
+
+ private:
+ base::WeakPtr<InstallIsolatedAppCommand> weak_this_;
+ base::WeakPtrFactory<InstallIsolatedAppCommand> weak_factory_{this};
+};
+
+} // namespace web_app
+
+#endif // CHROME_BROWSER_WEB_APPLICATIONS_COMMANDS_INSTALL_ISOLATED_APP_COMMAND_H_
diff --git a/chrome/browser/web_applications/commands/install_isolated_app_command_unittest.cc b/chrome/browser/web_applications/commands/install_isolated_app_command_unittest.cc
new file mode 100644
index 0000000..036a6333
--- /dev/null
+++ b/chrome/browser/web_applications/commands/install_isolated_app_command_unittest.cc
@@ -0,0 +1,57 @@
+// 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 <memory>
+
+#include "base/memory/raw_ptr.h"
+#include "chrome/browser/web_applications/commands/install_isolated_app_command.h"
+
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+#include "chrome/browser/web_applications/test/fake_web_app_provider.h"
+#include "chrome/browser/web_applications/test/test_web_app_url_loader.h"
+#include "chrome/browser/web_applications/test/web_app_install_test_utils.h"
+#include "chrome/browser/web_applications/test/web_app_test.h"
+#include "chrome/browser/web_applications/web_app_command_manager.h"
+
+namespace web_app {
+namespace {
+
+class InstallIsolatedAppCommandTest : public WebAppTest {
+ public:
+ void SetUp() override {
+ WebAppTest::SetUp();
+ FakeWebAppProvider* provider = FakeWebAppProvider::Get(profile());
+ provider->SetDefaultFakeSubsystems();
+ provider->SetRunSubsystemStartupTasks(true);
+
+ auto url_loader = std::make_unique<TestWebAppUrlLoader>();
+ url_loader_ = url_loader.get();
+ provider->GetCommandManager().SetUrlLoaderForTesting(std::move(url_loader));
+
+ test::AwaitStartWebAppProviderAndSubsystems(profile());
+ }
+
+ void AddPrepareForLoadResults(
+ const std::vector<WebAppUrlLoader::Result>& results) {
+ url_loader_->AddPrepareForLoadResults(results);
+ }
+
+ private:
+ base::raw_ptr<TestWebAppUrlLoader> url_loader_;
+};
+
+TEST_F(InstallIsolatedAppCommandTest, StartCanBeStartedSuccesfully) {
+ AddPrepareForLoadResults(std::vector<WebAppUrlLoader::Result>{
+ WebAppUrlLoader::Result::kUrlLoaded,
+ });
+
+ auto subject = std::make_unique<InstallIsolatedAppCommand>(
+ "some random application URL");
+ WebAppProvider::GetForTest(profile())->command_manager().ScheduleCommand(
+ std::move(subject));
+}
+} // namespace
+} // namespace web_app