#include "chrome/browser/web_applications/locks/web_app_lock_manager.h"
#include <memory>
#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/task_runner.h"
#include "base/values.h"
#include "chrome/browser/web_applications/locks/all_apps_lock.h"
#include "chrome/browser/web_applications/locks/app_lock.h"
#include "chrome/browser/web_applications/locks/lock.h"
#include "chrome/browser/web_applications/locks/noop_lock.h"
#include "chrome/browser/web_applications/locks/partitioned_lock_id.h"
#include "chrome/browser/web_applications/locks/partitioned_lock_manager.h"
#include "chrome/browser/web_applications/locks/shared_web_contents_lock.h"
#include "chrome/browser/web_applications/locks/shared_web_contents_with_app_lock.h"
#include "chrome/browser/web_applications/web_app_command_manager.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "components/webapps/common/web_app_id.h"
namespace web_app {
namespace {
enum class LockPartition { … };
enum KeysOnStaticPartition { … };
const char* KeysOnStaticPartitionToString(KeysOnStaticPartition key) { … }
PartitionedLockManager::PartitionedLockRequest GetAllAppsLock(
PartitionedLockManager::LockType type) { … }
PartitionedLockManager::PartitionedLockRequest GetSharedWebContentsLock() { … }
std::vector<PartitionedLockManager::PartitionedLockRequest>
GetExclusiveAppIdLocks(const base::flat_set<webapps::AppId>& app_ids) { … }
std::vector<PartitionedLockManager::PartitionedLockRequest>
GetLockRequestsForLock(const LockDescription& lock) { … }
#if DCHECK_IS_ON()
void LogLockRequest(
const LockDescription& description,
const base::Location& location,
const std::vector<PartitionedLockManager::PartitionedLockRequest>& requests,
const PartitionedLockManager& lock_manager) { … }
#endif
}
WebAppLockManager::WebAppLockManager() = default;
WebAppLockManager::~WebAppLockManager() = default;
void WebAppLockManager::SetProvider(base::PassKey<WebAppCommandManager>,
WebAppProvider& provider) { … }
bool WebAppLockManager::IsSharedWebContentsLockFree() { … }
template <>
void WebAppLockManager::AcquireLock(
const LockDescription& lock_description,
base::OnceCallback<void(std::unique_ptr<NoopLock>)> on_lock_acquired,
const base::Location& location) { … }
template <>
void WebAppLockManager::AcquireLock(
const LockDescription& lock_description,
base::OnceCallback<void(std::unique_ptr<SharedWebContentsLock>)>
on_lock_acquired,
const base::Location& location) { … }
template <>
void WebAppLockManager::AcquireLock(
const LockDescription& lock_description,
base::OnceCallback<void(std::unique_ptr<AppLock>)> on_lock_acquired,
const base::Location& location) { … }
template <>
void WebAppLockManager::AcquireLock(
const LockDescription& lock_description,
base::OnceCallback<void(std::unique_ptr<SharedWebContentsWithAppLock>)>
on_lock_acquired,
const base::Location& location) { … }
template <>
void WebAppLockManager::AcquireLock(
const LockDescription& lock_description,
base::OnceCallback<void(std::unique_ptr<AllAppsLock>)> on_lock_acquired,
const base::Location& location) { … }
std::unique_ptr<SharedWebContentsWithAppLockDescription>
WebAppLockManager::UpgradeAndAcquireLock(
std::unique_ptr<SharedWebContentsLock> lock,
const base::flat_set<webapps::AppId>& app_ids,
base::OnceCallback<void(std::unique_ptr<SharedWebContentsWithAppLock>)>
on_lock_acquired,
const base::Location& location) { … }
std::unique_ptr<AppLockDescription> WebAppLockManager::UpgradeAndAcquireLock(
std::unique_ptr<NoopLock> lock,
const base::flat_set<webapps::AppId>& app_ids,
base::OnceCallback<void(std::unique_ptr<AppLock>)> on_lock_acquired,
const base::Location& location) { … }
base::Value WebAppLockManager::ToDebugValue() const { … }
void WebAppLockManager::AcquireLock(base::WeakPtr<PartitionedLockHolder> holder,
const LockDescription& lock_description,
base::OnceClosure on_lock_acquired,
const base::Location& location) { … }
}