#include "components/services/app_service/public/cpp/app_storage/app_storage_file_handler.h"
#include <string_view>
#include "base/files/file_util.h"
#include "base/files/important_file_writer.h"
#include "base/json/json_string_value_serializer.h"
#include "base/json/values_util.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/thread_pool.h"
#include "base/threading/scoped_blocking_call.h"
#include "components/services/app_service/public/cpp/app.h"
#include "components/services/app_service/public/cpp/icon_effects.h"
#include "components/services/app_service/public/cpp/intent_filter_util.h"
#include "components/services/app_service/public/cpp/permission.h"
#include "components/services/app_service/public/cpp/run_on_os_login_types.h"
namespace apps {
AppInfo;
namespace {
constexpr char kAppServiceDirName[] = …;
constexpr char kAppStorageFileName[] = …;
constexpr char kTypeKey[] = …;
constexpr char kReadinessKey[] = …;
constexpr char kNameKey[] = …;
constexpr char kShortNameKey[] = …;
constexpr char kPublisherIdKey[] = …;
constexpr char kInstallerPackageIdKey[] = …;
constexpr char kDescriptionKey[] = …;
constexpr char kVersionKey[] = …;
constexpr char kAdditionalSearchTermsKey[] = …;
constexpr char kIconResourceIdKey[] = …;
constexpr char kIconEffectsKey[] = …;
constexpr char kLastLaunchTimeKey[] = …;
constexpr char kInstallTimeKey[] = …;
constexpr char kPermissionsKey[] = …;
constexpr char kInstallReasonKey[] = …;
constexpr char kInstallSourceKey[] = …;
constexpr char kPolicyIdsKey[] = …;
constexpr char kIsPlatformAppKey[] = …;
constexpr char kRecommendableKey[] = …;
constexpr char kSearchableKey[] = …;
constexpr char kShowInLauncherKey[] = …;
constexpr char kShowInShelfKey[] = …;
constexpr char kShowInSearchKey[] = …;
constexpr char kShowInManagementKey[] = …;
constexpr char kHandlesIntentsKey[] = …;
constexpr char kAllowUninstallKey[] = …;
constexpr char kIntentFiltersKey[] = …;
constexpr char kWindowModeKey[] = …;
constexpr char kRunOnOsLoginKey[] = …;
constexpr char kAllowCloseKey[] = …;
constexpr char kAppSizeInBytesKey[] = …;
constexpr char kDataSizeInBytesKey[] = …;
constexpr char kSupportedLocalesKey[] = …;
constexpr char kSelectedLocaleKey[] = …;
constexpr char kExtraKey[] = …;
std::optional<std::string> GetStringValueFromDict(const base::Value::Dict& dict,
std::string_view key_name) { … }
std::optional<uint64_t> GetUint64ValueFromDict(const base::Value::Dict& dict,
std::string_view key_name) { … }
template <typename T>
bool FieldHasValue(const AppPtr& app, T App::*field) { … }
template <typename T>
bool FieldHasValue(const AppPtr& app, std::optional<T> App::*field) { … }
template <typename T>
bool FieldHasValue(const AppPtr& app, std::vector<T> App::*field) { … }
template <typename T>
base::Value GetValue(const AppPtr& app, T App::*field) { … }
template <typename T>
base::Value GetValue(const AppPtr& app, std::optional<T> App::*field) { … }
template <>
base::Value GetValue(const AppPtr& app, std::optional<base::Time> App::*field) { … }
template <>
base::Value GetValue(const AppPtr& app,
std::optional<base::Value::Dict> App::*field) { … }
template <>
base::Value GetValue(const AppPtr& app, std::vector<std::string> App::*field) { … }
template <>
base::Value GetValue(const AppPtr& app,
std::vector<IntentFilterPtr> App::*field) { … }
template <>
base::Value GetValue(const AppPtr& app,
std::vector<PermissionPtr> App::*field) { … }
template <>
base::Value GetValue(const AppPtr& app,
std::optional<RunOnOsLogin> App::*field) { … }
template <>
base::Value GetValue(const AppPtr& app, std::optional<uint64_t> App::*field) { … }
template <>
base::Value GetValue(const AppPtr& app, std::optional<PackageId> App::*field) { … }
template <typename T>
void SetKey(const AppPtr& app,
T App::*field,
const std::string& key,
base::Value::Dict& app_details_dict) { … }
template <typename T>
void GetEnumFromKey(base::Value::Dict* value,
T App::*field,
const std::string& key,
AppPtr& app) { … }
template <typename T>
void GetListFromKey(base::Value::Dict* value,
T App::*field,
const std::string& key,
AppPtr& app) { … }
}
AppStorageFileHandler::AppInfo::AppInfo() = default;
AppStorageFileHandler::AppInfo::~AppInfo() = default;
AppStorageFileHandler::AppStorageFileHandler(const base::FilePath& base_path)
: … { … }
void AppStorageFileHandler::WriteToFile(std::vector<AppPtr> apps) { … }
std::unique_ptr<AppInfo> AppStorageFileHandler::ReadFromFile() { … }
AppStorageFileHandler::~AppStorageFileHandler() { … }
base::Value AppStorageFileHandler::ConvertAppsToValue(
std::vector<AppPtr> apps) { … }
std::unique_ptr<AppInfo> AppStorageFileHandler::ConvertValueToApps(
base::Value app_info_value) { … }
}