Remove lock screen apps [CL# 2]: Remove c/b/ash/lock_screen_apps
Bug: 376354347
Change-Id: I66b478c4bee532e97e6d20a4c72a57d3fe85941b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5985667
Reviewed-by: Finnur Thorarinsson <[email protected]>
Commit-Queue: Mitsuru Oshima <[email protected]>
Reviewed-by: Julian Pastarmov <[email protected]>
Reviewed-by: Toni Barzic <[email protected]>
Reviewed-by: Gabriel Charette <[email protected]>
Reviewed-by: Wenyu Zhang <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1379440}
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index c118aae..b3e8289 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -5068,7 +5068,6 @@
"//chrome/browser/ash/language_packs",
"//chrome/browser/ash/lobster",
"//chrome/browser/ash/locale",
- "//chrome/browser/ash/lock_screen_apps",
"//chrome/browser/ash/login",
"//chrome/browser/ash/login/app_mode",
"//chrome/browser/ash/login/auth",
@@ -5539,7 +5538,6 @@
"//chrome/browser/ash/keyed_service",
"//chrome/browser/ash/lobster",
"//chrome/browser/ash/locale",
- "//chrome/browser/ash/lock_screen_apps",
"//chrome/browser/ash/login",
"//chrome/browser/ash/login/app_mode",
"//chrome/browser/ash/login/auth",
diff --git a/chrome/browser/ash/BUILD.gn b/chrome/browser/ash/BUILD.gn
index 228bbaa..e9e4dcc 100644
--- a/chrome/browser/ash/BUILD.gn
+++ b/chrome/browser/ash/BUILD.gn
@@ -147,7 +147,6 @@
"//chrome/browser/ash/language_packs:unit_tests",
"//chrome/browser/ash/lobster:unit_tests",
"//chrome/browser/ash/locale:unit_tests",
- "//chrome/browser/ash/lock_screen_apps:unit_tests",
"//chrome/browser/ash/login:unit_tests",
"//chrome/browser/ash/magic_boost:unit_tests",
"//chrome/browser/ash/mahi:unit_tests",
@@ -293,7 +292,6 @@
"//chrome/browser/ash/kcer:browser_tests",
"//chrome/browser/ash/kerberos:browser_tests",
"//chrome/browser/ash/locale:browser_tests",
- "//chrome/browser/ash/lock_screen_apps:browser_tests",
"//chrome/browser/ash/logging:browser_tests",
"//chrome/browser/ash/login:browser_tests",
"//chrome/browser/ash/magic_boost:browser_tests",
diff --git a/chrome/browser/ash/keyed_service/BUILD.gn b/chrome/browser/ash/keyed_service/BUILD.gn
index 47210c3..d455cb0 100644
--- a/chrome/browser/ash/keyed_service/BUILD.gn
+++ b/chrome/browser/ash/keyed_service/BUILD.gn
@@ -56,7 +56,6 @@
"//chrome/browser/ash/kcer",
"//chrome/browser/ash/kcer/nssdb_migration",
"//chrome/browser/ash/kerberos",
- "//chrome/browser/ash/lock_screen_apps",
"//chrome/browser/ash/login",
"//chrome/browser/ash/login/extensions",
"//chrome/browser/ash/login/lock/online_reauth",
diff --git a/chrome/browser/ash/keyed_service/browser_context_keyed_service_factories.cc b/chrome/browser/ash/keyed_service/browser_context_keyed_service_factories.cc
index c24ebaadc..c97b735 100644
--- a/chrome/browser/ash/keyed_service/browser_context_keyed_service_factories.cc
+++ b/chrome/browser/ash/keyed_service/browser_context_keyed_service_factories.cc
@@ -66,7 +66,6 @@
#include "chrome/browser/ash/kcer/kcer_factory_ash.h"
#include "chrome/browser/ash/kcer/nssdb_migration/pkcs12_migrator.h"
#include "chrome/browser/ash/kerberos/kerberos_credentials_manager_factory.h"
-#include "chrome/browser/ash/lock_screen_apps/lock_screen_apps.h"
#include "chrome/browser/ash/login/extensions/login_screen_extensions_content_script_manager_factory.h"
#include "chrome/browser/ash/login/extensions/login_screen_extensions_lifetime_manager_factory.h"
#include "chrome/browser/ash/login/lock/online_reauth/lock_screen_reauth_manager_factory.h"
@@ -206,7 +205,6 @@
kcer::Pkcs12MigratorFactory::GetInstance();
KerberosCredentialsManagerFactory::GetInstance();
KioskAppUpdateServiceFactory::GetInstance();
- LockScreenAppsFactory::GetInstance();
LockScreenReauthManagerFactory::GetInstance();
LockedSessionWindowTrackerFactory::GetInstance();
login::SecurityTokenSessionControllerFactory::GetInstance();
diff --git a/chrome/browser/ash/lock_screen_apps/BUILD.gn b/chrome/browser/ash/lock_screen_apps/BUILD.gn
deleted file mode 100644
index 61b23e3..0000000
--- a/chrome/browser/ash/lock_screen_apps/BUILD.gn
+++ /dev/null
@@ -1,144 +0,0 @@
-# Copyright 2024 The Chromium Authors
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import("//build/config/chromeos/ui_mode.gni")
-
-assert(is_chromeos_ash)
-
-static_library("lock_screen_apps") {
- sources = [
- "app_manager.h",
- "app_manager_impl.cc",
- "app_manager_impl.h",
- "first_app_run_toast_manager.cc",
- "first_app_run_toast_manager.h",
- "focus_cycler_delegate.h",
- "lock_screen_apps.cc",
- "lock_screen_apps.h",
- "lock_screen_profile_creator.cc",
- "lock_screen_profile_creator.h",
- "lock_screen_profile_creator_impl.cc",
- "lock_screen_profile_creator_impl.h",
- "state_controller.cc",
- "state_controller.h",
- "state_observer.h",
- "toast_dialog_view.cc",
- "toast_dialog_view.h",
- ]
-
- public_deps = [ "//chrome/browser:browser_public_dependencies" ]
-
- deps = [
- "//apps",
- "//ash",
- "//ash/public/cpp",
- "//base",
- "//chrome/browser:browser_process",
- "//chrome/browser/apps/app_service",
- "//chrome/browser/ash/login/session",
- "//chrome/browser/ash/note_taking",
- "//chrome/browser/ash/profiles",
- "//chrome/browser/extensions",
- "//chrome/browser/profiles:profile",
- "//chrome/common",
- "//chromeos/dbus/power",
- "//chromeos/dbus/power:power_manager_proto",
- "//components/keyed_service/content",
- "//components/pref_registry",
- "//components/prefs",
- "//components/session_manager/core",
- "//components/user_manager",
- "//content/public/browser",
- "//content/public/common",
- "//extensions/browser",
- "//extensions/common",
- "//ui/aura",
- "//ui/events/devices",
- "//ui/gfx",
- "//ui/views",
- "//ui/wm",
- "//url",
- ]
-
- allow_circular_includes_from = [
- "//chrome/browser/ash/login/session",
- "//chrome/browser/ash/note_taking",
- ]
-}
-
-static_library("test_support") {
- testonly = true
-
- sources = [
- "fake_lock_screen_profile_creator.cc",
- "fake_lock_screen_profile_creator.h",
- ]
-
- deps = [
- ":lock_screen_apps",
- "//base",
- "//chrome/browser/extensions",
- "//chrome/test:test_support",
- "//chromeos/ash/components/browser_context_helper",
- ]
-}
-
-source_set("unit_tests") {
- testonly = true
-
- sources = []
-
- deps = [
- ":lock_screen_apps",
- ":test_support",
- "//ash/components/arc/session",
- "//base",
- "//base/test:test_support",
- "//chrome/browser/apps/app_service",
- "//chrome/browser/apps/app_service:test_support",
- "//chrome/browser/ash/arc/session",
- "//chrome/browser/ash/arc/test:arc_test_support",
- "//chrome/browser/ash/login/users:test_support",
- "//chrome/browser/ash/note_taking",
- "//chrome/browser/ash/settings:test_support",
- "//chrome/browser/ui/apps",
- "//chrome/common",
- "//chrome/test:test_support",
- "//chromeos/ash/components/dbus",
- "//chromeos/dbus/power:power_manager_proto",
- "//components/account_id",
- "//components/crx_file",
- "//components/prefs",
- "//components/user_manager",
- "//extensions/browser",
- "//extensions/common",
- "//testing/gtest",
- "//ui/events/devices:test_support",
- ]
-}
-
-source_set("browser_tests") {
- testonly = true
-
- defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
-
- sources = [ "note_taking_browsertest.cc" ]
-
- deps = [
- ":lock_screen_apps",
- "//apps",
- "//ash/constants",
- "//base",
- "//chrome/browser/ash/note_taking",
- "//chrome/browser/profiles:profile",
- "//chrome/common",
- "//chrome/test:test_support",
- "//components/prefs",
- "//components/session_manager/core",
- "//content/test:test_support",
- "//extensions:test_support",
- "//extensions/common",
- "//testing/gtest",
- ]
-}
diff --git a/chrome/browser/ash/lock_screen_apps/DEPS b/chrome/browser/ash/lock_screen_apps/DEPS
deleted file mode 100644
index 7ae7bd8..0000000
--- a/chrome/browser/ash/lock_screen_apps/DEPS
+++ /dev/null
@@ -1,40 +0,0 @@
-include_rules = [
- # ChromeOS should not depend on //chrome. See //docs/chromeos/code.md for
- # details.
- "-chrome",
-
- # This directory is in //chrome, which violates the rule above. Allow this
- # directory to #include its own files.
- "+chrome/browser/ash/lock_screen_apps",
-
- # Existing dependencies within //chrome. There is an active effort to
- # refactor //chrome/browser/ash to break these dependencies; see b/332804822.
- # Whenever possible, avoid adding new //chrome dependencies to this list.
- #
- # Files residing in certain directories (e.g., //chrome/browser) are listed
- # individually. Other dependencies within //chrome are listed on a per-
- # directory basis. See //tools/chromeos/gen_deps.sh for details.
- "+chrome/browser/apps/app_service",
- "+chrome/browser/ash/arc/session",
- "+chrome/browser/ash/arc/test",
- "+chrome/browser/ash/login/users",
- "+chrome/browser/ash/note_taking",
- "+chrome/browser/ash/profiles",
- "+chrome/browser/ash/settings",
- "+chrome/browser/ash/system_web_apps",
- "+chrome/browser/browser_process.h",
- "+chrome/browser/extensions/extension_assets_manager.h",
- "+chrome/browser/extensions/extension_browsertest.h",
- "+chrome/browser/extensions/extension_management.h",
- "+chrome/browser/extensions/extension_service.h",
- "+chrome/browser/extensions/test_extension_system.h",
- "+chrome/browser/profiles",
- "+chrome/browser/ui/apps",
- "+chrome/browser/ui/ash",
- "+chrome/browser/web_applications/web_app_provider.h",
- "+chrome/common/chrome_constants.h",
- "+chrome/common/chrome_paths.h",
- "+chrome/common/pref_names.h",
- "+chrome/grit",
- "+chrome/test/base",
-]
diff --git a/chrome/browser/ash/lock_screen_apps/OWNERS b/chrome/browser/ash/lock_screen_apps/OWNERS
deleted file mode 100644
index d063efc..0000000
--- a/chrome/browser/ash/lock_screen_apps/OWNERS
+++ /dev/null
@@ -1 +0,0 @@
[email protected]
diff --git a/chrome/browser/ash/lock_screen_apps/app_manager.h b/chrome/browser/ash/lock_screen_apps/app_manager.h
deleted file mode 100644
index 944b7488..0000000
--- a/chrome/browser/ash/lock_screen_apps/app_manager.h
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2017 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_APP_MANAGER_H_
-#define CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_APP_MANAGER_H_
-
-#include <string>
-
-#include "base/functional/callback_forward.h"
-
-class Profile;
-
-namespace lock_screen_apps {
-
-class LockScreenProfileCreator;
-
-// Interface for managing enabled apps in the lock screen profile. Apps must be
-// Chrome apps with a note taking action handler or web apps with a lock screen
-// URL declared, and may need to be on an allow-list or enterprise policy.
-class AppManager {
- public:
- virtual ~AppManager() {}
-
- // Initializes the manager.
- // |primary_profile| - the profile which is the source of the lock screen
- // action handler app (if one is set). This is the profile whose
- // settings are used to determine whether and for which app lock screen
- // action is enabled, and it should be associated with the primary user.
- // |lock_screen_profile_creator| - the object responsible for creating profile
- // in which lock screen apps should be launched. It will detect when an
- // app is enabled on lock screen and create the profile. The |AppManager|
- // implementation can observe this class to detect when the profile is
- // created and and update the availability of the lock screen app.
- virtual void Initialize(
- Profile* primary_profile,
- LockScreenProfileCreator* lock_screen_profile_creator) = 0;
-
- // Activates the manager - this should ensure that the lock screen app, if
- // available, is loaded and enabled in the lock screen profile.
- // |app_changed_callback| - used to notify the client when the lock screen app
- // availability changes. It's cleared when the AppManager is stopped. It
- // is not expected to be run after the app manager instance is destroyed.
- virtual void Start(const base::RepeatingClosure& app_changed_callback) = 0;
-
- // Stops the manager. After this is called, the app can be unloaded from the
- // lock screen enabled profile. Subsequent launch requests should not be
- // allowed.
- virtual void Stop() = 0;
-
- // If lock screen app is available, launches the app.
- // Returns whether the app launch was attempted.
- virtual bool LaunchLockScreenApp() = 0;
-
- // Returns whether a lock screen app is enabled and ready to launch.
- virtual bool IsLockScreenAppAvailable() const = 0;
-
- // Returns the ID of the current lock screen app, if one is enabled on lock
- // screen (for primary profile).
- virtual std::string GetLockScreenAppId() const = 0;
-};
-
-} // namespace lock_screen_apps
-
-#endif // CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_APP_MANAGER_H_
diff --git a/chrome/browser/ash/lock_screen_apps/app_manager_impl.cc b/chrome/browser/ash/lock_screen_apps/app_manager_impl.cc
deleted file mode 100644
index 578b31a..0000000
--- a/chrome/browser/ash/lock_screen_apps/app_manager_impl.cc
+++ /dev/null
@@ -1,595 +0,0 @@
-// Copyright 2017 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ash/lock_screen_apps/app_manager_impl.h"
-
-#include <atomic>
-#include <memory>
-#include <ostream>
-#include <string>
-#include <type_traits>
-#include <utility>
-
-#include "apps/launcher.h"
-#include "base/check.h"
-#include "base/check_op.h"
-#include "base/files/file_path.h"
-#include "base/files/file_util.h"
-#include "base/files/scoped_temp_dir.h"
-#include "base/functional/bind.h"
-#include "base/functional/callback.h"
-#include "base/location.h"
-#include "base/task/sequenced_task_runner.h"
-#include "base/task/single_thread_task_runner.h"
-#include "base/time/tick_clock.h"
-#include "base/time/time.h"
-#include "base/values.h"
-#include "chrome/browser/ash/lock_screen_apps/lock_screen_apps.h"
-#include "chrome/browser/ash/lock_screen_apps/lock_screen_profile_creator.h"
-#include "chrome/browser/ash/note_taking/note_taking_helper.h"
-#include "chrome/browser/ash/profiles/profile_helper.h"
-#include "chrome/browser/extensions/extension_assets_manager.h"
-#include "chrome/browser/extensions/extension_management.h"
-#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/common/pref_names.h"
-#include "components/prefs/pref_service.h"
-#include "components/sync/model/string_ordinal.h"
-#include "extensions/browser/extension_file_task_runner.h"
-#include "extensions/browser/extension_registry.h"
-#include "extensions/browser/extension_system.h"
-#include "extensions/browser/install_flag.h"
-#include "extensions/common/api/app_runtime.h"
-#include "extensions/common/extension.h"
-#include "extensions/common/extension_id.h"
-#include "extensions/common/extension_set.h"
-#include "extensions/common/extension_urls.h"
-#include "extensions/common/file_util.h"
-#include "extensions/common/manifest.h"
-#include "extensions/common/mojom/manifest.mojom-shared.h"
-#include "url/gurl.h"
-
-namespace lock_screen_apps {
-
-namespace {
-
-using ExtensionCallback = base::OnceCallback<void(
- const scoped_refptr<const extensions::Extension>& extension)>;
-
-// The max number of times the lock screen app can be relaoded if it gets
-// terminated while the lock screen is active.
-constexpr int kMaxLockScreenAppReloadsCount = 3;
-
-// The lock screen note taking availability state.
-enum class ActionAvailability {
- kAvailable = 0,
- kNoActionHandlerApp = 1,
- kAppNotSupportingLockScreen = 2,
- kActionNotEnabledOnLockScreen = 3,
- kDisallowedByPolicy = 4,
- kLockScreenProfileNotCreated = 5,
- kCount,
-};
-
-// The reason the note taking app was unloaded from the lock screen apps
-// profile.
-enum class AppUnloadStatus {
- kNotTerminated = 0,
- kTerminatedReloadable = 1,
- kTerminatedReloadAttemptsExceeded = 2,
- kCount = 3
-};
-
-ActionAvailability ToActionAvailability(
- ash::LockScreenAppSupport lock_screen_support) {
- switch (lock_screen_support) {
- case ash::LockScreenAppSupport::kNotSupported:
- return ActionAvailability::kAppNotSupportingLockScreen;
- case ash::LockScreenAppSupport::kSupported:
- return ActionAvailability::kActionNotEnabledOnLockScreen;
- case ash::LockScreenAppSupport::kNotAllowedByPolicy:
- return ActionAvailability::kDisallowedByPolicy;
- case ash::LockScreenAppSupport::kEnabled:
- return ActionAvailability::kAvailable;
- }
-
- return ActionAvailability::kAppNotSupportingLockScreen;
-}
-
-void InvokeCallbackOnTaskRunner(
- ExtensionCallback callback,
- const scoped_refptr<base::SequencedTaskRunner>& task_runner,
- const scoped_refptr<const extensions::Extension>& extension) {
- task_runner->PostTask(FROM_HERE,
- base::BindOnce(std::move(callback), extension));
-}
-
-// Loads extension with the provided |extension_id|, |location|, and
-// |creation_flags| from the |version_dir| directory - directory to which the
-// extension has been installed.
-// |temp_copy| - scoped dir that contains the path from which extension
-// resources have been installed. Not used in this method, but passed around
-// to keep the directory in scope while the app is being installed.
-// |callback| - callback to which the loaded app should be passed.
-void LoadInstalledExtension(const std::string& extension_id,
- extensions::mojom::ManifestLocation install_source,
- int creation_flags,
- std::unique_ptr<base::ScopedTempDir> temp_copy,
- ExtensionCallback callback,
- const base::FilePath& version_dir) {
- if (version_dir.empty()) {
- std::move(callback).Run(nullptr);
- return;
- }
-
- std::string error;
- scoped_refptr<const extensions::Extension> extension =
- extensions::file_util::LoadExtension(
- version_dir, extension_id, install_source, creation_flags, &error);
- std::move(callback).Run(extension);
-}
-
-// Installs |extension| as a copy of an extension unpacked at |original_path|
-// into |target_install_dir|.
-// |profile| is the profile to which the extension is being installed.
-// |callback| - called with the app loaded from the final installation path.
-void InstallExtensionCopy(
- const scoped_refptr<const extensions::Extension>& extension,
- const base::FilePath& original_path,
- const base::FilePath& target_install_dir,
- Profile* profile,
- bool updates_from_webstore_or_empty_update_url,
- ExtensionCallback callback) {
- base::FilePath target_dir = target_install_dir.Append(extension->id());
- base::FilePath install_temp_dir =
- extensions::file_util::GetInstallTempDir(target_dir);
- auto extension_temp_dir = std::make_unique<base::ScopedTempDir>();
- if (install_temp_dir.empty() ||
- !extension_temp_dir->CreateUniqueTempDirUnderPath(install_temp_dir)) {
- std::move(callback).Run(nullptr);
- return;
- }
-
- // Copy the original extension path to a temp path to prevent
- // ExtensionAssetsManager from deleting it (as InstallExtension renames the
- // source path to a new location under the target install directory).
- base::FilePath temp_copy =
- extension_temp_dir->GetPath().Append(original_path.BaseName());
- if (!base::CopyDirectory(original_path, temp_copy, true /* recursive */)) {
- std::move(callback).Run(nullptr);
- return;
- }
-
- // Note: |extension_temp_dir| is passed around to ensure it stays in scope
- // until the app installation is done.
- extensions::ExtensionAssetsManager::GetInstance()->InstallExtension(
- extension.get(), temp_copy, target_install_dir, profile,
- base::BindOnce(&LoadInstalledExtension, extension->id(),
- extension->location(), extension->creation_flags(),
- std::move(extension_temp_dir), std::move(callback)),
- updates_from_webstore_or_empty_update_url);
-}
-
-} // namespace
-
-AppManagerImpl::AppManagerImpl(const base::TickClock* tick_clock)
- : tick_clock_(tick_clock) {}
-
-AppManagerImpl::~AppManagerImpl() = default;
-
-void AppManagerImpl::Initialize(
- Profile* primary_profile,
- LockScreenProfileCreator* lock_screen_profile_creator) {
- DCHECK_EQ(State::kNotInitialized, state_);
- DCHECK(primary_profile);
-
- primary_profile_ = primary_profile;
- lock_screen_profile_creator_ = lock_screen_profile_creator;
-
- state_ = State::kInactive;
-
- note_taking_helper_observation_.Observe(ash::NoteTakingHelper::Get());
-
- lock_screen_profile_creator_->AddCreateProfileCallback(
- base::BindOnce(&AppManagerImpl::OnLockScreenProfileLoaded,
- weak_ptr_factory_.GetWeakPtr()));
-}
-
-void AppManagerImpl::OnLockScreenProfileLoaded() {
- if (!lock_screen_profile_creator_->lock_screen_profile())
- return;
-
- DCHECK_NE(primary_profile_,
- lock_screen_profile_creator_->lock_screen_profile());
-
- // Do not use OTR profile for lock screen Chrome apps. This is important for
- // profile usage in |LaunchLockScreenApp| - lock screen app background page
- // runs in original, non off the record profile, so the launch event has to be
- // dispatched to that profile. For other |lock_screen_profile_|, it makes no
- // difference - the profile is used to get browser context keyed services, all
- // of which redirect OTR profile to the original one.
- lock_screen_profile_ =
- lock_screen_profile_creator_->lock_screen_profile()->GetOriginalProfile();
-
- CHECK(!ash::ProfileHelper::Get()->GetUserByProfile(lock_screen_profile_))
- << "Lock screen profile should not be associated with any users.";
-
- UpdateLockScreenAppState();
-}
-
-void AppManagerImpl::Start(
- const base::RepeatingClosure& note_taking_changed_callback) {
- DCHECK_NE(State::kNotInitialized, state_);
-
- app_changed_callback_ = note_taking_changed_callback;
-
- if (state_ == State::kActive || state_ == State::kActivating)
- return;
-
- extensions_observation_.Observe(
- extensions::ExtensionRegistry::Get(primary_profile_));
-
- lock_screen_app_id_.clear();
- std::string app_id = FindLockScreenAppId();
- if (app_id.empty()) {
- state_ = State::kAppUnavailable;
- return;
- }
-
- state_ = AddAppToLockScreenProfile(app_id);
- if (state_ == State::kActive || state_ == State::kActivating)
- lock_screen_app_id_ = app_id;
-}
-
-void AppManagerImpl::Stop() {
- DCHECK_NE(State::kNotInitialized, state_);
-
- app_changed_callback_.Reset();
- extensions_observation_.Reset();
- available_lock_screen_app_reloads_ = 0;
-
- if (state_ == State::kInactive)
- return;
-
- RemoveChromeAppFromLockScreenProfile(lock_screen_app_id_);
- lock_screen_app_id_.clear();
- state_ = State::kInactive;
-}
-
-bool AppManagerImpl::IsLockScreenAppAvailable() const {
- return state_ == State::kActive && !lock_screen_app_id_.empty();
-}
-
-std::string AppManagerImpl::GetLockScreenAppId() const {
- if (!IsLockScreenAppAvailable())
- return std::string();
- return lock_screen_app_id_;
-}
-
-bool AppManagerImpl::LaunchLockScreenApp() {
- if (!IsLockScreenAppAvailable())
- return false;
-
- // TODO(crbug.com/40099955): Handle web apps here.
-
- const extensions::Extension* app = GetChromeAppForLockScreenAppLaunch();
- // If the app cannot be found at this point, it either got unexpectedly
- // disabled, or it failed to reload (in case it was previously terminated).
- // In either case, note taking should not be reported as available anymore.
- if (!app) {
- RemoveLockScreenAppDueToError();
- return false;
- }
-
- extensions::api::app_runtime::ActionData action_data;
- action_data.action_type = extensions::api::app_runtime::ActionType::kNewNote;
- action_data.is_lock_screen_action = true;
- action_data.restore_last_action_state =
- primary_profile_->GetPrefs()->GetBoolean(
- prefs::kRestoreLastLockScreenNote);
- apps::LaunchPlatformAppWithAction(lock_screen_profile_, app,
- std::move(action_data));
- return true;
-}
-
-void AppManagerImpl::OnExtensionLoaded(content::BrowserContext* browser_context,
- const extensions::Extension* extension) {
- if (browser_context == primary_profile_ &&
- extension->id() ==
- primary_profile_->GetPrefs()->GetString(prefs::kNoteTakingAppId)) {
- UpdateLockScreenAppState();
- }
-}
-
-void AppManagerImpl::OnExtensionUnloaded(
- content::BrowserContext* browser_context,
- const extensions::Extension* extension,
- extensions::UnloadedExtensionReason reason) {
- if (extension->id() != lock_screen_app_id_)
- return;
-
- if (browser_context == primary_profile_) {
- UpdateLockScreenAppState();
- } else if (browser_context == lock_screen_profile_) {
- HandleLockScreenChromeAppUnload(reason);
- }
-}
-
-void AppManagerImpl::OnExtensionUninstalled(
- content::BrowserContext* browser_context,
- const extensions::Extension* extension,
- extensions::UninstallReason reason) {
- // If the app is uninstalled from the lock screen apps profile, make sure
- // it's not reported as available anymore.
- if (browser_context == lock_screen_profile_ &&
- extension->id() == lock_screen_app_id_) {
- RemoveLockScreenAppDueToError();
- }
-}
-
-void AppManagerImpl::OnAvailableNoteTakingAppsUpdated() {}
-
-void AppManagerImpl::OnPreferredNoteTakingAppUpdated(Profile* profile) {
- if (profile != primary_profile_)
- return;
-
- UpdateLockScreenAppState();
-}
-
-void AppManagerImpl::UpdateLockScreenAppState() {
- if (state_ == State::kInactive)
- return;
-
- std::string app_id = FindLockScreenAppId();
- if (app_id == lock_screen_app_id_)
- return;
-
- RemoveChromeAppFromLockScreenProfile(lock_screen_app_id_);
- lock_screen_app_id_.clear();
-
- state_ = AddAppToLockScreenProfile(app_id);
- if (state_ == State::kActive || state_ == State::kActivating)
- lock_screen_app_id_ = app_id;
-
- if (!app_changed_callback_.is_null())
- app_changed_callback_.Run();
-}
-
-std::string AppManagerImpl::FindLockScreenAppId() const {
- ash::NoteTakingHelper* helper = ash::NoteTakingHelper::Get();
- std::string app_id = helper->GetPreferredAppId(primary_profile_);
- // Lock screen apps service should always exist on the primary profile.
- DCHECK(primary_profile_);
- DCHECK(ash::LockScreenAppsFactory::IsSupportedProfile(primary_profile_));
- ash::LockScreenAppSupport lock_screen_support =
- ash::LockScreenApps::GetSupport(primary_profile_, app_id);
-
- ActionAvailability availability =
- app_id.empty() ? ActionAvailability::kNoActionHandlerApp
- : ToActionAvailability(lock_screen_support);
-
- // |lock_screen_profile_| is created only if a note taking app is available
- // on the lock screen. If an app is not available, the profile is expected to
- // be nullptr.
- // If the app is available and the lock_screen_profile is not set, the profile
- // might still be loading, and |FindLockScreenAppId| will be called
- // again when the profile is loaded - until then, ignore the available app.
- if (!lock_screen_profile_ && availability == ActionAvailability::kAvailable)
- availability = ActionAvailability::kLockScreenProfileNotCreated;
-
- if (availability != ActionAvailability::kAvailable)
- return std::string();
-
- return app_id;
-}
-
-AppManagerImpl::State AppManagerImpl::AddAppToLockScreenProfile(
- const std::string& app_id) {
- // TODO(crbug.com/40099955): First check if app_id is an installed web app.
-
- extensions::ExtensionRegistry* primary_registry =
- extensions::ExtensionRegistry::Get(primary_profile_);
- const extensions::Extension* app =
- primary_registry->enabled_extensions().GetByID(app_id);
- if (!app)
- return State::kAppUnavailable;
-
- bool is_unpacked = extensions::Manifest::IsUnpackedLocation(app->location());
-
- // Unpacked apps in lock screen profile will be loaded from their original
- // file path, so their path will be the same as the primary profile app's.
- // For the rest, the app will be copied to a location in the lock screen
- // profile's extension install directory (using |InstallExtensionCopy|) - the
- // exact final path is not known at this point, and will be set as part of
- // |InstallExtensionCopy|.
- base::FilePath lock_profile_app_path =
- is_unpacked ? app->path() : base::FilePath();
-
- std::string error;
- scoped_refptr<extensions::Extension> lock_profile_app =
- extensions::Extension::Create(lock_profile_app_path, app->location(),
- app->manifest()->value()->Clone(),
- app->creation_flags(), app->id(), &error);
-
- // While extension creation can fail in general, in this case the lock screen
- // profile extension creation arguments come from an app already installed in
- // a user profile. If the extension parameters were invalid, the app would not
- // exist in a user profile, and thus |app| would be nullptr, which is not the
- // case at this point.
- DCHECK(lock_profile_app);
-
- install_count_++;
-
- if (is_unpacked) {
- InstallAndEnableLockScreenChromeAppInLockScreenProfile(
- lock_profile_app.get());
- return State::kActive;
- }
-
- extensions::ExtensionService* lock_screen_service =
- extensions::ExtensionSystem::Get(lock_screen_profile_)
- ->extension_service();
-
- const GURL update_url =
- extensions::ExtensionManagementFactory::GetForBrowserContext(
- lock_screen_profile_)
- ->GetEffectiveUpdateURL(*lock_profile_app);
- bool updates_from_webstore_or_empty_update_url =
- update_url.is_empty() || extension_urls::IsWebstoreUpdateUrl(update_url);
-
- extensions::GetExtensionFileTaskRunner()->PostTask(
- FROM_HERE,
- base::BindOnce(
- &InstallExtensionCopy, lock_profile_app, app->path(),
- lock_screen_service->install_directory(), lock_screen_profile_,
- updates_from_webstore_or_empty_update_url,
- base::BindOnce(
- &InvokeCallbackOnTaskRunner,
- base::BindOnce(
- &AppManagerImpl::CompleteLockScreenChromeAppInstall,
- weak_ptr_factory_.GetWeakPtr(), install_count_,
- tick_clock_->NowTicks()),
- base::SingleThreadTaskRunner::GetCurrentDefault())));
- return State::kActivating;
-}
-
-void AppManagerImpl::CompleteLockScreenChromeAppInstall(
- int install_id,
- base::TimeTicks install_start_time,
- const scoped_refptr<const extensions::Extension>& app) {
- // Bail out if the app manager is no longer waiting for this app's
- // installation - the copied resources will be cleaned up when the (ephemeral)
- // lock screen profile is destroyed.
- if (install_id != install_count_ || state_ != State::kActivating)
- return;
-
- if (app) {
- DCHECK_EQ(lock_screen_app_id_, app->id());
- InstallAndEnableLockScreenChromeAppInLockScreenProfile(app.get());
- state_ = State::kActive;
- } else {
- state_ = State::kAppUnavailable;
- }
-
- if (!app_changed_callback_.is_null())
- app_changed_callback_.Run();
-}
-
-void AppManagerImpl::InstallAndEnableLockScreenChromeAppInLockScreenProfile(
- const extensions::Extension* app) {
- extensions::ExtensionService* lock_screen_service =
- extensions::ExtensionSystem::Get(lock_screen_profile_)
- ->extension_service();
-
- lock_screen_service->OnExtensionInstalled(
- app, syncer::StringOrdinal(), extensions::kInstallFlagInstallImmediately);
- lock_screen_service->EnableExtension(app->id());
-
- available_lock_screen_app_reloads_ = kMaxLockScreenAppReloadsCount;
-
- lock_screen_profile_extensions_observation_.Observe(
- extensions::ExtensionRegistry::Get(lock_screen_profile_));
-}
-
-void AppManagerImpl::RemoveChromeAppFromLockScreenProfile(
- const std::string& app_id) {
- if (app_id.empty())
- return;
-
- lock_screen_profile_extensions_observation_.Reset();
-
- extensions::ExtensionRegistry* lock_screen_registry =
- extensions::ExtensionRegistry::Get(lock_screen_profile_);
- if (!lock_screen_registry->GetExtensionById(
- app_id, extensions::ExtensionRegistry::EVERYTHING)) {
- return;
- }
-
- std::u16string error;
- extensions::ExtensionSystem::Get(lock_screen_profile_)
- ->extension_service()
- ->UninstallExtension(
- app_id, extensions::UNINSTALL_REASON_INTERNAL_MANAGEMENT, &error);
-}
-
-const extensions::Extension*
-AppManagerImpl::GetChromeAppForLockScreenAppLaunch() {
- // TODO(crbug.com/40099955): First check if app_id is an installed web app.
-
- const extensions::ExtensionRegistry* extension_registry =
- extensions::ExtensionRegistry::Get(lock_screen_profile_);
-
- // Return the app, in case it's currently loaded.
- const extensions::Extension* app =
- extension_registry->enabled_extensions().GetByID(lock_screen_app_id_);
- if (app) {
- return app;
- }
-
- // If the app has been terminated (which can happen due to an app crash),
- // attempt a reload - otherwise, return nullptr to signal the app is
- // unavailable.
- app =
- extension_registry->terminated_extensions().GetByID(lock_screen_app_id_);
- if (!app) {
- return nullptr;
- }
-
- if (available_lock_screen_app_reloads_ <= 0) {
- return nullptr;
- }
-
- available_lock_screen_app_reloads_--;
-
- std::string error;
- scoped_refptr<extensions::Extension> lock_profile_app =
- extensions::Extension::Create(app->path(), app->location(),
- app->manifest()->value()->Clone(),
- app->creation_flags(), app->id(), &error);
-
- extensions::ExtensionService* extension_service =
- extensions::ExtensionSystem::Get(lock_screen_profile_)
- ->extension_service();
- extension_service->AddExtension(lock_profile_app.get());
- extension_service->EnableExtension(lock_profile_app->id());
-
- app = extension_registry->enabled_extensions().GetByID(lock_screen_app_id_);
-
- return app;
-}
-
-void AppManagerImpl::HandleLockScreenChromeAppUnload(
- extensions::UnloadedExtensionReason reason) {
- if (state_ != State::kActive && state_ != State::kActivating)
- return;
-
- AppUnloadStatus status = AppUnloadStatus::kNotTerminated;
- if (reason == extensions::UnloadedExtensionReason::TERMINATE) {
- status = available_lock_screen_app_reloads_ > 0
- ? AppUnloadStatus::kTerminatedReloadable
- : AppUnloadStatus::kTerminatedReloadAttemptsExceeded;
- }
-
- // If the app is terminated, it will be reloaded on the next app launch
- // request - if the app cannot be reloaded (e.g. if it was unloaded for a
- // different reason, or it was reloaded too many times already), change the
- // app managet to an error state. This will inform the app manager's user
- // that lock screen note action is not available anymore.
- if (status != AppUnloadStatus::kTerminatedReloadable)
- RemoveLockScreenAppDueToError();
-}
-
-void AppManagerImpl::RemoveLockScreenAppDueToError() {
- if (state_ != State::kActive && state_ != State::kActivating)
- return;
-
- RemoveChromeAppFromLockScreenProfile(lock_screen_app_id_);
- lock_screen_app_id_.clear();
- state_ = State::kInactive;
-
- if (!app_changed_callback_.is_null())
- app_changed_callback_.Run();
-}
-
-} // namespace lock_screen_apps
diff --git a/chrome/browser/ash/lock_screen_apps/app_manager_impl.h b/chrome/browser/ash/lock_screen_apps/app_manager_impl.h
deleted file mode 100644
index 63a453bf..0000000
--- a/chrome/browser/ash/lock_screen_apps/app_manager_impl.h
+++ /dev/null
@@ -1,187 +0,0 @@
-// Copyright 2017 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_APP_MANAGER_IMPL_H_
-#define CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_APP_MANAGER_IMPL_H_
-
-#include <string>
-
-#include "base/functional/callback_forward.h"
-#include "base/memory/raw_ptr.h"
-#include "base/memory/scoped_refptr.h"
-#include "base/memory/weak_ptr.h"
-#include "base/scoped_observation.h"
-#include "chrome/browser/ash/lock_screen_apps/app_manager.h"
-#include "chrome/browser/ash/note_taking/note_taking_helper.h"
-#include "extensions/browser/extension_registry.h"
-#include "extensions/browser/extension_registry_observer.h"
-#include "extensions/browser/uninstall_reason.h"
-#include "extensions/browser/unloaded_extension_reason.h"
-
-class Profile;
-
-namespace base {
-class TickClock;
-class TimeTicks;
-} // namespace base
-
-namespace content {
-class BrowserContext;
-}
-
-namespace extensions {
-class Extension;
-} // namespace extensions
-
-namespace lock_screen_apps {
-
-class LockScreenProfileCreator;
-
-// The default implementation of lock_screen_apps::AppManager.
-class AppManagerImpl : public AppManager,
- public ash::NoteTakingHelper::Observer,
- public extensions::ExtensionRegistryObserver {
- public:
- explicit AppManagerImpl(const base::TickClock* tick_clock);
-
- AppManagerImpl(const AppManagerImpl&) = delete;
- AppManagerImpl& operator=(const AppManagerImpl&) = delete;
-
- ~AppManagerImpl() override;
-
- // AppManager implementation:
- void Initialize(Profile* primary_profile,
- LockScreenProfileCreator* profile_creator) override;
- void Start(const base::RepeatingClosure& app_changed_callback) override;
- void Stop() override;
- bool LaunchLockScreenApp() override;
- bool IsLockScreenAppAvailable() const override;
- std::string GetLockScreenAppId() const override;
-
- // extensions::ExtensionRegistryObserver:
- void OnExtensionLoaded(content::BrowserContext* browser_context,
- const extensions::Extension* extension) override;
- void OnExtensionUnloaded(content::BrowserContext* browser_context,
- const extensions::Extension* extension,
- extensions::UnloadedExtensionReason reason) override;
- void OnExtensionUninstalled(content::BrowserContext* browser_context,
- const extensions::Extension* extension,
- extensions::UninstallReason reason) override;
-
- // ash::NoteTakingHelper::Observer:
- void OnAvailableNoteTakingAppsUpdated() override;
- void OnPreferredNoteTakingAppUpdated(Profile* profile) override;
-
- private:
- enum class State {
- // The manager has not yet been initialized.
- kNotInitialized,
- // The manager is initialized, but not started. The note taking app is
- // considered unset at this point, and cannot be launched.
- kInactive,
- // The manager is started. Lock screen note taking app, if set, is loaded
- // and ready to be launched.
- kActive,
- // The manager is started, but app is still being installed into the lock
- // screen apps profile.
- kActivating,
- // The manager is started, and there is no available lock screen enabled
- // app.
- kAppUnavailable,
- };
-
- // Called when lock screen apps profile is ready to be used. Calling this will
- // cause app availability re-calculation.
- void OnLockScreenProfileLoaded();
-
- // Called on UI thread when the lock screen profile is initialized with
- // lock screen extension assets. It completes the Chrome App installation to
- // the lock screen profile.
- // |app| - the installing Chrome App. Can be nullptr in case the app assets
- // installation failed.
- void CompleteLockScreenChromeAppInstall(
- int install_id,
- base::TimeTicks install_start_time,
- const scoped_refptr<const extensions::Extension>& app);
-
- // Installs |app| to the lock screen profile's extension service and enables
- // the Chrome App.
- void InstallAndEnableLockScreenChromeAppInLockScreenProfile(
- const extensions::Extension* app);
-
- // Updates internal state about the current lock screen app, replacing the app
- // installed on the lock screen if needed. Notifies
- // |note_taking_changed_callback| if there was a change.
- // Should be called when note taking or lock screen related prefs change.
- void UpdateLockScreenAppState();
-
- // Gets the currently enabled lock screen app, if one is selected.
- // If no such app exists, returns an empty string.
- std::string FindLockScreenAppId() const;
-
- // Starts installing the app to the lock screen profile if needed. Works for
- // both Chrome apps and web apps.
- // Returns the state to which the app manager should move as a result of this
- // method.
- State AddAppToLockScreenProfile(const std::string& app_id);
-
- // Uninstalls lock screen note taking app from the lock screen profile.
- void RemoveChromeAppFromLockScreenProfile(const std::string& app_id);
-
- // Returns the Chrome App to which lock screen app launch event should be
- // sent. If the app is disabled because it got terminated (e.g. due to an app
- // crash), this will attempt to reload the app.
- // Returns null if the extension is not enabled, and cannot be enabled, or if
- // a web app is the current lock screen app.
- const extensions::Extension* GetChromeAppForLockScreenAppLaunch();
-
- // Updates internal state, and reports relevant metrics when the lock screen
- // app gets unloaded from the lock screen profile.
- void HandleLockScreenChromeAppUnload(
- extensions::UnloadedExtensionReason reason);
-
- // Removes the lock screen app from the lock screen apps profile if the app
- // manager encountered an error - e.g. if the app unexpectedly got disabled in
- // the lock screen apps profile.
- void RemoveLockScreenAppDueToError();
-
- raw_ptr<Profile> primary_profile_ = nullptr;
- raw_ptr<Profile> lock_screen_profile_ = nullptr;
- raw_ptr<LockScreenProfileCreator> lock_screen_profile_creator_ = nullptr;
-
- State state_ = State::kNotInitialized;
- // ID may refer to a Chrome app or a web app.
- std::string lock_screen_app_id_;
-
- raw_ptr<const base::TickClock> tick_clock_;
-
- base::ScopedObservation<extensions::ExtensionRegistry,
- extensions::ExtensionRegistryObserver>
- extensions_observation_{this};
- base::ScopedObservation<extensions::ExtensionRegistry,
- extensions::ExtensionRegistryObserver>
- lock_screen_profile_extensions_observation_{this};
-
- base::ScopedObservation<ash::NoteTakingHelper,
- ash::NoteTakingHelper::Observer>
- note_taking_helper_observation_{this};
-
- // To be called when the lock screen app availability changes.
- base::RepeatingClosure app_changed_callback_;
-
- // Counts Chrome app installs. Passed to app install callback as install
- // request identifier to determine whether the completed install is stale.
- int install_count_ = 0;
-
- // The number of times the lock screen Chrome app can be reloaded in the
- // lock screen apps profile in case it get terminated.
- // This counter is reset when the AppManager is restarted.
- int available_lock_screen_app_reloads_ = 0;
-
- base::WeakPtrFactory<AppManagerImpl> weak_ptr_factory_{this};
-};
-
-} // namespace lock_screen_apps
-
-#endif // CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_APP_MANAGER_IMPL_H_
diff --git a/chrome/browser/ash/lock_screen_apps/fake_lock_screen_profile_creator.cc b/chrome/browser/ash/lock_screen_apps/fake_lock_screen_profile_creator.cc
deleted file mode 100644
index a953fc5..0000000
--- a/chrome/browser/ash/lock_screen_apps/fake_lock_screen_profile_creator.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2017 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ash/lock_screen_apps/fake_lock_screen_profile_creator.h"
-
-#include "base/command_line.h"
-#include "base/files/file_path.h"
-#include "base/functional/bind.h"
-#include "base/location.h"
-#include "chrome/browser/extensions/test_extension_system.h"
-#include "chrome/test/base/testing_profile_manager.h"
-#include "chromeos/ash/components/browser_context_helper/browser_context_types.h"
-
-namespace lock_screen_apps {
-
-FakeLockScreenProfileCreator::FakeLockScreenProfileCreator(
- TestingProfileManager* profile_manager)
- : profile_manager_(profile_manager) {}
-
-FakeLockScreenProfileCreator::~FakeLockScreenProfileCreator() {}
-
-void FakeLockScreenProfileCreator::CreateProfile() {
- OnLockScreenProfileCreateStarted();
-
- Profile* profile = profile_manager_->CreateTestingProfile(
- ash::kLockScreenAppBrowserContextBaseName);
-
- extensions::TestExtensionSystem* extension_system =
- static_cast<extensions::TestExtensionSystem*>(
- extensions::ExtensionSystem::Get(profile));
- extension_system->CreateExtensionService(
- base::CommandLine::ForCurrentProcess(),
- profile->GetPath().Append("Extensions") /* install_directory */,
- false /* autoupdate_enabled */);
-
- OnLockScreenProfileCreated(profile);
-}
-
-void FakeLockScreenProfileCreator::SetProfileCreationFailed() {
- OnLockScreenProfileCreateStarted();
- OnLockScreenProfileCreated(nullptr);
-}
-
-void FakeLockScreenProfileCreator::InitializeImpl() {}
-
-} // namespace lock_screen_apps
diff --git a/chrome/browser/ash/lock_screen_apps/fake_lock_screen_profile_creator.h b/chrome/browser/ash/lock_screen_apps/fake_lock_screen_profile_creator.h
deleted file mode 100644
index a2c7dd28..0000000
--- a/chrome/browser/ash/lock_screen_apps/fake_lock_screen_profile_creator.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2017 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_FAKE_LOCK_SCREEN_PROFILE_CREATOR_H_
-#define CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_FAKE_LOCK_SCREEN_PROFILE_CREATOR_H_
-
-#include "base/memory/raw_ptr.h"
-#include "chrome/browser/ash/lock_screen_apps/lock_screen_profile_creator.h"
-
-class TestingProfileManager;
-
-namespace lock_screen_apps {
-
-// Fake implementation of LockScreenProfileCreator that can be used in tests.
-class FakeLockScreenProfileCreator : public LockScreenProfileCreator {
- public:
- // |profile_manager| - Testing profile manager that can be used to create
- // testing profiles.
- explicit FakeLockScreenProfileCreator(TestingProfileManager* profile_manager);
-
- FakeLockScreenProfileCreator(const FakeLockScreenProfileCreator&) = delete;
- FakeLockScreenProfileCreator& operator=(const FakeLockScreenProfileCreator&) =
- delete;
-
- ~FakeLockScreenProfileCreator() override;
-
- // Simulate lock screen profile creation - this will create a TestingProfile
- // for lock screen apps, and initialize the profile's extension system.
- void CreateProfile();
-
- // Simulate lock screen profile creation failure - this will finish the
- // profile creation (notifying observers of the profile change), but the lock
- // screen profile provided by the class will remain null.
- void SetProfileCreationFailed();
-
- protected:
- void InitializeImpl() override;
-
- private:
- const raw_ptr<TestingProfileManager> profile_manager_;
-};
-
-} // namespace lock_screen_apps
-
-#endif // CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_FAKE_LOCK_SCREEN_PROFILE_CREATOR_H_
diff --git a/chrome/browser/ash/lock_screen_apps/first_app_run_toast_manager.cc b/chrome/browser/ash/lock_screen_apps/first_app_run_toast_manager.cc
deleted file mode 100644
index d238fb21..0000000
--- a/chrome/browser/ash/lock_screen_apps/first_app_run_toast_manager.cc
+++ /dev/null
@@ -1,178 +0,0 @@
-// Copyright 2017 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ash/lock_screen_apps/first_app_run_toast_manager.h"
-
-#include "base/functional/bind.h"
-#include "base/memory/raw_ptr.h"
-#include "base/strings/utf_string_conversions.h"
-#include "base/task/single_thread_task_runner.h"
-#include "base/values.h"
-#include "chrome/browser/ash/lock_screen_apps/toast_dialog_view.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/common/pref_names.h"
-#include "components/prefs/pref_service.h"
-#include "components/prefs/scoped_user_pref_update.h"
-#include "extensions/browser/app_window/app_window.h"
-#include "extensions/common/extension.h"
-#include "ui/aura/window.h"
-#include "ui/gfx/geometry/point.h"
-#include "ui/gfx/geometry/rect.h"
-#include "ui/gfx/geometry/size.h"
-
-namespace lock_screen_apps {
-
-namespace {
-
-// Toast dialog's vertical offset from the app window bottom.
-constexpr int kToastDialogVerticalOffset = 20;
-
-} // namespace
-
-// Observes the note taking app widget so bounds changes can update the toast
-// position.
-class FirstAppRunToastManager::AppWidgetObserver
- : public views::WidgetObserver {
- public:
- AppWidgetObserver(FirstAppRunToastManager* manager, views::Widget* widget)
- : manager_(manager), widget_(widget) {
- widget_->AddObserver(this);
- }
-
- AppWidgetObserver(const AppWidgetObserver&) = delete;
- AppWidgetObserver& operator=(const AppWidgetObserver&) = delete;
-
- ~AppWidgetObserver() override {
- // This is a no-op of the observer was previously removed.
- widget_->RemoveObserver(this);
- CHECK(!IsInObserverList());
- }
-
- // views::WidgetObserver:
- void OnWidgetBoundsChanged(views::Widget* widget,
- const gfx::Rect& new_bounds) override {
- manager_->AdjustToastWidgetBounds();
- }
-
- void OnWidgetDestroying(views::Widget* widget) override {
- widget_->RemoveObserver(this);
- }
-
- private:
- raw_ptr<FirstAppRunToastManager> manager_;
- raw_ptr<views::Widget> widget_;
-};
-
-FirstAppRunToastManager::FirstAppRunToastManager(Profile* profile)
- : profile_(profile) {}
-
-FirstAppRunToastManager::~FirstAppRunToastManager() {
- Reset();
-}
-
-void FirstAppRunToastManager::RunForAppWindow(
- extensions::AppWindow* app_window) {
- if (app_window_)
- return;
-
- DCHECK(app_window->GetNativeWindow());
-
- const extensions::Extension* app = app_window->GetExtension();
- const base::Value::Dict& toast_shown =
- profile_->GetPrefs()->GetDict(prefs::kNoteTakingAppsLockScreenToastShown);
- if (toast_shown.FindBoolByDottedPath(app->id()).value_or(false)) {
- return;
- }
-
- app_window_ = app_window;
- views::Widget* app_widget =
- views::Widget::GetWidgetForNativeWindow(app_window_->GetNativeWindow());
- DCHECK(app_widget);
- app_widget_observer_ = std::make_unique<AppWidgetObserver>(this, app_widget);
-
- if (app_window_->GetNativeWindow()->HasFocus()) {
- CreateAndShowToastDialog();
- } else {
- app_window_observation_.Observe(
- extensions::AppWindowRegistry::Get(app_window_->browser_context()));
- }
-}
-
-void FirstAppRunToastManager::Reset() {
- app_widget_observer_.reset();
- app_window_observation_.Reset();
- toast_widget_observation_.Reset();
-
- app_window_ = nullptr;
-
- weak_ptr_factory_.InvalidateWeakPtrs();
-
- if (toast_widget_ && !toast_widget_->IsClosed())
- toast_widget_->Close();
- toast_widget_ = nullptr;
-}
-
-void FirstAppRunToastManager::OnWidgetDestroyed(views::Widget* widget) {
- Reset();
-}
-
-void FirstAppRunToastManager::OnAppWindowActivated(
- extensions::AppWindow* app_window) {
- if (app_window == app_window_) {
- app_window_observation_.Reset();
-
- // Start toast dialog creation asynchronously so it happens after app window
- // activation completes.
- base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
- FROM_HERE,
- base::BindOnce(&FirstAppRunToastManager::CreateAndShowToastDialog,
- weak_ptr_factory_.GetWeakPtr()));
- }
-}
-
-void FirstAppRunToastManager::CreateAndShowToastDialog() {
- auto* toast_dialog = new ToastDialogView(
- base::UTF8ToUTF16(app_window_->GetExtension()->short_name()),
- base::BindOnce(&FirstAppRunToastManager::ToastDialogDismissed,
- weak_ptr_factory_.GetWeakPtr()));
- toast_widget_ = views::BubbleDialogDelegateView::CreateBubble(toast_dialog);
- toast_widget_->Show();
- AdjustToastWidgetBounds();
- toast_widget_observation_.Observe(toast_widget_.get());
-}
-
-void FirstAppRunToastManager::ToastDialogDismissed() {
- {
- const extensions::Extension* app = app_window_->GetExtension();
- ScopedDictPrefUpdate dict_update(
- profile_->GetPrefs(), prefs::kNoteTakingAppsLockScreenToastShown);
- dict_update->Set(app->id(), true);
- }
- Reset();
-}
-
-void FirstAppRunToastManager::AdjustToastWidgetBounds() {
- if (!toast_widget_)
- return;
-
- DCHECK(app_window_);
-
- const gfx::Rect app_window_bounds =
- app_window_->GetNativeWindow()->GetBoundsInScreen();
- const gfx::Rect original_bounds = toast_widget_->GetWindowBoundsInScreen();
-
- gfx::Point intended_origin = gfx::Point(
- // Center toast widget horizontally relative to app_window bounds.
- app_window_bounds.x() +
- (app_window_bounds.width() - original_bounds.width()) / 2,
- // Position toast widget dialog at the bottom of app window, with an
- // additional offset (so poirtion of the dialog is painted outside the
- // app window bounds).
- app_window_bounds.bottom() - original_bounds.height() +
- kToastDialogVerticalOffset);
-
- toast_widget_->SetBounds(gfx::Rect(intended_origin, original_bounds.size()));
-}
-
-} // namespace lock_screen_apps
diff --git a/chrome/browser/ash/lock_screen_apps/first_app_run_toast_manager.h b/chrome/browser/ash/lock_screen_apps/first_app_run_toast_manager.h
deleted file mode 100644
index a71a53bf..0000000
--- a/chrome/browser/ash/lock_screen_apps/first_app_run_toast_manager.h
+++ /dev/null
@@ -1,94 +0,0 @@
-// Copyright 2017 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_FIRST_APP_RUN_TOAST_MANAGER_H_
-#define CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_FIRST_APP_RUN_TOAST_MANAGER_H_
-
-#include "base/memory/raw_ptr.h"
-#include "base/memory/weak_ptr.h"
-#include "base/scoped_observation.h"
-#include "extensions/browser/app_window/app_window_registry.h"
-#include "ui/views/widget/widget.h"
-#include "ui/views/widget/widget_observer.h"
-
-class Profile;
-
-namespace extensions {
-class AppWindow;
-}
-
-namespace lock_screen_apps {
-
-// Manager that can be used on a lock screen note app to show a first run
-// dialog informing the user about the app that's been launched from the lock
-// screen.
-class FirstAppRunToastManager : public extensions::AppWindowRegistry::Observer,
- public views::WidgetObserver {
- public:
- explicit FirstAppRunToastManager(Profile* profile);
-
- FirstAppRunToastManager(const FirstAppRunToastManager&) = delete;
- FirstAppRunToastManager& operator=(const FirstAppRunToastManager&) = delete;
-
- ~FirstAppRunToastManager() override;
-
- // Runs the manager for an app window launch. It determines whether the first
- // lock screen run dialog for the app associated with the app window has been
- // previously shown to the user (this information is kept in the user prefs).
- // If the dialog has not yet been shown (and confirmed by the user), the
- // manager will show the dialog once the app window becomes visible.
- void RunForAppWindow(extensions::AppWindow* app_window);
-
- // Resets current manager state - if a first run dialog is being shown, this
- // method will close the dialog.
- void Reset();
-
- // views::WidgetObserver:
- void OnWidgetDestroyed(views::Widget* widget) override;
-
- // extensions::AppWindowRegistry::Observer:
- void OnAppWindowActivated(extensions::AppWindow* app_window) override;
-
- views::Widget* widget() { return toast_widget_; }
-
- private:
- // Creates and shows the first lock screen app dialog for the app associated
- // with |app_window_|.
- void CreateAndShowToastDialog();
-
- // Called when the user closes the first app run dialog, and thus unblocks
- // lock screen app UI.
- // The manager will mark the first run dialog as handled for the app.
- void ToastDialogDismissed();
-
- // Adjust toast dialog's bounds relative to the bounds of the app window for
- // which the toast dialog is shown - the dialog position is
- // * horizontally - centered
- // * vertically - at the bottom, with additional vertical offset (so a
- // portion of the dialog is rendered outside the app window bounds).
- void AdjustToastWidgetBounds();
-
- const raw_ptr<Profile> profile_;
-
- // If set, the app window for which the manager is being run.
- raw_ptr<extensions::AppWindow> app_window_ = nullptr;
-
- // The widget associated with the first run dialog, if the dialog is shown.
- raw_ptr<views::Widget> toast_widget_ = nullptr;
-
- base::ScopedObservation<views::Widget, views::WidgetObserver>
- toast_widget_observation_{this};
- base::ScopedObservation<extensions::AppWindowRegistry,
- extensions::AppWindowRegistry::Observer>
- app_window_observation_{this};
-
- class AppWidgetObserver;
- std::unique_ptr<AppWidgetObserver> app_widget_observer_;
-
- base::WeakPtrFactory<FirstAppRunToastManager> weak_ptr_factory_{this};
-};
-
-} // namespace lock_screen_apps
-
-#endif // CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_FIRST_APP_RUN_TOAST_MANAGER_H_
diff --git a/chrome/browser/ash/lock_screen_apps/focus_cycler_delegate.h b/chrome/browser/ash/lock_screen_apps/focus_cycler_delegate.h
deleted file mode 100644
index 24577c2..0000000
--- a/chrome/browser/ash/lock_screen_apps/focus_cycler_delegate.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2017 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_FOCUS_CYCLER_DELEGATE_H_
-#define CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_FOCUS_CYCLER_DELEGATE_H_
-
-#include "base/functional/callback_forward.h"
-
-namespace lock_screen_apps {
-
-// Used by the StateController to inject a lock screen app window in the tab
-// order cycle with the lock screen UI and system tray, i.e. to move the focus
-// away from the app window when the app window is tabbed through, and to
-// register a handler for receiving focus from the lock screen UI.
-class FocusCyclerDelegate {
- public:
- virtual ~FocusCyclerDelegate() = default;
-
- // Registers a callback that should be called when the focus should be moved
- // to the app window.
- using LockScreenAppFocusCallback =
- base::RepeatingCallback<void(bool reverse)>;
- virtual void RegisterLockScreenAppFocusHandler(
- const LockScreenAppFocusCallback& focus_handler) = 0;
-
- // Unregister the callback that should be called to move the focus to the
- // app window, if one was registered.
- virtual void UnregisterLockScreenAppFocusHandler() = 0;
-
- // Called when the focus leaves the lock screen app window. The delegate
- // should move the focus to the next appropriate UI element.
- virtual void HandleLockScreenAppFocusOut(bool reverse) = 0;
-};
-
-} // namespace lock_screen_apps
-
-#endif // CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_FOCUS_CYCLER_DELEGATE_H_
diff --git a/chrome/browser/ash/lock_screen_apps/lock_screen_apps.cc b/chrome/browser/ash/lock_screen_apps/lock_screen_apps.cc
deleted file mode 100644
index 34e4c9e..0000000
--- a/chrome/browser/ash/lock_screen_apps/lock_screen_apps.cc
+++ /dev/null
@@ -1,328 +0,0 @@
-// Copyright 2022 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ash/lock_screen_apps/lock_screen_apps.h"
-
-#include <memory>
-#include <ostream>
-
-#include "base/check.h"
-#include "base/check_op.h"
-#include "base/containers/contains.h"
-#include "base/feature_list.h"
-#include "base/functional/bind.h"
-#include "base/logging.h"
-#include "base/no_destructor.h"
-#include "base/values.h"
-#include "chrome/browser/apps/app_service/app_service_proxy.h"
-#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
-#include "chrome/browser/apps/app_service/app_service_proxy_forward.h"
-#include "chrome/browser/ash/note_taking/note_taking_helper.h"
-#include "chrome/browser/ash/profiles/profile_helper.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/common/pref_names.h"
-#include "components/keyed_service/content/browser_context_dependency_manager.h"
-#include "components/pref_registry/pref_registry_syncable.h"
-#include "components/prefs/pref_service.h"
-#include "components/services/app_service/public/cpp/app_registry_cache.h"
-#include "components/services/app_service/public/cpp/app_types.h"
-#include "components/services/app_service/public/cpp/app_update.h"
-#include "components/services/app_service/public/cpp/intent_util.h"
-#include "components/services/app_service/public/cpp/types_util.h"
-#include "content/public/browser/browser_context.h"
-#include "content/public/common/content_features.h"
-#include "extensions/browser/extension_registry.h"
-#include "extensions/common/api/app_runtime.h"
-#include "extensions/common/extension.h"
-#include "extensions/common/manifest_handlers/action_handlers_handler.h"
-#include "extensions/common/mojom/api_permission_id.mojom-shared.h"
-#include "extensions/common/permissions/permissions_data.h"
-
-namespace ash {
-
-namespace {
-
-namespace app_runtime = ::extensions::api::app_runtime;
-
-bool HasLockScreenIntentFilter(
- const std::vector<apps::IntentFilterPtr>& filters) {
- const auto lock_screen_intent = apps_util::CreateStartOnLockScreenIntent();
- for (const apps::IntentFilterPtr& filter : filters) {
- if (lock_screen_intent->MatchFilter(filter))
- return true;
- }
- return false;
-}
-
-bool IsInstalledWebApp(const std::string& app_id, Profile* profile) {
- if (!apps::AppServiceProxyFactory::IsAppServiceAvailableForProfile(profile))
- return false;
- auto* cache =
- &apps::AppServiceProxyFactory::GetForProfile(profile)->AppRegistryCache();
-
- bool result = false;
- cache->ForOneApp(app_id, [&result](const apps::AppUpdate& update) {
- if (apps_util::IsInstalled(update.Readiness()) &&
- update.AppType() == apps::AppType::kWeb) {
- result = true;
- }
- });
- return result;
-}
-
-// Whether the app's manifest indicates that the app supports use on the lock
-// screen.
-bool IsLockScreenCapable(Profile* profile, const std::string& app_id) {
- if (IsInstalledWebApp(app_id, profile)) {
- if (!base::FeatureList::IsEnabled(features::kWebLockScreenApi))
- return false;
- if (!apps::AppServiceProxyFactory::IsAppServiceAvailableForProfile(profile))
- return false;
-
- auto& cache = apps::AppServiceProxyFactory::GetForProfile(profile)
- ->AppRegistryCache();
- bool is_ready = false;
- bool has_lock_screen_intent_filter = false;
- cache.ForOneApp(app_id, [&has_lock_screen_intent_filter,
- &is_ready](const apps::AppUpdate& update) {
- if (HasLockScreenIntentFilter(update.IntentFilters()))
- has_lock_screen_intent_filter = true;
- is_ready = update.Readiness() == apps::Readiness::kReady;
- });
- return has_lock_screen_intent_filter && is_ready;
- }
-
- const extensions::Extension* chrome_app =
- extensions::ExtensionRegistry::Get(profile)->enabled_extensions().GetByID(
- app_id);
- if (!chrome_app)
- return false;
- if (!chrome_app->permissions_data()->HasAPIPermission(
- extensions::mojom::APIPermissionID::kLockScreen)) {
- return false;
- }
- return extensions::ActionHandlersInfo::HasLockScreenActionHandler(
- chrome_app, app_runtime::ActionType::kNewNote);
-}
-
-// Gets the set of app IDs that are allowed to be launched on the lock screen,
-// if the feature is restricted using the
-// `prefs::kNoteTakingAppsLockScreenAllowlist` preference. If the pref is not
-// set, this method will return null (in which case the set should not be
-// checked).
-// Note that `prefs::kNoteTakingAppsLockScreenAllowlist` is currently only
-// expected to be set by policy (if it's set at all).
-std::unique_ptr<std::set<std::string>> GetAllowedLockScreenApps(
- PrefService* prefs) {
- const PrefService::Preference* allowed_lock_screen_apps_pref =
- prefs->FindPreference(prefs::kNoteTakingAppsLockScreenAllowlist);
- if (!allowed_lock_screen_apps_pref ||
- allowed_lock_screen_apps_pref->IsDefaultValue()) {
- return nullptr;
- }
-
- const base::Value* allowed_lock_screen_apps_value =
- allowed_lock_screen_apps_pref->GetValue();
-
- if (!allowed_lock_screen_apps_value ||
- !allowed_lock_screen_apps_value->is_list()) {
- return nullptr;
- }
-
- auto allowed_apps = std::make_unique<std::set<std::string>>();
- for (const base::Value& app_value :
- allowed_lock_screen_apps_value->GetList()) {
- if (!app_value.is_string()) {
- LOG(ERROR) << "Invalid app ID value " << app_value;
- continue;
- }
-
- allowed_apps->insert(app_value.GetString());
- }
- return allowed_apps;
-}
-
-} // namespace
-
-std::ostream& operator<<(std::ostream& out,
- const LockScreenAppSupport& support) {
- switch (support) {
- case LockScreenAppSupport::kNotSupported:
- return out << "NotSupported";
- case LockScreenAppSupport::kNotAllowedByPolicy:
- return out << "NotAllowedByPolicy";
- case LockScreenAppSupport::kSupported:
- return out << "Supported";
- case LockScreenAppSupport::kEnabled:
- return out << "Enabled";
- }
-}
-
-// static
-LockScreenAppSupport LockScreenApps::GetSupport(Profile* profile,
- const std::string& app_id) {
- LockScreenApps* lock_screen_apps =
- LockScreenAppsFactory::GetInstance()->Get(profile);
- if (!lock_screen_apps)
- return LockScreenAppSupport::kNotSupported;
- return lock_screen_apps->GetSupport(app_id);
-}
-
-void LockScreenApps::UpdateAllowedLockScreenAppsList() {
- std::unique_ptr<std::set<std::string>> allowed_apps =
- GetAllowedLockScreenApps(profile_->GetPrefs());
-
- if (allowed_apps) {
- allowed_lock_screen_apps_state_ = AllowedAppListState::kAllowedAppsListed;
- allowed_lock_screen_apps_by_policy_.swap(*allowed_apps);
- } else {
- allowed_lock_screen_apps_state_ = AllowedAppListState::kAllAppsAllowed;
- allowed_lock_screen_apps_by_policy_.clear();
- }
-}
-
-LockScreenAppSupport LockScreenApps::GetSupport(const std::string& app_id) {
- if (app_id.empty())
- return LockScreenAppSupport::kNotSupported;
-
- if (!IsLockScreenCapable(profile_, app_id))
- return LockScreenAppSupport::kNotSupported;
-
- if (allowed_lock_screen_apps_state_ == AllowedAppListState::kUndetermined)
- UpdateAllowedLockScreenAppsList();
-
- if (allowed_lock_screen_apps_state_ ==
- AllowedAppListState::kAllowedAppsListed &&
- !base::Contains(allowed_lock_screen_apps_by_policy_, app_id)) {
- return LockScreenAppSupport::kNotAllowedByPolicy;
- }
-
- // Lock screen note-taking is currently enabled/disabled for all apps at once,
- // independent of which app is preferred for note-taking. This affects the
- // toggle shown in settings UI. Currently only the preferred app can be
- // launched on the lock screen.
- // TODO(crbug.com/40099955): Consider changing this so only the preferred app
- // is reported as enabled.
- // TODO(crbug.com/40227659): Remove this dependency on note taking code by
- // migrating to a separate prefs entry.
- if (profile_->GetPrefs()->GetBoolean(
- prefs::kNoteTakingAppEnabledOnLockScreen))
- return LockScreenAppSupport::kEnabled;
-
- return LockScreenAppSupport::kSupported;
-}
-
-bool LockScreenApps::SetAppEnabledOnLockScreen(const std::string& app_id,
- bool enabled) {
- DCHECK(!app_id.empty());
-
- // Currently only the preferred note-taking app is ever enabled on the lock
- // screen.
- // TODO(crbug.com/40227659): Remove this dependency on note taking code by
- // migrating to a separate prefs entry.
- DCHECK_EQ(app_id, NoteTakingHelper::Get()->GetPreferredAppId(profile_));
-
- LockScreenAppSupport current_state = GetSupport(app_id);
-
- if ((enabled && current_state != LockScreenAppSupport::kSupported) ||
- (!enabled && current_state != LockScreenAppSupport::kEnabled)) {
- return false;
- }
-
- // TODO(crbug.com/40227659): Migrate to a non-note-taking prefs entry.
- profile_->GetPrefs()->SetBoolean(prefs::kNoteTakingAppEnabledOnLockScreen,
- enabled);
-
- return true;
-}
-
-LockScreenApps::LockScreenApps(Profile* primary_profile)
- : profile_(primary_profile) {
- DCHECK(LockScreenAppsFactory::IsSupportedProfile(profile_));
-
- pref_change_registrar_.Init(profile_->GetPrefs());
- pref_change_registrar_.Add(
- prefs::kNoteTakingAppsLockScreenAllowlist,
- base::BindRepeating(&LockScreenApps::OnAllowedLockScreenAppsChanged,
- base::Unretained(this)));
- OnAllowedLockScreenAppsChanged();
-}
-LockScreenApps::~LockScreenApps() = default;
-
-// Called when kNoteTakingAppsLockScreenAllowlist pref changes for `profile_`.
-void LockScreenApps::OnAllowedLockScreenAppsChanged() {
- if (allowed_lock_screen_apps_state_ == AllowedAppListState::kUndetermined)
- return;
-
- std::string app_id = NoteTakingHelper::Get()->GetPreferredAppId(profile_);
- LockScreenAppSupport lock_screen_value_before_update = GetSupport(app_id);
-
- UpdateAllowedLockScreenAppsList();
-
- LockScreenAppSupport lock_screen_value_after_update = GetSupport(app_id);
-
- // Do not notify observers about preferred app change if its lock screen
- // support status has not actually changed.
- if (lock_screen_value_before_update != lock_screen_value_after_update) {
- // TODO(crbug.com/40227659): Reverse this dependency by making note taking
- // code observe this class instead.
- NoteTakingHelper::Get()->NotifyAppUpdated(profile_, app_id);
- }
-}
-
-// ---------------------------------------
-// LockScreenAppsFactory implementation
-// ---------------------------------------
-
-// static
-LockScreenAppsFactory* LockScreenAppsFactory::GetInstance() {
- static base::NoDestructor<LockScreenAppsFactory> instance;
- return instance.get();
-}
-
-// static
-bool LockScreenAppsFactory::IsSupportedProfile(Profile* profile) {
- if (!profile)
- return false;
- if (!apps::AppServiceProxyFactory::IsAppServiceAvailableForProfile(profile))
- return false;
- if (!ProfileHelper::IsPrimaryProfile(profile))
- return false;
- return true;
-}
-
-LockScreenApps* LockScreenAppsFactory::Get(Profile* profile) {
- return static_cast<LockScreenApps*>(
- GetInstance()->GetServiceForBrowserContext(profile, /*create=*/true));
-}
-
-LockScreenAppsFactory::LockScreenAppsFactory()
- : BrowserContextKeyedServiceFactory(
- "LockScreenApps",
- BrowserContextDependencyManager::GetInstance()) {
- DependsOn(apps::AppServiceProxyFactory::GetInstance());
-}
-
-LockScreenAppsFactory::~LockScreenAppsFactory() = default;
-
-void LockScreenAppsFactory::RegisterProfilePrefs(
- user_prefs::PrefRegistrySyncable* registry) {
- registry->RegisterListPref(::prefs::kNoteTakingAppsLockScreenAllowlist);
- registry->RegisterBooleanPref(::prefs::kNoteTakingAppEnabledOnLockScreen,
- true);
-}
-
-KeyedService* LockScreenAppsFactory::BuildServiceInstanceFor(
- content::BrowserContext* context) const {
- Profile* profile = Profile::FromBrowserContext(context);
- return new LockScreenApps(profile);
-}
-
-content::BrowserContext* LockScreenAppsFactory::GetBrowserContextToUse(
- content::BrowserContext* context) const {
- Profile* profile = Profile::FromBrowserContext(context);
- return IsSupportedProfile(profile) ? context : nullptr;
-}
-
-} // namespace ash
diff --git a/chrome/browser/ash/lock_screen_apps/lock_screen_apps.h b/chrome/browser/ash/lock_screen_apps/lock_screen_apps.h
deleted file mode 100644
index 8332282..0000000
--- a/chrome/browser/ash/lock_screen_apps/lock_screen_apps.h
+++ /dev/null
@@ -1,135 +0,0 @@
-// Copyright 2022 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_LOCK_SCREEN_APPS_H_
-#define CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_LOCK_SCREEN_APPS_H_
-
-#include <set>
-#include <string>
-
-#include "base/memory/raw_ptr.h"
-#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
-#include "components/keyed_service/core/keyed_service.h"
-#include "components/prefs/pref_change_registrar.h"
-
-class Profile;
-
-namespace content {
-class BrowserContext;
-}
-namespace user_prefs {
-class PrefRegistrySyncable;
-}
-
-namespace ash {
-
-// Describes an app's level of support for use on the lock screen.
-// IMPORTANT: These constants are used in settings UI, so be careful about
-// reordering/adding/removing items.
-enum class LockScreenAppSupport {
- // The app does not support use on lock screen.
- kNotSupported = 0,
- // The app supports use on the lock screen, but is not allowed to run on the
- // lock screen due to policy settings.
- kNotAllowedByPolicy = 1,
- // The app supports use on the lock screen, but is not enabled as a lock
- // screen app by the user. This state implies that the user
- // can be offered to enable this app for use on the lock screen.
- kSupported = 2,
- // The app is enabled by the user to run as on the lock screen. Note that,
- // while more than one app can be in enabled state at a
- // same time, currently only the preferred note taking app will be launchable
- // from the lock screen UI.
- kEnabled = 3,
-};
-
-// For logging and debug purposes.
-std::ostream& operator<<(std::ostream& out, const LockScreenAppSupport& app);
-
-// Tracks available lock screen apps. Only exists for the primary profile.
-class LockScreenApps : public KeyedService {
- public:
- // Convenience method for `GetSupport`. Returns the support status, or
- // `kNotSupported` if `profile` doesn't support lock screen apps.
- static LockScreenAppSupport GetSupport(Profile* profile,
- const std::string& app_id);
-
- LockScreenApps(const LockScreenApps&) = delete;
- LockScreenApps& operator=(const LockScreenApps&) = delete;
-
- // Updates the cached list of apps allowed on the lock screen. Sets
- // `allowed_lock_screen_apps_state_` and `allowed_lock_screen_apps_by_policy_`
- // to values appropriate for the current `profile_` state.
- void UpdateAllowedLockScreenAppsList();
-
- // Returns the state of the app's support for running on the lock screen.
- LockScreenAppSupport GetSupport(const std::string& app_id);
-
- // Attempts to set the given app as enabled on the lock screen. Returns
- // whether the app status changed.
- bool SetAppEnabledOnLockScreen(const std::string& app_id, bool enabled);
-
- private:
- explicit LockScreenApps(Profile* primary_profile);
- ~LockScreenApps() override;
- friend class LockScreenAppsFactory;
-
- // The state of the allowed app ID cache (used for determining the state of
- // note-taking apps allowed on the lock screen).
- enum class AllowedAppListState {
- // The allowed apps have not yet been determined.
- kUndetermined,
- // No app ID restriction exists in the profile.
- kAllAppsAllowed,
- // A list of allowed app IDs exists in the profile.
- kAllowedAppsListed
- };
-
- // Called when kNoteTakingAppsLockScreenAllowlist pref changes for `profile_`.
- void OnAllowedLockScreenAppsChanged();
-
- // The profile for which lock screen apps are enabled.
- raw_ptr<Profile> profile_ = nullptr;
-
- // Tracks kNoteTakingAppsLockScreenAllowlist pref for the profile for which
- // lock screen apps are enabled.
- PrefChangeRegistrar pref_change_registrar_;
-
- // The current AllowedAppListState for lock screen note taking in `profile_`.
- // If kAllowedAppsListed, `lock_screen_apps_allowed_by_policy_` should contain
- // the set of allowed app IDs.
- AllowedAppListState allowed_lock_screen_apps_state_ =
- AllowedAppListState::kUndetermined;
-
- // If `allowed_lock_screen_apps_state_` is kAllowedAppsListed, contains all
- // app IDs that are allowed to handle new-note action on the lock screen. The
- // set should only be used for apps from `profile_` and when
- // `allowed_lock_screen_apps_state_` equals kAllowedAppsListed.
- std::set<std::string> allowed_lock_screen_apps_by_policy_;
-};
-
-class LockScreenAppsFactory : public BrowserContextKeyedServiceFactory {
- public:
- LockScreenAppsFactory();
- ~LockScreenAppsFactory() override;
-
- static LockScreenAppsFactory* GetInstance();
- // Returns whether a profile supports lock screen apps.
- static bool IsSupportedProfile(Profile* profile);
- // Returns nullptr if profile does not support lock screen apps.
- LockScreenApps* Get(Profile* profile);
-
- private:
- // BrowserContextKeyedServiceFactory:
- void RegisterProfilePrefs(
- user_prefs::PrefRegistrySyncable* registry) override;
- KeyedService* BuildServiceInstanceFor(
- content::BrowserContext* context) const override;
- content::BrowserContext* GetBrowserContextToUse(
- content::BrowserContext* context) const override;
-};
-
-} // namespace ash
-
-#endif // CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_LOCK_SCREEN_APPS_H_
diff --git a/chrome/browser/ash/lock_screen_apps/lock_screen_profile_creator.cc b/chrome/browser/ash/lock_screen_apps/lock_screen_profile_creator.cc
deleted file mode 100644
index 36e88e70..0000000
--- a/chrome/browser/ash/lock_screen_apps/lock_screen_profile_creator.cc
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright 2017 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ash/lock_screen_apps/lock_screen_profile_creator.h"
-
-#include <memory>
-#include <utility>
-
-#include "base/check_op.h"
-#include "base/functional/bind.h"
-#include "base/functional/callback.h"
-
-namespace lock_screen_apps {
-
-LockScreenProfileCreator::LockScreenProfileCreator() {}
-
-LockScreenProfileCreator::~LockScreenProfileCreator() {}
-
-void LockScreenProfileCreator::Initialize() {
- CHECK_EQ(state_, State::kNotInitialized);
- state_ = State::kInitialized;
-
- InitializeImpl();
-}
-
-void LockScreenProfileCreator::AddCreateProfileCallback(
- base::OnceClosure callback) {
- CHECK_NE(state_, State::kNotInitialized);
-
- if (ProfileCreated()) {
- std::move(callback).Run();
- return;
- }
-
- create_profile_callbacks_.emplace_back(std::move(callback));
-}
-
-bool LockScreenProfileCreator::Initialized() const {
- return state_ != State::kNotInitialized;
-}
-
-bool LockScreenProfileCreator::ProfileCreated() const {
- return state_ == State::kProfileCreated;
-}
-
-void LockScreenProfileCreator::OnLockScreenProfileCreateStarted() {
- CHECK_EQ(State::kInitialized, state_);
-
- state_ = State::kCreatingProfile;
-}
-
-void LockScreenProfileCreator::OnLockScreenProfileCreated(
- Profile* lock_screen_profile) {
- CHECK_EQ(State::kCreatingProfile, state_);
- state_ = State::kProfileCreated;
-
- lock_screen_profile_ = lock_screen_profile;
-
- while (!create_profile_callbacks_.empty()) {
- std::move(create_profile_callbacks_.front()).Run();
- create_profile_callbacks_.pop_front();
- }
-}
-
-} // namespace lock_screen_apps
diff --git a/chrome/browser/ash/lock_screen_apps/lock_screen_profile_creator.h b/chrome/browser/ash/lock_screen_apps/lock_screen_profile_creator.h
deleted file mode 100644
index 0d26335..0000000
--- a/chrome/browser/ash/lock_screen_apps/lock_screen_profile_creator.h
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2017 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_LOCK_SCREEN_PROFILE_CREATOR_H_
-#define CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_LOCK_SCREEN_PROFILE_CREATOR_H_
-
-#include <list>
-
-#include "base/functional/callback_forward.h"
-#include "base/memory/raw_ptr.h"
-
-class Profile;
-
-namespace lock_screen_apps {
-
-// Abstract class to be used to create the lock screen apps profile - the
-// profile used for launching/running lock screen enabled apps.
-class LockScreenProfileCreator {
- public:
- LockScreenProfileCreator();
-
- LockScreenProfileCreator(const LockScreenProfileCreator&) = delete;
- LockScreenProfileCreator& operator=(const LockScreenProfileCreator&) = delete;
-
- virtual ~LockScreenProfileCreator();
-
- // Initializes the creator - it marks the object as initialized and calls
- // |InitializeImpl|, a function that should be override to provide actual
- // initialization logic. After this, the |LockScreenProfileCreator|
- // implementation should be allowed to create lock screen profile.
- void Initialize();
-
- // Adds a closure that should be called when the lock screen profile provided
- // by the class is created. If the profile is alredy created at the time this
- // is called, |callback| will be run immediately.
- void AddCreateProfileCallback(base::OnceClosure callback);
-
- // Whether the |LockScreenProfileCreator| has been initialized.
- bool Initialized() const;
-
- // Whether the |LockScreenProfileCreator| finished profile creation, and the
- // created, if any, profile can be retrieved using |lock_screen_profile()|.
- // Note that |lock_screen_profile| might be null even if |ProfileCreated|
- // returns true - in case the profile creation failed.
- bool ProfileCreated() const;
-
- Profile* lock_screen_profile() const { return lock_screen_profile_; }
-
- protected:
- // Should be overriden to provide initialization logic - the
- // |LockScreenProfileCreator| instance should be put in state where it can
- // determine whether the lock screen profile should be created and start
- // profile creation when appropriate.
- // For example, the class instance might start observing lock screen note
- // taking availability, and start profile creation when a lock screen note
- // taking app is available.
- virtual void InitializeImpl() = 0;
-
- // Should be called by the implementation to indicate profile creation has
- // started.
- void OnLockScreenProfileCreateStarted();
-
- // Should be called by the implementation to finish profile creation - to
- // set |lock_screen_profile_| and run profile creation callbacks.
- void OnLockScreenProfileCreated(Profile* lock_screen_profile);
-
- private:
- enum class State {
- kNotInitialized,
- kInitialized,
- kCreatingProfile,
- kProfileCreated
- };
-
- // The current profile creator state.
- State state_ = State::kNotInitialized;
-
- // The lock screen profile created by this, set when the profile creation
- // finishes.
- raw_ptr<Profile> lock_screen_profile_ = nullptr;
-
- std::list<base::OnceClosure> create_profile_callbacks_;
-};
-
-} // namespace lock_screen_apps
-
-#endif // CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_LOCK_SCREEN_PROFILE_CREATOR_H_
diff --git a/chrome/browser/ash/lock_screen_apps/lock_screen_profile_creator_impl.cc b/chrome/browser/ash/lock_screen_apps/lock_screen_profile_creator_impl.cc
deleted file mode 100644
index 4429cb3..0000000
--- a/chrome/browser/ash/lock_screen_apps/lock_screen_profile_creator_impl.cc
+++ /dev/null
@@ -1,107 +0,0 @@
-// Copyright 2017 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ash/lock_screen_apps/lock_screen_profile_creator_impl.h"
-
-#include <memory>
-#include <string>
-#include <utility>
-
-#include "base/functional/bind.h"
-#include "base/metrics/histogram_macros.h"
-#include "base/one_shot_event.h"
-#include "base/time/tick_clock.h"
-#include "base/time/time.h"
-#include "chrome/browser/ash/lock_screen_apps/lock_screen_apps.h"
-#include "chrome/browser/ash/profiles/profile_helper.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/profiles/profile_manager.h"
-#include "chrome/common/pref_names.h"
-#include "components/prefs/pref_service.h"
-#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
-#include "extensions/browser/extension_system.h"
-
-namespace lock_screen_apps {
-
-LockScreenProfileCreatorImpl::LockScreenProfileCreatorImpl(
- Profile* primary_profile,
- const base::TickClock* tick_clock)
- : primary_profile_(primary_profile), tick_clock_(tick_clock) {}
-
-LockScreenProfileCreatorImpl::~LockScreenProfileCreatorImpl() {}
-
-void LockScreenProfileCreatorImpl::OnAvailableNoteTakingAppsUpdated() {}
-
-void LockScreenProfileCreatorImpl::OnPreferredNoteTakingAppUpdated(
- Profile* profile) {
- if (profile != primary_profile_)
- return;
-
- ash::NoteTakingHelper* helper = ash::NoteTakingHelper::Get();
- std::string app_id = helper->GetPreferredAppId(primary_profile_);
- // Lock screen apps service should always exist on the primary profile.
- DCHECK(ash::LockScreenAppsFactory::IsSupportedProfile(primary_profile_));
- ash::LockScreenAppSupport support =
- ash::LockScreenApps::GetSupport(primary_profile_, app_id);
-
- if (support != ash::LockScreenAppSupport::kEnabled)
- return;
-
- // Lock screen profile creation should be attempted only once - stop observing
- // note taking apps status so profile creation is not attempted again if lock
- // screen note availability changes.
- note_taking_helper_observation_.Reset();
-
- OnLockScreenProfileCreateStarted();
-
- g_browser_process->profile_manager()->CreateProfileAsync(
- ash::ProfileHelper::GetLockScreenAppProfilePath(),
- /*initialized_callback=*/
- base::BindOnce(&LockScreenProfileCreatorImpl::OnProfileReady,
- weak_ptr_factory_.GetWeakPtr(), tick_clock_->NowTicks()),
- /*created_callback=*/base::BindOnce([](Profile* profile) {
- // Disable safe browsing for the profile to avoid activating
- // SafeBrowsingService when the user has safe browsing disabled
- // (reasoning similar to http://crbug.com/461493).
- // TODO(tbarzic): Revisit this if webviews get enabled for lock screen
- // apps.
- profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnabled, false);
- profile->GetPrefs()->SetBoolean(prefs::kSafeBrowsingEnhanced, false);
- }));
-}
-
-void LockScreenProfileCreatorImpl::InitializeImpl() {
- // Make sure that extension system is ready (and extension regustry is loaded)
- // before testing for lock screen enabled app existence.
- extensions::ExtensionSystem::Get(primary_profile_)
- ->ready()
- .Post(
- FROM_HERE,
- base::BindOnce(&LockScreenProfileCreatorImpl::OnExtensionSystemReady,
- weak_ptr_factory_.GetWeakPtr()));
-}
-
-void LockScreenProfileCreatorImpl::OnExtensionSystemReady() {
- note_taking_helper_observation_.Observe(ash::NoteTakingHelper::Get());
-
- // Determine the current note taking state.
- OnPreferredNoteTakingAppUpdated(primary_profile_);
-}
-
-void LockScreenProfileCreatorImpl::OnProfileReady(
- const base::TimeTicks& start_time,
- Profile* profile) {
- // On error, bail out - this will cause the lock screen apps to remain
- // unavailable on the device.
- if (!profile) {
- OnLockScreenProfileCreated(nullptr);
- return;
- }
-
- profile->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, true);
-
- OnLockScreenProfileCreated(profile);
-}
-
-} // namespace lock_screen_apps
diff --git a/chrome/browser/ash/lock_screen_apps/lock_screen_profile_creator_impl.h b/chrome/browser/ash/lock_screen_apps/lock_screen_profile_creator_impl.h
deleted file mode 100644
index 7705f3c..0000000
--- a/chrome/browser/ash/lock_screen_apps/lock_screen_profile_creator_impl.h
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright 2017 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_LOCK_SCREEN_PROFILE_CREATOR_IMPL_H_
-#define CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_LOCK_SCREEN_PROFILE_CREATOR_IMPL_H_
-
-#include "base/memory/raw_ptr.h"
-#include "base/memory/weak_ptr.h"
-#include "base/scoped_observation.h"
-#include "chrome/browser/ash/lock_screen_apps/lock_screen_profile_creator.h"
-#include "chrome/browser/ash/note_taking/note_taking_helper.h"
-#include "chrome/browser/profiles/profile.h"
-
-namespace base {
-class TickClock;
-class TimeTicks;
-} // namespace base
-
-namespace lock_screen_apps {
-
-// Real, production implementation of |LockScreenProfileCreator|.
-// When initialized, it starts observing lock screen note taking availabiltiy.
-// If/when a note taking app enaled on the lock screen is detected,
-// |LockScreenProfileCreatorImpl| will start async lock screen profile creation.
-class LockScreenProfileCreatorImpl : public LockScreenProfileCreator,
- public ash::NoteTakingHelper::Observer {
- public:
- // |primary_profile| - the primary profile - i.e. the profile which should be
- // used to determine lock screen note taking availability.
- LockScreenProfileCreatorImpl(Profile* primary_profile,
- const base::TickClock* tick_clock);
-
- LockScreenProfileCreatorImpl(const LockScreenProfileCreatorImpl&) = delete;
- LockScreenProfileCreatorImpl& operator=(const LockScreenProfileCreatorImpl&) =
- delete;
-
- ~LockScreenProfileCreatorImpl() override;
-
- // ash::NoteTakingHelper::Observer:
- void OnAvailableNoteTakingAppsUpdated() override;
- void OnPreferredNoteTakingAppUpdated(Profile* profile) override;
-
- protected:
- // lock_screen_apps::LockScreenProfileCreator:
- void InitializeImpl() override;
-
- private:
- // Called when the extension system for the primary profile is ready.
- // Testing note taking app availability before this is called might be
- // unreliable, as extension list in the profile's extension registry might not
- // be complete.
- void OnExtensionSystemReady();
-
- // Called when the lock screen profile is created and initialized (i.e. this
- // is called more than once for a single profile).
- // |start_time| - time at which the profile creation started.
- // |profile| - the created profile - i.e. the lock screen profile.
- void OnProfileReady(const base::TimeTicks& start_time, Profile* profile);
-
- const raw_ptr<Profile> primary_profile_;
- raw_ptr<const base::TickClock> tick_clock_;
-
- base::ScopedObservation<ash::NoteTakingHelper,
- ash::NoteTakingHelper::Observer>
- note_taking_helper_observation_{this};
-
- base::WeakPtrFactory<LockScreenProfileCreatorImpl> weak_ptr_factory_{this};
-};
-
-} // namespace lock_screen_apps
-
-#endif // CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_LOCK_SCREEN_PROFILE_CREATOR_IMPL_H_
diff --git a/chrome/browser/ash/lock_screen_apps/note_taking_browsertest.cc b/chrome/browser/ash/lock_screen_apps/note_taking_browsertest.cc
deleted file mode 100644
index 2fe8f588..0000000
--- a/chrome/browser/ash/lock_screen_apps/note_taking_browsertest.cc
+++ /dev/null
@@ -1,328 +0,0 @@
-// Copyright 2017 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <memory>
-#include <string>
-#include <type_traits>
-#include <utility>
-
-#include "apps/launcher.h"
-#include "ash/constants/ash_switches.h"
-#include "ash/public/mojom/tray_action.mojom-shared.h"
-#include "base/command_line.h"
-#include "base/files/file_path.h"
-#include "base/functional/callback_forward.h"
-#include "base/memory/scoped_refptr.h"
-#include "base/run_loop.h"
-#include "base/scoped_observation.h"
-#include "chrome/browser/ash/lock_screen_apps/state_controller.h"
-#include "chrome/browser/ash/lock_screen_apps/state_observer.h"
-#include "chrome/browser/ash/note_taking/note_taking_helper.h"
-#include "chrome/browser/extensions/extension_browsertest.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/common/pref_names.h"
-#include "components/prefs/pref_service.h"
-#include "components/session_manager/core/session_manager.h"
-#include "components/session_manager/session_manager_types.h"
-#include "content/public/test/browser_test.h"
-#include "extensions/common/api/app_runtime.h"
-#include "extensions/common/extension.h"
-#include "extensions/common/switches.h"
-#include "extensions/test/extension_test_message_listener.h"
-#include "extensions/test/result_catcher.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace content {
-class BrowserMainParts;
-}
-
-namespace {
-
-using ash::mojom::TrayActionState;
-
-const char kTestAppId[] = "cadfeochfldmbdgoccgbeianhamecbae";
-
-// Class used to wait for a specific lock_screen_apps::StateController state.
-class LockScreenAppsEnabledWaiter : public lock_screen_apps::StateObserver {
- public:
- LockScreenAppsEnabledWaiter() = default;
-
- LockScreenAppsEnabledWaiter(const LockScreenAppsEnabledWaiter&) = delete;
- LockScreenAppsEnabledWaiter& operator=(const LockScreenAppsEnabledWaiter&) =
- delete;
-
- ~LockScreenAppsEnabledWaiter() override {}
-
- // Runs loop until lock_screen_apps::StateController enters |target_state|.
- // Note: as currently implemented, this will fail if a transition to a state
- // different than |target_state| is observed.
- bool WaitForState(TrayActionState target_state) {
- TrayActionState state =
- lock_screen_apps::StateController::Get()->GetLockScreenNoteState();
- if (target_state == state)
- return true;
-
- base::RunLoop run_loop;
- state_change_callback_ = run_loop.QuitClosure();
- lock_screen_apps_state_observation_.Observe(
- lock_screen_apps::StateController::Get());
- run_loop.Run();
-
- lock_screen_apps_state_observation_.Reset();
-
- return target_state ==
- lock_screen_apps::StateController::Get()->GetLockScreenNoteState();
- }
-
- void OnLockScreenNoteStateChanged(TrayActionState state) override {
- ASSERT_FALSE(state_change_callback_.is_null());
- std::move(state_change_callback_).Run();
- }
-
- private:
- base::ScopedObservation<lock_screen_apps::StateController,
- lock_screen_apps::StateObserver>
- lock_screen_apps_state_observation_{this};
-
- base::OnceClosure state_change_callback_;
-};
-
-class LockScreenNoteTakingTest : public extensions::ExtensionBrowserTest {
- public:
- LockScreenNoteTakingTest() { set_chromeos_user_ = true; }
-
- LockScreenNoteTakingTest(const LockScreenNoteTakingTest&) = delete;
- LockScreenNoteTakingTest& operator=(const LockScreenNoteTakingTest&) = delete;
-
- ~LockScreenNoteTakingTest() override = default;
-
- void SetUpCommandLine(base::CommandLine* cmd_line) override {
- cmd_line->AppendSwitchASCII(extensions::switches::kAllowlistedExtensionID,
- kTestAppId);
- cmd_line->AppendSwitch(ash::switches::kAshForceEnableStylusTools);
-
- extensions::ExtensionBrowserTest::SetUpCommandLine(cmd_line);
- }
-
- void CreatedBrowserMainParts(
- content::BrowserMainParts* browser_main_parts) override {
- // Creating result catcher to be used by tests eary on to avoid flaky hangs
- // in the DataAvailableOnRestart test.
- // The tests expects the test app (which is installed in the tests PRE_
- // part) to run in response to the
- // lockScreen.data.onDataItemsAvailable event which is dispatched early on,
- // during "user" session start-up, which happens before test body is run.
- // This means that result catchers created in the test body might miss test
- // completion notifications from the app.
- result_catcher_ = std::make_unique<extensions::ResultCatcher>();
- extensions::ExtensionBrowserTest::CreatedBrowserMainParts(
- browser_main_parts);
- }
-
- void TearDownOnMainThread() override {
- result_catcher_.reset();
- extensions::ExtensionBrowserTest::TearDownOnMainThread();
- }
-
- bool EnableLockScreenAppLaunch(const std::string& app_id) {
- ash::NoteTakingHelper::Get()->SetPreferredApp(profile(), app_id);
- ash::NoteTakingHelper::Get()->SetPreferredAppEnabledOnLockScreen(profile(),
- true);
-
- session_manager::SessionManager::Get()->SetSessionState(
- session_manager::SessionState::LOCKED);
-
- return LockScreenAppsEnabledWaiter().WaitForState(
- ash::mojom::TrayActionState::kAvailable);
- }
-
- bool RunTestAppInLockScreenContext(const std::string& test_app,
- std::string* error) {
- scoped_refptr<const extensions::Extension> app =
- LoadExtension(test_data_dir_.AppendASCII(test_app));
- if (!app) {
- *error = "Unable to load the test app.";
- return false;
- }
-
- if (!EnableLockScreenAppLaunch(app->id())) {
- *error = "Failed to enable app for lock screen.";
- return false;
- }
-
- // The test app will send "readyToClose" message from the app window created
- // as part of the test. The message will be sent after the tests in the app
- // window context have been run and the window is ready to be closed.
- // The test should reply to this message in order for the app window to
- // close itself.
- ExtensionTestMessageListener ready_to_close("readyToClose",
- ReplyBehavior::kWillReply);
-
- lock_screen_apps::StateController::Get()->RequestNewLockScreenNote(
- ash::mojom::LockScreenNoteOrigin::kLockScreenButtonTap);
-
- if (lock_screen_apps::StateController::Get()->GetLockScreenNoteState() !=
- ash::mojom::TrayActionState::kLaunching) {
- *error = "App launch request failed";
- return false;
- }
-
- // The test will run two sets of tests:
- // * in the window that gets created as the response to the new_note action
- // launch
- // * in the app background page - the test will launch an app window and
- // wait for it to be closed
- // Test runner should wait for both of those to finish (test result message
- // will be sent for each set of tests).
- if (!result_catcher_->GetNextResult()) {
- *error = result_catcher_->message();
- if (ready_to_close.was_satisfied())
- ready_to_close.Reply("failed");
- return false;
- }
-
- if (!ready_to_close.WaitUntilSatisfied()) {
- *error = "Failed waiting for readyToClose message.";
- return false;
- }
-
- // Close the app window created by the API test.
- ready_to_close.Reply("close");
-
- if (!result_catcher_->GetNextResult()) {
- *error = result_catcher_->message();
- return false;
- }
-
- return true;
- }
-
- extensions::ResultCatcher* result_catcher() { return result_catcher_.get(); }
-
- private:
- std::unique_ptr<extensions::ResultCatcher> result_catcher_;
-};
-
-} // namespace
-
-IN_PROC_BROWSER_TEST_F(LockScreenNoteTakingTest, Launch) {
- std::string error_message;
- ASSERT_TRUE(RunTestAppInLockScreenContext("lock_screen_apps/app_launch",
- &error_message))
- << error_message;
-
- EXPECT_EQ(ash::mojom::TrayActionState::kAvailable,
- lock_screen_apps::StateController::Get()->GetLockScreenNoteState());
-}
-
-// Tests that lock screen app window creation fails if not requested from the
-// lock screen context - the test app runs tests as a response to a launch event
-// in the user's profile (rather than the lock screen profile).
-IN_PROC_BROWSER_TEST_F(LockScreenNoteTakingTest, LaunchInNonLockScreenContext) {
- scoped_refptr<const extensions::Extension> app = LoadExtension(
- test_data_dir_.AppendASCII("lock_screen_apps/non_lock_screen_context"));
- ASSERT_TRUE(app);
- ASSERT_TRUE(EnableLockScreenAppLaunch(app->id()));
-
- // Get the lock screen apps state controller to the state where lock screen
- // enabled app window creation is allowed (provided the window is created
- // from a lock screen context).
- // NOTE: This is not mandatory for the test to pass, but without it, app
- // window creation would fail regardless of the context from which
- // chrome.app.window.create is called.
- lock_screen_apps::StateController::Get()->RequestNewLockScreenNote(
- ash::mojom::LockScreenNoteOrigin::kLockScreenButtonTap);
-
- ASSERT_EQ(ash::mojom::TrayActionState::kLaunching,
- lock_screen_apps::StateController::Get()->GetLockScreenNoteState());
-
- // Launch note taking in regular, non lock screen context. The test will
- // verify the app cannot create lock screen enabled app windows in this case.
- extensions::api::app_runtime::ActionData action_data;
- action_data.action_type = extensions::api::app_runtime::ActionType::kNewNote;
- apps::LaunchPlatformAppWithAction(profile(), app.get(),
- std::move(action_data));
-
- ASSERT_TRUE(result_catcher()->GetNextResult()) << result_catcher()->message();
-}
-
-IN_PROC_BROWSER_TEST_F(LockScreenNoteTakingTest, DataCreation) {
- std::string error_message;
- ASSERT_TRUE(RunTestAppInLockScreenContext("lock_screen_apps/data_provider",
- &error_message))
- << error_message;
-
- EXPECT_EQ(ash::mojom::TrayActionState::kAvailable,
- lock_screen_apps::StateController::Get()->GetLockScreenNoteState());
-
- session_manager::SessionManager::Get()->SetSessionState(
- session_manager::SessionState::ACTIVE);
-
- // Unlocking the session should trigger onDataItemsAvailable event, which
- // should be catched by the background page in the main app - the event should
- // start another test sequence.
- ASSERT_TRUE(result_catcher()->GetNextResult()) << result_catcher()->message();
-}
-
-IN_PROC_BROWSER_TEST_F(LockScreenNoteTakingTest, PRE_DataAvailableOnRestart) {
- std::string error_message;
- ASSERT_TRUE(RunTestAppInLockScreenContext("lock_screen_apps/data_provider",
- &error_message))
- << error_message;
-
- EXPECT_EQ(ash::mojom::TrayActionState::kAvailable,
- lock_screen_apps::StateController::Get()->GetLockScreenNoteState());
-}
-
-IN_PROC_BROWSER_TEST_F(LockScreenNoteTakingTest, DataAvailableOnRestart) {
- // In PRE_ part of the test there were data items created in the lock screen
- // storage - when the lock screen note taking is initialized,
- // OnDataItemsAvailable should be dispatched to the test app (given that the
- // lock screen app's data storage is not empty), which should in turn run a
- // sequence of API tests (in the test app background page).
- // This test is intended to catch the result of these tests.
- ASSERT_TRUE(result_catcher()->GetNextResult()) << result_catcher()->message();
-}
-
-IN_PROC_BROWSER_TEST_F(LockScreenNoteTakingTest, AppLaunchActionDataParams) {
- scoped_refptr<const extensions::Extension> app = LoadExtension(
- test_data_dir_.AppendASCII("lock_screen_apps/app_launch_action_data"));
- ASSERT_TRUE(app);
- ASSERT_TRUE(EnableLockScreenAppLaunch(app->id()));
-
- lock_screen_apps::StateController::Get()->RequestNewLockScreenNote(
- ash::mojom::LockScreenNoteOrigin::kLockScreenButtonTap);
- ASSERT_EQ(ash::mojom::TrayActionState::kLaunching,
- lock_screen_apps::StateController::Get()->GetLockScreenNoteState());
-
- ExtensionTestMessageListener expected_action_data("getExpectedActionData",
- ReplyBehavior::kWillReply);
-
- ASSERT_TRUE(expected_action_data.WaitUntilSatisfied());
- expected_action_data.Reply(R"({"actionType": "new_note",
- "isLockScreenAction": true,
- "restoreLastActionState": true})");
- ASSERT_TRUE(result_catcher()->GetNextResult()) << result_catcher()->message();
- expected_action_data.Reset();
-
- // Reset the lock screen app state by resetting screen lock, so the app is
- // launchable again.
- session_manager::SessionManager::Get()->SetSessionState(
- session_manager::SessionState::ACTIVE);
- session_manager::SessionManager::Get()->SetSessionState(
- session_manager::SessionState::LOCKED);
-
- profile()->GetPrefs()->SetBoolean(prefs::kRestoreLastLockScreenNote, false);
-
- lock_screen_apps::StateController::Get()->RequestNewLockScreenNote(
- ash::mojom::LockScreenNoteOrigin::kLockScreenButtonTap);
- ASSERT_EQ(ash::mojom::TrayActionState::kLaunching,
- lock_screen_apps::StateController::Get()->GetLockScreenNoteState());
-
- ASSERT_TRUE(expected_action_data.WaitUntilSatisfied());
- expected_action_data.Reply(R"({"actionType": "new_note",
- "isLockScreenAction": true,
- "restoreLastActionState": false})");
- ASSERT_TRUE(result_catcher()->GetNextResult()) << result_catcher()->message();
-}
diff --git a/chrome/browser/ash/lock_screen_apps/state_controller.cc b/chrome/browser/ash/lock_screen_apps/state_controller.cc
deleted file mode 100644
index 2218199..0000000
--- a/chrome/browser/ash/lock_screen_apps/state_controller.cc
+++ /dev/null
@@ -1,523 +0,0 @@
-// Copyright 2017 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ash/lock_screen_apps/state_controller.h"
-
-#include <atomic>
-#include <ostream>
-#include <string>
-#include <type_traits>
-#include <utility>
-
-#include "ash/public/ash_interfaces.h"
-#include "ash/public/cpp/stylus_utils.h"
-#include "ash/public/mojom/tray_action.mojom.h"
-#include "base/base64.h"
-#include "base/check.h"
-#include "base/check_op.h"
-#include "base/feature_list.h"
-#include "base/files/file_path.h"
-#include "base/functional/bind.h"
-#include "base/logging.h"
-#include "base/path_service.h"
-#include "base/time/default_tick_clock.h"
-#include "base/trace_event/trace_event.h"
-#include "chrome/browser/ash/lock_screen_apps/app_manager.h"
-#include "chrome/browser/ash/lock_screen_apps/app_manager_impl.h"
-#include "chrome/browser/ash/lock_screen_apps/first_app_run_toast_manager.h"
-#include "chrome/browser/ash/lock_screen_apps/focus_cycler_delegate.h"
-#include "chrome/browser/ash/lock_screen_apps/lock_screen_apps.h"
-#include "chrome/browser/ash/lock_screen_apps/lock_screen_profile_creator.h"
-#include "chrome/browser/ash/lock_screen_apps/lock_screen_profile_creator_impl.h"
-#include "chrome/browser/ash/lock_screen_apps/state_observer.h"
-#include "chrome/browser/ash/profiles/profile_helper.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/common/chrome_paths.h"
-#include "components/prefs/pref_registry_simple.h"
-#include "components/prefs/pref_service.h"
-#include "components/session_manager/core/session_manager.h"
-#include "components/user_manager/user.h"
-#include "content/public/browser/lock_screen_storage.h"
-#include "content/public/browser/web_contents.h"
-#include "content/public/common/content_features.h"
-#include "crypto/symmetric_key.h"
-#include "extensions/browser/api/lock_screen_data/crypto.h"
-#include "extensions/browser/api/lock_screen_data/lock_screen_item_storage.h"
-#include "extensions/browser/app_window/app_delegate.h"
-#include "extensions/browser/app_window/app_window.h"
-#include "extensions/browser/app_window/native_app_window.h"
-#include "extensions/common/extension.h"
-#include "extensions/common/extension_id.h"
-#include "mojo/public/cpp/bindings/pending_remote.h"
-#include "ui/aura/window.h"
-#include "ui/events/devices/device_data_manager.h"
-#include "ui/wm/core/window_animations.h"
-#include "ui/wm/core/window_properties.h"
-
-using ash::mojom::CloseLockScreenNoteReason;
-using ash::mojom::LockScreenNoteOrigin;
-using ash::mojom::TrayActionState;
-
-namespace lock_screen_apps {
-
-namespace {
-
-// Key for user pref that contains the 256 bit AES key that should be used to
-// encrypt persisted user data created on the lock screen.
-constexpr char kDataCryptoKeyPref[] = "lockScreenAppDataCryptoKey";
-
-StateController* g_state_controller_instance = nullptr;
-
-// Generates a random 256 bit AES key. Returns an empty string on error.
-std::string GenerateCryptoKey() {
- std::unique_ptr<crypto::SymmetricKey> symmetric_key =
- crypto::SymmetricKey::GenerateRandomKey(
- crypto::SymmetricKey::AES,
- extensions::lock_screen_data::kAesKeySize * 8);
- if (!symmetric_key)
- return "";
- return symmetric_key->key();
-}
-
-} // namespace
-
-// static
-StateController* StateController::Get() {
- DCHECK(g_state_controller_instance);
- return g_state_controller_instance;
-}
-
-// static
-void StateController::RegisterProfilePrefs(PrefRegistrySimple* registry) {
- registry->RegisterStringPref(kDataCryptoKeyPref, "");
-}
-
-StateController::StateController() {
- DCHECK(!g_state_controller_instance);
-
- g_state_controller_instance = this;
-}
-
-StateController::~StateController() {
- DCHECK_EQ(g_state_controller_instance, this);
- g_state_controller_instance = nullptr;
-}
-
-void StateController::SetTrayActionForTesting(
- mojo::PendingRemote<ash::mojom::TrayAction> tray_action) {
- tray_action_.Bind(std::move(tray_action));
-}
-
-void StateController::FlushTrayActionForTesting() {
- tray_action_.FlushForTesting();
-}
-
-void StateController::SetReadyCallbackForTesting(
- base::OnceClosure ready_callback) {
- DCHECK(ready_callback_.is_null());
-
- ready_callback_ = std::move(ready_callback);
-}
-
-void StateController::SetTickClockForTesting(const base::TickClock* clock) {
- DCHECK(!tick_clock_);
- tick_clock_ = clock;
-}
-
-void StateController::SetAppManagerForTesting(
- std::unique_ptr<AppManager> app_manager) {
- DCHECK(!app_manager_);
- app_manager_ = std::move(app_manager);
-}
-
-void StateController::SetLockScreenLockScreenProfileCreatorForTesting(
- std::unique_ptr<LockScreenProfileCreator> profile_creator) {
- DCHECK(!lock_screen_profile_creator_);
- lock_screen_profile_creator_ = std::move(profile_creator);
-}
-
-void StateController::Initialize() {
- if (!tick_clock_)
- tick_clock_ = base::DefaultTickClock::GetInstance();
-
- // The tray action ptr might be set previously if the client was being created
-
- if (!tray_action_)
- ash::BindTrayAction(tray_action_.BindNewPipeAndPassReceiver());
- mojo::PendingRemote<ash::mojom::TrayActionClient> client;
- receiver_.Bind(client.InitWithNewPipeAndPassReceiver());
- tray_action_->SetClient(std::move(client), lock_screen_note_state_);
-}
-
-void StateController::SetPrimaryProfile(Profile* profile) {
- const user_manager::User* user =
- ash::ProfileHelper::Get()->GetUserByProfile(profile);
- if (!user || !user->HasGaiaAccount()) {
- if (!ready_callback_.is_null())
- std::move(ready_callback_).Run();
- return;
- }
-
- std::string key;
- if (!GetUserCryptoKey(profile, &key)) {
- LOG(ERROR) << "Failed to get crypto key for user lock screen apps.";
- return;
- }
-
- InitializeWithCryptoKey(profile, key);
- if (base::FeatureList::IsEnabled(features::kWebLockScreenApi)) {
- base::FilePath base_path;
- base::PathService::Get(chrome::DIR_USER_DATA, &base_path);
- base_path = base_path.AppendASCII("web_lock_screen_api_data");
- base_path =
- base_path.Append(ash::ProfileHelper::GetUserIdHashFromProfile(profile));
- content::LockScreenStorage::GetInstance()->Init(profile, base_path);
- }
-}
-
-void StateController::Shutdown() {
- session_observation_.Reset();
- lock_screen_data_.reset();
- if (app_manager_) {
- app_manager_->Stop();
- ResetNoteTakingWindowAndMoveToNextState(
- true /*close_window*/, CloseLockScreenNoteReason::kShutdown);
- app_manager_.reset();
- }
- first_app_run_toast_manager_.reset();
- lock_screen_profile_creator_.reset();
- focus_cycler_delegate_ = nullptr;
- power_manager_client_observation_.Reset();
- input_devices_observation_.Reset();
- receiver_.reset();
- weak_ptr_factory_.InvalidateWeakPtrs();
-}
-
-bool StateController::GetUserCryptoKey(Profile* profile, std::string* key) {
- *key = profile->GetPrefs()->GetString(kDataCryptoKeyPref);
- if (!key->empty() && base::Base64Decode(*key, key) &&
- key->size() == extensions::lock_screen_data::kAesKeySize) {
- return true;
- }
-
- *key = GenerateCryptoKey();
-
- if (key->empty())
- return false;
-
- profile->GetPrefs()->SetString(kDataCryptoKeyPref, base::Base64Encode(*key));
- return true;
-}
-
-void StateController::InitializeWithCryptoKey(Profile* profile,
- const std::string& crypto_key) {
- base::FilePath base_path;
- if (!base::PathService::Get(chrome::DIR_USER_DATA, &base_path)) {
- LOG(ERROR) << "Failed to get base storage dir for lock screen app data.";
- return;
- }
-
- lock_screen_data_ =
- std::make_unique<extensions::lock_screen_data::LockScreenItemStorage>(
- profile, g_browser_process->local_state(), crypto_key,
- base_path.AppendASCII("lock_screen_app_data"),
- base_path.AppendASCII("lock_screen_app_data_v2"));
- lock_screen_data_->SetSessionLocked(false);
-
- // Initialize a LockScreenApps instance.
- ash::LockScreenAppsFactory::GetInstance()->Get(profile);
-
- // Lock screen profile creator might have been set by a test.
- if (!lock_screen_profile_creator_) {
- lock_screen_profile_creator_ =
- std::make_unique<LockScreenProfileCreatorImpl>(profile, tick_clock_);
- }
- lock_screen_profile_creator_->Initialize();
-
- // App manager might have been set previously by a test.
- if (!app_manager_)
- app_manager_ = std::make_unique<AppManagerImpl>(tick_clock_);
- app_manager_->Initialize(profile, lock_screen_profile_creator_.get());
-
- first_app_run_toast_manager_ =
- std::make_unique<FirstAppRunToastManager>(profile);
-
- input_devices_observation_.Observe(ui::DeviceDataManager::GetInstance());
-
- // Do not start state controller if stylus input is not present as lock
- // screen notes apps are geared towards stylus.
- // State controller will observe inpt device changes and continue
- // initialization if stylus input is found.
- if (!ash::stylus_utils::HasStylusInput()) {
- stylus_input_missing_ = true;
-
- if (!ready_callback_.is_null())
- std::move(ready_callback_).Run();
- return;
- }
-
- InitializeWithStylusInputPresent();
-}
-
-void StateController::InitializeWithStylusInputPresent() {
- stylus_input_missing_ = false;
-
- power_manager_client_observation_.Observe(
- chromeos::PowerManagerClient::Get());
- session_observation_.Observe(session_manager::SessionManager::Get());
- OnSessionStateChanged();
-
- // SessionController is fully initialized at this point.
- if (!ready_callback_.is_null())
- std::move(ready_callback_).Run();
-}
-
-void StateController::AddObserver(StateObserver* observer) {
- observers_.AddObserver(observer);
-}
-
-void StateController::RemoveObserver(StateObserver* observer) {
- observers_.RemoveObserver(observer);
-}
-
-void StateController::SetFocusCyclerDelegate(FocusCyclerDelegate* delegate) {
- DCHECK(!focus_cycler_delegate_ || !delegate);
-
- if (focus_cycler_delegate_ && note_app_window_)
- focus_cycler_delegate_->UnregisterLockScreenAppFocusHandler();
-
- focus_cycler_delegate_ = delegate;
-
- if (focus_cycler_delegate_ && note_app_window_) {
- focus_cycler_delegate_->RegisterLockScreenAppFocusHandler(
- base::BindRepeating(&StateController::FocusAppWindow,
- weak_ptr_factory_.GetWeakPtr()));
- }
-}
-
-TrayActionState StateController::GetLockScreenNoteState() const {
- return lock_screen_note_state_;
-}
-
-void StateController::RequestNewLockScreenNote(LockScreenNoteOrigin origin) {
- if (lock_screen_note_state_ != TrayActionState::kAvailable)
- return;
-
- DCHECK(app_manager_->IsLockScreenAppAvailable());
-
- // Update state to launching even if app fails to launch - this is to notify
- // listeners that a lock screen note request was handled.
- UpdateLockScreenNoteState(TrayActionState::kLaunching);
-
- if (!app_manager_->LaunchLockScreenApp()) {
- UpdateLockScreenNoteState(TrayActionState::kAvailable);
- return;
- }
-}
-
-void StateController::CloseLockScreenNote(CloseLockScreenNoteReason reason) {
- ResetNoteTakingWindowAndMoveToNextState(true /*close_window*/, reason);
-}
-
-void StateController::OnSessionStateChanged() {
- TRACE_EVENT0("ui", "StateController::OnSessionStateChanged");
- if (!session_manager::SessionManager::Get()->IsScreenLocked()) {
- lock_screen_data_->SetSessionLocked(false);
- app_manager_->Stop();
- ResetNoteTakingWindowAndMoveToNextState(
- true /*close_window*/, CloseLockScreenNoteReason::kSessionUnlock);
- return;
- }
-
- // base::Unretained is safe here because |app_manager_| is owned by |this|,
- // and the callback will not be invoked after |app_manager_| goes out of
- // scope.
- app_manager_->Start(
- base::BindRepeating(&StateController::OnNoteTakingAvailabilityChanged,
- base::Unretained(this)));
- lock_screen_data_->SetSessionLocked(true);
- OnNoteTakingAvailabilityChanged();
-}
-
-void StateController::OnWindowVisibilityChanged(aura::Window* window,
- bool visible) {
- if (lock_screen_note_state_ != TrayActionState::kLaunching)
- return;
-
- if (window != note_app_window_->GetNativeWindow() || !window->IsVisible())
- return;
-
- DCHECK(note_window_observation_.IsObservingSource(window));
- note_window_observation_.Reset();
-
- UpdateLockScreenNoteState(TrayActionState::kActive);
- if (focus_cycler_delegate_) {
- focus_cycler_delegate_->RegisterLockScreenAppFocusHandler(
- base::BindRepeating(&StateController::FocusAppWindow,
- weak_ptr_factory_.GetWeakPtr()));
- }
-}
-
-void StateController::OnWindowDestroying(aura::Window* window) {
- if (window != note_app_window_->GetNativeWindow())
- return;
- ResetNoteTakingWindowAndMoveToNextState(
- false /*close_window*/, CloseLockScreenNoteReason::kAppWindowClosed);
-}
-
-void StateController::OnAppWindowAdded(extensions::AppWindow* app_window) {
- if (note_app_window_ != app_window)
- return;
- note_window_observation_.Observe(note_app_window_->GetNativeWindow());
- first_app_run_toast_manager_->RunForAppWindow(note_app_window_);
-}
-
-void StateController::OnAppWindowRemoved(extensions::AppWindow* app_window) {
- if (note_app_window_ != app_window)
- return;
- ResetNoteTakingWindowAndMoveToNextState(
- false /*close_window*/, CloseLockScreenNoteReason::kAppWindowClosed);
-}
-
-void StateController::OnInputDeviceConfigurationChanged(
- uint8_t input_device_types) {
- if ((input_device_types & ui::InputDeviceEventObserver::kTouchscreen) &&
- stylus_input_missing_ && ash::stylus_utils::HasStylusInput()) {
- InitializeWithStylusInputPresent();
- }
-}
-
-void StateController::SuspendImminent(
- power_manager::SuspendImminent::Reason reason) {
- ResetNoteTakingWindowAndMoveToNextState(true /*close_window*/,
- CloseLockScreenNoteReason::kSuspend);
-}
-
-extensions::AppWindow* StateController::CreateAppWindowForLockScreenAction(
- content::BrowserContext* context,
- const extensions::Extension* extension,
- extensions::api::app_runtime::ActionType action,
- std::unique_ptr<extensions::AppDelegate> app_delegate) {
- if (action != extensions::api::app_runtime::ActionType::kNewNote) {
- return nullptr;
- }
-
- if (note_app_window_)
- return nullptr;
-
- if (lock_screen_note_state_ != TrayActionState::kLaunching)
- return nullptr;
-
- // StateController should not be able to get into kLaunching state if the
- // lock screen profile has not been loaded, and |lock_screen_profile_creator_|
- // has |lock_screen_profile| set to null - if the lock screen profile is not
- // loaded, |app_manager_| should not report that note taking app is available,
- // so state controller should not allow note launch attempt.
- // Thus, it should be safe to assume lock screen profile is set at this point.
- DCHECK(lock_screen_profile_creator_->lock_screen_profile());
-
- if (!lock_screen_profile_creator_->lock_screen_profile()->IsSameOrParent(
- Profile::FromBrowserContext(context))) {
- return nullptr;
- }
-
- if (!extension || app_manager_->GetLockScreenAppId() != extension->id())
- return nullptr;
-
- // The ownership of the window is passed to the caller of this method.
- note_app_window_ =
- new extensions::AppWindow(context, std::move(app_delegate), extension);
- app_window_observation_.Observe(extensions::AppWindowRegistry::Get(
- lock_screen_profile_creator_->lock_screen_profile()));
- return note_app_window_;
-}
-
-bool StateController::HandleTakeFocus(content::WebContents* web_contents,
- bool reverse) {
- if (!focus_cycler_delegate_ ||
- GetLockScreenNoteState() != TrayActionState::kActive ||
- note_app_window_->web_contents() != web_contents) {
- return false;
- }
-
- focus_cycler_delegate_->HandleLockScreenAppFocusOut(reverse);
- return true;
-}
-
-void StateController::OnNoteTakingAvailabilityChanged() {
- if (!app_manager_->IsLockScreenAppAvailable() ||
- (note_app_window_ && note_app_window_->GetExtension()->id() !=
- app_manager_->GetLockScreenAppId())) {
- ResetNoteTakingWindowAndMoveToNextState(
- true /*close_window*/,
- CloseLockScreenNoteReason::kAppLockScreenSupportDisabled);
- return;
- }
-
- if (GetLockScreenNoteState() == TrayActionState::kNotAvailable)
- UpdateLockScreenNoteState(TrayActionState::kAvailable);
-}
-
-void StateController::FocusAppWindow(bool reverse) {
- // If the app window is not active, pass the focus on to the delegate..
- if (GetLockScreenNoteState() != TrayActionState::kActive) {
- focus_cycler_delegate_->HandleLockScreenAppFocusOut(reverse);
- return;
- }
-
- note_app_window_->web_contents()->FocusThroughTabTraversal(reverse);
- note_app_window_->GetBaseWindow()->Activate();
- note_app_window_->web_contents()->Focus();
-}
-
-void StateController::ResetNoteTakingWindowAndMoveToNextState(
- bool close_window,
- CloseLockScreenNoteReason reason) {
- note_window_observation_.Reset();
- app_window_observation_.Reset();
- if (first_app_run_toast_manager_)
- first_app_run_toast_manager_->Reset();
-
- if (focus_cycler_delegate_ &&
- lock_screen_note_state_ == TrayActionState::kActive) {
- focus_cycler_delegate_->UnregisterLockScreenAppFocusHandler();
- }
-
- if (note_app_window_) {
- if (close_window && note_app_window_->GetBaseWindow()) {
- // Whenever we close the window we want to immediately hide it without
- // animating, as the underlying UI implements a special animation. If we
- // also animate the window the animations will conflict.
- ::wm::SetWindowVisibilityAnimationTransition(
- note_app_window_->GetNativeWindow(), ::wm::ANIMATE_NONE);
- note_app_window_->GetBaseWindow()->Close();
- }
- note_app_window_ = nullptr;
- }
-
- UpdateLockScreenNoteState(app_manager_ &&
- app_manager_->IsLockScreenAppAvailable()
- ? TrayActionState::kAvailable
- : TrayActionState::kNotAvailable);
-}
-
-bool StateController::UpdateLockScreenNoteState(TrayActionState state) {
- const TrayActionState old_state = GetLockScreenNoteState();
- if (old_state == state)
- return false;
-
- lock_screen_note_state_ = state;
- NotifyLockScreenNoteStateChanged();
- return true;
-}
-
-void StateController::NotifyLockScreenNoteStateChanged() {
- for (auto& observer : observers_)
- observer.OnLockScreenNoteStateChanged(lock_screen_note_state_);
-
- tray_action_->UpdateLockScreenNoteState(lock_screen_note_state_);
-}
-
-} // namespace lock_screen_apps
diff --git a/chrome/browser/ash/lock_screen_apps/state_controller.h b/chrome/browser/ash/lock_screen_apps/state_controller.h
deleted file mode 100644
index f4b7f0b..0000000
--- a/chrome/browser/ash/lock_screen_apps/state_controller.h
+++ /dev/null
@@ -1,279 +0,0 @@
-// Copyright 2017 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_
-#define CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_
-
-#include <stdint.h>
-#include <memory>
-#include <string>
-
-#include "ash/public/mojom/tray_action.mojom-forward.h"
-#include "ash/public/mojom/tray_action.mojom-shared.h"
-#include "ash/public/mojom/tray_action.mojom.h"
-#include "base/functional/callback_forward.h"
-#include "base/memory/raw_ptr.h"
-#include "base/memory/weak_ptr.h"
-#include "base/observer_list.h"
-#include "base/scoped_observation.h"
-#include "chromeos/dbus/power/power_manager_client.h"
-#include "chromeos/dbus/power_manager/suspend.pb.h"
-#include "components/session_manager/core/session_manager.h"
-#include "components/session_manager/core/session_manager_observer.h"
-#include "extensions/browser/app_window/app_window_registry.h"
-#include "extensions/common/api/app_runtime.h"
-#include "mojo/public/cpp/bindings/pending_remote.h"
-#include "mojo/public/cpp/bindings/receiver.h"
-#include "mojo/public/cpp/bindings/remote.h"
-#include "ui/aura/window.h"
-#include "ui/aura/window_observer.h"
-#include "ui/events/devices/device_data_manager.h"
-#include "ui/events/devices/input_device_event_observer.h"
-
-class PrefRegistrySimple;
-class Profile;
-
-namespace base {
-class TickClock;
-}
-
-namespace content {
-class BrowserContext;
-class WebContents;
-} // namespace content
-
-namespace extensions {
-class AppDelegate;
-class AppWindow;
-class Extension;
-
-namespace lock_screen_data {
-class LockScreenItemStorage;
-}
-} // namespace extensions
-
-namespace lock_screen_apps {
-
-class AppManager;
-class FirstAppRunToastManager;
-class FocusCyclerDelegate;
-class LockScreenProfileCreator;
-class StateObserver;
-
-// Manages state of lock screen action handler apps, and notifies
-// interested parties as the state changes.
-// Currently assumes single supported action - NEW_NOTE.
-class StateController : public ash::mojom::TrayActionClient,
- public session_manager::SessionManagerObserver,
- public aura::WindowObserver,
- public extensions::AppWindowRegistry::Observer,
- public ui::InputDeviceEventObserver,
- public chromeos::PowerManagerClient::Observer {
- public:
- // Returns the global StateController instance.
- static StateController* Get();
-
- static void RegisterProfilePrefs(PrefRegistrySimple* pref_registry);
-
- // Note that only one StateController is allowed per process. Creating a
- // StateController will set global instance ptr that can be accessed using
- // |Get|. This pointer will be reset when the StateController is destroyed.
- StateController();
-
- StateController(const StateController&) = delete;
- StateController& operator=(const StateController&) = delete;
-
- ~StateController() override;
-
- // Sets the tray action that should be used by |StateController|.
- // Has to be called before |Initialize|.
- void SetTrayActionForTesting(
- mojo::PendingRemote<ash::mojom::TrayAction> tray_action);
- void FlushTrayActionForTesting();
- // Sets the callback that will be run when the state controller is fully
- // initialized and ready for action.
- void SetReadyCallbackForTesting(base::OnceClosure ready_callback);
- // Sets the tick clock to be used in tests.
- void SetTickClockForTesting(const base::TickClock* clock);
- // Sets test AppManager implementation. Should be called before
- // |SetPrimaryProfile|
- void SetAppManagerForTesting(std::unique_ptr<AppManager> app_manager);
- // Sets test LockScreenProfileCreator implementation. Should be called before
- // |SetPrimaryProfile|
- void SetLockScreenLockScreenProfileCreatorForTesting(
- std::unique_ptr<LockScreenProfileCreator> profile_creator);
-
- // Initializes mojo bindings for the StateController - it creates binding to
- // ash's tray action interface and sets this object as the interface's client.
- void Initialize();
- void SetPrimaryProfile(Profile* profile);
-
- // Shuts down the state controller, reseting all dependencies on profiles.
- // Should be called on global instance before profile destruction starts.
- // TODO(tbarzic): Consider removing this after lock screen implementation
- // moves to ash - the main reason the method is needed is to enable
- // SigninScreenHandler to safely remove itself as an observer on its
- // destruction (which might happen after state controller has to be
- // shutdown). When this is not the case anymore StateController::Shutdown
- // usage can be replaced with destructing the StateController instance.
- // https://crbug.com/741145
- void Shutdown();
-
- void AddObserver(StateObserver* observer);
- void RemoveObserver(StateObserver* observer);
-
- // Sets the focus cycler delegate the state controller should use to pass on
- // from and give focus to the active lock screen app window.
- void SetFocusCyclerDelegate(FocusCyclerDelegate* delegate);
-
- // Gets current state assiciated with the lock screen note action.
- ash::mojom::TrayActionState GetLockScreenNoteState() const;
-
- // ash::mojom::TrayActionClient:
- void RequestNewLockScreenNote(
- ash::mojom::LockScreenNoteOrigin origin) override;
- void CloseLockScreenNote(
- ash::mojom::CloseLockScreenNoteReason reason) override;
-
- // session_manager::SessionManagerObserver:
- void OnSessionStateChanged() override;
-
- // aura::WindowObserver:
- void OnWindowVisibilityChanged(aura::Window* window, bool visible) override;
- void OnWindowDestroying(aura::Window* window) override;
-
- // extensions::AppWindowRegistry::Observer:
- void OnAppWindowAdded(extensions::AppWindow* app_window) override;
- void OnAppWindowRemoved(extensions::AppWindow* app_window) override;
-
- // ui::InputDeviceEventObserver:
- void OnInputDeviceConfigurationChanged(uint8_t input_device_types) override;
-
- // chromeos::PowerManagerClient::Observer
- void SuspendImminent(power_manager::SuspendImminent::Reason reason) override;
-
- // Creates and registers an app window as action handler for the action on
- // Chrome OS lock screen. The ownership of the returned app window is passed
- // to the caller.
- // If the app is not allowed to create an app window for handling the action
- // on lock screen (e.g. if the action has not been requested), it will return
- // nullptr.
- extensions::AppWindow* CreateAppWindowForLockScreenAction(
- content::BrowserContext* context,
- const extensions::Extension* extension,
- extensions::api::app_runtime::ActionType action,
- std::unique_ptr<extensions::AppDelegate> app_delegate);
-
- // Should be called when the active app window is tabbed through. If needed,
- // the method will take focus from the app window and pass it on using
- // |focus_cycler_delegate_|.
- // Returns whether the focus has been taken from the app window.
- bool HandleTakeFocus(content::WebContents* web_contents, bool reverse);
-
- FirstAppRunToastManager* first_app_run_toast_manager() {
- return first_app_run_toast_manager_.get();
- }
-
- private:
- // Gets the encryption key that should be used to encrypt user data created on
- // the lock screen. If a key hadn't previously been created and saved to
- // user prefs, a new key is created and saved.
- // |crypto_key| - the found/created key.
- // Returns whether |crypto_key| was successfully retrieved.
- bool GetUserCryptoKey(Profile* profile, std::string* crypto_key);
-
- // Continues lock screen apps initialization with primary user profile and
- // associated encryption key to be used for encrypting user data created in
- // lock screen context.
- void InitializeWithCryptoKey(Profile* profile, const std::string& crypto_key);
-
- // Continues lock screen apps initialization. Should be called when stylus
- // input has been detected.
- void InitializeWithStylusInputPresent();
-
- // Called when app manager reports that note taking availability has changed.
- void OnNoteTakingAvailabilityChanged();
-
- // If there is an app window registered as a handler for note taking action
- // on lock screen, unregisters the window, and closes is if |close_window| is
- // set. It changes the current state to kAvailable or kNotAvailable, depending
- // on whether lock screen note taking action can still be handled.
- void ResetNoteTakingWindowAndMoveToNextState(
- bool close_window,
- ash::mojom::CloseLockScreenNoteReason reason);
-
- // Requests lock screen note action state change to |state|.
- // Returns whether the action state has changed.
- bool UpdateLockScreenNoteState(ash::mojom::TrayActionState state);
-
- // Notifies observers that the lock screen note action state changed.
- void NotifyLockScreenNoteStateChanged();
-
- // Passed as a focus handler to |focus_cycler_delegate_| when the assiciated
- // app window is visible (active or in background).
- // It focuses the app window.
- void FocusAppWindow(bool reverse);
-
- // Lock screen note action state.
- ash::mojom::TrayActionState lock_screen_note_state_ =
- ash::mojom::TrayActionState::kNotAvailable;
-
- base::ObserverList<StateObserver>::Unchecked observers_;
-
- mojo::Receiver<ash::mojom::TrayActionClient> receiver_{this};
- mojo::Remote<ash::mojom::TrayAction> tray_action_;
-
- std::unique_ptr<LockScreenProfileCreator> lock_screen_profile_creator_;
-
- // Whether lock screen apps initialization was stopped due to stylus input
- // missing (or stylus not being otherwise enabled). If stylus availability
- // changes due to stylus input being detected, initialization will continue.
- bool stylus_input_missing_ = false;
-
- std::unique_ptr<extensions::lock_screen_data::LockScreenItemStorage>
- lock_screen_data_;
-
- std::unique_ptr<AppManager> app_manager_;
-
- raw_ptr<FocusCyclerDelegate> focus_cycler_delegate_ = nullptr;
-
- raw_ptr<extensions::AppWindow> note_app_window_ = nullptr;
-
- // Used to show first lock screen app run (toast) dialog when an app window
- // is first launched for an app.
- // NOTE: The manager can be used for every app launch - before showing the
- // toast dialog, the manager will bail out if it determines that the toast
-
- std::unique_ptr<FirstAppRunToastManager> first_app_run_toast_manager_;
-
- base::ScopedObservation<aura::Window, aura::WindowObserver>
- note_window_observation_{this};
- base::ScopedObservation<extensions::AppWindowRegistry,
- extensions::AppWindowRegistry::Observer>
- app_window_observation_{this};
- base::ScopedObservation<session_manager::SessionManager,
- session_manager::SessionManagerObserver>
- session_observation_{this};
- base::ScopedObservation<ui::DeviceDataManager, ui::InputDeviceEventObserver>
- input_devices_observation_{this};
- base::ScopedObservation<chromeos::PowerManagerClient,
- chromeos::PowerManagerClient::Observer>
- power_manager_client_observation_{this};
-
- // If set, this callback will be run when the state controller is fully
- // initialized. It can be used to throttle tests until state controller
- // is ready for action - i.e. until the state controller starts reacting
- // to session / app manager changes.
- base::OnceClosure ready_callback_;
-
- // The clock used to keep track of time, for example to report app window
- // lifetime metrics.
- raw_ptr<const base::TickClock> tick_clock_ = nullptr;
-
- base::WeakPtrFactory<StateController> weak_ptr_factory_{this};
-};
-
-} // namespace lock_screen_apps
-
-#endif // CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_STATE_CONTROLLER_H_
diff --git a/chrome/browser/ash/lock_screen_apps/state_observer.h b/chrome/browser/ash/lock_screen_apps/state_observer.h
deleted file mode 100644
index 2dea417..0000000
--- a/chrome/browser/ash/lock_screen_apps/state_observer.h
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2017 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_STATE_OBSERVER_H_
-#define CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_STATE_OBSERVER_H_
-
-#include "ash/public/mojom/tray_action.mojom.h"
-
-namespace lock_screen_apps {
-
-// Interface that can be used to observe lock screen apps state.
-class StateObserver {
- public:
- virtual ~StateObserver() {}
-
- // Invoked when the state of support for app provided lock screen actions
- // changes.
- virtual void OnLockScreenNoteStateChanged(
- ash::mojom::TrayActionState state) = 0;
-};
-
-} // namespace lock_screen_apps
-
-#endif // CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_STATE_OBSERVER_H_
diff --git a/chrome/browser/ash/lock_screen_apps/toast_dialog_view.cc b/chrome/browser/ash/lock_screen_apps/toast_dialog_view.cc
deleted file mode 100644
index da29e17..0000000
--- a/chrome/browser/ash/lock_screen_apps/toast_dialog_view.cc
+++ /dev/null
@@ -1,98 +0,0 @@
-// Copyright 2017 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/ash/lock_screen_apps/toast_dialog_view.h"
-
-#include <memory>
-#include <utility>
-
-#include "ash/public/cpp/shell_window_ids.h"
-#include "ash/utility/wm_util.h"
-#include "chrome/grit/generated_resources.h"
-#include "ui/aura/window.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/metadata/metadata_impl_macros.h"
-#include "ui/base/mojom/dialog_button.mojom.h"
-#include "ui/base/mojom/ui_base_types.mojom-shared.h"
-#include "ui/gfx/geometry/rect.h"
-#include "ui/gfx/geometry/size.h"
-#include "ui/views/bubble/bubble_border.h"
-#include "ui/views/bubble/bubble_frame_view.h"
-#include "ui/views/controls/label.h"
-#include "ui/views/layout/fill_layout.h"
-
-namespace lock_screen_apps {
-
-namespace {
-
-constexpr int kDialogWidthDp = 292;
-
-constexpr int kDialogMessageMarginTopDp = 0;
-constexpr int kDialogMessageMarginStartDp = 16;
-constexpr int kDialogMessageMarginBottomDp = 18;
-constexpr int kDialogMessageMarginEndDp = 12;
-constexpr int kDialogMessageLineHeightDp = 20;
-
-constexpr int kDialogTitleMarginTopDp = 14;
-constexpr int kDialogTitleMarginStartDp = 16;
-constexpr int kDialogTitleMarginBottomDp = 5;
-constexpr int kDialogTitleMarginEndDp = 0;
-
-} // namespace
-
-ToastDialogView::ToastDialogView(const std::u16string& app_name,
- base::OnceClosure dismissed_callback) {
- SetButtons(static_cast<int>(ui::mojom::DialogButton::kNone));
- SetCloseCallback(std::move(dismissed_callback));
- SetModalType(ui::mojom::ModalType::kNone);
- SetShowCloseButton(true);
- SetTitle(l10n_util::GetStringFUTF16(
- IDS_LOCK_SCREEN_NOTE_APP_TOAST_DIALOG_TITLE, app_name));
-
- SetArrow(views::BubbleBorder::NONE);
- set_margins(gfx::Insets::TLBR(
- kDialogMessageMarginTopDp, kDialogMessageMarginStartDp,
- kDialogMessageMarginBottomDp, kDialogMessageMarginEndDp));
- set_title_margins(
- gfx::Insets::TLBR(kDialogTitleMarginTopDp, kDialogTitleMarginStartDp,
- kDialogTitleMarginBottomDp, kDialogTitleMarginEndDp));
- set_shadow(views::BubbleBorder::STANDARD_SHADOW);
-
- SetLayoutManager(std::make_unique<views::FillLayout>());
- auto* label = new views::Label(l10n_util::GetStringFUTF16(
- IDS_LOCK_SCREEN_NOTE_APP_TOAST_DIALOG_MESSAGE, app_name));
- label->SetMultiLine(true);
- label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- label->SetEnabledColor(SkColorSetARGB(138, 0, 0, 0));
- label->SetLineHeight(kDialogMessageLineHeightDp);
- label->SetFontList(views::Label::GetDefaultFontList().Derive(
- 1, gfx::Font::NORMAL, gfx::Font::Weight::NORMAL));
- label->SetPreferredSize(
- gfx::Size(kDialogWidthDp, label->GetHeightForWidth(kDialogWidthDp)));
- label->SizeToPreferredSize();
-
- AddChildView(label);
-}
-
-ToastDialogView::~ToastDialogView() = default;
-
-void ToastDialogView::AddedToWidget() {
- std::unique_ptr<views::Label> title =
- views::BubbleFrameView::CreateDefaultTitleLabel(GetWindowTitle());
- title->SetFontList(views::Label::GetDefaultFontList().Derive(
- 3, gfx::Font::NORMAL, gfx::Font::Weight::MEDIUM));
- GetBubbleFrameView()->SetTitleView(std::move(title));
-}
-
-void ToastDialogView::OnBeforeBubbleWidgetInit(
- views::Widget::InitParams* params,
- views::Widget* widget) const {
- ash_util::SetupWidgetInitParamsForContainer(
- params, ash::kShellWindowId_SettingBubbleContainer);
-}
-
-BEGIN_METADATA(ToastDialogView)
-END_METADATA
-
-} // namespace lock_screen_apps
diff --git a/chrome/browser/ash/lock_screen_apps/toast_dialog_view.h b/chrome/browser/ash/lock_screen_apps/toast_dialog_view.h
deleted file mode 100644
index 31d17064..0000000
--- a/chrome/browser/ash/lock_screen_apps/toast_dialog_view.h
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2017 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_TOAST_DIALOG_VIEW_H_
-#define CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_TOAST_DIALOG_VIEW_H_
-
-#include <string>
-
-#include "base/functional/callback.h"
-#include "ui/base/metadata/metadata_header_macros.h"
-#include "ui/views/bubble/bubble_dialog_delegate_view.h"
-
-namespace lock_screen_apps {
-
-// The system modal bubble dialog shown to the user when a lock screen app is
-// first launched from the lock screen. The dialog will block the app UI until
-// the user closes it.
-class ToastDialogView : public views::BubbleDialogDelegateView {
- METADATA_HEADER(ToastDialogView, views::BubbleDialogDelegateView)
-
- public:
- ToastDialogView(const std::u16string& app_name,
- base::OnceClosure dismissed_callback);
- ToastDialogView(const ToastDialogView&) = delete;
- ToastDialogView& operator=(const ToastDialogView&) = delete;
- ~ToastDialogView() override;
-
- // views::BubbleDialogDelegateView:
- void AddedToWidget() override;
- void OnBeforeBubbleWidgetInit(views::Widget::InitParams* params,
- views::Widget* widget) const override;
-
- private:
- // Callback to be called when the user closes the dialog.
- base::OnceClosure dismissed_callback_;
-};
-
-} // namespace lock_screen_apps
-
-#endif // CHROME_BROWSER_ASH_LOCK_SCREEN_APPS_TOAST_DIALOG_VIEW_H_
diff --git a/chrome/browser/ash/login/lock/BUILD.gn b/chrome/browser/ash/login/lock/BUILD.gn
index 08ae965..7c345689 100644
--- a/chrome/browser/ash/login/lock/BUILD.gn
+++ b/chrome/browser/ash/login/lock/BUILD.gn
@@ -19,7 +19,6 @@
"//ash/public/cpp",
"//base",
"//chrome/browser:browser_public_dependencies",
- "//chrome/browser/ash/lock_screen_apps",
"//chromeos/ash/components/login/auth",
"//chromeos/ash/components/login/auth/public:authpublic",
"//chromeos/ash/components/login/auth/public:challenge_response_key",
@@ -180,7 +179,6 @@
"//ash/public/cpp",
"//base",
"//chrome/browser",
- "//chrome/browser/ash/lock_screen_apps",
"//chrome/browser/ash/login/users:test_support",
"//chrome/browser/ash/settings:test_support",
"//chrome/browser/ui/ash/assistant",
diff --git a/chrome/browser/ash/login/lock/screen_locker_unittest.cc b/chrome/browser/ash/login/lock/screen_locker_unittest.cc
index 9f82111..4fe08f0 100644
--- a/chrome/browser/ash/login/lock/screen_locker_unittest.cc
+++ b/chrome/browser/ash/login/lock/screen_locker_unittest.cc
@@ -13,7 +13,6 @@
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
-#include "chrome/browser/ash/lock_screen_apps/state_controller.h"
#include "chrome/browser/ash/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/ash/profiles/profile_helper.h"
#include "chrome/browser/ash/settings/device_settings_test_helper.h"
@@ -157,8 +156,6 @@
// Needed for main loop and posting async tasks.
content::BrowserTaskEnvironment task_environment_;
- // ViewsScreenLocker dependencies:
- lock_screen_apps::StateController state_controller_;
// * MojoSystemInfoDispatcher dependencies:
ScopedTestingCrosSettings scoped_testing_cros_settings_;
system::ScopedFakeStatisticsProvider fake_statictics_provider_;
diff --git a/chrome/browser/ash/login/lock/views_screen_locker.cc b/chrome/browser/ash/login/lock/views_screen_locker.cc
index a5b554af..6d517f74 100644
--- a/chrome/browser/ash/login/lock/views_screen_locker.cc
+++ b/chrome/browser/ash/login/lock/views_screen_locker.cc
@@ -18,7 +18,6 @@
#include "base/metrics/histogram_macros.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
-#include "chrome/browser/ash/lock_screen_apps/state_controller.h"
#include "chrome/browser/ash/login/challenge_response_auth_keys_loader.h"
#include "chrome/browser/ash/login/helper.h"
#include "chrome/browser/ash/login/lock/screen_locker.h"
@@ -57,7 +56,6 @@
}
ViewsScreenLocker::~ViewsScreenLocker() {
- lock_screen_apps::StateController::Get()->SetFocusCyclerDelegate(nullptr);
LoginScreenClientImpl::Get()->SetDelegate(nullptr);
}
@@ -88,7 +86,6 @@
user_selection_screen_->InitEasyUnlock();
UMA_HISTOGRAM_TIMES("LockScreen.LockReady",
base::TimeTicks::Now() - lock_time_);
- lock_screen_apps::StateController::Get()->SetFocusCyclerDelegate(this);
}
void ViewsScreenLocker::OnAshLockAnimationFinished() {
@@ -146,11 +143,8 @@
}
bool ViewsScreenLocker::HandleFocusLockScreenApps(bool reverse) {
- if (lock_screen_app_focus_handler_.is_null())
- return false;
-
- lock_screen_app_focus_handler_.Run(reverse);
- return true;
+ // TODO(crbug.com/376354347): Remove this method.
+ return false;
}
void ViewsScreenLocker::HandleFocusOobeDialog() {
@@ -171,19 +165,6 @@
}
}
-void ViewsScreenLocker::RegisterLockScreenAppFocusHandler(
- const LockScreenAppFocusCallback& focus_handler) {
- lock_screen_app_focus_handler_ = focus_handler;
-}
-
-void ViewsScreenLocker::UnregisterLockScreenAppFocusHandler() {
- lock_screen_app_focus_handler_.Reset();
-}
-
-void ViewsScreenLocker::HandleLockScreenAppFocusOut(bool reverse) {
- LoginScreen::Get()->GetModel()->HandleFocusLeavingLockScreenApps(reverse);
-}
-
void ViewsScreenLocker::OnAuthenticated(
const AccountId& account_id,
base::OnceCallback<void(bool)> success_callback,
diff --git a/chrome/browser/ash/login/lock/views_screen_locker.h b/chrome/browser/ash/login/lock/views_screen_locker.h
index e8fd678a..29f94c9 100644
--- a/chrome/browser/ash/login/lock/views_screen_locker.h
+++ b/chrome/browser/ash/login/lock/views_screen_locker.h
@@ -13,7 +13,6 @@
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
-#include "chrome/browser/ash/lock_screen_apps/focus_cycler_delegate.h"
#include "chrome/browser/ash/login/help_app_launcher.h"
#include "chrome/browser/ui/ash/login/login_screen_client_impl.h"
#include "chromeos/ash/components/cryptohome/auth_factor.h"
@@ -30,8 +29,7 @@
// method calls coming from ash into chrome.
// It also handles calls from chrome into ash (views-based lockscreen).
class ViewsScreenLocker : public LoginScreenClientImpl::Delegate,
- public chromeos::PowerManagerClient::Observer,
- public lock_screen_apps::FocusCyclerDelegate {
+ public chromeos::PowerManagerClient::Observer {
public:
ViewsScreenLocker();
@@ -66,12 +64,6 @@
// PowerManagerClient::Observer:
void SuspendDone(base::TimeDelta sleep_duration) override;
- // lock_screen_apps::FocusCyclerDelegate:
- void RegisterLockScreenAppFocusHandler(
- const LockScreenAppFocusCallback& focus_handler) override;
- void UnregisterLockScreenAppFocusHandler() override;
- void HandleLockScreenAppFocusOut(bool reverse) override;
-
private:
void OnAuthenticated(const AccountId& account_id,
base::OnceCallback<void(bool)> success_callback,
@@ -91,10 +83,6 @@
// Time when lock was initiated, required for metrics.
base::TimeTicks lock_time_;
- // Callback registered as a lock screen apps focus handler - it should be
- // called to hand focus over to lock screen apps.
- LockScreenAppFocusCallback lock_screen_app_focus_handler_;
-
// Fetches system information and sends it to the UI over mojo.
std::unique_ptr<MojoSystemInfoDispatcher> system_info_updater_;
diff --git a/chrome/browser/ash/login/session/user_session_initializer.cc b/chrome/browser/ash/login/session/user_session_initializer.cc
index 4d7e7e06..2f3ef0ba 100644
--- a/chrome/browser/ash/login/session/user_session_initializer.cc
+++ b/chrome/browser/ash/login/session/user_session_initializer.cc
@@ -28,7 +28,6 @@
#include "chrome/browser/ash/eche_app/eche_app_manager_factory.h"
#include "chrome/browser/ash/guest_os/guest_os_session_tracker.h"
#include "chrome/browser/ash/guest_os/guest_os_session_tracker_factory.h"
-#include "chrome/browser/ash/lock_screen_apps/state_controller.h"
#include "chrome/browser/ash/login/startup_utils.h"
#include "chrome/browser/ash/phonehub/phone_hub_manager_factory.h"
#include "chrome/browser/ash/plugin_vm/plugin_vm_manager.h"
@@ -269,8 +268,6 @@
++call_count;
CHECK_EQ(call_count, 1);
- lock_screen_apps::StateController::Get()->SetPrimaryProfile(profile);
-
if (user->GetType() == user_manager::UserType::kRegular) {
// App install logs for extensions and ARC++ are uploaded via the user's
// communication channel with the management server. This channel exists for
diff --git a/chrome/browser/ash/main_parts/BUILD.gn b/chrome/browser/ash/main_parts/BUILD.gn
index 11bcc37..b04333e 100644
--- a/chrome/browser/ash/main_parts/BUILD.gn
+++ b/chrome/browser/ash/main_parts/BUILD.gn
@@ -55,7 +55,6 @@
"//chrome/browser/ash/input_method",
"//chrome/browser/ash/lobster",
"//chrome/browser/ash/locale",
- "//chrome/browser/ash/lock_screen_apps",
"//chrome/browser/ash/logging",
"//chrome/browser/ash/login",
"//chrome/browser/ash/login/demo_mode",
diff --git a/chrome/browser/ash/main_parts/chrome_browser_main_parts_ash.cc b/chrome/browser/ash/main_parts/chrome_browser_main_parts_ash.cc
index 5438c22..45e97d7 100644
--- a/chrome/browser/ash/main_parts/chrome_browser_main_parts_ash.cc
+++ b/chrome/browser/ash/main_parts/chrome_browser_main_parts_ash.cc
@@ -106,7 +106,6 @@
#include "chrome/browser/ash/input_method/input_method_configuration.h"
#include "chrome/browser/ash/lobster/lobster_client_factory_impl.h"
#include "chrome/browser/ash/locale/startup_settings_cache.h"
-#include "chrome/browser/ash/lock_screen_apps/state_controller.h"
#include "chrome/browser/ash/logging/logging.h"
#include "chrome/browser/ash/login/demo_mode/demo_session.h"
#include "chrome/browser/ash/login/helper.h"
@@ -1033,10 +1032,6 @@
// loading the default profile).
keyboard::InitializeKeyboardResources();
- lock_screen_apps_state_controller_ =
- std::make_unique<lock_screen_apps::StateController>();
- lock_screen_apps_state_controller_->Initialize();
-
// Always construct BrowserManager, even if the lacros flag is disabled, so
// it can do cleanup work if needed. Initialized in PreProfileInit because the
// profile-keyed service AppService can call into it.
@@ -1525,10 +1520,6 @@
// SessionControllerClientImpl is destroyed there.
browser_manager_->RemoveObserver(SessionControllerClientImpl::Get());
- if (lock_screen_apps_state_controller_) {
- lock_screen_apps_state_controller_->Shutdown();
- }
-
// This must be shut down before |arc_service_launcher_|.
if (pre_profile_init_called_) {
NoteTakingHelper::Shutdown();
diff --git a/chrome/browser/ash/main_parts/chrome_browser_main_parts_ash.h b/chrome/browser/ash/main_parts/chrome_browser_main_parts_ash.h
index fd56bed..4721c73 100644
--- a/chrome/browser/ash/main_parts/chrome_browser_main_parts_ash.h
+++ b/chrome/browser/ash/main_parts/chrome_browser_main_parts_ash.h
@@ -47,10 +47,6 @@
class CrostiniUnsupportedActionNotifier;
} // namespace crostini
-namespace lock_screen_apps {
-class StateController;
-}
-
namespace policy {
class LockToSingleUserManager;
} // namespace policy
@@ -227,8 +223,6 @@
std::unique_ptr<ChromeKeyboardControllerClient>
chrome_keyboard_controller_client_;
- std::unique_ptr<lock_screen_apps::StateController>
- lock_screen_apps_state_controller_;
std::unique_ptr<crosapi::CrosapiManager> crosapi_manager_;
std::unique_ptr<crosapi::BrowserManager> browser_manager_;
diff --git a/chrome/browser/ash/note_taking/note_taking_helper.cc b/chrome/browser/ash/note_taking/note_taking_helper.cc
index 7d12b2c..efebc78b 100644
--- a/chrome/browser/ash/note_taking/note_taking_helper.cc
+++ b/chrome/browser/ash/note_taking/note_taking_helper.cc
@@ -48,7 +48,6 @@
#include "chrome/browser/apps/app_service/launch_utils.h"
#include "chrome/browser/ash/arc/arc_util.h"
#include "chrome/browser/ash/arc/session/arc_session_manager.h"
-#include "chrome/browser/ash/lock_screen_apps/lock_screen_apps.h"
#include "chrome/browser/ash/note_taking/note_taking_controller_client.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
@@ -301,11 +300,8 @@
std::vector<std::string> app_ids = GetNoteTakingAppIds(profile);
for (const auto& app_id : app_ids) {
- LockScreenAppSupport lock_screen_support =
- LockScreenApps::GetSupport(profile, app_id);
infos.push_back(NoteTakingAppInfo{GetAppName(profile, app_id), app_id,
- /*preferred=*/false,
- lock_screen_support});
+ /*preferred=*/false});
}
if (arc::IsArcAllowedForProfile(profile))
@@ -345,30 +341,6 @@
observer.OnPreferredNoteTakingAppUpdated(profile);
}
-bool NoteTakingHelper::SetPreferredAppEnabledOnLockScreen(Profile* profile,
- bool enabled) {
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- DCHECK(profile);
-
- std::string app_id = profile->GetPrefs()->GetString(prefs::kNoteTakingAppId);
- if (app_id.empty())
- return false;
-
- LockScreenApps* lock_screen_apps =
- LockScreenAppsFactory::GetInstance()->Get(profile);
- if (!lock_screen_apps)
- return false;
-
- bool changed = lock_screen_apps->SetAppEnabledOnLockScreen(app_id, enabled);
- if (!changed)
- return false;
-
- for (Observer& observer : observers_)
- observer.OnPreferredNoteTakingAppUpdated(profile);
-
- return true;
-}
-
bool NoteTakingHelper::IsAppAvailable(Profile* profile) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(profile);
@@ -599,8 +571,7 @@
android_apps_.reserve(handlers.size());
for (const auto& it : handlers) {
android_apps_.emplace_back(
- NoteTakingAppInfo{it->name, it->package_name, false,
- LockScreenAppSupport::kNotSupported});
+ NoteTakingAppInfo{it->name, it->package_name, false});
}
android_apps_received_ = true;
diff --git a/chrome/browser/ash/note_taking/note_taking_helper.h b/chrome/browser/ash/note_taking/note_taking_helper.h
index 4a0f93d..3cedfe7 100644
--- a/chrome/browser/ash/note_taking/note_taking_helper.h
+++ b/chrome/browser/ash/note_taking/note_taking_helper.h
@@ -17,7 +17,6 @@
#include "base/scoped_multi_source_observation.h"
#include "base/scoped_observation.h"
#include "chrome/browser/ash/arc/session/arc_session_manager_observer.h"
-#include "chrome/browser/ash/lock_screen_apps/lock_screen_apps.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_manager_observer.h"
#include "components/arc/intent_helper/arc_intent_helper_bridge.h"
@@ -58,9 +57,6 @@
// True if this is the preferred note-taking app.
bool preferred;
-
- // Whether the app supports use on the Chrome OS lock screen.
- LockScreenAppSupport lock_screen_support;
};
// Singleton class used to launch a note-taking app.
@@ -171,11 +167,6 @@
// NoteTakingAppInfo object.
void SetPreferredApp(Profile* profile, const std::string& app_id);
- // Sets whether the preferred note taking app is allowed to run on the lock
- // screen.
- // Returns whether the app status changed.
- bool SetPreferredAppEnabledOnLockScreen(Profile* profile, bool enabled);
-
// Returns true if an app that can be used to take notes is available. UI
// surfaces that call LaunchAppForNewNote() should be hidden otherwise.
bool IsAppAvailable(Profile* profile);
diff --git a/chrome/browser/ash/preferences/preferences.cc b/chrome/browser/ash/preferences/preferences.cc
index 6f1d5f0..99c8aea 100644
--- a/chrome/browser/ash/preferences/preferences.cc
+++ b/chrome/browser/ash/preferences/preferences.cc
@@ -375,9 +375,6 @@
// Don't sync the note-taking app; it may not be installed on other devices.
registry->RegisterStringPref(::prefs::kNoteTakingAppId, std::string());
- registry->RegisterBooleanPref(::prefs::kRestoreLastLockScreenNote, true);
- registry->RegisterDictionaryPref(
- ::prefs::kNoteTakingAppsLockScreenToastShown);
registry->RegisterBooleanPref(::prefs::kLockScreenAutoStartOnlineReauth,
false);
diff --git a/chrome/browser/extensions/api/settings_private/prefs_util.cc b/chrome/browser/extensions/api/settings_private/prefs_util.cc
index 37a471c..0a24ab09 100644
--- a/chrome/browser/extensions/api/settings_private/prefs_util.cc
+++ b/chrome/browser/extensions/api/settings_private/prefs_util.cc
@@ -907,8 +907,6 @@
settings_api::PrefType::kBoolean;
(*s_allowlist)[ash::kAttestationForContentProtectionEnabled] =
settings_api::PrefType::kBoolean;
- (*s_allowlist)[prefs::kRestoreLastLockScreenNote] =
- settings_api::PrefType::kBoolean;
(*s_allowlist)[ash::kDevicePeripheralDataAccessEnabled] =
settings_api::PrefType::kBoolean;
(*s_allowlist)[::ash::prefs::kLocalStateDevicePeripheralDataAccessEnabled] =
diff --git a/chrome/browser/policy/configuration_policy_handler_list_factory.cc b/chrome/browser/policy/configuration_policy_handler_list_factory.cc
index 2ab068c..c9be388f 100644
--- a/chrome/browser/policy/configuration_policy_handler_list_factory.cc
+++ b/chrome/browser/policy/configuration_policy_handler_list_factory.cc
@@ -2982,9 +2982,6 @@
handlers->AddHandler(std::make_unique<DefaultGeolocationPolicyHandler>());
handlers->AddHandler(
std::make_unique<DeviceLoginScreenGeolocationAccessLevelPolicyHandler>());
- handlers->AddHandler(std::make_unique<extensions::ExtensionListPolicyHandler>(
- key::kNoteTakingAppsLockScreenAllowlist,
- prefs::kNoteTakingAppsLockScreenAllowlist, false /*allow_wildcards*/));
handlers->AddHandler(std::make_unique<BooleanDisablingPolicyHandler>(
key::kSecondaryGoogleAccountSigninAllowed,
::account_manager::prefs::kSecondaryGoogleAccountSigninAllowed));
diff --git a/chrome/browser/prefs/BUILD.gn b/chrome/browser/prefs/BUILD.gn
index d12bd179..156a2f34 100644
--- a/chrome/browser/prefs/BUILD.gn
+++ b/chrome/browser/prefs/BUILD.gn
@@ -162,7 +162,6 @@
"//chrome/browser/ash/floating_workspace:utils",
"//chrome/browser/ash/guest_os",
"//chrome/browser/ash/kerberos",
- "//chrome/browser/ash/lock_screen_apps",
"//chrome/browser/ash/login",
"//chrome/browser/ash/login/demo_mode",
"//chrome/browser/ash/login/quick_unlock",
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index faf4d34..0561627 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -378,7 +378,6 @@
#include "chrome/browser/ash/guest_os/guest_id.h"
#include "chrome/browser/ash/guest_os/guest_os_pref_names.h"
#include "chrome/browser/ash/guest_os/guest_os_terminal.h"
-#include "chrome/browser/ash/lock_screen_apps/state_controller.h"
#include "chrome/browser/ash/login/quick_unlock/fingerprint_storage.h"
#include "chrome/browser/ash/login/quick_unlock/pin_storage_prefs.h"
#include "chrome/browser/ash/login/quick_unlock/quick_unlock_utils.h"
@@ -1153,6 +1152,18 @@
inline constexpr char kHasNavigatedToExpsSuccessPage[] =
"Companion.HasNavigatedToExpsSuccessPage";
+// Deprecated 11/2024.
+#if BUILDFLAG(IS_CHROMEOS)
+constexpr char kNoteTakingAppEnabledOnLockScreen[] =
+ "settings.note_taking_app_enabled_on_lock_screen";
+constexpr char kNoteTakingAppsLockScreenAllowlist[] =
+ "settings.note_taking_apps_lock_screen_whitelist";
+constexpr char kNoteTakingAppsLockScreenToastShown[] =
+ "settings.note_taking_apps_lock_screen_toast_shown";
+constexpr char kRestoreLastLockScreenNote[] =
+ "settings.restore_last_lock_screen_note";
+#endif
+
// Register local state used only for migration (clearing or moving to a new
// key).
void RegisterLocalStatePrefsForMigration(PrefRegistrySimple* registry) {
@@ -1634,6 +1645,15 @@
registry->RegisterIntegerPref(kPcoPromoDeclinedCountPref, 0);
registry->RegisterBooleanPref(kExpsOptInStatusGrantedPref, false);
registry->RegisterBooleanPref(kHasNavigatedToExpsSuccessPage, false);
+
+#if BUILDFLAG(IS_CHROMEOS)
+ // Deprecated 11/2024
+ registry->RegisterBooleanPref(kNoteTakingAppEnabledOnLockScreen, false);
+ registry->RegisterListPref(kNoteTakingAppsLockScreenAllowlist,
+ base::Value::List());
+ registry->RegisterDictionaryPref(kNoteTakingAppsLockScreenToastShown);
+ registry->RegisterBooleanPref(kRestoreLastLockScreenNote, false);
+#endif
}
void ClearSyncRequestedPrefAndMaybeMigrate(PrefService* profile_prefs) {
@@ -2276,7 +2296,6 @@
crostini::prefs::RegisterProfilePrefs(registry);
flags_ui::PrefServiceFlagsStorage::RegisterProfilePrefs(registry);
guest_os::prefs::RegisterProfilePrefs(registry);
- lock_screen_apps::StateController::RegisterProfilePrefs(registry);
plugin_vm::prefs::RegisterProfilePrefs(registry);
policy::ArcAppInstallEventLogger::RegisterProfilePrefs(registry);
policy::AppInstallEventLogManagerWrapper::RegisterProfilePrefs(registry);
@@ -3001,6 +3020,14 @@
profile_prefs->ClearPref(kExpsOptInStatusGrantedPref);
profile_prefs->ClearPref(kHasNavigatedToExpsSuccessPage);
+#if BUILDFLAG(IS_CHROMEOS)
+ // Deprecated 11/2024
+ profile_prefs->ClearPref(kNoteTakingAppEnabledOnLockScreen);
+ profile_prefs->ClearPref(kNoteTakingAppsLockScreenAllowlist);
+ profile_prefs->ClearPref(kNoteTakingAppsLockScreenToastShown);
+ profile_prefs->ClearPref(kRestoreLastLockScreenNote);
+#endif
+
// Please don't delete the following line. It is used by PRESUBMIT.py.
// END_MIGRATE_OBSOLETE_PROFILE_PREFS
diff --git a/chrome/browser/ui/BUILD.gn b/chrome/browser/ui/BUILD.gn
index 3d2ad62..20a06ce 100644
--- a/chrome/browser/ui/BUILD.gn
+++ b/chrome/browser/ui/BUILD.gn
@@ -2235,7 +2235,6 @@
"//chrome/browser/ash/kcer",
"//chrome/browser/ash/kerberos",
"//chrome/browser/ash/locale",
- "//chrome/browser/ash/lock_screen_apps",
"//chrome/browser/ash/login",
"//chrome/browser/ash/login/app_mode",
"//chrome/browser/ash/login/demo_mode",
@@ -2753,7 +2752,6 @@
"//chrome/browser/ash/input_method",
"//chrome/browser/ash/kerberos",
"//chrome/browser/ash/locale",
- "//chrome/browser/ash/lock_screen_apps",
"//chrome/browser/ash/login",
"//chrome/browser/ash/login/app_mode",
"//chrome/browser/ash/login/demo_mode",
diff --git a/chrome/browser/ui/apps/BUILD.gn b/chrome/browser/ui/apps/BUILD.gn
index 2f56543b..473708d 100644
--- a/chrome/browser/ui/apps/BUILD.gn
+++ b/chrome/browser/ui/apps/BUILD.gn
@@ -56,10 +56,6 @@
"//ui/base",
]
- if (is_chromeos_ash) {
- deps += [ "//chrome/browser/ash/lock_screen_apps:lock_screen_apps" ]
- }
-
if (is_chromeos) {
deps += [ "//chrome/browser/chromeos/policy/dlp" ]
}
diff --git a/chrome/browser/ui/apps/chrome_app_delegate.cc b/chrome/browser/ui/apps/chrome_app_delegate.cc
index 3f69c37..239aace 100644
--- a/chrome/browser/ui/apps/chrome_app_delegate.cc
+++ b/chrome/browser/ui/apps/chrome_app_delegate.cc
@@ -48,10 +48,6 @@
#include "printing/buildflags/buildflags.h"
#include "services/service_manager/public/cpp/interface_provider.h"
-#if BUILDFLAG(IS_CHROMEOS_ASH)
-#include "chrome/browser/ash/lock_screen_apps/state_controller.h"
-#endif
-
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/chromeos/policy/dlp/dlp_content_tab_helper.h"
#endif
@@ -412,14 +408,8 @@
bool ChromeAppDelegate::TakeFocus(content::WebContents* web_contents,
bool reverse) {
- if (!for_lock_screen_app_)
- return false;
-#if BUILDFLAG(IS_CHROMEOS_ASH)
- return lock_screen_apps::StateController::Get()->HandleTakeFocus(web_contents,
- reverse);
-#else
+ // TODO(crbug.com/376354347): Remove this method.
return false;
-#endif
}
content::PictureInPictureResult ChromeAppDelegate::EnterPictureInPicture(
diff --git a/chrome/browser/ui/apps/chrome_app_window_client.cc b/chrome/browser/ui/apps/chrome_app_window_client.cc
index b30c2395..963fd92 100644
--- a/chrome/browser/ui/apps/chrome_app_window_client.cc
+++ b/chrome/browser/ui/apps/chrome_app_window_client.cc
@@ -19,10 +19,6 @@
#include "extensions/common/extension.h"
#include "extensions/common/features/feature_channel.h"
-#if BUILDFLAG(IS_CHROMEOS_ASH)
-#include "chrome/browser/ash/lock_screen_apps/state_controller.h"
-#endif
-
// TODO(jamescook): We probably shouldn't compile this class at all on Android.
// See http://crbug.com/343612
#if !BUILDFLAG(IS_ANDROID)
@@ -58,17 +54,8 @@
content::BrowserContext* context,
const extensions::Extension* extension,
extensions::api::app_runtime::ActionType action) {
-#if BUILDFLAG(IS_CHROMEOS_ASH)
- auto app_delegate = std::make_unique<ChromeAppDelegate>(
- Profile::FromBrowserContext(context), true /*keep_alive*/);
- app_delegate->set_for_lock_screen_app(true);
-
- return lock_screen_apps::StateController::Get()
- ->CreateAppWindowForLockScreenAction(context, extension, action,
- std::move(app_delegate));
-#else
+ // TODO(crbug.com/376354347): Remove this method.
return nullptr;
-#endif
}
std::unique_ptr<extensions::NativeAppWindow>
diff --git a/chrome/browser/ui/ash/BUILD.gn b/chrome/browser/ui/ash/BUILD.gn
index a6be0d12..0bda696 100644
--- a/chrome/browser/ui/ash/BUILD.gn
+++ b/chrome/browser/ui/ash/BUILD.gn
@@ -61,7 +61,6 @@
"//chrome/browser/ash/growth",
"//chrome/browser/ash/input_device_settings",
"//chrome/browser/ash/input_method",
- "//chrome/browser/ash/lock_screen_apps",
"//chrome/browser/ash/login",
"//chrome/browser/ash/login/demo_mode",
"//chrome/browser/ash/login/lock",
@@ -225,7 +224,6 @@
"//chrome/browser/ash/eol",
"//chrome/browser/ash/extensions/autotest_private",
"//chrome/browser/ash/input_method",
- "//chrome/browser/ash/lock_screen_apps",
"//chrome/browser/ash/login",
"//chrome/browser/ash/login/demo_mode",
"//chrome/browser/ash/login/lock",
diff --git a/chrome/browser/ui/webui/ash/settings/pages/device/device_stylus_handler.cc b/chrome/browser/ui/webui/ash/settings/pages/device/device_stylus_handler.cc
index 8ae87c8..5b01868 100644
--- a/chrome/browser/ui/webui/ash/settings/pages/device/device_stylus_handler.cc
+++ b/chrome/browser/ui/webui/ash/settings/pages/device/device_stylus_handler.cc
@@ -25,7 +25,6 @@
constexpr char kAppNameKey[] = "name";
constexpr char kAppIdKey[] = "value";
constexpr char kAppPreferredKey[] = "preferred";
-constexpr char kAppLockScreenSupportKey[] = "lockScreenSupport";
} // namespace
@@ -50,11 +49,6 @@
base::BindRepeating(&StylusHandler::HandleSetPreferredNoteTakingApp,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
- "setPreferredNoteTakingAppEnabledOnLockScreen",
- base::BindRepeating(
- &StylusHandler::HandleSetPreferredNoteTakingAppEnabledOnLockScreen,
- base::Unretained(this)));
- web_ui()->RegisterMessageCallback(
"showPlayStoreApps",
base::BindRepeating(&StylusHandler::HandleShowPlayStoreApps,
base::Unretained(this)));
@@ -101,9 +95,7 @@
apps_list.Append(base::Value::Dict()
.Set(kAppNameKey, info.name)
.Set(kAppIdKey, info.app_id)
- .Set(kAppPreferredKey, info.preferred)
- .Set(kAppLockScreenSupportKey,
- static_cast<int>(info.lock_screen_support)));
+ .Set(kAppPreferredKey, info.preferred));
note_taking_app_ids_.insert(info.app_id);
}
@@ -133,16 +125,6 @@
app_id);
}
-void StylusHandler::HandleSetPreferredNoteTakingAppEnabledOnLockScreen(
- const base::Value::List& args) {
- bool enabled = false;
- CHECK(args[0].is_bool());
- enabled = args[0].GetBool();
-
- NoteTakingHelper::Get()->SetPreferredAppEnabledOnLockScreen(
- Profile::FromWebUI(web_ui()), enabled);
-}
-
void StylusHandler::HandleInitialize(const base::Value::List& args) {
AllowJavascript();
if (ui::DeviceDataManager::GetInstance()->AreDeviceListsComplete()) {
diff --git a/chrome/browser/ui/webui/ash/settings/pages/device/device_stylus_handler.h b/chrome/browser/ui/webui/ash/settings/pages/device/device_stylus_handler.h
index de0ed63..ce6923e8 100644
--- a/chrome/browser/ui/webui/ash/settings/pages/device/device_stylus_handler.h
+++ b/chrome/browser/ui/webui/ash/settings/pages/device/device_stylus_handler.h
@@ -44,8 +44,6 @@
void UpdateNoteTakingApps();
void HandleRequestApps(const base::Value::List& unused_args);
void HandleSetPreferredNoteTakingApp(const base::Value::List& args);
- void HandleSetPreferredNoteTakingAppEnabledOnLockScreen(
- const base::Value::List& args);
void HandleInitialize(const base::Value::List& args);
// Enables or disables the stylus UI section.
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 63f17527..c757cbe 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -583,31 +583,6 @@
// indicates that the user hasn't selected an app yet.
inline constexpr char kNoteTakingAppId[] = "settings.note_taking_app_id";
-// A boolean pref indicating whether preferred note-taking app (see
-// |kNoteTakingAppId|) is allowed to handle note taking actions on the lock
-// screen.
-inline constexpr char kNoteTakingAppEnabledOnLockScreen[] =
- "settings.note_taking_app_enabled_on_lock_screen";
-
-// List of note taking aps that can be enabled to run on the lock screen.
-// The intended usage is to allow the set of apps that the user can enable
-// to run on lock screen, not to actually enable the apps to run on lock screen.
-// Note that this used to be `kNoteTakingAppsLockScreenWhitelist`, hence the
-// difference between the variable name and the string value.
-inline constexpr char kNoteTakingAppsLockScreenAllowlist[] =
- "settings.note_taking_apps_lock_screen_whitelist";
-
-// Dictionary pref that maps lock screen app ID to a boolean indicating whether
-// the toast dialog has been show and dismissed as the app was being launched
-// on the lock screen.
-inline constexpr char kNoteTakingAppsLockScreenToastShown[] =
- "settings.note_taking_apps_lock_screen_toast_shown";
-
-// Whether the preferred note taking app should be requested to restore the last
-// note created on lock screen when launched on lock screen.
-inline constexpr char kRestoreLastLockScreenNote[] =
- "settings.restore_last_lock_screen_note";
-
// Automatically open online re-authentication window on the lock screen.
inline constexpr char kLockScreenAutoStartOnlineReauth[] =
"lock_screen_auto_start_online_reauth";
diff --git a/components/policy/test/data/pref_mapping/NoteTakingAppsLockScreenAllowlist.json b/components/policy/test/data/pref_mapping/NoteTakingAppsLockScreenAllowlist.json
index 977846b..5868d79 100644
--- a/components/policy/test/data/pref_mapping/NoteTakingAppsLockScreenAllowlist.json
+++ b/components/policy/test/data/pref_mapping/NoteTakingAppsLockScreenAllowlist.json
@@ -1,19 +1,5 @@
[
{
- "os": [
- "chromeos_ash"
- ],
- "policy_pref_mapping_tests": [
- {
- "policies": {
- "NoteTakingAppsLockScreenAllowlist": []
- },
- "prefs": {
- "settings.note_taking_apps_lock_screen_whitelist": {
- "value": []
- }
- }
- }
- ]
+ "reason_for_missing_test": "Policy was removed"
}
]