Commit ca8aa373 authored by Nicholas Hollingum's avatar Nicholas Hollingum Committed by Commit Bot

Created the BorealisService and refactored Features

Based on a discussion with Chrome Sydney C++, it is preferable not to
have fine-grained Keyed services, and instead use an approach like the
WebAppsPlatform does.  Diagram in go/borealis-arch.

Reasons given were:
1) Complicated crashes for getting keyed service per Profile-type
   (incognito OTR. guest, login-porile see
   http://go/chromium-profile-types)
2) Two-pass shutdown but no symmetric Two-pass Setup (circular deps)
3) The base classes API which you don't own (inability to control it)
4) A dependent KeyedService may enforce the creation of the dependee
   KeyedService for the unwanted profile type
5) 2 .cc + 2 .h files for each service (instead of simple one .cc + .h
   pair)
6) Simplicity vs overkill

Bug: b/170596931
Change-Id: Iee61e29b5ac29abf1ba9b00b4939ffea65bd8be1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2465887
Commit-Queue: Nic Hollingum <hollingum@google.com>
Reviewed-by: default avatarNancy Wang <nancylingwang@google.com>
Reviewed-by: default avatarNancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarDaniel Ng <danielng@google.com>
Cr-Commit-Position: refs/heads/master@{#817213}
parent 7cff2599
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "chrome/browser/chromeos/borealis/borealis_context_manager_factory.h" #include "chrome/browser/chromeos/borealis/borealis_context_manager_factory.h"
#include "chrome/browser/chromeos/borealis/borealis_context_manager_impl.h" #include "chrome/browser/chromeos/borealis/borealis_context_manager_impl.h"
#include "chrome/browser/chromeos/borealis/borealis_features.h" #include "chrome/browser/chromeos/borealis/borealis_features.h"
#include "chrome/browser/chromeos/borealis/borealis_features_factory.h" #include "chrome/browser/chromeos/borealis/borealis_service.h"
#include "chrome/browser/chromeos/borealis/borealis_util.h" #include "chrome/browser/chromeos/borealis/borealis_util.h"
#include "chrome/browser/chromeos/guest_os/guest_os_registry_service.h" #include "chrome/browser/chromeos/guest_os/guest_os_registry_service.h"
#include "chrome/browser/chromeos/guest_os/guest_os_registry_service_factory.h" #include "chrome/browser/chromeos/guest_os/guest_os_registry_service_factory.h"
...@@ -130,8 +130,9 @@ void BorealisApps::Connect( ...@@ -130,8 +130,9 @@ void BorealisApps::Connect(
apps::mojom::ConnectOptionsPtr opts) { apps::mojom::ConnectOptionsPtr opts) {
std::vector<apps::mojom::AppPtr> apps; std::vector<apps::mojom::AppPtr> apps;
apps.push_back(GetBorealisLauncher( apps.push_back(GetBorealisLauncher(
profile_, profile_, borealis::BorealisService::GetForProfile(profile_)
borealis::BorealisFeaturesFactory::GetForProfile(profile_)->IsAllowed())); ->Features()
.IsAllowed()));
for (const auto& pair : for (const auto& pair :
Registry()->GetRegisteredApps(guest_os::GuestOsRegistryService::VmType:: Registry()->GetRegisteredApps(guest_os::GuestOsRegistryService::VmType::
...@@ -164,9 +165,12 @@ void BorealisApps::Launch(const std::string& app_id, ...@@ -164,9 +165,12 @@ void BorealisApps::Launch(const std::string& app_id,
apps::mojom::LaunchSource launch_source, apps::mojom::LaunchSource launch_source,
int64_t display_id) { int64_t display_id) {
DCHECK_EQ(borealis::kBorealisAppId, app_id); DCHECK_EQ(borealis::kBorealisAppId, app_id);
DCHECK( DCHECK(borealis::BorealisService::GetForProfile(profile_)
borealis::BorealisFeaturesFactory::GetForProfile(profile_)->IsAllowed()); ->Features()
if (borealis::BorealisFeaturesFactory::GetForProfile(profile_)->IsEnabled()) { .IsAllowed());
if (borealis::BorealisService::GetForProfile(profile_)
->Features()
.IsEnabled()) {
borealis::BorealisContextManagerFactory::GetForProfile(profile_) borealis::BorealisContextManagerFactory::GetForProfile(profile_)
->StartBorealis(base::DoNothing()); ->StartBorealis(base::DoNothing());
return; return;
......
...@@ -844,8 +844,6 @@ source_set("chromeos") { ...@@ -844,8 +844,6 @@ source_set("chromeos") {
"borealis/borealis_context_manager_impl.h", "borealis/borealis_context_manager_impl.h",
"borealis/borealis_features.cc", "borealis/borealis_features.cc",
"borealis/borealis_features.h", "borealis/borealis_features.h",
"borealis/borealis_features_factory.cc",
"borealis/borealis_features_factory.h",
"borealis/borealis_installer.cc", "borealis/borealis_installer.cc",
"borealis/borealis_installer.h", "borealis/borealis_installer.h",
"borealis/borealis_installer_factory.cc", "borealis/borealis_installer_factory.cc",
...@@ -854,6 +852,12 @@ source_set("chromeos") { ...@@ -854,6 +852,12 @@ source_set("chromeos") {
"borealis/borealis_installer_impl.h", "borealis/borealis_installer_impl.h",
"borealis/borealis_prefs.cc", "borealis/borealis_prefs.cc",
"borealis/borealis_prefs.h", "borealis/borealis_prefs.h",
"borealis/borealis_service.cc",
"borealis/borealis_service.h",
"borealis/borealis_service_factory.cc",
"borealis/borealis_service_factory.h",
"borealis/borealis_service_impl.cc",
"borealis/borealis_service_impl.h",
"borealis/borealis_task.cc", "borealis/borealis_task.cc",
"borealis/borealis_task.h", "borealis/borealis_task.h",
"borealis/borealis_util.cc", "borealis/borealis_util.cc",
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include "chrome/browser/chromeos/borealis/borealis_features.h" #include "chrome/browser/chromeos/borealis/borealis_features.h"
#include "chrome/browser/chromeos/borealis/borealis_features_factory.h"
#include "chrome/browser/chromeos/borealis/borealis_prefs.h" #include "chrome/browser/chromeos/borealis/borealis_prefs.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
...@@ -14,8 +13,6 @@ namespace borealis { ...@@ -14,8 +13,6 @@ namespace borealis {
BorealisFeatures::BorealisFeatures(Profile* profile) : profile_(profile) {} BorealisFeatures::BorealisFeatures(Profile* profile) : profile_(profile) {}
BorealisFeatures::~BorealisFeatures() = default;
bool BorealisFeatures::IsAllowed() { bool BorealisFeatures::IsAllowed() {
return base::FeatureList::IsEnabled(features::kBorealis); return base::FeatureList::IsEnabled(features::kBorealis);
} }
......
...@@ -5,19 +5,15 @@ ...@@ -5,19 +5,15 @@
#ifndef CHROME_BROWSER_CHROMEOS_BOREALIS_BOREALIS_FEATURES_H_ #ifndef CHROME_BROWSER_CHROMEOS_BOREALIS_BOREALIS_FEATURES_H_
#define CHROME_BROWSER_CHROMEOS_BOREALIS_BOREALIS_FEATURES_H_ #define CHROME_BROWSER_CHROMEOS_BOREALIS_BOREALIS_FEATURES_H_
#include "components/keyed_service/core/keyed_service.h"
class Profile; class Profile;
namespace borealis { namespace borealis {
class BorealisFeatures : public KeyedService { class BorealisFeatures {
public: public:
// Creates a per-profile instance of the feature-checker for borealis. // Creates a per-profile instance of the feature-checker for borealis.
explicit BorealisFeatures(Profile* profile); explicit BorealisFeatures(Profile* profile);
~BorealisFeatures() override;
// Returns true if borealis can be installed on the profile associated with // Returns true if borealis can be installed on the profile associated with
// this feature check. // this feature check.
bool IsAllowed(); bool IsAllowed();
...@@ -26,7 +22,7 @@ class BorealisFeatures : public KeyedService { ...@@ -26,7 +22,7 @@ class BorealisFeatures : public KeyedService {
bool IsEnabled(); bool IsEnabled();
private: private:
Profile* profile_; Profile* const profile_;
}; };
} // namespace borealis } // namespace borealis
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "chrome/browser/chromeos/borealis/borealis_features.h" #include "chrome/browser/chromeos/borealis/borealis_features.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "chrome/browser/chromeos/borealis/borealis_features_factory.h"
#include "chrome/browser/chromeos/borealis/borealis_prefs.h" #include "chrome/browser/chromeos/borealis/borealis_prefs.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
...@@ -25,13 +24,13 @@ class BorealisFeaturesTest : public testing::Test { ...@@ -25,13 +24,13 @@ class BorealisFeaturesTest : public testing::Test {
TEST_F(BorealisFeaturesTest, DisallowedWhenFeatureIsDisabled) { TEST_F(BorealisFeaturesTest, DisallowedWhenFeatureIsDisabled) {
base::test::ScopedFeatureList features; base::test::ScopedFeatureList features;
features.InitAndDisableFeature(features::kBorealis); features.InitAndDisableFeature(features::kBorealis);
EXPECT_FALSE(BorealisFeaturesFactory::GetForProfile(&profile_)->IsAllowed()); EXPECT_FALSE(BorealisFeatures(&profile_).IsAllowed());
} }
TEST_F(BorealisFeaturesTest, AllowedWhenFeatureIsEnabled) { TEST_F(BorealisFeaturesTest, AllowedWhenFeatureIsEnabled) {
base::test::ScopedFeatureList features; base::test::ScopedFeatureList features;
features.InitAndEnableFeature(features::kBorealis); features.InitAndEnableFeature(features::kBorealis);
EXPECT_TRUE(BorealisFeaturesFactory::GetForProfile(&profile_)->IsAllowed()); EXPECT_TRUE(BorealisFeatures(&profile_).IsAllowed());
} }
TEST_F(BorealisFeaturesTest, EnablednessDependsOnInstallation) { TEST_F(BorealisFeaturesTest, EnablednessDependsOnInstallation) {
...@@ -39,11 +38,11 @@ TEST_F(BorealisFeaturesTest, EnablednessDependsOnInstallation) { ...@@ -39,11 +38,11 @@ TEST_F(BorealisFeaturesTest, EnablednessDependsOnInstallation) {
features.InitAndEnableFeature(features::kBorealis); features.InitAndEnableFeature(features::kBorealis);
// The pref is false by default // The pref is false by default
EXPECT_FALSE(BorealisFeaturesFactory::GetForProfile(&profile_)->IsEnabled()); EXPECT_FALSE(BorealisFeatures(&profile_).IsEnabled());
profile_.GetPrefs()->SetBoolean(prefs::kBorealisInstalledOnDevice, true); profile_.GetPrefs()->SetBoolean(prefs::kBorealisInstalledOnDevice, true);
EXPECT_TRUE(BorealisFeaturesFactory::GetForProfile(&profile_)->IsEnabled()); EXPECT_TRUE(BorealisFeatures(&profile_).IsEnabled());
} }
} // namespace } // namespace
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include "base/bind.h" #include "base/bind.h"
#include "chrome/browser/chromeos/borealis/borealis_features.h" #include "chrome/browser/chromeos/borealis/borealis_features.h"
#include "chrome/browser/chromeos/borealis/borealis_features_factory.h"
#include "chrome/browser/chromeos/borealis/borealis_prefs.h" #include "chrome/browser/chromeos/borealis/borealis_prefs.h"
#include "chrome/browser/chromeos/borealis/borealis_service.h"
#include "chrome/browser/chromeos/borealis/borealis_util.h" #include "chrome/browser/chromeos/borealis/borealis_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
...@@ -28,7 +28,7 @@ bool BorealisInstallerImpl::IsProcessing() { ...@@ -28,7 +28,7 @@ bool BorealisInstallerImpl::IsProcessing() {
} }
void BorealisInstallerImpl::Start() { void BorealisInstallerImpl::Start() {
if (!BorealisFeaturesFactory::GetForProfile(profile_)->IsAllowed()) { if (!BorealisService::GetForProfile(profile_)->Features().IsAllowed()) {
LOG(ERROR) << "Installation of Borealis cannot be started because " LOG(ERROR) << "Installation of Borealis cannot be started because "
<< "Borealis is not allowed."; << "Borealis is not allowed.";
InstallationEnded(InstallationResult::kNotAllowed); InstallationEnded(InstallationResult::kNotAllowed);
......
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "chrome/browser/chromeos/borealis/borealis_features.h" #include "chrome/browser/chromeos/borealis/borealis_features.h"
#include "chrome/browser/chromeos/borealis/borealis_features_factory.h"
#include "chrome/browser/chromeos/borealis/borealis_installer_factory.h" #include "chrome/browser/chromeos/borealis/borealis_installer_factory.h"
#include "chrome/browser/chromeos/borealis/borealis_prefs.h" #include "chrome/browser/chromeos/borealis/borealis_prefs.h"
#include "chrome/browser/chromeos/borealis/borealis_service.h"
#include "chrome/browser/chromeos/borealis/borealis_util.h" #include "chrome/browser/chromeos/borealis/borealis_util.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
...@@ -58,7 +58,7 @@ class BorealisInstallerTest : public testing::Test { ...@@ -58,7 +58,7 @@ class BorealisInstallerTest : public testing::Test {
UpdateCurrentDlcs(); UpdateCurrentDlcs();
ASSERT_EQ(current_dlcs_.dlc_infos_size(), 0); ASSERT_EQ(current_dlcs_.dlc_infos_size(), 0);
ASSERT_FALSE( ASSERT_FALSE(
BorealisFeaturesFactory::GetForProfile(profile_.get())->IsEnabled()); BorealisService::GetForProfile(profile_.get())->Features().IsEnabled());
} }
void TearDown() override { void TearDown() override {
...@@ -138,7 +138,7 @@ TEST_F(BorealisInstallerTest, BorealisNotAllowed) { ...@@ -138,7 +138,7 @@ TEST_F(BorealisInstallerTest, BorealisNotAllowed) {
UpdateCurrentDlcs(); UpdateCurrentDlcs();
ASSERT_EQ(current_dlcs_.dlc_infos_size(), 0); ASSERT_EQ(current_dlcs_.dlc_infos_size(), 0);
EXPECT_FALSE( EXPECT_FALSE(
BorealisFeaturesFactory::GetForProfile(profile_.get())->IsEnabled()); BorealisService::GetForProfile(profile_.get())->Features().IsEnabled());
} }
TEST_F(BorealisInstallerTest, SucessfulInstallation) { TEST_F(BorealisInstallerTest, SucessfulInstallation) {
...@@ -154,7 +154,7 @@ TEST_F(BorealisInstallerTest, SucessfulInstallation) { ...@@ -154,7 +154,7 @@ TEST_F(BorealisInstallerTest, SucessfulInstallation) {
ASSERT_EQ(current_dlcs_.dlc_infos_size(), 1); ASSERT_EQ(current_dlcs_.dlc_infos_size(), 1);
EXPECT_EQ(current_dlcs_.dlc_infos(0).id(), borealis::kBorealisDlcName); EXPECT_EQ(current_dlcs_.dlc_infos(0).id(), borealis::kBorealisDlcName);
EXPECT_TRUE( EXPECT_TRUE(
BorealisFeaturesFactory::GetForProfile(profile_.get())->IsEnabled()); BorealisService::GetForProfile(profile_.get())->Features().IsEnabled());
} }
TEST_F(BorealisInstallerTest, CancelledInstallation) { TEST_F(BorealisInstallerTest, CancelledInstallation) {
...@@ -173,7 +173,7 @@ TEST_F(BorealisInstallerTest, CancelledInstallation) { ...@@ -173,7 +173,7 @@ TEST_F(BorealisInstallerTest, CancelledInstallation) {
ASSERT_EQ(current_dlcs_.dlc_infos_size(), 1); ASSERT_EQ(current_dlcs_.dlc_infos_size(), 1);
EXPECT_EQ(current_dlcs_.dlc_infos(0).id(), borealis::kBorealisDlcName); EXPECT_EQ(current_dlcs_.dlc_infos(0).id(), borealis::kBorealisDlcName);
EXPECT_FALSE( EXPECT_FALSE(
BorealisFeaturesFactory::GetForProfile(profile_.get())->IsEnabled()); BorealisService::GetForProfile(profile_.get())->Features().IsEnabled());
} }
TEST_F(BorealisInstallerTest, InstallationInProgess) { TEST_F(BorealisInstallerTest, InstallationInProgess) {
...@@ -193,7 +193,7 @@ TEST_F(BorealisInstallerTest, InstallationInProgess) { ...@@ -193,7 +193,7 @@ TEST_F(BorealisInstallerTest, InstallationInProgess) {
ASSERT_EQ(current_dlcs_.dlc_infos_size(), 1); ASSERT_EQ(current_dlcs_.dlc_infos_size(), 1);
EXPECT_EQ(current_dlcs_.dlc_infos(0).id(), borealis::kBorealisDlcName); EXPECT_EQ(current_dlcs_.dlc_infos(0).id(), borealis::kBorealisDlcName);
EXPECT_TRUE( EXPECT_TRUE(
BorealisFeaturesFactory::GetForProfile(profile_.get())->IsEnabled()); BorealisService::GetForProfile(profile_.get())->Features().IsEnabled());
} }
// Note that we don't check if the DLC has/hasn't been installed, since the // Note that we don't check if the DLC has/hasn't been installed, since the
......
// Copyright 2020 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 "chrome/browser/chromeos/borealis/borealis_service.h"
#include "chrome/browser/chromeos/borealis/borealis_service_factory.h"
namespace borealis {
BorealisService* BorealisService::GetForProfile(Profile* profile) {
return BorealisServiceFactory::GetForProfile(profile);
}
} // namespace borealis
// Copyright 2020 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_CHROMEOS_BOREALIS_BOREALIS_SERVICE_H_
#define CHROME_BROWSER_CHROMEOS_BOREALIS_BOREALIS_SERVICE_H_
#include "components/keyed_service/core/keyed_service.h"
class Profile;
namespace borealis {
class BorealisFeatures;
// A common location for all the interdependant components of borealis.
class BorealisService : public KeyedService {
public:
// Helper method to get the service instance for the given profile.
static BorealisService* GetForProfile(Profile* profile);
~BorealisService() override = default;
virtual BorealisFeatures& Features() = 0;
};
} // namespace borealis
#endif // CHROME_BROWSER_CHROMEOS_BOREALIS_BOREALIS_SERVICE_H_
...@@ -2,34 +2,35 @@ ...@@ -2,34 +2,35 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/chromeos/borealis/borealis_features_factory.h" #include "chrome/browser/chromeos/borealis/borealis_service_factory.h"
#include "chrome/browser/chromeos/borealis/borealis_service_impl.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
namespace borealis { namespace borealis {
BorealisFeatures* BorealisFeaturesFactory::GetForProfile(Profile* profile) { BorealisService* BorealisServiceFactory::GetForProfile(Profile* profile) {
return static_cast<BorealisFeatures*>( return static_cast<BorealisService*>(
GetInstance()->GetServiceForBrowserContext(profile, GetInstance()->GetServiceForBrowserContext(profile,
/* create */ true)); /* create */ true));
} }
BorealisFeaturesFactory* BorealisFeaturesFactory::GetInstance() { BorealisServiceFactory* BorealisServiceFactory::GetInstance() {
static base::NoDestructor<BorealisFeaturesFactory> factory; static base::NoDestructor<BorealisServiceFactory> factory;
return factory.get(); return factory.get();
} }
// This service does not depend on any other services. // This service does not depend on any other services.
BorealisFeaturesFactory::BorealisFeaturesFactory() BorealisServiceFactory::BorealisServiceFactory()
: BrowserContextKeyedServiceFactory( : BrowserContextKeyedServiceFactory(
"BorealisFeaturesService", "BorealisService",
BrowserContextDependencyManager::GetInstance()) {} BrowserContextDependencyManager::GetInstance()) {}
BorealisFeaturesFactory::~BorealisFeaturesFactory() = default; BorealisServiceFactory::~BorealisServiceFactory() = default;
KeyedService* BorealisFeaturesFactory::BuildServiceInstanceFor( KeyedService* BorealisServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const { content::BrowserContext* context) const {
return new BorealisFeatures(Profile::FromBrowserContext(context)); return new BorealisServiceImpl(Profile::FromBrowserContext(context));
} }
} // namespace borealis } // namespace borealis
...@@ -2,34 +2,35 @@ ...@@ -2,34 +2,35 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_BOREALIS_BOREALIS_FEATURES_FACTORY_H_ #ifndef CHROME_BROWSER_CHROMEOS_BOREALIS_BOREALIS_SERVICE_FACTORY_H_
#define CHROME_BROWSER_CHROMEOS_BOREALIS_BOREALIS_FEATURES_FACTORY_H_ #define CHROME_BROWSER_CHROMEOS_BOREALIS_BOREALIS_SERVICE_FACTORY_H_
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "chrome/browser/chromeos/borealis/borealis_features.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h" #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class Profile;
namespace borealis { namespace borealis {
class BorealisService;
// Implementation of the factory used to access profile-keyed instances of the // Implementation of the factory used to access profile-keyed instances of the
// features service. // features service.
class BorealisFeaturesFactory : public BrowserContextKeyedServiceFactory { class BorealisServiceFactory : public BrowserContextKeyedServiceFactory {
public: public:
static BorealisFeatures* GetForProfile(Profile* profile); static BorealisService* GetForProfile(Profile* profile);
static BorealisFeaturesFactory* GetInstance(); static BorealisServiceFactory* GetInstance();
// Can not be moved or copied. // Can not be moved or copied.
BorealisFeaturesFactory(const BorealisFeaturesFactory&) = delete; BorealisServiceFactory(const BorealisServiceFactory&) = delete;
BorealisFeaturesFactory(BorealisFeaturesFactory&&) = delete; BorealisServiceFactory& operator=(const BorealisServiceFactory&) = delete;
BorealisFeaturesFactory& operator=(const BorealisFeaturesFactory&) = delete;
BorealisFeaturesFactory& operator=(BorealisFeaturesFactory&&) = delete;
private: private:
friend base::NoDestructor<BorealisFeaturesFactory>; friend base::NoDestructor<BorealisServiceFactory>;
BorealisFeaturesFactory(); BorealisServiceFactory();
~BorealisFeaturesFactory() override; ~BorealisServiceFactory() override;
KeyedService* BuildServiceInstanceFor( KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override; content::BrowserContext* context) const override;
...@@ -37,4 +38,4 @@ class BorealisFeaturesFactory : public BrowserContextKeyedServiceFactory { ...@@ -37,4 +38,4 @@ class BorealisFeaturesFactory : public BrowserContextKeyedServiceFactory {
} // namespace borealis } // namespace borealis
#endif // CHROME_BROWSER_CHROMEOS_BOREALIS_BOREALIS_FEATURES_FACTORY_H_ #endif // CHROME_BROWSER_CHROMEOS_BOREALIS_BOREALIS_SERVICE_FACTORY_H_
// Copyright 2020 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 "chrome/browser/chromeos/borealis/borealis_service_impl.h"
#include "chrome/browser/chromeos/borealis/borealis_features.h"
#include "chrome/browser/profiles/profile.h"
namespace borealis {
BorealisServiceImpl::BorealisServiceImpl(Profile* profile)
: profile_(profile), features_(profile_) {}
BorealisServiceImpl::~BorealisServiceImpl() = default;
BorealisFeatures& BorealisServiceImpl::Features() {
return features_;
}
} // namespace borealis
// Copyright 2020 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_CHROMEOS_BOREALIS_BOREALIS_SERVICE_IMPL_H_
#define CHROME_BROWSER_CHROMEOS_BOREALIS_BOREALIS_SERVICE_IMPL_H_
#include "chrome/browser/chromeos/borealis/borealis_service.h"
#include "chrome/browser/chromeos/borealis/borealis_features.h"
namespace borealis {
class BorealisServiceImpl : public BorealisService {
public:
explicit BorealisServiceImpl(Profile* profile);
~BorealisServiceImpl() override;
BorealisFeatures& Features() override;
private:
Profile* const profile_;
BorealisFeatures features_;
};
} // namespace borealis
#endif // CHROME_BROWSER_CHROMEOS_BOREALIS_BOREALIS_SERVICE_IMPL_H_
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
#include <vector> #include <vector>
#include "base/bind.h" #include "base/bind.h"
#include "chrome/browser/chromeos/borealis/borealis_features_factory.h" #include "chrome/browser/chromeos/borealis/borealis_features.h"
#include "chrome/browser/chromeos/borealis/borealis_service.h"
#include "chrome/browser/chromeos/crostini/crostini_features.h" #include "chrome/browser/chromeos/crostini/crostini_features.h"
#include "chrome/browser/chromeos/crostini/crostini_mime_types_service.h" #include "chrome/browser/chromeos/crostini/crostini_mime_types_service.h"
#include "chrome/browser/chromeos/crostini/crostini_mime_types_service_factory.h" #include "chrome/browser/chromeos/crostini/crostini_mime_types_service_factory.h"
...@@ -85,7 +86,9 @@ void VmApplicationsServiceProvider::UpdateApplicationList( ...@@ -85,7 +86,9 @@ void VmApplicationsServiceProvider::UpdateApplicationList(
Profile* profile = ProfileManager::GetPrimaryUserProfile(); Profile* profile = ProfileManager::GetPrimaryUserProfile();
if (crostini::CrostiniFeatures::Get()->IsEnabled(profile) || if (crostini::CrostiniFeatures::Get()->IsEnabled(profile) ||
plugin_vm::PluginVmFeatures::Get()->IsEnabled(profile) || plugin_vm::PluginVmFeatures::Get()->IsEnabled(profile) ||
borealis::BorealisFeaturesFactory::GetForProfile(profile)->IsEnabled()) { borealis::BorealisService::GetForProfile(profile)
->Features()
.IsEnabled()) {
auto* registry_service = auto* registry_service =
guest_os::GuestOsRegistryServiceFactory::GetForProfile(profile); guest_os::GuestOsRegistryServiceFactory::GetForProfile(profile);
registry_service->UpdateApplicationList(request); registry_service->UpdateApplicationList(request);
......
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/apps/app_service/dip_px_util.h" #include "chrome/browser/apps/app_service/dip_px_util.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/borealis/borealis_features_factory.h" #include "chrome/browser/chromeos/borealis/borealis_features.h"
#include "chrome/browser/chromeos/borealis/borealis_service.h"
#include "chrome/browser/chromeos/crostini/crostini_features.h" #include "chrome/browser/chromeos/crostini/crostini_features.h"
#include "chrome/browser/chromeos/crostini/crostini_manager.h" #include "chrome/browser/chromeos/crostini/crostini_manager.h"
#include "chrome/browser/chromeos/crostini/crostini_shelf_utils.h" #include "chrome/browser/chromeos/crostini/crostini_shelf_utils.h"
...@@ -569,8 +570,9 @@ GuestOsRegistryService::GetEnabledApps() const { ...@@ -569,8 +570,9 @@ GuestOsRegistryService::GetEnabledApps() const {
crostini::CrostiniFeatures::Get()->IsEnabled(profile_); crostini::CrostiniFeatures::Get()->IsEnabled(profile_);
bool plugin_vm_enabled = bool plugin_vm_enabled =
plugin_vm::PluginVmFeatures::Get()->IsEnabled(profile_); plugin_vm::PluginVmFeatures::Get()->IsEnabled(profile_);
bool borealis_enabled = bool borealis_enabled = borealis::BorealisService::GetForProfile(profile_)
borealis::BorealisFeaturesFactory::GetForProfile(profile_)->IsEnabled(); ->Features()
.IsEnabled();
if (!crostini_enabled && !plugin_vm_enabled && !borealis_enabled) if (!crostini_enabled && !plugin_vm_enabled && !borealis_enabled)
return {}; return {};
...@@ -638,8 +640,9 @@ void GuestOsRegistryService::RecordStartupMetrics() { ...@@ -638,8 +640,9 @@ void GuestOsRegistryService::RecordStartupMetrics() {
crostini::CrostiniFeatures::Get()->IsEnabled(profile_); crostini::CrostiniFeatures::Get()->IsEnabled(profile_);
bool plugin_vm_enabled = bool plugin_vm_enabled =
plugin_vm::PluginVmFeatures::Get()->IsEnabled(profile_); plugin_vm::PluginVmFeatures::Get()->IsEnabled(profile_);
bool borealis_enabled = bool borealis_enabled = borealis::BorealisService::GetForProfile(profile_)
borealis::BorealisFeaturesFactory::GetForProfile(profile_)->IsEnabled(); ->Features()
.IsEnabled();
if (!crostini_enabled && !plugin_vm_enabled && !borealis_enabled) if (!crostini_enabled && !plugin_vm_enabled && !borealis_enabled)
return; return;
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h" #include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/apps/app_service/app_service_test.h" #include "chrome/browser/apps/app_service/app_service_test.h"
#include "chrome/browser/chromeos/borealis/borealis_features.h" #include "chrome/browser/chromeos/borealis/borealis_features.h"
#include "chrome/browser/chromeos/borealis/borealis_features_factory.h" #include "chrome/browser/chromeos/borealis/borealis_service.h"
#include "chrome/browser/chromeos/borealis/borealis_util.h" #include "chrome/browser/chromeos/borealis/borealis_util.h"
#include "chrome/browser/chromeos/crostini/crostini_test_helper.h" #include "chrome/browser/chromeos/crostini/crostini_test_helper.h"
#include "chrome/browser/chromeos/crostini/crostini_util.h" #include "chrome/browser/chromeos/crostini/crostini_util.h"
...@@ -1014,9 +1014,9 @@ class BorealisAppTest : public AppServiceAppModelBuilderTest { ...@@ -1014,9 +1014,9 @@ class BorealisAppTest : public AppServiceAppModelBuilderTest {
}; };
TEST_F(BorealisAppTest, BorealisDisabled) { TEST_F(BorealisAppTest, BorealisDisabled) {
EXPECT_FALSE( EXPECT_FALSE(borealis::BorealisService::GetForProfile(testing_profile_.get())
borealis::BorealisFeaturesFactory::GetForProfile(testing_profile_.get()) ->Features()
->IsAllowed()); .IsAllowed());
EXPECT_EQ(std::vector<std::string>{}, GetModelContent(model_updater_.get())); EXPECT_EQ(std::vector<std::string>{}, GetModelContent(model_updater_.get()));
} }
...@@ -1027,9 +1027,9 @@ TEST_F(BorealisAppTest, BorealisEnabled) { ...@@ -1027,9 +1027,9 @@ TEST_F(BorealisAppTest, BorealisEnabled) {
// Borealis was enabled. // Borealis was enabled.
CreateBuilder(/*guest_mode=*/false); CreateBuilder(/*guest_mode=*/false);
EXPECT_TRUE( EXPECT_TRUE(borealis::BorealisService::GetForProfile(testing_profile_.get())
borealis::BorealisFeaturesFactory::GetForProfile(testing_profile_.get()) ->Features()
->IsAllowed()); .IsAllowed());
EXPECT_EQ( EXPECT_EQ(
std::vector<std::string>{l10n_util::GetStringUTF8(IDS_BOREALIS_APP_NAME)}, std::vector<std::string>{l10n_util::GetStringUTF8(IDS_BOREALIS_APP_NAME)},
GetModelContent(model_updater_.get())); GetModelContent(model_updater_.get()));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment