1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57

ash / wallpaper / wallpaper_utils / wallpaper_file_utils.h [blame]

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_WALLPAPER_WALLPAPER_UTILS_WALLPAPER_FILE_UTILS_H_
#define ASH_WALLPAPER_WALLPAPER_UTILS_WALLPAPER_FILE_UTILS_H_

#include <string>

#include "ash/ash_export.h"
#include "ash/public/cpp/wallpaper/wallpaper_types.h"

namespace base {
class FilePath;
}  // namespace base

namespace gfx {
class ImageSkia;
class Size;
}  // namespace gfx

namespace ash {

// Directory names of custom wallpapers.
inline constexpr char kSmallWallpaperSubDir[] = "small";
inline constexpr char kLargeWallpaperSubDir[] = "large";
inline constexpr char kOriginalWallpaperSubDir[] = "original";

// Saves the wallpaper `image` to disk at the given `path`, encoded as jpg.
// Returns true if successfully saved and false otherwise. This function is not
// specific to any one WallpaperType.
//
// The `image` may be resized first according to the `preferred_size`
// depending on the `layout` specified.
//
// `image_metadata` is optional. Sets the value if it is required to store the
// XMP metadata for the image. `image_metadata`, if not empty, should be
// constructed as XMP format (like XML standard format). Otherwise,
// `image_metadata` is empty by default, and no metadata is saved for the image.
//
// This performs synchronous blocking file operations and must be called from a
// thread or sequence that allows it.
ASH_EXPORT bool ResizeAndSaveWallpaper(
    const gfx::ImageSkia& image,
    const base::FilePath& path,
    WallpaperLayout layout,
    gfx::Size preferred_size,
    const std::string& image_metadata = std::string());

// Create `directory` and any missing parent directories if it does not exist.
// Does nothing if `directory` already exists. Logs error message for any
// failures. Functionally equivalent to `mkdir -p`.
ASH_EXPORT void CreateDirectoryAndLogError(const base::FilePath& directory);

}  // namespace ash

#endif  // ASH_WALLPAPER_WALLPAPER_UTILS_WALLPAPER_FILE_UTILS_H_