David Bienvenu | fa7a2cd | 2025-03-26 22:56:51 | [diff] [blame] | 1 | // Copyright 2025 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_WIN_TASKBAR_MANAGER_H_ |
| 6 | #define CHROME_BROWSER_WIN_TASKBAR_MANAGER_H_ |
| 7 | |
David Bienvenu | ec47f98 | 2025-03-28 21:32:29 | [diff] [blame^] | 8 | #include <string> |
| 9 | |
David Bienvenu | fa7a2cd | 2025-03-26 22:56:51 | [diff] [blame] | 10 | #include "base/functional/callback_forward.h" |
David Bienvenu | fa7a2cd | 2025-03-26 22:56:51 | [diff] [blame] | 11 | |
| 12 | namespace browser_util { |
| 13 | |
| 14 | using PinResultCallback = base::OnceCallback<void(bool)>; |
| 15 | |
| 16 | // Functions to pin an icon for a Chrome window to the Windows taskbar, and to |
| 17 | // check if Chrome should offer to pin. These functions do most of their work on |
| 18 | // a background thread, but have to finish the work on the UI thread. |
| 19 | // The result callback will be called from the UI thread. |
| 20 | |
| 21 | // `callback` is called with true if pinning is supported, and the app is not |
| 22 | // currently pinned to the taskbar, false otherwise. There must be a shortcut |
| 23 | // with `app_user_model_id` in the start menu for pinning to be supported. |
David Bienvenu | ec47f98 | 2025-03-28 21:32:29 | [diff] [blame^] | 24 | void ShouldOfferToPin(const std::wstring& app_user_model_id, |
David Bienvenu | fa7a2cd | 2025-03-26 22:56:51 | [diff] [blame] | 25 | PinResultCallback callback); |
| 26 | |
| 27 | // Pins a Chrome window to the taskbar. `app_user_model_id` is the AUMI for |
| 28 | // the window to pin. The user should have requested this window be pinned, |
| 29 | // per the Microsoft limited feature access request form. |
| 30 | // There must be a shortcut in the Start Menu folder with the same AUMI. |
| 31 | // It uses the Windows TaskbarManager method `RequestPinCurrentAppAsync`, which |
| 32 | // will confirm that the user wishes to pin the window to the taskbar. |
David Bienvenu | ec47f98 | 2025-03-28 21:32:29 | [diff] [blame^] | 33 | void PinAppToTaskbar(const std::wstring& app_user_model_id, |
David Bienvenu | fa7a2cd | 2025-03-26 22:56:51 | [diff] [blame] | 34 | PinResultCallback callback); |
| 35 | |
| 36 | // These values are persisted to logs. Entries should not be renumbered and |
| 37 | // numeric values should never be reused. These values are recorded both for |
| 38 | // determining if Chrome can be pinned to the taskbar, and if an attempt was |
| 39 | // made to pin Chrome to the taskbar. Public for testing. |
| 40 | enum class PinResultMetric { |
| 41 | // Shortcut was pinned, or we successfully determined if we should pin. |
| 42 | kSuccess = 0, |
| 43 | |
| 44 | // `PinLimitedAccessFeatureAvailable` returned false. |
| 45 | kFeatureNotAvailable = 1, |
| 46 | |
| 47 | // There are a number of COM calls that can fail. This is unexpected. |
| 48 | kCOMError = 2, |
| 49 | |
| 50 | // Error calling ITaskbarManager method. |
| 51 | kTaskbarManagerError = 3, |
| 52 | |
| 53 | // Error posting async results. |
| 54 | kPostAsyncResultsFailed = 4, |
| 55 | |
| 56 | // `get_IsPinningAllowed` false. This could be because there is no shortcut to |
| 57 | // the app in the start menu, or some other Windows criteria for app pinning |
| 58 | // has not been met. |
| 59 | kPinningNotAllowed = 5, |
| 60 | |
| 61 | // Chrome already pinned to taskbar. |
| 62 | kAlreadyPinned = 6, |
| 63 | |
| 64 | // Successfully called RequestPinCurrentAppAsync and the request failed. |
| 65 | // This could be because the user rejected the Windows confirmation, or some |
| 66 | // other internal failure. |
| 67 | kPinCurrentAppFailed = 7, |
| 68 | kMaxValue = kPinCurrentAppFailed, |
| 69 | }; |
| 70 | |
| 71 | } // namespace browser_util |
| 72 | |
| 73 | #endif // CHROME_BROWSER_WIN_TASKBAR_MANAGER_H_ |