#include "chrome/browser/search/background/wallpaper_search/wallpaper_search_background_manager.h"
#include <optional>
#include <string>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/task/thread_pool.h"
#include "base/timer/elapsed_timer.h"
#include "base/token.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/background/ntp_custom_background_service_factory.h"
#include "chrome/browser/search/background/wallpaper_search/wallpaper_search_data.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/image/image.h"
namespace {
const char kWallpaperSearchHistoryId[] = …;
const char kWallpaperSearchHistoryMood[] = …;
const char kWallpaperSearchHistoryStyle[] = …;
const char kWallpaperSearchHistorySubject[] = …;
void WriteFileToPath(const std::string& data, const base::FilePath& path) { … }
void DeleteWallpaperSearchImage(const std::string& id,
const base::FilePath& profile_path) { … }
std::optional<HistoryEntry> GetHistoryEntryFromPrefValue(
const base::Value& pref_value) { … }
base::Value::Dict GetHistoryEntryDict(const HistoryEntry& history_entry) { … }
}
void WallpaperSearchBackgroundManager::RegisterProfilePrefs(
PrefRegistrySimple* registry) { … }
void WallpaperSearchBackgroundManager::RemoveWallpaperSearchBackground(
Profile* profile) { … }
void WallpaperSearchBackgroundManager::ResetProfilePrefs(Profile* profile) { … }
WallpaperSearchBackgroundManager::WallpaperSearchBackgroundManager(
Profile* profile)
: … { … }
WallpaperSearchBackgroundManager::~WallpaperSearchBackgroundManager() = default;
std::vector<HistoryEntry> WallpaperSearchBackgroundManager::GetHistory() { … }
bool WallpaperSearchBackgroundManager::IsCurrentBackground(
const base::Token& id) { … }
void WallpaperSearchBackgroundManager::SelectHistoryImage(
const base::Token& id,
const gfx::Image& image,
base::ElapsedTimer timer) { … }
void WallpaperSearchBackgroundManager::SelectLocalBackgroundImage(
const base::Token& id,
const SkBitmap& bitmap,
bool is_inspiration_image,
base::ElapsedTimer timer) { … }
std::optional<base::Token>
WallpaperSearchBackgroundManager::SaveCurrentBackgroundToHistory(
const HistoryEntry& history_entry) { … }
void WallpaperSearchBackgroundManager::AddObserver(
WallpaperSearchBackgroundManagerObserver* observer) { … }
void WallpaperSearchBackgroundManager::RemoveObserver(
WallpaperSearchBackgroundManagerObserver* observer) { … }
void WallpaperSearchBackgroundManager::SetBackgroundToLocalResourceWithId(
const base::Token& id,
base::ElapsedTimer timer,
const SkBitmap& bitmap,
bool is_inspiration_image) { … }
void WallpaperSearchBackgroundManager::NotifyAboutHistory() { … }