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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ASH_FILE_SYSTEM_PROVIDER_REQUEST_VALUE_H_
#define CHROME_BROWSER_ASH_FILE_SYSTEM_PROVIDER_REQUEST_VALUE_H_
#include <string>
#include <variant>
#include "chrome/common/extensions/api/file_system_provider_internal.h"
namespace ash::file_system_provider {
// Holds a parsed value returned by a file system provider. Each accessor can
// return nullptr in case the requested value type is not available. It is used
// to pass values of success callbacks.
class RequestValue {
public:
// Creates an empty value. Use static methods to create a value holding a
// proper content.
RequestValue() noexcept;
RequestValue(RequestValue&& other) noexcept;
RequestValue& operator=(RequestValue&& other) noexcept;
~RequestValue() noexcept;
static RequestValue CreateForUnmountSuccess(
extensions::api::file_system_provider_internal::UnmountRequestedSuccess::
Params params);
static RequestValue CreateForGetMetadataSuccess(
extensions::api::file_system_provider_internal::
GetMetadataRequestedSuccess::Params params);
static RequestValue CreateForGetActionsSuccess(
extensions::api::file_system_provider_internal::
GetActionsRequestedSuccess::Params params);
static RequestValue CreateForReadDirectorySuccess(
extensions::api::file_system_provider_internal::
ReadDirectoryRequestedSuccess::Params params);
static RequestValue CreateForReadFileSuccess(
extensions::api::file_system_provider_internal::ReadFileRequestedSuccess::
Params params);
static RequestValue CreateForOpenFileSuccess(
extensions::api::file_system_provider_internal::OpenFileRequestedSuccess::
Params params);
static RequestValue CreateForOperationSuccess(
extensions::api::file_system_provider_internal::
OperationRequestedSuccess::Params params);
static RequestValue CreateForOperationError(
extensions::api::file_system_provider_internal::OperationRequestedError::
Params params);
static RequestValue CreateForTesting(const std::string& params);
const extensions::api::file_system_provider_internal::
UnmountRequestedSuccess::Params*
unmount_success_params() const {
return std::get_if<extensions::api::file_system_provider_internal::
UnmountRequestedSuccess::Params>(&data_);
}
const extensions::api::file_system_provider_internal::
GetMetadataRequestedSuccess::Params*
get_metadata_success_params() const {
return std::get_if<extensions::api::file_system_provider_internal::
GetMetadataRequestedSuccess::Params>(&data_);
}
const extensions::api::file_system_provider_internal::
GetActionsRequestedSuccess::Params*
get_actions_success_params() const {
return std::get_if<extensions::api::file_system_provider_internal::
GetActionsRequestedSuccess::Params>(&data_);
}
const extensions::api::file_system_provider_internal::
ReadDirectoryRequestedSuccess::Params*
read_directory_success_params() const {
return std::get_if<extensions::api::file_system_provider_internal::
ReadDirectoryRequestedSuccess::Params>(&data_);
}
const extensions::api::file_system_provider_internal::
ReadFileRequestedSuccess::Params*
read_file_success_params() const {
return std::get_if<extensions::api::file_system_provider_internal::
ReadFileRequestedSuccess::Params>(&data_);
}
const extensions::api::file_system_provider_internal::
OpenFileRequestedSuccess::Params*
open_file_success_params() const {
return std::get_if<extensions::api::file_system_provider_internal::
OpenFileRequestedSuccess::Params>(&data_);
}
const extensions::api::file_system_provider_internal::
OperationRequestedSuccess::Params*
operation_success_params() const {
return std::get_if<extensions::api::file_system_provider_internal::
OperationRequestedSuccess::Params>(&data_);
}
const extensions::api::file_system_provider_internal::
OperationRequestedError::Params*
operation_error_params() const {
return std::get_if<extensions::api::file_system_provider_internal::
OperationRequestedError::Params>(&data_);
}
const std::string* testing_params() const {
return std::get_if<std::string>(&data_);
}
bool is_valid() const {
return !std::holds_alternative<std::monostate>(data_);
}
private:
// A variant holding the possible types of data held as a value.
std::variant<std::monostate,
extensions::api::file_system_provider_internal::
UnmountRequestedSuccess::Params,
extensions::api::file_system_provider_internal::
GetMetadataRequestedSuccess::Params,
extensions::api::file_system_provider_internal::
GetActionsRequestedSuccess::Params,
extensions::api::file_system_provider_internal::
ReadDirectoryRequestedSuccess::Params,
extensions::api::file_system_provider_internal::
ReadFileRequestedSuccess::Params,
extensions::api::file_system_provider_internal::
OpenFileRequestedSuccess::Params,
extensions::api::file_system_provider_internal::
OperationRequestedSuccess::Params,
extensions::api::file_system_provider_internal::
OperationRequestedError::Params,
std::string>
data_;
};
} // namespace ash::file_system_provider
#endif // CHROME_BROWSER_ASH_FILE_SYSTEM_PROVIDER_REQUEST_VALUE_H_
|