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 { ...@@ -162,14 +162,13 @@ struct FileInfo {
storage::FileSystemURL url; storage::FileSystemURL url;
}; };
void ShareAndSend(aura::Window* target, void ShareAndSend(ui::EndpointType target,
std::vector<FileInfo> files, std::vector<FileInfo> files,
exo::DataExchangeDelegate::SendDataCallback callback) { exo::DataExchangeDelegate::SendDataCallback callback) {
Profile* primary_profile = ProfileManager::GetPrimaryUserProfile(); Profile* primary_profile = ProfileManager::GetPrimaryUserProfile();
aura::Window* toplevel = target->GetToplevelWindow(); bool is_arc = target == ui::EndpointType::kArc;
bool is_arc = ash::IsArcWindow(target->GetToplevelWindow()); bool is_crostini = target == ui::EndpointType::kCrostini;
bool is_crostini = crostini::IsCrostiniWindow(toplevel); bool is_plugin_vm = target == ui::EndpointType::kPluginVm;
bool is_plugin_vm = plugin_vm::IsPluginVmAppWindow(toplevel);
base::FilePath vm_mount; base::FilePath vm_mount;
std::string vm_name; std::string vm_name;
...@@ -285,22 +284,12 @@ ui::EndpointType ChromeDataExchangeDelegate::GetDataTransferEndpointType( ...@@ -285,22 +284,12 @@ ui::EndpointType ChromeDataExchangeDelegate::GetDataTransferEndpointType(
return ui::EndpointType::kUnknownVm; 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( std::vector<ui::FileInfo> ChromeDataExchangeDelegate::GetFilenames(
aura::Window* source, ui::EndpointType source,
const std::vector<uint8_t>& data) const { const std::vector<uint8_t>& data) const {
Profile* primary_profile = ProfileManager::GetPrimaryUserProfile(); Profile* primary_profile = ProfileManager::GetPrimaryUserProfile();
aura::Window* toplevel = source->GetToplevelWindow(); bool is_crostini = source == ui::EndpointType::kCrostini;
bool is_crostini = crostini::IsCrostiniWindow(toplevel); bool is_plugin_vm = source == ui::EndpointType::kPluginVm;
bool is_plugin_vm = plugin_vm::IsPluginVmAppWindow(toplevel);
base::FilePath vm_mount; base::FilePath vm_mount;
std::string vm_name; std::string vm_name;
...@@ -349,13 +338,13 @@ std::vector<ui::FileInfo> ChromeDataExchangeDelegate::GetFilenames( ...@@ -349,13 +338,13 @@ std::vector<ui::FileInfo> ChromeDataExchangeDelegate::GetFilenames(
} }
std::string ChromeDataExchangeDelegate::GetMimeTypeForUriList( std::string ChromeDataExchangeDelegate::GetMimeTypeForUriList(
aura::Window* target) const { ui::EndpointType target) const {
return ash::IsArcWindow(target->GetToplevelWindow()) ? kMimeTypeArcUriList return target == ui::EndpointType::kArc ? kMimeTypeArcUriList
: kMimeTypeTextUriList; : kMimeTypeTextUriList;
} }
void ChromeDataExchangeDelegate::SendFileInfo( void ChromeDataExchangeDelegate::SendFileInfo(
aura::Window* target, ui::EndpointType target,
const std::vector<ui::FileInfo>& files, const std::vector<ui::FileInfo>& files,
SendDataCallback callback) const { SendDataCallback callback) const {
storage::ExternalMountPoints* mount_points = storage::ExternalMountPoints* mount_points =
...@@ -383,14 +372,14 @@ bool ChromeDataExchangeDelegate::HasUrlsInPickle( ...@@ -383,14 +372,14 @@ bool ChromeDataExchangeDelegate::HasUrlsInPickle(
return !file_system_urls.empty(); return !file_system_urls.empty();
} }
void ChromeDataExchangeDelegate::SendPickle(aura::Window* target, void ChromeDataExchangeDelegate::SendPickle(ui::EndpointType target,
const base::Pickle& pickle, const base::Pickle& pickle,
SendDataCallback callback) { SendDataCallback callback) {
std::vector<storage::FileSystemURL> file_system_urls; std::vector<storage::FileSystemURL> file_system_urls;
GetFileSystemUrlsFromPickle(pickle, &file_system_urls); GetFileSystemUrlsFromPickle(pickle, &file_system_urls);
// ARC FileSystemURLs are converted to Content URLs. // ARC FileSystemURLs are converted to Content URLs.
if (ash::IsArcWindow(target->GetToplevelWindow())) { if (target == ui::EndpointType::kArc) {
if (file_system_urls.empty()) { if (file_system_urls.empty()) {
std::move(callback).Run(nullptr); std::move(callback).Run(nullptr);
return; return;
......
...@@ -19,19 +19,16 @@ class ChromeDataExchangeDelegate : public exo::DataExchangeDelegate { ...@@ -19,19 +19,16 @@ class ChromeDataExchangeDelegate : public exo::DataExchangeDelegate {
// DataExchangeDelegate: // DataExchangeDelegate:
ui::EndpointType GetDataTransferEndpointType( ui::EndpointType GetDataTransferEndpointType(
aura::Window* target) const override; aura::Window* window) const override;
void SetSourceOnOSExchangeData(
aura::Window* target,
ui::OSExchangeData* os_exchange_data) const override;
std::vector<ui::FileInfo> GetFilenames( std::vector<ui::FileInfo> GetFilenames(
aura::Window* source, ui::EndpointType source,
const std::vector<uint8_t>& data) const override; const std::vector<uint8_t>& data) const override;
std::string GetMimeTypeForUriList(aura::Window* target) const override; std::string GetMimeTypeForUriList(ui::EndpointType target) const override;
void SendFileInfo(aura::Window* target, void SendFileInfo(ui::EndpointType target,
const std::vector<ui::FileInfo>& files, const std::vector<ui::FileInfo>& files,
SendDataCallback callback) const override; SendDataCallback callback) const override;
bool HasUrlsInPickle(const base::Pickle& pickle) const override; bool HasUrlsInPickle(const base::Pickle& pickle) const override;
void SendPickle(aura::Window* target, void SendPickle(ui::EndpointType target,
const base::Pickle& pickle, const base::Pickle& pickle,
SendDataCallback callback) override; SendDataCallback callback) override;
}; };
......
...@@ -22,7 +22,6 @@ class RefCountedMemory; ...@@ -22,7 +22,6 @@ class RefCountedMemory;
namespace ui { namespace ui {
struct FileInfo; struct FileInfo;
class OSExchangeData;
enum class EndpointType; enum class EndpointType;
} // namespace ui } // namespace ui
...@@ -34,31 +33,25 @@ class DataExchangeDelegate { ...@@ -34,31 +33,25 @@ class DataExchangeDelegate {
public: public:
virtual ~DataExchangeDelegate() {} virtual ~DataExchangeDelegate() {}
// Returns the type of DataTransferEndpoint according to the `target` window. // Returns the endpoint type of `window`.
virtual ui::EndpointType GetDataTransferEndpointType( 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. // Read filenames from text/uri-list |data| which was provided by |source|
virtual void SetSourceOnOSExchangeData( // endpoint. Translates paths from source to host format.
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.
virtual std::vector<ui::FileInfo> GetFilenames( virtual std::vector<ui::FileInfo> GetFilenames(
aura::Window* source, ui::EndpointType source,
const std::vector<uint8_t>& data) const = 0; 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. // 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. // Sends the given list of |files| to |target| endpoint. Translates paths from
// Translates paths from host format to the target and performs any required // host format to the target and performs any required file sharing for VMs.
// file sharing for VMs.
using SendDataCallback = using SendDataCallback =
base::OnceCallback<void(scoped_refptr<base::RefCountedMemory>)>; 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, const std::vector<ui::FileInfo>& files,
SendDataCallback callback) const = 0; SendDataCallback callback) const = 0;
...@@ -67,9 +60,9 @@ class DataExchangeDelegate { ...@@ -67,9 +60,9 @@ class DataExchangeDelegate {
virtual bool HasUrlsInPickle(const base::Pickle& pickle) const = 0; virtual bool HasUrlsInPickle(const base::Pickle& pickle) const = 0;
// Takes in |pickle| constructed by the web contents view containing // Takes in |pickle| constructed by the web contents view containing
// filesystem URLs. Provides translations for the specified target window // filesystem URLs. Provides translations for the specified |target| endpoint
// |target| and performs any required file sharing for VMs.. // and performs any required file sharing for VMs.
virtual void SendPickle(aura::Window* target, virtual void SendPickle(ui::EndpointType target,
const base::Pickle& pickle, const base::Pickle& pickle,
SendDataCallback callback) = 0; SendDataCallback callback) = 0;
}; };
......
...@@ -234,16 +234,18 @@ void DataOffer::SetDropData(DataExchangeDelegate* data_exchange_delegate, ...@@ -234,16 +234,18 @@ void DataOffer::SetDropData(DataExchangeDelegate* data_exchange_delegate,
const ui::OSExchangeData& data) { const ui::OSExchangeData& data) {
DCHECK_EQ(0u, data_callbacks_.size()); DCHECK_EQ(0u, data_callbacks_.size());
ui::EndpointType endpoint_type =
data_exchange_delegate->GetDataTransferEndpointType(target);
const std::string uri_list_mime_type = const std::string uri_list_mime_type =
data_exchange_delegate->GetMimeTypeForUriList(target); data_exchange_delegate->GetMimeTypeForUriList(endpoint_type);
if (data.HasFile()) { if (data.HasFile()) {
std::vector<ui::FileInfo> files; std::vector<ui::FileInfo> files;
if (data.GetFilenames(&files)) { if (data.GetFilenames(&files)) {
data_callbacks_.emplace( data_callbacks_.emplace(
uri_list_mime_type, uri_list_mime_type,
base::BindOnce(&DataExchangeDelegate::SendFileInfo, base::BindOnce(&DataExchangeDelegate::SendFileInfo,
base::Unretained(data_exchange_delegate), target, base::Unretained(data_exchange_delegate),
std::move(files))); endpoint_type, std::move(files)));
delegate_->OnOffer(uri_list_mime_type); delegate_->OnOffer(uri_list_mime_type);
return; return;
} }
...@@ -255,7 +257,7 @@ void DataOffer::SetDropData(DataExchangeDelegate* data_exchange_delegate, ...@@ -255,7 +257,7 @@ void DataOffer::SetDropData(DataExchangeDelegate* data_exchange_delegate,
data_callbacks_.emplace( data_callbacks_.emplace(
uri_list_mime_type, uri_list_mime_type,
base::BindOnce(&DataExchangeDelegate::SendPickle, base::BindOnce(&DataExchangeDelegate::SendPickle,
base::Unretained(data_exchange_delegate), target, base::Unretained(data_exchange_delegate), endpoint_type,
pickle)); pickle));
delegate_->OnOffer(uri_list_mime_type); delegate_->OnOffer(uri_list_mime_type);
return; return;
......
...@@ -184,8 +184,9 @@ DragDropOperation::DragDropOperation( ...@@ -184,8 +184,9 @@ DragDropOperation::DragDropOperation(
drag_drop_controller_->AddObserver(this); drag_drop_controller_->AddObserver(this);
data_exchange_delegate->SetSourceOnOSExchangeData(origin_->get()->window(), os_exchange_data_->SetSource(std::make_unique<ui::DataTransferEndpoint>(
os_exchange_data_.get()); data_exchange_delegate->GetDataTransferEndpointType(
origin_->get()->window())));
#if BUILDFLAG(IS_CHROMEOS_ASH) #if BUILDFLAG(IS_CHROMEOS_ASH)
extended_drag_source_ = ExtendedDragSource::Get(); extended_drag_source_ = ExtendedDragSource::Get();
...@@ -266,8 +267,8 @@ void DragDropOperation::OnFilenamesRead( ...@@ -266,8 +267,8 @@ void DragDropOperation::OnFilenamesRead(
const std::string& mime_type, const std::string& mime_type,
const std::vector<uint8_t>& data) { const std::vector<uint8_t>& data) {
DCHECK(os_exchange_data_); DCHECK(os_exchange_data_);
os_exchange_data_->SetFilenames( os_exchange_data_->SetFilenames(data_exchange_delegate->GetFilenames(
data_exchange_delegate->GetFilenames(source, data)); data_exchange_delegate->GetDataTransferEndpointType(source), data));
mime_type_ = mime_type; mime_type_ = mime_type;
counter_.Run(); counter_.Run();
} }
......
...@@ -25,16 +25,12 @@ TestDataExchangeDelegate::TestDataExchangeDelegate() = default; ...@@ -25,16 +25,12 @@ TestDataExchangeDelegate::TestDataExchangeDelegate() = default;
TestDataExchangeDelegate::~TestDataExchangeDelegate() = default; TestDataExchangeDelegate::~TestDataExchangeDelegate() = default;
ui::EndpointType TestDataExchangeDelegate::GetDataTransferEndpointType( ui::EndpointType TestDataExchangeDelegate::GetDataTransferEndpointType(
aura::Window* target) const { aura::Window* window) const {
return ui::EndpointType::kUnknownVm; return ui::EndpointType::kUnknownVm;
} }
void TestDataExchangeDelegate::SetSourceOnOSExchangeData(
aura::Window* target,
ui::OSExchangeData* os_exchange_data) const {}
std::vector<ui::FileInfo> TestDataExchangeDelegate::GetFilenames( std::vector<ui::FileInfo> TestDataExchangeDelegate::GetFilenames(
aura::Window* source, ui::EndpointType source,
const std::vector<uint8_t>& data) const { const std::vector<uint8_t>& data) const {
std::string lines(data.begin(), data.end()); std::string lines(data.begin(), data.end());
std::vector<ui::FileInfo> filenames; std::vector<ui::FileInfo> filenames;
...@@ -48,12 +44,12 @@ std::vector<ui::FileInfo> TestDataExchangeDelegate::GetFilenames( ...@@ -48,12 +44,12 @@ std::vector<ui::FileInfo> TestDataExchangeDelegate::GetFilenames(
} }
std::string TestDataExchangeDelegate::GetMimeTypeForUriList( std::string TestDataExchangeDelegate::GetMimeTypeForUriList(
aura::Window* target) const { ui::EndpointType target) const {
return "text/uri-list"; return "text/uri-list";
} }
void TestDataExchangeDelegate::SendFileInfo( void TestDataExchangeDelegate::SendFileInfo(
aura::Window* target, ui::EndpointType target,
const std::vector<ui::FileInfo>& files, const std::vector<ui::FileInfo>& files,
SendDataCallback callback) const { SendDataCallback callback) const {
std::vector<std::string> lines; std::vector<std::string> lines;
...@@ -69,7 +65,7 @@ bool TestDataExchangeDelegate::HasUrlsInPickle( ...@@ -69,7 +65,7 @@ bool TestDataExchangeDelegate::HasUrlsInPickle(
return true; return true;
} }
void TestDataExchangeDelegate::SendPickle(aura::Window* target, void TestDataExchangeDelegate::SendPickle(ui::EndpointType target,
const base::Pickle& pickle, const base::Pickle& pickle,
SendDataCallback callback) { SendDataCallback callback) {
send_pickle_callback_ = std::move(callback); send_pickle_callback_ = std::move(callback);
......
...@@ -20,19 +20,16 @@ class TestDataExchangeDelegate : public DataExchangeDelegate { ...@@ -20,19 +20,16 @@ class TestDataExchangeDelegate : public DataExchangeDelegate {
// DataExchangeDelegate: // DataExchangeDelegate:
ui::EndpointType GetDataTransferEndpointType( ui::EndpointType GetDataTransferEndpointType(
aura::Window* target) const override; aura::Window* window) const override;
void SetSourceOnOSExchangeData(
aura::Window* target,
ui::OSExchangeData* os_exchange_data) const override;
std::vector<ui::FileInfo> GetFilenames( std::vector<ui::FileInfo> GetFilenames(
aura::Window* source, ui::EndpointType source,
const std::vector<uint8_t>& data) const override; const std::vector<uint8_t>& data) const override;
std::string GetMimeTypeForUriList(aura::Window* target) const override; std::string GetMimeTypeForUriList(ui::EndpointType target) const override;
void SendFileInfo(aura::Window* target, void SendFileInfo(ui::EndpointType target,
const std::vector<ui::FileInfo>& files, const std::vector<ui::FileInfo>& files,
SendDataCallback callback) const override; SendDataCallback callback) const override;
bool HasUrlsInPickle(const base::Pickle& pickle) const override; bool HasUrlsInPickle(const base::Pickle& pickle) const override;
void SendPickle(aura::Window* target, void SendPickle(ui::EndpointType target,
const base::Pickle& pickle, const base::Pickle& pickle,
SendDataCallback callback) override; 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