blob: 69f6a93b3d1ca93174e2d76dd165cc22e84622c8 [file] [log] [blame]
Marijn Kruisselbrink9aba65e2024-04-18 21:54:241// Copyright 2024 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_SHORTCUTS_PLATFORM_UTIL_MAC_H_
6#define CHROME_BROWSER_SHORTCUTS_PLATFORM_UTIL_MAC_H_
7
Marijn Kruisselbrink1bfda682024-05-02 00:23:088#include <optional>
9
10#include "base/files/safe_base_name.h"
Marijn Kruisselbrink9aba65e2024-04-18 21:54:2411#include "base/functional/callback_forward.h"
12
13@class NSError;
14@class NSImage;
15@class NSURL;
16
17namespace base {
18class FilePath;
19}
20
21namespace shortcuts {
22
23// Wrapper around NSWorkspace setIcon:forFile: that can be called from any
24// thread. While the underlying NSWorkspace method can also be called from any
25// thread, it is not reentrancy safe (i.e. multiple calls to it need to be
26// sequenced). This wrapper takes care of the sequencing needed. The `callback`
27// will be called on the calling sequence.
28void SetIconForFile(NSImage* image,
29 const base::FilePath& file,
30 base::OnceCallback<void(bool)> callback);
31
32// Wrapper around NSWorkspace setDefaultApplicationAtURL:toOpenFileAtURL:. The
33// NSWorkspace method only exists on macOS 12.0 and newer; this method polyfills
34// its implementation for older macOS versions.
35void SetDefaultApplicationToOpenFile(
36 NSURL* file_url,
37 NSURL* application_url,
38 base::OnceCallback<void(NSError*)> callback);
39
Marijn Kruisselbrink1bfda682024-05-02 00:23:0840// Return a version of `title` that is safe to use as a filename on macOS.
41std::optional<base::SafeBaseName> SanitizeTitleForFileName(
42 const std::string& title);
43
Marijn Kruisselbrink9aba65e2024-04-18 21:54:2444} // namespace shortcuts
45
46#endif // CHROME_BROWSER_SHORTCUTS_PLATFORM_UTIL_MAC_H_