Daniel Murphy | 037d94fd | 2023-04-14 16:17:44 | [diff] [blame] | 1 | // 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 Murphy | 037d94fd | 2023-04-14 16:17:44 | [diff] [blame] | 8 | #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 Hartmann | 5f992ed | 2023-09-25 18:05:36 | [diff] [blame] | 12 | #include "components/webapps/common/web_app_id.h" |
Daniel Murphy | 037d94fd | 2023-04-14 16:17:44 | [diff] [blame] | 13 | |
Daniel Murphy | 037d94fd | 2023-04-14 16:17:44 | [diff] [blame] | 14 | namespace web_app { |
| 15 | |
| 16 | class WebAppLockManager; |
| 17 | |
| 18 | // This locks all app ids in the WebAppProvider system. |
| 19 | // |
| 20 | // Locks can be acquired by using the `WebAppLockManager`. |
| 21 | class AllAppsLockDescription : public LockDescription { |
| 22 | public: |
| 23 | AllAppsLockDescription(); |
Daniel Murphy | 77abe975 | 2024-01-11 20:57:03 | [diff] [blame] | 24 | AllAppsLockDescription(AllAppsLockDescription&&); |
Daniel Murphy | 037d94fd | 2023-04-14 16:17:44 | [diff] [blame] | 25 | ~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 Murphy | 51461d5 | 2024-10-04 19:57:26 | [diff] [blame] | 36 | // 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 Murphy | 037d94fd | 2023-04-14 16:17:44 | [diff] [blame] | 38 | class AllAppsLock : public Lock, public WithAppResources { |
| 39 | public: |
| 40 | using LockDescription = AllAppsLockDescription; |
| 41 | |
Daniel Murphy | 51461d5 | 2024-10-04 19:57:26 | [diff] [blame] | 42 | AllAppsLock(); |
Daniel Murphy | 037d94fd | 2023-04-14 16:17:44 | [diff] [blame] | 43 | ~AllAppsLock(); |
| 44 | |
| 45 | base::WeakPtr<AllAppsLock> AsWeakPtr() { return weak_factory_.GetWeakPtr(); } |
| 46 | |
| 47 | private: |
| 48 | friend class WebAppLockManager; |
Daniel Murphy | 51461d5 | 2024-10-04 19:57:26 | [diff] [blame] | 49 | void GrantLock(WebAppLockManager& lock_manager); |
Daniel Murphy | 037d94fd | 2023-04-14 16:17:44 | [diff] [blame] | 50 | |
| 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_ |