Commit 94141dd6 authored by Fabio Rocha's avatar Fabio Rocha Committed by Chromium LUCI CQ

desktop-pwas: Add web_app_protocol_handler_manager

This CL changes GetAppProtocolHandlerInfos to be virtual and adds
web_app_protocol_handler_manager. This mimics the design of other
components and avoids a layer of indirection between web_applications
and web_applications/components.

Bug: 1019239
Change-Id: Ibf9abbe66a4bf1addb13955040889b740cf578bd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2577888
Commit-Queue: Fabio Rocha <fabio.rocha@microsoft.com>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837767}
parent e3245e26
......@@ -56,6 +56,8 @@ source_set("web_applications") {
"web_app_migration_user_display_mode_clean_up.h",
"web_app_proto_utils.cc",
"web_app_proto_utils.h",
"web_app_protocol_handler_manager.cc",
"web_app_protocol_handler_manager.h",
"web_app_provider.cc",
"web_app_provider.h",
"web_app_provider_factory.cc",
......@@ -124,6 +126,8 @@ source_set("web_applications_test_support") {
testonly = true
sources = [
"test/fake_protocol_handler_manager.cc",
"test/fake_protocol_handler_manager.h",
"test/service_worker_registration_waiter.cc",
"test/service_worker_registration_waiter.h",
"test/test_app_registrar.cc",
......@@ -144,8 +148,6 @@ source_set("web_applications_test_support") {
"test/test_pending_app_manager.h",
"test/test_pending_app_manager_impl.cc",
"test/test_pending_app_manager_impl.h",
"test/test_protocol_handler_manager.cc",
"test/test_protocol_handler_manager.h",
"test/test_system_web_app_manager.cc",
"test/test_system_web_app_manager.h",
"test/test_system_web_app_url_data_source.cc",
......
......@@ -25,8 +25,8 @@ class ProtocolHandlerManager {
void Start();
// Gets all protocol handlers for |app_id|.
std::vector<apps::ProtocolHandlerInfo> GetAppProtocolHandlerInfos(
const std::string& app_id) const;
virtual std::vector<apps::ProtocolHandlerInfo> GetAppProtocolHandlerInfos(
const std::string& app_id) const = 0;
// Registers OS specific protocol handlers for OSs that need them, using the
// protocol handler information supplied in the app manifest.
......@@ -48,7 +48,6 @@ class ProtocolHandlerManager {
const AppId& app_id,
const std::vector<apps::ProtocolHandlerInfo>& protocol_handlers);
private:
AppRegistrar* app_registrar_;
};
......
// 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/web_applications/test/fake_protocol_handler_manager.h"
namespace web_app {
FakeProtocolHandlerManager::FakeProtocolHandlerManager(Profile* profile)
: ProtocolHandlerManager(profile) {}
FakeProtocolHandlerManager::~FakeProtocolHandlerManager() = default;
void FakeProtocolHandlerManager::RegisterProtocolHandler(
const AppId& app_id,
const apps::ProtocolHandlerInfo& protocol_handler) {
protocol_handlers_[app_id].push_back(protocol_handler);
}
std::vector<apps::ProtocolHandlerInfo>
FakeProtocolHandlerManager::GetAppProtocolHandlerInfos(
const std::string& app_id) const {
auto app_protocol_handlers = protocol_handlers_.find(app_id);
return app_protocol_handlers != protocol_handlers_.end()
? app_protocol_handlers->second
: std::vector<apps::ProtocolHandlerInfo>();
}
} // namespace web_app
// 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_WEB_APPLICATIONS_TEST_FAKE_PROTOCOL_HANDLER_MANAGER_H_
#define CHROME_BROWSER_WEB_APPLICATIONS_TEST_FAKE_PROTOCOL_HANDLER_MANAGER_H_
#include <vector>
#include "base/containers/flat_map.h"
#include "chrome/browser/web_applications/components/protocol_handler_manager.h"
namespace web_app {
// Fake implementation of ProtocolHandlerManager
class FakeProtocolHandlerManager : public ProtocolHandlerManager {
public:
explicit FakeProtocolHandlerManager(Profile* profile);
~FakeProtocolHandlerManager() override;
void RegisterProtocolHandler(
const AppId& app_id,
const apps::ProtocolHandlerInfo& protocol_handler);
std::vector<apps::ProtocolHandlerInfo> GetAppProtocolHandlerInfos(
const std::string& app_id) const override;
private:
base::flat_map<AppId, std::vector<apps::ProtocolHandlerInfo>>
protocol_handlers_;
};
} // namespace web_app
#endif // CHROME_BROWSER_WEB_APPLICATIONS_TEST_FAKE_PROTOCOL_HANDLER_MANAGER_H_
......@@ -10,8 +10,8 @@
#include "chrome/browser/web_applications/components/protocol_handler_manager.h"
#include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/components/web_app_ui_manager.h"
#include "chrome/browser/web_applications/test/fake_protocol_handler_manager.h"
#include "chrome/browser/web_applications/test/test_file_handler_manager.h"
#include "chrome/browser/web_applications/test/test_protocol_handler_manager.h"
namespace web_app {
TestOsIntegrationManager::TestOsIntegrationManager(
......@@ -31,7 +31,7 @@ TestOsIntegrationManager::TestOsIntegrationManager(
}
if (!this->protocol_handler_manager()) {
set_protocol_handler_manager(
std::make_unique<TestProtocolHandlerManager>(profile));
std::make_unique<FakeProtocolHandlerManager>(profile));
}
}
......
// 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/web_applications/test/test_protocol_handler_manager.h"
namespace web_app {
TestProtocolHandlerManager::TestProtocolHandlerManager(Profile* profile)
: ProtocolHandlerManager(profile) {}
TestProtocolHandlerManager::~TestProtocolHandlerManager() = default;
} // namespace web_app
// 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/web_applications/web_app_protocol_handler_manager.h"
#include "chrome/browser/web_applications/components/app_registrar.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
namespace web_app {
WebAppProtocolHandlerManager::WebAppProtocolHandlerManager(Profile* profile)
: ProtocolHandlerManager(profile) {}
WebAppProtocolHandlerManager::~WebAppProtocolHandlerManager() = default;
std::vector<apps::ProtocolHandlerInfo>
WebAppProtocolHandlerManager::GetAppProtocolHandlerInfos(
const std::string& app_id) const {
const WebApp* web_app =
app_registrar_->AsWebAppRegistrar()->GetAppById(app_id);
if (!web_app)
return {};
return web_app->protocol_handlers();
}
} // namespace web_app
......@@ -2,20 +2,23 @@
// 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_TEST_TEST_PROTOCOL_HANDLER_MANAGER_H_
#define CHROME_BROWSER_WEB_APPLICATIONS_TEST_TEST_PROTOCOL_HANDLER_MANAGER_H_
#ifndef CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_PROTOCOL_HANDLER_MANAGER_H_
#define CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_PROTOCOL_HANDLER_MANAGER_H_
#include "chrome/browser/web_applications/components/protocol_handler_manager.h"
namespace web_app {
// testing implementation of ProtocolHandlerManager
class TestProtocolHandlerManager : public ProtocolHandlerManager {
class WebAppProtocolHandlerManager : public ProtocolHandlerManager {
public:
explicit TestProtocolHandlerManager(Profile* profile);
~TestProtocolHandlerManager() override;
explicit WebAppProtocolHandlerManager(Profile* profile);
~WebAppProtocolHandlerManager() override;
protected:
std::vector<apps::ProtocolHandlerInfo> GetAppProtocolHandlerInfos(
const std::string& app_id) const override;
};
} // namespace web_app
#endif // CHROME_BROWSER_WEB_APPLICATIONS_TEST_TEST_PROTOCOL_HANDLER_MANAGER_H_
#endif // CHROME_BROWSER_WEB_APPLICATIONS_WEB_APP_PROTOCOL_HANDLER_MANAGER_H_
......@@ -13,7 +13,6 @@
#include "chrome/browser/web_applications/components/install_bounce_metric.h"
#include "chrome/browser/web_applications/components/os_integration_manager.h"
#include "chrome/browser/web_applications/components/policy/web_app_policy_manager.h"
#include "chrome/browser/web_applications/components/protocol_handler_manager.h"
#include "chrome/browser/web_applications/components/web_app_audio_focus_id_map.h"
#include "chrome/browser/web_applications/components/web_app_prefs_utils.h"
#include "chrome/browser/web_applications/components/web_app_ui_manager.h"
......@@ -31,6 +30,7 @@
#include "chrome/browser/web_applications/web_app_install_manager.h"
#include "chrome/browser/web_applications/web_app_migration_manager.h"
#include "chrome/browser/web_applications/web_app_migration_user_display_mode_clean_up.h"
#include "chrome/browser/web_applications/web_app_protocol_handler_manager.h"
#include "chrome/browser/web_applications/web_app_provider_factory.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/browser/web_applications/web_app_shortcut_manager.h"
......@@ -227,7 +227,7 @@ void WebAppProvider::CreateWebAppsSubsystems(Profile* profile) {
auto file_handler_manager =
std::make_unique<WebAppFileHandlerManager>(profile);
auto protocol_handler_manager =
std::make_unique<ProtocolHandlerManager>(profile);
std::make_unique<WebAppProtocolHandlerManager>(profile);
auto shortcut_manager = std::make_unique<WebAppShortcutManager>(
profile, icon_manager.get(), file_handler_manager.get());
os_integration_manager_ = std::make_unique<OsIntegrationManager>(
......
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