Commit 194e0a7a authored by Eric Willigers's avatar Eric Willigers Committed by Commit Bot

WebApps: AndroidSmsAppSetupController no longer relies on Extensions

Migrate AndroidSmsAppSetupController to use the new web_app:: APIs,
in preparation for the extensions-based implementation of desktop PWAs
being retired.

Bug: 1052709
Change-Id: I2dfb503975d5073dc7f152d2dcced2943819e8c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2060403
Auto-Submit: Eric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarAzeem Arshad <azeemarshad@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743323}
parent 9d049d98
...@@ -2588,6 +2588,7 @@ static_library("test_support") { ...@@ -2588,6 +2588,7 @@ static_library("test_support") {
deps = [ deps = [
":chromeos", ":chromeos",
"//chrome/browser/web_applications/components",
"//chrome/test:test_support", "//chrome/test:test_support",
"//chromeos", "//chromeos",
"//chromeos/components/drivefs", "//chromeos/components/drivefs",
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "chromeos/components/multidevice/logging/logging.h" #include "chromeos/components/multidevice/logging/logging.h"
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "extensions/common/extension.h"
namespace chromeos { namespace chromeos {
...@@ -177,7 +176,7 @@ void AndroidSmsAppManagerImpl::OnSetUpNewAppResult( ...@@ -177,7 +176,7 @@ void AndroidSmsAppManagerImpl::OnSetUpNewAppResult(
bool success) { bool success) {
is_new_app_setup_in_progress_ = false; is_new_app_setup_in_progress_ = false;
const extensions::Extension* new_pwa = setup_controller_->GetPwa( base::Optional<web_app::AppId> new_pwa = setup_controller_->GetPwa(
GetAndroidMessagesURL(true /* use_install_url */)); GetAndroidMessagesURL(true /* use_install_url */));
// If the app failed to install or the PWA does not exist, do not launch. // If the app failed to install or the PWA does not exist, do not launch.
...@@ -196,13 +195,13 @@ void AndroidSmsAppManagerImpl::OnSetUpNewAppResult( ...@@ -196,13 +195,13 @@ void AndroidSmsAppManagerImpl::OnSetUpNewAppResult(
return; return;
} }
const extensions::Extension* old_pwa = setup_controller_->GetPwa( base::Optional<web_app::AppId> old_pwa = setup_controller_->GetPwa(
GetAndroidMessagesURL(true /* use_install_url */, *migrating_from)); GetAndroidMessagesURL(true /* use_install_url */, *migrating_from));
// Transfer attributes from the old PWA to the new one. This ensures that the // Transfer attributes from the old PWA to the new one. This ensures that the
// PWA's placement in the app launcher and shelf remains constant.. // PWA's placement in the app launcher and shelf remains constant..
bool transfer_attributes_success = pwa_delegate_->TransferItemAttributes( bool transfer_attributes_success = pwa_delegate_->TransferItemAttributes(
old_pwa->id() /* from_app_id */, new_pwa->id() /* to_app_id */, *old_pwa /* from_app_id */, *new_pwa /* to_app_id */,
app_list_syncable_service_); app_list_syncable_service_);
if (!transfer_attributes_success) { if (!transfer_attributes_success) {
PA_LOG(ERROR) << "AndroidSmsAppManagerImpl::OnSetUpNewAppResult(): Failed " PA_LOG(ERROR) << "AndroidSmsAppManagerImpl::OnSetUpNewAppResult(): Failed "
...@@ -253,10 +252,8 @@ void AndroidSmsAppManagerImpl::HandleAppSetupFinished() { ...@@ -253,10 +252,8 @@ void AndroidSmsAppManagerImpl::HandleAppSetupFinished() {
<< "Launching Messages PWA."; << "Launching Messages PWA.";
pwa_delegate_->OpenApp( pwa_delegate_->OpenApp(
profile_, apps::AppLaunchParams( profile_, apps::AppLaunchParams(
setup_controller_ *setup_controller_->GetPwa(GetAndroidMessagesURL(
->GetPwa(GetAndroidMessagesURL( true /* use_install_url */, *domain)),
true /* use_install_url */, *domain))
->id(),
apps::mojom::LaunchContainer::kLaunchContainerWindow, apps::mojom::LaunchContainer::kLaunchContainerWindow,
WindowOpenDisposition::NEW_WINDOW, WindowOpenDisposition::NEW_WINDOW,
apps::mojom::AppLaunchSource::kSourceChromeInternal)); apps::mojom::AppLaunchSource::kSourceChromeInternal));
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/sync_preferences/testing_pref_service_syncable.h" #include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "extensions/common/extension.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace chromeos { namespace chromeos {
...@@ -195,7 +194,7 @@ TEST_F(AndroidSmsAppManagerImplTest, ...@@ -195,7 +194,7 @@ TEST_F(AndroidSmsAppManagerImplTest,
EXPECT_EQ(kNewAppId, fake_android_sms_app_setup_controller() EXPECT_EQ(kNewAppId, fake_android_sms_app_setup_controller()
->GetAppMetadataAtUrl(GetAndroidMessagesURL( ->GetAppMetadataAtUrl(GetAndroidMessagesURL(
true /* use_install_url */)) true /* use_install_url */))
->pwa->id()); ->pwa);
EXPECT_TRUE(fake_android_sms_app_setup_controller() EXPECT_TRUE(fake_android_sms_app_setup_controller()
->GetAppMetadataAtUrl(install_url) ->GetAppMetadataAtUrl(install_url)
->is_cookie_present); ->is_cookie_present);
...@@ -232,7 +231,7 @@ TEST_F(AndroidSmsAppManagerImplTest, TestSetUpMessagesAndLaunch_NoPreviousApp) { ...@@ -232,7 +231,7 @@ TEST_F(AndroidSmsAppManagerImplTest, TestSetUpMessagesAndLaunch_NoPreviousApp) {
EXPECT_EQ(kNewAppId, fake_android_sms_app_setup_controller() EXPECT_EQ(kNewAppId, fake_android_sms_app_setup_controller()
->GetAppMetadataAtUrl(GetAndroidMessagesURL( ->GetAppMetadataAtUrl(GetAndroidMessagesURL(
true /* use_install_url */)) true /* use_install_url */))
->pwa->id()); ->pwa);
EXPECT_TRUE(fake_android_sms_app_setup_controller() EXPECT_TRUE(fake_android_sms_app_setup_controller()
->GetAppMetadataAtUrl(install_url) ->GetAppMetadataAtUrl(install_url)
->is_cookie_present); ->is_cookie_present);
...@@ -275,7 +274,7 @@ TEST_F(AndroidSmsAppManagerImplTest, ...@@ -275,7 +274,7 @@ TEST_F(AndroidSmsAppManagerImplTest,
EXPECT_EQ(kOldAppId, fake_android_sms_app_setup_controller() EXPECT_EQ(kOldAppId, fake_android_sms_app_setup_controller()
->GetAppMetadataAtUrl(GetAndroidMessagesURLOld( ->GetAppMetadataAtUrl(GetAndroidMessagesURLOld(
true /* use_install_url */)) true /* use_install_url */))
->pwa->id()); ->pwa);
EXPECT_TRUE(fake_android_sms_app_setup_controller() EXPECT_TRUE(fake_android_sms_app_setup_controller()
->GetAppMetadataAtUrl( ->GetAppMetadataAtUrl(
GetAndroidMessagesURLOld(true /* use_install_url */)) GetAndroidMessagesURLOld(true /* use_install_url */))
...@@ -301,7 +300,7 @@ TEST_F(AndroidSmsAppManagerImplTest, ...@@ -301,7 +300,7 @@ TEST_F(AndroidSmsAppManagerImplTest,
EXPECT_EQ(kNewAppId, fake_android_sms_app_setup_controller() EXPECT_EQ(kNewAppId, fake_android_sms_app_setup_controller()
->GetAppMetadataAtUrl(GetAndroidMessagesURL( ->GetAppMetadataAtUrl(GetAndroidMessagesURL(
true /* use_install_url */)) true /* use_install_url */))
->pwa->id()); ->pwa);
EXPECT_TRUE(fake_android_sms_app_setup_controller() EXPECT_TRUE(fake_android_sms_app_setup_controller()
->GetAppMetadataAtUrl( ->GetAppMetadataAtUrl(
GetAndroidMessagesURL(true /* use_install_url */)) GetAndroidMessagesURL(true /* use_install_url */))
...@@ -340,7 +339,7 @@ TEST_F(AndroidSmsAppManagerImplTest, TestManualUninstall) { ...@@ -340,7 +339,7 @@ TEST_F(AndroidSmsAppManagerImplTest, TestManualUninstall) {
EXPECT_EQ(kNewAppId, fake_android_sms_app_setup_controller() EXPECT_EQ(kNewAppId, fake_android_sms_app_setup_controller()
->GetAppMetadataAtUrl(GetAndroidMessagesURL( ->GetAppMetadataAtUrl(GetAndroidMessagesURL(
true /* use_install_url */)) true /* use_install_url */))
->pwa->id()); ->pwa);
EXPECT_TRUE(fake_android_sms_app_setup_controller() EXPECT_TRUE(fake_android_sms_app_setup_controller()
->GetAppMetadataAtUrl(install_url) ->GetAppMetadataAtUrl(install_url)
->is_cookie_present); ->is_cookie_present);
......
...@@ -7,12 +7,9 @@ ...@@ -7,12 +7,9 @@
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/web_applications/components/web_app_id.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace extensions {
class Extension;
} // namespace extensions
namespace chromeos { namespace chromeos {
namespace android_sms { namespace android_sms {
...@@ -38,9 +35,9 @@ class AndroidSmsAppSetupController { ...@@ -38,9 +35,9 @@ class AndroidSmsAppSetupController {
const GURL& install_url, const GURL& install_url,
SuccessCallback callback) = 0; SuccessCallback callback) = 0;
// Returns the extension for the PWA at |install_url|; if no PWA exists, null // Returns the id for the PWA at |install_url|; if no PWA exists,
// is returned. // base::nullopt is returned.
virtual const extensions::Extension* GetPwa(const GURL& install_url) = 0; virtual base::Optional<web_app::AppId> GetPwa(const GURL& install_url) = 0;
// Deletes the cookie which causes the PWA to remember this computer by // Deletes the cookie which causes the PWA to remember this computer by
// default. Note that this does not actually stop the PWA from remembering // default. Note that this does not actually stop the PWA from remembering
......
...@@ -14,19 +14,18 @@ ...@@ -14,19 +14,18 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/components/external_install_options.h" #include "chrome/browser/web_applications/components/external_install_options.h"
#include "chrome/browser/web_applications/components/install_finalizer.h"
#include "chrome/browser/web_applications/components/pending_app_manager.h" #include "chrome/browser/web_applications/components/pending_app_manager.h"
#include "chrome/browser/web_applications/components/web_app_constants.h" #include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h" #include "chrome/browser/web_applications/components/web_app_helpers.h"
#include "chrome/browser/web_applications/components/web_app_provider_base.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chromeos/components/multidevice/logging/logging.h" #include "chromeos/components/multidevice/logging/logging.h"
#include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/content_settings/core/browser/host_content_settings_map.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/storage_partition.h" #include "content/public/browser/storage_partition.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/uninstall_reason.h"
#include "net/base/url_util.h" #include "net/base/url_util.h"
#include "services/network/public/mojom/cookie_manager.mojom.h" #include "services/network/public/mojom/cookie_manager.mojom.h"
#include "third_party/blink/public/mojom/manifest/display_mode.mojom.h" #include "third_party/blink/public/mojom/manifest/display_mode.mojom.h"
...@@ -53,17 +52,11 @@ AndroidSmsAppSetupControllerImpl::PwaDelegate::PwaDelegate() = default; ...@@ -53,17 +52,11 @@ AndroidSmsAppSetupControllerImpl::PwaDelegate::PwaDelegate() = default;
AndroidSmsAppSetupControllerImpl::PwaDelegate::~PwaDelegate() = default; AndroidSmsAppSetupControllerImpl::PwaDelegate::~PwaDelegate() = default;
const extensions::Extension* base::Optional<web_app::AppId>
AndroidSmsAppSetupControllerImpl::PwaDelegate::GetPwaForUrl( AndroidSmsAppSetupControllerImpl::PwaDelegate::GetPwaForUrl(
const GURL& install_url, const GURL& install_url,
Profile* profile) { Profile* profile) {
base::Optional<web_app::AppId> app_id = return web_app::FindInstalledAppWithUrlInScope(profile, install_url);
web_app::FindInstalledAppWithUrlInScope(profile, install_url);
// TODO(crbug.com/1052709): Return app_id, avoid dependence on Extensions.
return app_id ? extensions::ExtensionRegistry::Get(profile)
->GetInstalledExtension(*app_id)
: nullptr;
} }
network::mojom::CookieManager* network::mojom::CookieManager*
...@@ -74,15 +67,19 @@ AndroidSmsAppSetupControllerImpl::PwaDelegate::GetCookieManager( ...@@ -74,15 +67,19 @@ AndroidSmsAppSetupControllerImpl::PwaDelegate::GetCookieManager(
->GetCookieManagerForBrowserProcess(); ->GetCookieManagerForBrowserProcess();
} }
bool AndroidSmsAppSetupControllerImpl::PwaDelegate::RemovePwa( void AndroidSmsAppSetupControllerImpl::PwaDelegate::RemovePwa(
const extensions::ExtensionId& extension_id, const web_app::AppId& app_id,
base::string16* error, Profile* profile,
Profile* profile) { SuccessCallback callback) {
return extensions::ExtensionSystem::Get(profile) auto* provider = web_app::WebAppProviderBase::GetProviderBase(profile);
->extension_service() if (!provider) {
->UninstallExtension( std::move(callback).Run(false);
extension_id, return;
extensions::UNINSTALL_REASON_ORPHANED_EXTERNAL_EXTENSION, error); }
provider->install_finalizer().UninstallExternalWebApp(
app_id, web_app::ExternalInstallSource::kInternalDefault,
std::move(callback));
} }
AndroidSmsAppSetupControllerImpl::AndroidSmsAppSetupControllerImpl( AndroidSmsAppSetupControllerImpl::AndroidSmsAppSetupControllerImpl(
...@@ -122,7 +119,7 @@ void AndroidSmsAppSetupControllerImpl::SetUpApp(const GURL& app_url, ...@@ -122,7 +119,7 @@ void AndroidSmsAppSetupControllerImpl::SetUpApp(const GURL& app_url,
std::move(callback))); std::move(callback)));
} }
const extensions::Extension* AndroidSmsAppSetupControllerImpl::GetPwa( base::Optional<web_app::AppId> AndroidSmsAppSetupControllerImpl::GetPwa(
const GURL& install_url) { const GURL& install_url) {
return pwa_delegate_->GetPwaForUrl(install_url, profile_); return pwa_delegate_->GetPwaForUrl(install_url, profile_);
} }
...@@ -151,11 +148,11 @@ void AndroidSmsAppSetupControllerImpl::RemoveApp( ...@@ -151,11 +148,11 @@ void AndroidSmsAppSetupControllerImpl::RemoveApp(
const GURL& install_url, const GURL& install_url,
const GURL& migrated_to_app_url, const GURL& migrated_to_app_url,
SuccessCallback callback) { SuccessCallback callback) {
const extensions::Extension* extension = base::Optional<web_app::AppId> app_id =
pwa_delegate_->GetPwaForUrl(install_url, profile_); pwa_delegate_->GetPwaForUrl(install_url, profile_);
// If there is no app installed at |url|, there is nothing more to do. // If there is no app installed at |url|, there is nothing more to do.
if (!extension) { if (!app_id) {
PA_LOG(VERBOSE) << "AndroidSmsAppSetupControllerImpl::RemoveApp(): No app " PA_LOG(VERBOSE) << "AndroidSmsAppSetupControllerImpl::RemoveApp(): No app "
<< "is installed at " << install_url << "is installed at " << install_url
<< "; skipping removal process."; << "; skipping removal process.";
...@@ -166,17 +163,24 @@ void AndroidSmsAppSetupControllerImpl::RemoveApp( ...@@ -166,17 +163,24 @@ void AndroidSmsAppSetupControllerImpl::RemoveApp(
PA_LOG(INFO) << "AndroidSmsAppSetupControllerImpl::RemoveApp(): " PA_LOG(INFO) << "AndroidSmsAppSetupControllerImpl::RemoveApp(): "
<< "Uninstalling app at " << install_url << "."; << "Uninstalling app at " << install_url << ".";
const extensions::ExtensionId& extension_id = extension->id(); pwa_delegate_->RemovePwa(
base::string16 error; *app_id, profile_,
bool uninstalled_successfully = base::BindOnce(&AndroidSmsAppSetupControllerImpl::OnAppRemoved,
pwa_delegate_->RemovePwa(extension_id, &error, profile_); weak_ptr_factory_.GetWeakPtr(), std::move(callback),
UMA_HISTOGRAM_BOOLEAN("AndroidSms.PWAUninstallationResult", app_url, install_url, migrated_to_app_url));
uninstalled_successfully); }
void AndroidSmsAppSetupControllerImpl::OnAppRemoved(
SuccessCallback callback,
const GURL& app_url,
const GURL& install_url,
const GURL& migrated_to_app_url,
bool uninstalled) {
UMA_HISTOGRAM_BOOLEAN("AndroidSms.PWAUninstallationResult", uninstalled);
if (!uninstalled_successfully) { if (!uninstalled) {
PA_LOG(ERROR) << "AndroidSmsAppSetupControllerImpl::RemoveApp(): " PA_LOG(ERROR) << "AndroidSmsAppSetupControllerImpl::RemoveApp(): "
<< "PWA for " << install_url << " failed to uninstall. " << "PWA for " << install_url << " failed to uninstall.";
<< error;
std::move(callback).Run(false /* success */); std::move(callback).Run(false /* success */);
return; return;
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/unguessable_token.h" #include "base/unguessable_token.h"
#include "chrome/browser/chromeos/android_sms/android_sms_app_setup_controller.h" #include "chrome/browser/chromeos/android_sms/android_sms_app_setup_controller.h"
#include "extensions/common/extension_id.h" #include "chrome/browser/web_applications/components/web_app_id.h"
#include "net/cookies/canonical_cookie.h" #include "net/cookies/canonical_cookie.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -54,21 +54,20 @@ class AndroidSmsAppSetupControllerImpl : public AndroidSmsAppSetupController { ...@@ -54,21 +54,20 @@ class AndroidSmsAppSetupControllerImpl : public AndroidSmsAppSetupController {
PwaDelegate(); PwaDelegate();
virtual ~PwaDelegate(); virtual ~PwaDelegate();
virtual const extensions::Extension* GetPwaForUrl(const GURL& install_url, virtual base::Optional<web_app::AppId> GetPwaForUrl(const GURL& install_url,
Profile* profile); Profile* profile);
virtual network::mojom::CookieManager* GetCookieManager(const GURL& app_url, virtual network::mojom::CookieManager* GetCookieManager(const GURL& app_url,
Profile* profile); Profile* profile);
// |error| will contain the failure reason if RemovePwa returns false. virtual void RemovePwa(const web_app::AppId& app_id,
virtual bool RemovePwa(const extensions::ExtensionId& extension_id, Profile* profile,
base::string16* error, SuccessCallback callback);
Profile* profile);
}; };
// AndroidSmsAppSetupController: // AndroidSmsAppSetupController:
void SetUpApp(const GURL& app_url, void SetUpApp(const GURL& app_url,
const GURL& install_url, const GURL& install_url,
SuccessCallback callback) override; SuccessCallback callback) override;
const extensions::Extension* GetPwa(const GURL& install_url) override; base::Optional<web_app::AppId> GetPwa(const GURL& install_url) override;
void DeleteRememberDeviceByDefaultCookie(const GURL& app_url, void DeleteRememberDeviceByDefaultCookie(const GURL& app_url,
SuccessCallback callback) override; SuccessCallback callback) override;
void RemoveApp(const GURL& app_url, void RemoveApp(const GURL& app_url,
...@@ -76,6 +75,11 @@ class AndroidSmsAppSetupControllerImpl : public AndroidSmsAppSetupController { ...@@ -76,6 +75,11 @@ class AndroidSmsAppSetupControllerImpl : public AndroidSmsAppSetupController {
const GURL& migrated_to_app_url, const GURL& migrated_to_app_url,
SuccessCallback callback) override; SuccessCallback callback) override;
void OnAppRemoved(SuccessCallback callback,
const GURL& app_url,
const GURL& install_url,
const GURL& migrated_to_app_url,
bool uninstalled);
void OnSetRememberDeviceByDefaultCookieResult( void OnSetRememberDeviceByDefaultCookieResult(
const GURL& app_url, const GURL& app_url,
const GURL& install_url, const GURL& install_url,
......
...@@ -22,13 +22,11 @@ ...@@ -22,13 +22,11 @@
#include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/web_applications/components/external_install_options.h" #include "chrome/browser/web_applications/components/external_install_options.h"
#include "chrome/browser/web_applications/components/web_app_constants.h" #include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h"
#include "chrome/browser/web_applications/test/test_pending_app_manager.h" #include "chrome/browser/web_applications/test/test_pending_app_manager.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/content_settings/core/browser/host_content_settings_map.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/extension_paths.h"
#include "services/network/test/test_cookie_manager.h" #include "services/network/test/test_cookie_manager.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/manifest/display_mode.mojom.h" #include "third_party/blink/public/mojom/manifest/display_mode.mojom.h"
...@@ -143,21 +141,16 @@ class AndroidSmsAppSetupControllerImplTest : public testing::Test { ...@@ -143,21 +141,16 @@ class AndroidSmsAppSetupControllerImplTest : public testing::Test {
if (base::Contains(url_to_pwa_map_, url)) if (base::Contains(url_to_pwa_map_, url))
return; return;
// Create a test Extension and add it to |url_to_pwa_map_|. url_to_pwa_map_[url] = web_app::GenerateAppIdFromURL(url);
base::FilePath path;
base::PathService::Get(extensions::DIR_TEST_DATA, &path);
url_to_pwa_map_[url] = extensions::ExtensionBuilder(url.spec())
.SetPath(path.AppendASCII(url.spec()))
.Build();
} }
// AndroidSmsAppSetupControllerImpl::PwaDelegate: // AndroidSmsAppSetupControllerImpl::PwaDelegate:
const extensions::Extension* GetPwaForUrl(const GURL& install_url, base::Optional<web_app::AppId> GetPwaForUrl(const GURL& install_url,
Profile* profile) override { Profile* profile) override {
if (!base::Contains(url_to_pwa_map_, install_url)) if (!base::Contains(url_to_pwa_map_, install_url))
return nullptr; return base::nullopt;
return url_to_pwa_map_[install_url].get(); return url_to_pwa_map_[install_url];
} }
network::mojom::CookieManager* GetCookieManager(const GURL& app_url, network::mojom::CookieManager* GetCookieManager(const GURL& app_url,
...@@ -165,23 +158,24 @@ class AndroidSmsAppSetupControllerImplTest : public testing::Test { ...@@ -165,23 +158,24 @@ class AndroidSmsAppSetupControllerImplTest : public testing::Test {
return fake_cookie_manager_; return fake_cookie_manager_;
} }
bool RemovePwa(const extensions::ExtensionId& extension_id, void RemovePwa(
base::string16* error, const web_app::AppId& app_id,
Profile* profile) override { Profile* profile,
AndroidSmsAppSetupController::SuccessCallback callback) override {
for (const auto& url_pwa_pair : url_to_pwa_map_) { for (const auto& url_pwa_pair : url_to_pwa_map_) {
if (url_pwa_pair.second->id() == extension_id) { if (url_pwa_pair.second == app_id) {
url_to_pwa_map_.erase(url_pwa_pair.first); url_to_pwa_map_.erase(url_pwa_pair.first);
return true; std::move(callback).Run(true);
return;
} }
} }
return false; std::move(callback).Run(false);
} }
private: private:
FakeCookieManager* fake_cookie_manager_; FakeCookieManager* fake_cookie_manager_;
base::flat_map<GURL, scoped_refptr<const extensions::Extension>> base::flat_map<GURL, web_app::AppId> url_to_pwa_map_;
url_to_pwa_map_;
}; };
AndroidSmsAppSetupControllerImplTest() AndroidSmsAppSetupControllerImplTest()
...@@ -358,7 +352,7 @@ class AndroidSmsAppSetupControllerImplTest : public testing::Test { ...@@ -358,7 +352,7 @@ class AndroidSmsAppSetupControllerImplTest : public testing::Test {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
bool was_installed = bool was_installed =
test_pwa_delegate_->GetPwaForUrl(install_url, &profile_) != nullptr; test_pwa_delegate_->GetPwaForUrl(install_url, &profile_).has_value();
setup_controller_->RemoveApp( setup_controller_->RemoveApp(
app_url, install_url, migrated_to_app_url, app_url, install_url, migrated_to_app_url,
base::BindOnce(&AndroidSmsAppSetupControllerImplTest::OnRemoveAppResult, base::BindOnce(&AndroidSmsAppSetupControllerImplTest::OnRemoveAppResult,
......
...@@ -7,9 +7,6 @@ ...@@ -7,9 +7,6 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/extension_paths.h"
namespace chromeos { namespace chromeos {
...@@ -37,27 +34,19 @@ FakeAndroidSmsAppSetupController::GetAppMetadataAtUrl( ...@@ -37,27 +34,19 @@ FakeAndroidSmsAppSetupController::GetAppMetadataAtUrl(
void FakeAndroidSmsAppSetupController::SetAppAtUrl( void FakeAndroidSmsAppSetupController::SetAppAtUrl(
const GURL& install_url, const GURL& install_url,
const base::Optional<extensions::ExtensionId>& id_for_app) { const base::Optional<web_app::AppId>& id_for_app) {
if (!id_for_app) { if (!id_for_app) {
install_url_to_metadata_map_.erase(install_url); install_url_to_metadata_map_.erase(install_url);
return; return;
} }
// Create a test Extension and add it to |install_url_to_metadata_map_|. install_url_to_metadata_map_[install_url].pwa = *id_for_app;
base::FilePath path;
base::PathService::Get(extensions::DIR_TEST_DATA, &path);
install_url_to_metadata_map_[install_url].pwa =
extensions::ExtensionBuilder(
install_url.spec(), extensions::ExtensionBuilder::Type::PLATFORM_APP)
.SetPath(path.AppendASCII(install_url.spec()))
.SetID(*id_for_app)
.Build();
} }
void FakeAndroidSmsAppSetupController::CompletePendingSetUpAppRequest( void FakeAndroidSmsAppSetupController::CompletePendingSetUpAppRequest(
const GURL& expected_app_url, const GURL& expected_app_url,
const GURL& expected_install_url, const GURL& expected_install_url,
const base::Optional<extensions::ExtensionId>& id_for_app) { const base::Optional<web_app::AppId>& id_for_app) {
DCHECK(!pending_set_up_app_requests_.empty()); DCHECK(!pending_set_up_app_requests_.empty());
auto request = std::move(pending_set_up_app_requests_.front()); auto request = std::move(pending_set_up_app_requests_.front());
...@@ -119,12 +108,12 @@ void FakeAndroidSmsAppSetupController::SetUpApp(const GURL& app_url, ...@@ -119,12 +108,12 @@ void FakeAndroidSmsAppSetupController::SetUpApp(const GURL& app_url,
app_url, install_url, std::move(callback))); app_url, install_url, std::move(callback)));
} }
const extensions::Extension* FakeAndroidSmsAppSetupController::GetPwa( base::Optional<web_app::AppId> FakeAndroidSmsAppSetupController::GetPwa(
const GURL& install_url) { const GURL& install_url) {
auto it = install_url_to_metadata_map_.find(install_url); auto it = install_url_to_metadata_map_.find(install_url);
if (it == install_url_to_metadata_map_.end()) if (it == install_url_to_metadata_map_.end())
return nullptr; return base::nullopt;
return it->second.pwa.get(); return it->second.pwa;
} }
void FakeAndroidSmsAppSetupController::DeleteRememberDeviceByDefaultCookie( void FakeAndroidSmsAppSetupController::DeleteRememberDeviceByDefaultCookie(
......
...@@ -14,13 +14,9 @@ ...@@ -14,13 +14,9 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/optional.h" #include "base/optional.h"
#include "chrome/browser/chromeos/android_sms/android_sms_app_setup_controller.h" #include "chrome/browser/chromeos/android_sms/android_sms_app_setup_controller.h"
#include "extensions/common/extension_id.h" #include "chrome/browser/web_applications/components/web_app_id.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace extensions {
class Extension;
} // namespace extensions
namespace chromeos { namespace chromeos {
namespace android_sms { namespace android_sms {
...@@ -36,7 +32,7 @@ class FakeAndroidSmsAppSetupController : public AndroidSmsAppSetupController { ...@@ -36,7 +32,7 @@ class FakeAndroidSmsAppSetupController : public AndroidSmsAppSetupController {
AppMetadata(const AppMetadata& other); AppMetadata(const AppMetadata& other);
~AppMetadata(); ~AppMetadata();
scoped_refptr<const extensions::Extension> pwa; web_app::AppId pwa;
bool is_cookie_present = true; bool is_cookie_present = true;
}; };
...@@ -47,15 +43,15 @@ class FakeAndroidSmsAppSetupController : public AndroidSmsAppSetupController { ...@@ -47,15 +43,15 @@ class FakeAndroidSmsAppSetupController : public AndroidSmsAppSetupController {
// ID at |install_url|. Otherwise, this function removes any existing app at // ID at |install_url|. Otherwise, this function removes any existing app at
// that URL. // that URL.
void SetAppAtUrl(const GURL& install_url, void SetAppAtUrl(const GURL& install_url,
const base::Optional<extensions::ExtensionId>& id_for_app); const base::Optional<web_app::AppId>& id_for_app);
// Completes a pending setup request (i.e., a previous call to SetUpApp()). // Completes a pending setup request (i.e., a previous call to SetUpApp()).
// If |id_for_app| is set, the request is successful and the installed app // If |id_for_app| is set, the request is successful and the installed app
// will have the provided ID; if |id_for_app| is null, the request fails. // will have the provided ID; if |id_for_app| is nullopt, the request fails.
void CompletePendingSetUpAppRequest( void CompletePendingSetUpAppRequest(
const GURL& expected_app_url, const GURL& expected_app_url,
const GURL& expected_install_url, const GURL& expected_install_url,
const base::Optional<extensions::ExtensionId>& id_for_app); const base::Optional<web_app::AppId>& id_for_app);
// Completes a pending cookie deletion request (i.e., a previous call to // Completes a pending cookie deletion request (i.e., a previous call to
// DeleteRememberDeviceByDefaultCookie()). // DeleteRememberDeviceByDefaultCookie()).
...@@ -75,7 +71,7 @@ class FakeAndroidSmsAppSetupController : public AndroidSmsAppSetupController { ...@@ -75,7 +71,7 @@ class FakeAndroidSmsAppSetupController : public AndroidSmsAppSetupController {
void SetUpApp(const GURL& app_url, void SetUpApp(const GURL& app_url,
const GURL& install_url, const GURL& install_url,
SuccessCallback callback) override; SuccessCallback callback) override;
const extensions::Extension* GetPwa(const GURL& install_url) override; base::Optional<web_app::AppId> GetPwa(const GURL& install_url) override;
void DeleteRememberDeviceByDefaultCookie(const GURL& app_url, void DeleteRememberDeviceByDefaultCookie(const GURL& app_url,
SuccessCallback callback) override; SuccessCallback callback) override;
void RemoveApp(const GURL& app_url, void RemoveApp(const GURL& app_url,
......
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