Commit e2e48a58 authored by Joel Hockey's avatar Joel Hockey Committed by Chromium LUCI CQ

Use EndpointType in exo::DataExchangeDelegate

Refactor only change.

Now that EndpointType exists, we will use it rather than passing a
source or target aura::Window* for functions in
exo::DataExchangeDelegate.

Removed (inlined) 1-liner function SetSourceOnOSExchangeData which
does not relate to DataExchangeDelegate.

Bug: b/162602338
Change-Id: I20e7aa0c3702155bdafcc15a101c22668a62f621
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2639719Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845453}
parent c8d9c980
......@@ -162,14 +162,13 @@ struct FileInfo {
storage::FileSystemURL url;
};
void ShareAndSend(aura::Window* target,
void ShareAndSend(ui::EndpointType target,
std::vector<FileInfo> files,
exo::DataExchangeDelegate::SendDataCallback callback) {
Profile* primary_profile = ProfileManager::GetPrimaryUserProfile();
aura::Window* toplevel = target->GetToplevelWindow();
bool is_arc = ash::IsArcWindow(target->GetToplevelWindow());
bool is_crostini = crostini::IsCrostiniWindow(toplevel);
bool is_plugin_vm = plugin_vm::IsPluginVmAppWindow(toplevel);
bool is_arc = target == ui::EndpointType::kArc;
bool is_crostini = target == ui::EndpointType::kCrostini;
bool is_plugin_vm = target == ui::EndpointType::kPluginVm;
base::FilePath vm_mount;
std::string vm_name;
......@@ -285,22 +284,12 @@ ui::EndpointType ChromeDataExchangeDelegate::GetDataTransferEndpointType(
return ui::EndpointType::kUnknownVm;
}
void ChromeDataExchangeDelegate::SetSourceOnOSExchangeData(
aura::Window* target,
ui::OSExchangeData* os_exchange_data) const {
DCHECK(os_exchange_data);
os_exchange_data->SetSource(std::make_unique<ui::DataTransferEndpoint>(
GetDataTransferEndpointType(target)));
}
std::vector<ui::FileInfo> ChromeDataExchangeDelegate::GetFilenames(
aura::Window* source,
ui::EndpointType source,
const std::vector<uint8_t>& data) const {
Profile* primary_profile = ProfileManager::GetPrimaryUserProfile();
aura::Window* toplevel = source->GetToplevelWindow();
bool is_crostini = crostini::IsCrostiniWindow(toplevel);
bool is_plugin_vm = plugin_vm::IsPluginVmAppWindow(toplevel);
bool is_crostini = source == ui::EndpointType::kCrostini;
bool is_plugin_vm = source == ui::EndpointType::kPluginVm;
base::FilePath vm_mount;
std::string vm_name;
......@@ -349,13 +338,13 @@ std::vector<ui::FileInfo> ChromeDataExchangeDelegate::GetFilenames(
}
std::string ChromeDataExchangeDelegate::GetMimeTypeForUriList(
aura::Window* target) const {
return ash::IsArcWindow(target->GetToplevelWindow()) ? kMimeTypeArcUriList
: kMimeTypeTextUriList;
ui::EndpointType target) const {
return target == ui::EndpointType::kArc ? kMimeTypeArcUriList
: kMimeTypeTextUriList;
}
void ChromeDataExchangeDelegate::SendFileInfo(
aura::Window* target,
ui::EndpointType target,
const std::vector<ui::FileInfo>& files,
SendDataCallback callback) const {
storage::ExternalMountPoints* mount_points =
......@@ -383,14 +372,14 @@ bool ChromeDataExchangeDelegate::HasUrlsInPickle(
return !file_system_urls.empty();
}
void ChromeDataExchangeDelegate::SendPickle(aura::Window* target,
void ChromeDataExchangeDelegate::SendPickle(ui::EndpointType target,
const base::Pickle& pickle,
SendDataCallback callback) {
std::vector<storage::FileSystemURL> file_system_urls;
GetFileSystemUrlsFromPickle(pickle, &file_system_urls);
// ARC FileSystemURLs are converted to Content URLs.
if (ash::IsArcWindow(target->GetToplevelWindow())) {
if (target == ui::EndpointType::kArc) {
if (file_system_urls.empty()) {
std::move(callback).Run(nullptr);
return;
......
......@@ -19,19 +19,16 @@ class ChromeDataExchangeDelegate : public exo::DataExchangeDelegate {
// DataExchangeDelegate:
ui::EndpointType GetDataTransferEndpointType(
aura::Window* target) const override;
void SetSourceOnOSExchangeData(
aura::Window* target,
ui::OSExchangeData* os_exchange_data) const override;
aura::Window* window) const override;
std::vector<ui::FileInfo> GetFilenames(
aura::Window* source,
ui::EndpointType source,
const std::vector<uint8_t>& data) const override;
std::string GetMimeTypeForUriList(aura::Window* target) const override;
void SendFileInfo(aura::Window* target,
std::string GetMimeTypeForUriList(ui::EndpointType target) const override;
void SendFileInfo(ui::EndpointType target,
const std::vector<ui::FileInfo>& files,
SendDataCallback callback) const override;
bool HasUrlsInPickle(const base::Pickle& pickle) const override;
void SendPickle(aura::Window* target,
void SendPickle(ui::EndpointType target,
const base::Pickle& pickle,
SendDataCallback callback) override;
};
......
......@@ -22,7 +22,6 @@ class RefCountedMemory;
namespace ui {
struct FileInfo;
class OSExchangeData;
enum class EndpointType;
} // namespace ui
......@@ -34,31 +33,25 @@ class DataExchangeDelegate {
public:
virtual ~DataExchangeDelegate() {}
// Returns the type of DataTransferEndpoint according to the `target` window.
// Returns the endpoint type of `window`.
virtual ui::EndpointType GetDataTransferEndpointType(
aura::Window* target) const = 0;
aura::Window* window) const = 0;
// Sets the source of `os_exchange_data` according to the `target` window.
virtual void SetSourceOnOSExchangeData(
aura::Window* target,
ui::OSExchangeData* os_exchange_data) const = 0;
// Read filenames from |data| which was provided by source window |source|.
// Translates paths from source to host format.
// Read filenames from text/uri-list |data| which was provided by |source|
// endpoint. Translates paths from source to host format.
virtual std::vector<ui::FileInfo> GetFilenames(
aura::Window* source,
ui::EndpointType source,
const std::vector<uint8_t>& data) const = 0;
// Returns the mime type which is used by target window |target| for a list of
// Returns the mime type which is used by |target| endpoint for a list of
// file path URIs.
virtual std::string GetMimeTypeForUriList(aura::Window* target) const = 0;
virtual std::string GetMimeTypeForUriList(ui::EndpointType target) const = 0;
// Sends the given file list |files| to target window |target| window.
// Translates paths from host format to the target and performs any required
// file sharing for VMs.
// Sends the given list of |files| to |target| endpoint. Translates paths from
// host format to the target and performs any required file sharing for VMs.
using SendDataCallback =
base::OnceCallback<void(scoped_refptr<base::RefCountedMemory>)>;
virtual void SendFileInfo(aura::Window* target,
virtual void SendFileInfo(ui::EndpointType target,
const std::vector<ui::FileInfo>& files,
SendDataCallback callback) const = 0;
......@@ -67,9 +60,9 @@ class DataExchangeDelegate {
virtual bool HasUrlsInPickle(const base::Pickle& pickle) const = 0;
// Takes in |pickle| constructed by the web contents view containing
// filesystem URLs. Provides translations for the specified target window
// |target| and performs any required file sharing for VMs..
virtual void SendPickle(aura::Window* target,
// filesystem URLs. Provides translations for the specified |target| endpoint
// and performs any required file sharing for VMs.
virtual void SendPickle(ui::EndpointType target,
const base::Pickle& pickle,
SendDataCallback callback) = 0;
};
......
......@@ -234,16 +234,18 @@ void DataOffer::SetDropData(DataExchangeDelegate* data_exchange_delegate,
const ui::OSExchangeData& data) {
DCHECK_EQ(0u, data_callbacks_.size());
ui::EndpointType endpoint_type =
data_exchange_delegate->GetDataTransferEndpointType(target);
const std::string uri_list_mime_type =
data_exchange_delegate->GetMimeTypeForUriList(target);
data_exchange_delegate->GetMimeTypeForUriList(endpoint_type);
if (data.HasFile()) {
std::vector<ui::FileInfo> files;
if (data.GetFilenames(&files)) {
data_callbacks_.emplace(
uri_list_mime_type,
base::BindOnce(&DataExchangeDelegate::SendFileInfo,
base::Unretained(data_exchange_delegate), target,
std::move(files)));
base::Unretained(data_exchange_delegate),
endpoint_type, std::move(files)));
delegate_->OnOffer(uri_list_mime_type);
return;
}
......@@ -255,7 +257,7 @@ void DataOffer::SetDropData(DataExchangeDelegate* data_exchange_delegate,
data_callbacks_.emplace(
uri_list_mime_type,
base::BindOnce(&DataExchangeDelegate::SendPickle,
base::Unretained(data_exchange_delegate), target,
base::Unretained(data_exchange_delegate), endpoint_type,
pickle));
delegate_->OnOffer(uri_list_mime_type);
return;
......
......@@ -184,8 +184,9 @@ DragDropOperation::DragDropOperation(
drag_drop_controller_->AddObserver(this);
data_exchange_delegate->SetSourceOnOSExchangeData(origin_->get()->window(),
os_exchange_data_.get());
os_exchange_data_->SetSource(std::make_unique<ui::DataTransferEndpoint>(
data_exchange_delegate->GetDataTransferEndpointType(
origin_->get()->window())));
#if BUILDFLAG(IS_CHROMEOS_ASH)
extended_drag_source_ = ExtendedDragSource::Get();
......@@ -266,8 +267,8 @@ void DragDropOperation::OnFilenamesRead(
const std::string& mime_type,
const std::vector<uint8_t>& data) {
DCHECK(os_exchange_data_);
os_exchange_data_->SetFilenames(
data_exchange_delegate->GetFilenames(source, data));
os_exchange_data_->SetFilenames(data_exchange_delegate->GetFilenames(
data_exchange_delegate->GetDataTransferEndpointType(source), data));
mime_type_ = mime_type;
counter_.Run();
}
......
......@@ -25,16 +25,12 @@ TestDataExchangeDelegate::TestDataExchangeDelegate() = default;
TestDataExchangeDelegate::~TestDataExchangeDelegate() = default;
ui::EndpointType TestDataExchangeDelegate::GetDataTransferEndpointType(
aura::Window* target) const {
aura::Window* window) const {
return ui::EndpointType::kUnknownVm;
}
void TestDataExchangeDelegate::SetSourceOnOSExchangeData(
aura::Window* target,
ui::OSExchangeData* os_exchange_data) const {}
std::vector<ui::FileInfo> TestDataExchangeDelegate::GetFilenames(
aura::Window* source,
ui::EndpointType source,
const std::vector<uint8_t>& data) const {
std::string lines(data.begin(), data.end());
std::vector<ui::FileInfo> filenames;
......@@ -48,12 +44,12 @@ std::vector<ui::FileInfo> TestDataExchangeDelegate::GetFilenames(
}
std::string TestDataExchangeDelegate::GetMimeTypeForUriList(
aura::Window* target) const {
ui::EndpointType target) const {
return "text/uri-list";
}
void TestDataExchangeDelegate::SendFileInfo(
aura::Window* target,
ui::EndpointType target,
const std::vector<ui::FileInfo>& files,
SendDataCallback callback) const {
std::vector<std::string> lines;
......@@ -69,7 +65,7 @@ bool TestDataExchangeDelegate::HasUrlsInPickle(
return true;
}
void TestDataExchangeDelegate::SendPickle(aura::Window* target,
void TestDataExchangeDelegate::SendPickle(ui::EndpointType target,
const base::Pickle& pickle,
SendDataCallback callback) {
send_pickle_callback_ = std::move(callback);
......
......@@ -20,19 +20,16 @@ class TestDataExchangeDelegate : public DataExchangeDelegate {
// DataExchangeDelegate:
ui::EndpointType GetDataTransferEndpointType(
aura::Window* target) const override;
void SetSourceOnOSExchangeData(
aura::Window* target,
ui::OSExchangeData* os_exchange_data) const override;
aura::Window* window) const override;
std::vector<ui::FileInfo> GetFilenames(
aura::Window* source,
ui::EndpointType source,
const std::vector<uint8_t>& data) const override;
std::string GetMimeTypeForUriList(aura::Window* target) const override;
void SendFileInfo(aura::Window* target,
std::string GetMimeTypeForUriList(ui::EndpointType target) const override;
void SendFileInfo(ui::EndpointType target,
const std::vector<ui::FileInfo>& files,
SendDataCallback callback) const override;
bool HasUrlsInPickle(const base::Pickle& pickle) const override;
void SendPickle(aura::Window* target,
void SendPickle(ui::EndpointType target,
const base::Pickle& pickle,
SendDataCallback callback) override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment