Commit c5d6bcb1 authored by Nigel Tao's avatar Nigel Tao Committed by Commit Bot

Factor web app types out of WebAppPolicyManager

Upcoming changes will refer to these types without being associated with
"policy" per se.

Change-Id: I1d3e98592686ee640fb5a22f24b180f267d43381
Reviewed-on: https://chromium-review.googlesource.com/1149422
Commit-Queue: Nigel Tao <nigeltao@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577802}
parent 5aa7e3f4
......@@ -15,19 +15,6 @@
namespace web_app {
WebAppPolicyManager::AppInfo::AppInfo(GURL url,
LaunchContainer launch_container)
: url(std::move(url)), launch_container(launch_container) {}
WebAppPolicyManager::AppInfo::AppInfo(AppInfo&& other) = default;
WebAppPolicyManager::AppInfo::~AppInfo() = default;
bool WebAppPolicyManager::AppInfo::operator==(const AppInfo& other) const {
return std::tie(url, launch_container) ==
std::tie(other.url, other.launch_container);
}
WebAppPolicyManager::WebAppPolicyManager(
PrefService* pref_service,
std::unique_ptr<PendingAppManager> pending_app_manager)
......@@ -43,12 +30,12 @@ WebAppPolicyManager::WebAppPolicyManager(PrefService* pref_service)
WebAppPolicyManager::~WebAppPolicyManager() = default;
std::vector<WebAppPolicyManager::AppInfo>
std::vector<PendingAppManager::AppInfo>
WebAppPolicyManager::GetAppsToInstall() {
const base::Value* web_apps =
pref_service_->GetList(prefs::kWebAppInstallForceList);
std::vector<AppInfo> apps_to_install;
std::vector<PendingAppManager::AppInfo> apps_to_install;
for (const base::Value& info : web_apps->GetList()) {
const base::Value& url = *info.FindKey(kUrlKey);
const base::Value& launch_container = *info.FindKey(kLaunchContainerKey);
......@@ -59,14 +46,10 @@ WebAppPolicyManager::GetAppsToInstall() {
apps_to_install.emplace_back(
GURL(url.GetString()),
launch_container.GetString() == kLaunchContainerWindowValue
? LaunchContainer::kWindow
: LaunchContainer::kTab);
? PendingAppManager::LaunchContainer::kWindow
: PendingAppManager::LaunchContainer::kTab);
}
return apps_to_install;
}
WebAppPolicyManager::PendingAppManager::PendingAppManager() = default;
WebAppPolicyManager::PendingAppManager::~PendingAppManager() = default;
} // namespace web_app
......@@ -9,41 +9,18 @@
#include <vector>
#include "base/macros.h"
#include "chrome/browser/web_applications/components/pending_app_manager.h"
#include "url/gurl.h"
class PrefService;
class GURL;
namespace web_app {
// Tracks the policy that affects Web Apps and also tracks which Web Apps are
// currently installed based on this policy. Based on these, it decides
// which apps need to be installed, uninstalled, and updated. It uses
// WebAppPolicyManager::PendingAppManager to actually install, uninstall,
// and update apps.
// currently installed based on this policy. Based on these, it decides which
// apps to install, uninstall, and update, via a PendingAppManager.
class WebAppPolicyManager {
public:
class PendingAppManager;
// How the app will be launched after installation.
enum class LaunchContainer {
kTab,
kWindow,
};
struct AppInfo {
AppInfo(GURL url, LaunchContainer launch_container);
AppInfo(AppInfo&& other);
~AppInfo();
bool operator==(const AppInfo& other) const;
GURL url;
LaunchContainer launch_container;
DISALLOW_COPY_AND_ASSIGN(AppInfo);
};
// Constructs a WebAppPolicyManager instance that uses
// extensions::PendingBookmarkAppManager to manage apps.
explicit WebAppPolicyManager(PrefService* pref_service);
......@@ -61,7 +38,7 @@ class WebAppPolicyManager {
}
private:
std::vector<AppInfo> GetAppsToInstall();
std::vector<PendingAppManager::AppInfo> GetAppsToInstall();
PrefService* pref_service_;
std::unique_ptr<PendingAppManager> pending_app_manager_;
......@@ -69,23 +46,6 @@ class WebAppPolicyManager {
DISALLOW_COPY_AND_ASSIGN(WebAppPolicyManager);
};
// Used by WebAppPolicyManager to install, uninstall, and update apps.
//
// Implementations of this class should perform each set of operations serially
// in the order in which they arrive. For example, if an uninstall request gets
// queued while an update request for the same app is pending, implementations
// should wait for the update request to finish before uninstalling the app.
class WebAppPolicyManager::PendingAppManager {
public:
PendingAppManager();
virtual ~PendingAppManager();
// Starts the installation of |apps_to_install|.
virtual void ProcessAppOperations(std::vector<AppInfo> apps_to_install) = 0;
DISALLOW_COPY_AND_ASSIGN(PendingAppManager);
};
} // namespace web_app
#endif // CHROME_BROWSER_WEB_APPLICATIONS_BOOKMARK_APPS_POLICY_WEB_APP_POLICY_MANAGER_H_
......@@ -10,13 +10,13 @@
#include "base/values.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/web_applications/bookmark_apps/policy/web_app_policy_constants.h"
#include "chrome/browser/web_applications/components/pending_app_manager.h"
#include "chrome/common/pref_names.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using sync_preferences::TestingPrefServiceSyncable;
using AppInfo = web_app::WebAppPolicyManager::AppInfo;
namespace web_app {
......@@ -33,13 +33,12 @@ class WebAppPolicyManagerTest : public testing::Test {
};
class WebAppPolicyManagerTest::TestPendingAppManager
: public WebAppPolicyManager::PendingAppManager {
: public PendingAppManager {
public:
TestPendingAppManager() = default;
~TestPendingAppManager() override = default;
void ProcessAppOperations(
std::vector<WebAppPolicyManager::AppInfo> apps_to_install) override {
void ProcessAppOperations(std::vector<AppInfo> apps_to_install) override {
last_apps_to_install_ = std::move(apps_to_install);
}
......@@ -112,11 +111,11 @@ TEST_F(WebAppPolicyManagerTest, TwoForceInstalledApps) {
std::move(pending_app_manager));
const auto& apps_to_install = pending_app_manager_ptr->last_apps_to_install();
std::vector<AppInfo> expected_apps_to_install;
std::vector<PendingAppManager::AppInfo> expected_apps_to_install;
expected_apps_to_install.emplace_back(
GURL(kUrl1), WebAppPolicyManager::LaunchContainer::kWindow);
GURL(kUrl1), PendingAppManager::LaunchContainer::kWindow);
expected_apps_to_install.emplace_back(
GURL(kUrl2), WebAppPolicyManager::LaunchContainer::kTab);
GURL(kUrl2), PendingAppManager::LaunchContainer::kTab);
EXPECT_EQ(apps_to_install, expected_apps_to_install);
}
......
......@@ -4,6 +4,8 @@
source_set("components") {
sources = [
"pending_app_manager.cc",
"pending_app_manager.h",
"web_app_helpers.cc",
"web_app_helpers.h",
]
......
// Copyright 2018 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/components/pending_app_manager.h"
namespace web_app {
PendingAppManager::AppInfo::AppInfo(GURL url, LaunchContainer launch_container)
: url(std::move(url)), launch_container(launch_container) {}
PendingAppManager::AppInfo::AppInfo(PendingAppManager::AppInfo&& other) =
default;
PendingAppManager::AppInfo::~AppInfo() = default;
bool PendingAppManager::AppInfo::operator==(
const PendingAppManager::AppInfo& other) const {
return std::tie(url, launch_container) ==
std::tie(other.url, other.launch_container);
}
PendingAppManager::PendingAppManager() = default;
PendingAppManager::~PendingAppManager() = default;
} // namespace web_app
// Copyright 2018 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_COMPONENTS_PENDING_APP_MANAGER_H_
#define CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_PENDING_APP_MANAGER_H_
#include <vector>
#include "base/macros.h"
#include "url/gurl.h"
namespace web_app {
// PendingAppManager installs, uninstalls, and updates apps.
//
// Implementations of this class should perform each set of operations serially
// in the order in which they arrive. For example, if an uninstall request gets
// queued while an update request for the same app is pending, implementations
// should wait for the update request to finish before uninstalling the app.
class PendingAppManager {
public:
// How the app will be launched after installation.
enum class LaunchContainer {
kTab,
kWindow,
};
struct AppInfo {
AppInfo(GURL url, LaunchContainer launch_container);
AppInfo(AppInfo&& other);
~AppInfo();
bool operator==(const AppInfo& other) const;
GURL url;
LaunchContainer launch_container;
DISALLOW_COPY_AND_ASSIGN(AppInfo);
};
PendingAppManager();
virtual ~PendingAppManager();
// Starts the installation of |apps_to_install|.
virtual void ProcessAppOperations(std::vector<AppInfo> apps_to_install) = 0;
DISALLOW_COPY_AND_ASSIGN(PendingAppManager);
};
} // namespace web_app
#endif // CHROME_BROWSER_WEB_APPLICATIONS_COMPONENTS_PENDING_APP_MANAGER_H_
......@@ -13,6 +13,6 @@ PendingBookmarkAppManager::PendingBookmarkAppManager() = default;
PendingBookmarkAppManager::~PendingBookmarkAppManager() = default;
void PendingBookmarkAppManager::ProcessAppOperations(
std::vector<web_app::WebAppPolicyManager::AppInfo> apps_to_install) {}
std::vector<web_app::PendingAppManager::AppInfo> apps_to_install) {}
} // namespace extensions
......@@ -8,23 +8,22 @@
#include <vector>
#include "base/macros.h"
#include "chrome/browser/web_applications/bookmark_apps/policy/web_app_policy_manager.h"
#include "chrome/browser/web_applications/components/pending_app_manager.h"
namespace extensions {
// Implementation of WebAppPolicyManager::PendingAppManager that manages the set
// of Bookmark Apps which are being installed, uninstalled, and updated.
// Implementation of web_app::PendingAppManager that manages the set of
// Bookmark Apps which are being installed, uninstalled, and updated.
//
// WebAppPolicyManager creates an instance of this class and manages its
// lifetime. This class should only be used from the UI thread.
class PendingBookmarkAppManager final
: public web_app::WebAppPolicyManager::PendingAppManager {
class PendingBookmarkAppManager final : public web_app::PendingAppManager {
public:
PendingBookmarkAppManager();
~PendingBookmarkAppManager() override;
// WebAppPolicyManager::PendingAppManager
void ProcessAppOperations(std::vector<web_app::WebAppPolicyManager::AppInfo>
// web_app::PendingAppManager
void ProcessAppOperations(std::vector<web_app::PendingAppManager::AppInfo>
apps_to_install) override;
DISALLOW_COPY_AND_ASSIGN(PendingBookmarkAppManager);
......
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