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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_DESKS_STORAGE_CORE_DESK_TEMPLATE_CONVERSION_H_
#define COMPONENTS_DESKS_STORAGE_CORE_DESK_TEMPLATE_CONVERSION_H_
#include "ash/public/cpp/desk_template.h"
#include "base/time/time.h"
#include "base/types/expected.h"
#include "base/values.h"
#include "components/services/app_service/public/cpp/app_launch_util.h"
#include "components/services/app_service/public/cpp/app_types.h"
#include "components/sync/protocol/workspace_desk_specifics.pb.h"
#include "ui/base/window_open_disposition.h"
namespace apps {
class AppRegistryCache;
}
namespace desks_storage::desk_template_conversion {
// Error codes for parsing a saved desk.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class SavedDeskParseError {
kOk = 0,
kBaseValueIsNotDict = 1,
kMissingRequiredFields = 2,
kInvalidUuid = 3,
kInvalidDeskType = 4,
kFileNotExist = 5,
kInvalidJson = 6,
kMaxValue = kInvalidJson,
};
using SyncWindowOpenDisposition =
sync_pb::WorkspaceDeskSpecifics_WindowOpenDisposition;
using SyncLaunchContainer = sync_pb::WorkspaceDeskSpecifics_LaunchContainer;
using ParseSavedDeskResult =
base::expected<std::unique_ptr<ash::DeskTemplate>, SavedDeskParseError>;
// Converts the TabGroupColorId passed into its string equivalent
// as defined in the k constants above.
std::string ConvertTabGroupColorIdToString(tab_groups::TabGroupColorId color);
// Converts a time field from sync protobufs to a time object.
base::Time ProtoTimeToTime(int64_t proto_time);
// Converts a time object to the format used in sync protobufs
// (Microseconds since the Windows epoch).
int64_t TimeToProtoTime(const base::Time& t);
// Creates a default template from policy. Template will be created without
// window information. Expects a list value containing the different template
// definitions. Schema located at:
// `components/policy/resources/templates/policy_definitions/miscellaneous/...
// ...AppLaunchAutomation.yaml`
std::vector<std::unique_ptr<ash::DeskTemplate>>
ParseAdminTemplatesFromPolicyValue(const base::Value& value);
// Converts a JSON desk template to an ash desk template. The returned desk
// template will have source set to `source`. The policy associated is
// PreconfiguredDeskTemplates.
ParseSavedDeskResult ParseDeskTemplateFromBaseValue(
const base::Value& value,
ash::DeskTemplateSource source);
base::Value SerializeDeskTemplateAsBaseValue(
const ash::DeskTemplate* desk_template,
apps::AppRegistryCache* app_cache);
// Converts a WorkspaceDesk proto to its corresponding ash::DeskTemplate
std::unique_ptr<ash::DeskTemplate> FromSyncProto(
const sync_pb::WorkspaceDeskSpecifics& pb_entry);
// Converts an ash::DeskTemplate to its corresponding WorkspaceDesk proto.
sync_pb::WorkspaceDeskSpecifics ToSyncProto(
const ash::DeskTemplate* desk_template,
apps::AppRegistryCache* app_cache);
} // namespace desks_storage::desk_template_conversion
#endif // COMPONENTS_DESKS_STORAGE_CORE_DESK_TEMPLATE_CONVERSION_H_
|