blob: 15d91fc0462809ff1655c5704d4916b735709bf9 [file] [log] [blame]
Daniel Murphy037d94fd2023-04-14 16:17:441// Copyright 2023 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_WEB_APPLICATIONS_LOCKS_ALL_APPS_LOCK_H_
6#define CHROME_BROWSER_WEB_APPLICATIONS_LOCKS_ALL_APPS_LOCK_H_
7
Daniel Murphy037d94fd2023-04-14 16:17:448#include "base/containers/flat_set.h"
9#include "base/memory/weak_ptr.h"
10#include "chrome/browser/web_applications/locks/lock.h"
11#include "chrome/browser/web_applications/locks/with_app_resources.h"
Glenn Hartmann5f992ed2023-09-25 18:05:3612#include "components/webapps/common/web_app_id.h"
Daniel Murphy037d94fd2023-04-14 16:17:4413
Daniel Murphy037d94fd2023-04-14 16:17:4414namespace web_app {
15
16class WebAppLockManager;
17
18// This locks all app ids in the WebAppProvider system.
19//
20// Locks can be acquired by using the `WebAppLockManager`.
21class AllAppsLockDescription : public LockDescription {
22 public:
23 AllAppsLockDescription();
Daniel Murphy77abe9752024-01-11 20:57:0324 AllAppsLockDescription(AllAppsLockDescription&&);
Daniel Murphy037d94fd2023-04-14 16:17:4425 ~AllAppsLockDescription();
26};
27
28// Holding this lock means that no other lock-compatible operations are touching
29// the same app id/s. This does not ensure that the app/s are installed when the
30// lock is granted. Checks for that will need to be handled by the user of
31// the lock.
32//
33// See `WebAppLockManager` for how to use locks. Destruction of this class will
34// release the lock or cancel the lock request if it is not acquired yet.
35//
Daniel Murphy51461d52024-10-04 19:57:2636// Note: Accessing a lock before it is granted or after the WebAppProvider
37// system has shutdown (or the profile has shut down) will CHECK-fail.
Daniel Murphy037d94fd2023-04-14 16:17:4438class AllAppsLock : public Lock, public WithAppResources {
39 public:
40 using LockDescription = AllAppsLockDescription;
41
Daniel Murphy51461d52024-10-04 19:57:2642 AllAppsLock();
Daniel Murphy037d94fd2023-04-14 16:17:4443 ~AllAppsLock();
44
45 base::WeakPtr<AllAppsLock> AsWeakPtr() { return weak_factory_.GetWeakPtr(); }
46
47 private:
48 friend class WebAppLockManager;
Daniel Murphy51461d52024-10-04 19:57:2649 void GrantLock(WebAppLockManager& lock_manager);
Daniel Murphy037d94fd2023-04-14 16:17:4450
51 base::WeakPtrFactory<AllAppsLock> weak_factory_{this};
52};
53
54} // namespace web_app
55
56#endif // CHROME_BROWSER_WEB_APPLICATIONS_LOCKS_ALL_APPS_LOCK_H_