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 151 152 153 154 155 156 157 158
|
// 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.
#include "chrome/browser/ash/file_system_provider/provided_file_system_info.h"
#include "base/check_op.h"
namespace ash::file_system_provider {
ProviderId::ProviderId(const std::string& internal_id,
ProviderType provider_type)
: internal_id_(internal_id), type_(provider_type) {}
ProviderId::ProviderId() : type_(INVALID) {}
// static
ProviderId ProviderId::CreateFromExtensionId(
const extensions::ExtensionId& extension_id) {
return ProviderId(extension_id, EXTENSION);
}
// static
ProviderId ProviderId::CreateFromNativeId(const std::string& native_id) {
return ProviderId(native_id, NATIVE);
}
ProviderId ProviderId::FromString(const std::string& str) {
if (str.length() == 0)
return ProviderId(); // Invalid.
if (str[0] == '@')
return ProviderId::CreateFromNativeId(str.substr(1));
return ProviderId::CreateFromExtensionId(str);
}
const extensions::ExtensionId& ProviderId::GetExtensionId() const {
CHECK_EQ(EXTENSION, type_);
return internal_id_;
}
const std::string& ProviderId::GetNativeId() const {
CHECK_EQ(NATIVE, type_);
return internal_id_;
}
ProviderId::ProviderType ProviderId::GetType() const {
return type_;
}
// Returns the internal_id_ for extensions for backwards compatibility,
// Adds '@' for native ids to avoid collisions.
std::string ProviderId::ToString() const {
switch (type_) {
case EXTENSION:
return internal_id_;
case NATIVE:
return std::string("@") + internal_id_;
case INVALID:
return "";
}
}
bool ProviderId::operator<(const ProviderId& other) const {
return std::tie(type_, internal_id_) <
std::tie(other.type_, other.internal_id_);
}
MountOptions::MountOptions()
: writable(false),
supports_notify_tag(false),
opened_files_limit(0),
persistent(true) {}
MountOptions::MountOptions(const std::string& file_system_id,
const std::string& display_name)
: file_system_id(file_system_id),
display_name(display_name),
writable(false),
supports_notify_tag(false),
opened_files_limit(0),
persistent(true) {}
MountOptions::MountOptions(const MountOptions& source) = default;
MountOptions& MountOptions::operator=(const MountOptions& source) = default;
ProvidedFileSystemInfo::ProvidedFileSystemInfo()
: writable_(false),
supports_notify_tag_(false),
configurable_(false),
watchable_(false),
source_(extensions::SOURCE_FILE),
cache_type_(CacheType::NONE) {}
ProvidedFileSystemInfo::ProvidedFileSystemInfo(
const ProviderId& provider_id,
const MountOptions& mount_options,
const base::FilePath& mount_path,
bool configurable,
bool watchable,
extensions::FileSystemProviderSource source,
const IconSet& icon_set,
CacheType cache_type)
: provider_id_(provider_id),
file_system_id_(mount_options.file_system_id),
display_name_(mount_options.display_name),
writable_(mount_options.writable),
supports_notify_tag_(mount_options.supports_notify_tag),
opened_files_limit_(mount_options.opened_files_limit),
mount_path_(mount_path),
configurable_(configurable),
watchable_(watchable),
source_(source),
icon_set_(icon_set),
cache_type_(cache_type) {
DCHECK_LE(0, mount_options.opened_files_limit);
}
ProvidedFileSystemInfo::ProvidedFileSystemInfo(
const extensions::ExtensionId& extension_id,
const MountOptions& mount_options,
const base::FilePath& mount_path,
bool configurable,
bool watchable,
extensions::FileSystemProviderSource source,
const IconSet& icon_set,
CacheType cache_type)
: ProvidedFileSystemInfo(ProviderId::CreateFromExtensionId(extension_id),
mount_options,
mount_path,
configurable,
watchable,
source,
icon_set,
cache_type) {}
ProvidedFileSystemInfo::ProvidedFileSystemInfo(
const ProvidedFileSystemInfo& other) = default;
ProvidedFileSystemInfo::~ProvidedFileSystemInfo() = default;
bool ProvidedFileSystemInfo::operator==(
const ProvidedFileSystemInfo& other) const {
return provider_id() == other.provider_id() &&
file_system_id() == other.file_system_id() &&
display_name() == other.display_name() &&
writable() == other.writable() &&
supports_notify_tag() == other.supports_notify_tag() &&
opened_files_limit() == other.opened_files_limit() &&
mount_path() == other.mount_path() &&
configurable() == other.configurable() &&
watchable() == other.watchable() && source() == other.source() &&
icon_set() == other.icon_set() && cache_type() == other.cache_type();
}
} // namespace ash::file_system_provider
|