Commit a9a0b0b3 authored by Alexey Baskakov's avatar Alexey Baskakov Committed by Commit Bot

WebApp: Rename passes for subsystems startup.

- Rename Init as Start.
- Rename CreateSubsystems as Init.

As a result, Init is truely the first thing that must be called before using the
instance.

Bug: 920062
Change-Id: I5606250f10c3d249a994f19b71682a8d95e44be0
Reviewed-on: https://chromium-review.googlesource.com/c/1442072Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Commit-Queue: Alexey Baskakov <loyso@chromium.org>
Cr-Commit-Position: refs/heads/master@{#626911}
parent 9382aadb
...@@ -120,7 +120,7 @@ TEST_F(WebAppPolicyManagerTest, NoForceInstalledAppsPrefValue) { ...@@ -120,7 +120,7 @@ TEST_F(WebAppPolicyManagerTest, NoForceInstalledAppsPrefValue) {
auto pending_app_manager = std::make_unique<TestPendingAppManager>(); auto pending_app_manager = std::make_unique<TestPendingAppManager>();
WebAppPolicyManager web_app_policy_manager(profile(), WebAppPolicyManager web_app_policy_manager(profile(),
pending_app_manager.get()); pending_app_manager.get());
web_app_policy_manager.Init(); web_app_policy_manager.Start();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
const auto& apps_to_install = pending_app_manager->install_requests(); const auto& apps_to_install = pending_app_manager->install_requests();
...@@ -134,7 +134,7 @@ TEST_F(WebAppPolicyManagerTest, NoForceInstalledApps) { ...@@ -134,7 +134,7 @@ TEST_F(WebAppPolicyManagerTest, NoForceInstalledApps) {
auto pending_app_manager = std::make_unique<TestPendingAppManager>(); auto pending_app_manager = std::make_unique<TestPendingAppManager>();
WebAppPolicyManager web_app_policy_manager(profile(), WebAppPolicyManager web_app_policy_manager(profile(),
pending_app_manager.get()); pending_app_manager.get());
web_app_policy_manager.Init(); web_app_policy_manager.Start();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
const auto& apps_to_install = pending_app_manager->install_requests(); const auto& apps_to_install = pending_app_manager->install_requests();
...@@ -151,7 +151,7 @@ TEST_F(WebAppPolicyManagerTest, TwoForceInstalledApps) { ...@@ -151,7 +151,7 @@ TEST_F(WebAppPolicyManagerTest, TwoForceInstalledApps) {
auto pending_app_manager = std::make_unique<TestPendingAppManager>(); auto pending_app_manager = std::make_unique<TestPendingAppManager>();
WebAppPolicyManager web_app_policy_manager(profile(), WebAppPolicyManager web_app_policy_manager(profile(),
pending_app_manager.get()); pending_app_manager.get());
web_app_policy_manager.Init(); web_app_policy_manager.Start();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
const auto& apps_to_install = pending_app_manager->install_requests(); const auto& apps_to_install = pending_app_manager->install_requests();
...@@ -171,7 +171,7 @@ TEST_F(WebAppPolicyManagerTest, ForceInstallAppWithNoForcedLaunchContainer) { ...@@ -171,7 +171,7 @@ TEST_F(WebAppPolicyManagerTest, ForceInstallAppWithNoForcedLaunchContainer) {
auto pending_app_manager = std::make_unique<TestPendingAppManager>(); auto pending_app_manager = std::make_unique<TestPendingAppManager>();
WebAppPolicyManager web_app_policy_manager(profile(), WebAppPolicyManager web_app_policy_manager(profile(),
pending_app_manager.get()); pending_app_manager.get());
web_app_policy_manager.Init(); web_app_policy_manager.Start();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
const auto& apps_to_install = pending_app_manager->install_requests(); const auto& apps_to_install = pending_app_manager->install_requests();
...@@ -191,7 +191,7 @@ TEST_F(WebAppPolicyManagerTest, DynamicRefresh) { ...@@ -191,7 +191,7 @@ TEST_F(WebAppPolicyManagerTest, DynamicRefresh) {
auto pending_app_manager = std::make_unique<TestPendingAppManager>(); auto pending_app_manager = std::make_unique<TestPendingAppManager>();
WebAppPolicyManager web_app_policy_manager(profile(), WebAppPolicyManager web_app_policy_manager(profile(),
pending_app_manager.get()); pending_app_manager.get());
web_app_policy_manager.Init(); web_app_policy_manager.Start();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
const auto& apps_to_install = pending_app_manager->install_requests(); const auto& apps_to_install = pending_app_manager->install_requests();
...@@ -234,7 +234,7 @@ TEST_F(WebAppPolicyManagerTest, UninstallAppInstalledInPreviousSession) { ...@@ -234,7 +234,7 @@ TEST_F(WebAppPolicyManagerTest, UninstallAppInstalledInPreviousSession) {
WebAppPolicyManager web_app_policy_manager(profile(), WebAppPolicyManager web_app_policy_manager(profile(),
pending_app_manager.get()); pending_app_manager.get());
web_app_policy_manager.Init(); web_app_policy_manager.Start();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// We should only try to install the app in the policy. // We should only try to install the app in the policy.
...@@ -253,7 +253,7 @@ TEST_F(WebAppPolicyManagerTest, UninstallAppInstalledInCurrentSession) { ...@@ -253,7 +253,7 @@ TEST_F(WebAppPolicyManagerTest, UninstallAppInstalledInCurrentSession) {
auto pending_app_manager = std::make_unique<TestPendingAppManager>(); auto pending_app_manager = std::make_unique<TestPendingAppManager>();
WebAppPolicyManager web_app_policy_manager(profile(), WebAppPolicyManager web_app_policy_manager(profile(),
pending_app_manager.get()); pending_app_manager.get());
web_app_policy_manager.Init(); web_app_policy_manager.Start();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// Add two sites, one that opens in a window and one that opens in a tab. // Add two sites, one that opens in a window and one that opens in a tab.
......
...@@ -149,8 +149,8 @@ SystemWebAppManagerBrowserTest::CreateWebAppProvider( ...@@ -149,8 +149,8 @@ SystemWebAppManagerBrowserTest::CreateWebAppProvider(
return nullptr; return nullptr;
auto provider = std::make_unique<TestWebAppProvider>(profile); auto provider = std::make_unique<TestWebAppProvider>(profile);
// Create all real subsystems: // Create all real subsystems but do not start them:
provider->CreateSubsystems(); provider->Init();
// But override SystemWebAppManager with TestSystemWebAppManager: // But override SystemWebAppManager with TestSystemWebAppManager:
DCHECK(!test_system_web_app_manager_); DCHECK(!test_system_web_app_manager_);
...@@ -163,8 +163,8 @@ SystemWebAppManagerBrowserTest::CreateWebAppProvider( ...@@ -163,8 +163,8 @@ SystemWebAppManagerBrowserTest::CreateWebAppProvider(
system_apps.emplace_back(GURL("chrome://test-system-app/pwa.html")); system_apps.emplace_back(GURL("chrome://test-system-app/pwa.html"));
test_system_web_app_manager_->SetSystemApps(std::move(system_apps)); test_system_web_app_manager_->SetSystemApps(std::move(system_apps));
// Initialize all subsystems: // Start all subsystems:
provider->Init(); provider->Start();
return provider; return provider;
} }
......
...@@ -99,7 +99,7 @@ TEST_F(SystemWebAppManagerTest, Disabled) { ...@@ -99,7 +99,7 @@ TEST_F(SystemWebAppManagerTest, Disabled) {
TestSystemWebAppManager system_web_app_manager(profile(), TestSystemWebAppManager system_web_app_manager(profile(),
pending_app_manager.get()); pending_app_manager.get());
system_web_app_manager.SetSystemApps(std::move(system_apps)); system_web_app_manager.SetSystemApps(std::move(system_apps));
system_web_app_manager.Init(); system_web_app_manager.Start();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -122,7 +122,7 @@ TEST_F(SystemWebAppManagerTest, Enabled) { ...@@ -122,7 +122,7 @@ TEST_F(SystemWebAppManagerTest, Enabled) {
TestSystemWebAppManager system_web_app_manager(profile(), TestSystemWebAppManager system_web_app_manager(profile(),
pending_app_manager.get()); pending_app_manager.get());
system_web_app_manager.SetSystemApps(std::move(system_apps)); system_web_app_manager.SetSystemApps(std::move(system_apps));
system_web_app_manager.Init(); system_web_app_manager.Start();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -148,7 +148,7 @@ TEST_F(SystemWebAppManagerTest, UninstallAppInstalledInPreviousSession) { ...@@ -148,7 +148,7 @@ TEST_F(SystemWebAppManagerTest, UninstallAppInstalledInPreviousSession) {
TestSystemWebAppManager system_web_app_manager(profile(), TestSystemWebAppManager system_web_app_manager(profile(),
pending_app_manager.get()); pending_app_manager.get());
system_web_app_manager.SetSystemApps(std::move(system_apps)); system_web_app_manager.SetSystemApps(std::move(system_apps));
system_web_app_manager.Init(); system_web_app_manager.Start();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
......
...@@ -29,7 +29,7 @@ WebAppPolicyManager::WebAppPolicyManager(Profile* profile, ...@@ -29,7 +29,7 @@ WebAppPolicyManager::WebAppPolicyManager(Profile* profile,
WebAppPolicyManager::~WebAppPolicyManager() = default; WebAppPolicyManager::~WebAppPolicyManager() = default;
void WebAppPolicyManager::Init() { void WebAppPolicyManager::Start() {
content::BrowserThread::PostAfterStartupTask( content::BrowserThread::PostAfterStartupTask(
FROM_HERE, FROM_HERE,
base::CreateSingleThreadTaskRunnerWithTraits( base::CreateSingleThreadTaskRunnerWithTraits(
......
...@@ -33,7 +33,7 @@ class WebAppPolicyManager { ...@@ -33,7 +33,7 @@ class WebAppPolicyManager {
WebAppPolicyManager(Profile* profile, PendingAppManager* pending_app_manager); WebAppPolicyManager(Profile* profile, PendingAppManager* pending_app_manager);
~WebAppPolicyManager(); ~WebAppPolicyManager();
void Init(); void Start();
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
......
...@@ -41,7 +41,7 @@ SystemWebAppManager::SystemWebAppManager(Profile* profile, ...@@ -41,7 +41,7 @@ SystemWebAppManager::SystemWebAppManager(Profile* profile,
SystemWebAppManager::~SystemWebAppManager() = default; SystemWebAppManager::~SystemWebAppManager() = default;
void SystemWebAppManager::Init() { void SystemWebAppManager::Start() {
content::BrowserThread::PostAfterStartupTask( content::BrowserThread::PostAfterStartupTask(
FROM_HERE, FROM_HERE,
base::CreateSingleThreadTaskRunnerWithTraits( base::CreateSingleThreadTaskRunnerWithTraits(
......
...@@ -25,7 +25,7 @@ class SystemWebAppManager { ...@@ -25,7 +25,7 @@ class SystemWebAppManager {
SystemWebAppManager(Profile* profile, PendingAppManager* pending_app_manager); SystemWebAppManager(Profile* profile, PendingAppManager* pending_app_manager);
virtual ~SystemWebAppManager(); virtual ~SystemWebAppManager();
void Init(); void Start();
static bool ShouldEnableForProfile(Profile* profile); static bool ShouldEnableForProfile(Profile* profile);
......
...@@ -64,7 +64,7 @@ WebAppProvider::WebAppProvider(Profile* profile) : profile_(profile) { ...@@ -64,7 +64,7 @@ WebAppProvider::WebAppProvider(Profile* profile) : profile_(profile) {
WebAppProvider::~WebAppProvider() = default; WebAppProvider::~WebAppProvider() = default;
void WebAppProvider::CreateSubsystems() { void WebAppProvider::Init() {
audio_focus_id_map_ = std::make_unique<WebAppAudioFocusIdMap>(); audio_focus_id_map_ = std::make_unique<WebAppAudioFocusIdMap>();
if (base::FeatureList::IsEnabled(features::kDesktopPWAsWithoutExtensions)) if (base::FeatureList::IsEnabled(features::kDesktopPWAsWithoutExtensions))
...@@ -73,7 +73,7 @@ void WebAppProvider::CreateSubsystems() { ...@@ -73,7 +73,7 @@ void WebAppProvider::CreateSubsystems() {
CreateBookmarkAppsSubsystems(profile_); CreateBookmarkAppsSubsystems(profile_);
} }
void WebAppProvider::Init() { void WebAppProvider::Start() {
notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
content::Source<Profile>(profile_)); content::Source<Profile>(profile_));
...@@ -81,10 +81,11 @@ void WebAppProvider::Init() { ...@@ -81,10 +81,11 @@ void WebAppProvider::Init() {
registrar_->Init(base::BindOnce(&WebAppProvider::OnRegistryReady, registrar_->Init(base::BindOnce(&WebAppProvider::OnRegistryReady,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} else { } else {
web_app_policy_manager_->Init(); web_app_policy_manager_->Start();
system_web_app_manager_->Init(); system_web_app_manager_->Start();
web_app::ScanForExternalWebApps( // Start ExternalWebApps subsystem:
ScanForExternalWebApps(
profile_, base::BindOnce(&WebAppProvider::OnScanForExternalWebApps, profile_, base::BindOnce(&WebAppProvider::OnScanForExternalWebApps,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
......
...@@ -57,10 +57,10 @@ class WebAppProvider : public KeyedService, ...@@ -57,10 +57,10 @@ class WebAppProvider : public KeyedService,
explicit WebAppProvider(Profile* profile); explicit WebAppProvider(Profile* profile);
~WebAppProvider() override; ~WebAppProvider() override;
// 1st pass: Just create subsystems. // Create subsystems but do not start them (yet).
void CreateSubsystems();
// 2nd pass: Initialize subsystems.
void Init(); void Init();
// Start all subsystems.
void Start();
// Clients can use PendingAppManager to install, uninstall, and update // Clients can use PendingAppManager to install, uninstall, and update
// Web Apps. // Web Apps.
......
...@@ -39,8 +39,8 @@ KeyedService* WebAppProviderFactory::BuildServiceInstanceFor( ...@@ -39,8 +39,8 @@ KeyedService* WebAppProviderFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const { content::BrowserContext* context) const {
Profile* profile = Profile::FromBrowserContext(context); Profile* profile = Profile::FromBrowserContext(context);
WebAppProvider* provider = new WebAppProvider(profile); WebAppProvider* provider = new WebAppProvider(profile);
provider->CreateSubsystems();
provider->Init(); provider->Init();
provider->Start();
return provider; return provider;
} }
......
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