0

ash: Remove DownloadController crosapi

Lacros is gone. Remove the unused DownloadController crosapi and its
implementation (DownloadControllerAsh) and support utilities.

Bug: b:365741912, b:365902693
Change-Id: I89b90ebee85cbe9ba0c93b28d41c69bfc4212d74
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6290672
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: David Trainor <dtrainor@chromium.org>
Reviewed-by: Hidehiko Abe <hidehiko@chromium.org>
Auto-Submit: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1425549}
This commit is contained in:
Georg Neis
2025-02-26 19:58:15 -08:00
committed by Chromium LUCI CQ
parent fd50414600
commit 1d955fd813
13 changed files with 1 additions and 726 deletions

@ -51,8 +51,6 @@ static_library("crosapi") {
"document_scan_ash.h",
"document_scan_ash_type_converters.cc",
"document_scan_ash_type_converters.h",
"download_controller_ash.cc",
"download_controller_ash.h",
"drive_integration_service_ash.cc",
"drive_integration_service_ash.h",
"echo_private_ash.cc",
@ -491,7 +489,6 @@ source_set("unit_tests") {
"device_oauth2_token_service_ash_unittest.cc",
"document_scan_ash_type_converters_unittest.cc",
"document_scan_ash_unittest.cc",
"download_controller_ash_unittest.cc",
"fullscreen_controller_ash_unittest.cc",
"input_methods_ash_unittest.cc",
"keystore_service_ash_unittest.cc",

@ -28,7 +28,6 @@
#include "chrome/browser/ash/crosapi/device_local_account_extension_service_ash.h"
#include "chrome/browser/ash/crosapi/device_oauth2_token_service_ash.h"
#include "chrome/browser/ash/crosapi/document_scan_ash.h"
#include "chrome/browser/ash/crosapi/download_controller_ash.h"
#include "chrome/browser/ash/crosapi/drive_integration_service_ash.h"
#include "chrome/browser/ash/crosapi/echo_private_ash.h"
#include "chrome/browser/ash/crosapi/embedded_accessibility_helper_client_ash.h"
@ -171,7 +170,6 @@ CrosapiAsh::CrosapiAsh()
std::make_unique<DeviceOAuth2TokenServiceAsh>()),
diagnostics_service_ash_(std::make_unique<ash::DiagnosticsServiceAsh>()),
document_scan_ash_(std::make_unique<DocumentScanAsh>()),
download_controller_ash_(std::make_unique<DownloadControllerAsh>()),
drive_integration_service_ash_(
std::make_unique<DriveIntegrationServiceAsh>()),
echo_private_ash_(std::make_unique<EchoPrivateAsh>()),
@ -356,11 +354,6 @@ void CrosapiAsh::BindDocumentScan(
document_scan_ash_->BindReceiver(std::move(receiver));
}
void CrosapiAsh::BindDownloadController(
mojo::PendingReceiver<mojom::DownloadController> receiver) {
download_controller_ash_->BindReceiver(std::move(receiver));
}
void CrosapiAsh::BindDriveIntegrationService(
mojo::PendingReceiver<crosapi::mojom::DriveIntegrationService> receiver) {
drive_integration_service_ash_->BindReceiver(std::move(receiver));

@ -57,7 +57,6 @@ class DeviceAttributesAsh;
class DeviceLocalAccountExtensionServiceAsh;
class DeviceOAuth2TokenServiceAsh;
class DocumentScanAsh;
class DownloadControllerAsh;
class DriveIntegrationServiceAsh;
class EchoPrivateAsh;
class EmbeddedAccessibilityHelperClientAsh;
@ -156,8 +155,6 @@ class CrosapiAsh : public mojom::Crosapi {
mojo::PendingReceiver<mojom::DiagnosticsService> receiver) override;
void BindDocumentScan(
mojo::PendingReceiver<mojom::DocumentScan> receiver) override;
void BindDownloadController(
mojo::PendingReceiver<mojom::DownloadController> receiver) override;
void BindDriveIntegrationService(
mojo::PendingReceiver<mojom::DriveIntegrationService> receiver) override;
void BindEchoPrivate(
@ -324,10 +321,6 @@ class CrosapiAsh : public mojom::Crosapi {
DocumentScanAsh* document_scan_ash() { return document_scan_ash_.get(); }
DownloadControllerAsh* download_controller_ash() {
return download_controller_ash_.get();
}
EchoPrivateAsh* echo_private_ash() { return echo_private_ash_.get(); }
EmbeddedAccessibilityHelperClientAsh*
@ -459,7 +452,6 @@ class CrosapiAsh : public mojom::Crosapi {
std::unique_ptr<DeviceOAuth2TokenServiceAsh> device_oauth2_token_service_ash_;
std::unique_ptr<ash::DiagnosticsServiceAsh> diagnostics_service_ash_;
std::unique_ptr<DocumentScanAsh> document_scan_ash_;
std::unique_ptr<DownloadControllerAsh> download_controller_ash_;
std::unique_ptr<DriveIntegrationServiceAsh> drive_integration_service_ash_;
std::unique_ptr<EchoPrivateAsh> echo_private_ash_;
std::unique_ptr<EmbeddedAccessibilityHelperClientAsh>

@ -1,125 +0,0 @@
// 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.
#include "chrome/browser/ash/crosapi/download_controller_ash.h"
#include <functional>
#include "base/barrier_callback.h"
#include "base/containers/extend.h"
#include "mojo/public/cpp/bindings/callback_helpers.h"
namespace crosapi {
DownloadControllerAsh::DownloadControllerAsh() = default;
DownloadControllerAsh::~DownloadControllerAsh() = default;
void DownloadControllerAsh::BindReceiver(
mojo::PendingReceiver<mojom::DownloadController> pending_receiver) {
receivers_.Add(this, std::move(pending_receiver));
}
void DownloadControllerAsh::BindClient(
mojo::PendingRemote<mojom::DownloadControllerClient> client) {
clients_.Add(std::move(client));
}
void DownloadControllerAsh::OnDownloadCreated(
crosapi::mojom::DownloadItemPtr download) {
for (auto& observer : observers_)
observer.OnLacrosDownloadCreated(*download);
}
void DownloadControllerAsh::OnDownloadUpdated(
crosapi::mojom::DownloadItemPtr download) {
for (auto& observer : observers_)
observer.OnLacrosDownloadUpdated(*download);
}
void DownloadControllerAsh::OnDownloadDestroyed(
crosapi::mojom::DownloadItemPtr download) {
for (auto& observer : observers_)
observer.OnLacrosDownloadDestroyed(*download);
}
void DownloadControllerAsh::AddObserver(DownloadControllerObserver* observer) {
observers_.AddObserver(observer);
}
void DownloadControllerAsh::RemoveObserver(
DownloadControllerObserver* observer) {
observers_.RemoveObserver(observer);
}
void DownloadControllerAsh::GetAllDownloads(
mojom::DownloadControllerClient::GetAllDownloadsCallback callback) {
if (clients_.empty()) {
std::move(callback).Run({});
return;
}
// This callback will be invoked by each Lacros client to aggregate all
// downloads, sort them chronologically by start time, and ultimately provide
// them to the original `callback`.
auto aggregating_downloads_callback =
base::BarrierCallback<std::vector<mojom::DownloadItemPtr>>(
clients_.size(),
base::BindOnce([](std::vector<std::vector<mojom::DownloadItemPtr>>
client_downloads) {
std::vector<mojom::DownloadItemPtr> aggregated_downloads;
// Aggregate downloads from each Lacros client.
for (auto& entry : client_downloads) {
base::Extend(aggregated_downloads, std::move(entry));
}
// Sort aggregated downloads chronologically by start time.
// `start_time` equal to `std::nullopt` is by default less than any
// non-empty `start_time`.
std::ranges::sort(aggregated_downloads, std::ranges::less{},
&mojom::DownloadItem::start_time);
return aggregated_downloads;
}).Then(std::move(callback)));
// Aggregate downloads from each Lacros `client`. Note that if the `client` is
// not of a supported `version` or if the connection is dropped before the
// `client` returns a response, it will not contribute any downloads.
for (auto& client : clients_) {
const uint32_t version = client.version();
if (mojom::DownloadControllerClient::kGetAllDownloadsMinVersion > version) {
aggregating_downloads_callback.Run(std::vector<mojom::DownloadItemPtr>());
continue;
}
client->GetAllDownloads(mojo::WrapCallbackWithDefaultInvokeIfNotRun(
base::BindOnce(aggregating_downloads_callback),
/*default_invoke_args=*/std::vector<mojom::DownloadItemPtr>()));
}
}
void DownloadControllerAsh::Pause(const std::string& download_guid) {
for (auto& client : clients_)
client->Pause(download_guid);
}
void DownloadControllerAsh::Resume(const std::string& download_guid,
bool user_resume) {
for (auto& client : clients_)
client->Resume(download_guid, user_resume);
}
void DownloadControllerAsh::Cancel(const std::string& download_guid,
bool user_cancel) {
for (auto& client : clients_)
client->Cancel(download_guid, user_cancel);
}
void DownloadControllerAsh::SetOpenWhenComplete(
const std::string& download_guid,
bool open_when_complete) {
for (auto& client : clients_)
client->SetOpenWhenComplete(download_guid, open_when_complete);
}
} // namespace crosapi

@ -1,88 +0,0 @@
// 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 CHROME_BROWSER_ASH_CROSAPI_DOWNLOAD_CONTROLLER_ASH_H_
#define CHROME_BROWSER_ASH_CROSAPI_DOWNLOAD_CONTROLLER_ASH_H_
#include <string>
#include "base/observer_list.h"
#include "base/observer_list_types.h"
#include "chromeos/crosapi/mojom/download_controller.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote_set.h"
namespace crosapi {
// The ash-chrome implementation of the DownloadController crosapi interface.
// This is where ash-chrome receives information on download events from lacros.
// This class must only be used from the main thread.
class DownloadControllerAsh : public mojom::DownloadController {
public:
// Allows ash classes to observe download events.
class DownloadControllerObserver : public base::CheckedObserver {
public:
virtual void OnLacrosDownloadCreated(const mojom::DownloadItem&) {}
virtual void OnLacrosDownloadUpdated(const mojom::DownloadItem&) {}
virtual void OnLacrosDownloadDestroyed(const mojom::DownloadItem&) {}
};
DownloadControllerAsh();
DownloadControllerAsh(const DownloadControllerAsh&) = delete;
DownloadControllerAsh& operator=(const DownloadControllerAsh&) = delete;
~DownloadControllerAsh() override;
// Bind this receiver for `mojom::DownloadController`. This is used by
// crosapi.
void BindReceiver(mojo::PendingReceiver<mojom::DownloadController> receiver);
// mojom::DownloadController:
void BindClient(
mojo::PendingRemote<mojom::DownloadControllerClient> client) override;
void OnDownloadCreated(mojom::DownloadItemPtr download) override;
void OnDownloadUpdated(mojom::DownloadItemPtr download) override;
void OnDownloadDestroyed(mojom::DownloadItemPtr download) override;
// Required for the below `base::ObserverList`:
void AddObserver(DownloadControllerObserver* observer);
void RemoveObserver(DownloadControllerObserver* observer);
// Asynchronously returns all downloads from each Lacros client via the
// specified `callback`, no matter the type or state. Downloads are sorted
// chronologically by start time.
void GetAllDownloads(
mojom::DownloadControllerClient::GetAllDownloadsCallback callback);
// Pauses the download associated with the specified `download_guid`. This
// method will ultimately invoke `download::DownloadItem::Pause()`.
void Pause(const std::string& download_guid);
// Resumes the download associated with the specified `download_guid`. If
// `user_resume` is set to `true`, it signifies that this invocation was
// triggered by an explicit user action. This method will ultimately invoke
// `download::DownloadItem::Resume()`.
void Resume(const std::string& download_guid, bool user_resume);
// Cancels the download associated with the specified `download_guid`. If
// `user_cancel` is set to `true`, it signifies that this invocation was
// triggered by an explicit user action. This method will ultimately invoke
// `download::DownloadItem::Cancel()`.
void Cancel(const std::string& download_guid, bool user_cancel);
// Marks the download associated with the specified `download_guid` to be
// `open_when_complete`. This method will ultimately invoke
// `download::DownloadItem::SetOpenWhenComplete()`.
void SetOpenWhenComplete(const std::string& download_guid,
bool open_when_complete);
private:
mojo::ReceiverSet<mojom::DownloadController> receivers_;
mojo::RemoteSet<mojom::DownloadControllerClient> clients_;
base::ObserverList<DownloadControllerObserver> observers_;
};
} // namespace crosapi
#endif // CHROME_BROWSER_ASH_CROSAPI_DOWNLOAD_CONTROLLER_ASH_H_

@ -1,136 +0,0 @@
// 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.
#include "chrome/browser/ash/crosapi/download_controller_ash.h"
#include <string>
#include <vector>
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "chromeos/crosapi/mojom/download_controller.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace crosapi {
// Helpers ---------------------------------------------------------------------
mojom::DownloadItemPtr CreateDownloadItemWithStartTimeOffset(
base::TimeDelta start_time_offset) {
auto download = mojom::DownloadItem::New();
download->start_time = base::Time::Now() + start_time_offset;
return download;
}
bool IsSortedChronologicallyByStartTime(
const std::vector<mojom::DownloadItemPtr>& downloads) {
for (size_t i = 1; i < downloads.size(); ++i) {
if (downloads[i]->start_time.value_or(base::Time()) <
downloads[i - 1]->start_time.value_or(base::Time())) {
return false;
}
}
return true;
}
// Mocks -----------------------------------------------------------------------
class MockDownloadControllerClient : public mojom::DownloadControllerClient {
public:
MOCK_METHOD(void,
GetAllDownloads,
(mojom::DownloadControllerClient::GetAllDownloadsCallback),
(override));
MOCK_METHOD(void, Pause, (const std::string& download_guid), (override));
MOCK_METHOD(void,
Resume,
(const std::string& download_guid, bool user_resume),
(override));
MOCK_METHOD(void,
Cancel,
(const std::string& download_guid, bool user_cancel),
(override));
MOCK_METHOD(void,
SetOpenWhenComplete,
(const std::string& download_guid, bool open_when_complete),
(override));
};
// DownloadControllerAshTest ---------------------------------------------------
class DownloadControllerAshTest : public testing::Test {
public:
DownloadControllerAsh* download_controller_ash() {
return &download_controller_ash_;
}
std::vector<mojom::DownloadItemPtr> GetAllDownloads() {
base::test::TestFuture<std::vector<mojom::DownloadItemPtr>> future;
download_controller_ash()->GetAllDownloads(future.GetCallback());
return future.Take();
}
private:
base::test::SingleThreadTaskEnvironment task_environment_;
DownloadControllerAsh download_controller_ash_;
};
// Tests -----------------------------------------------------------------------
TEST_F(DownloadControllerAshTest, GetAllDownloads_NoBoundClients) {
// Invoke `GetAllDownloads()` with no clients bound.
const std::vector<mojom::DownloadItemPtr> downloads = GetAllDownloads();
EXPECT_EQ(downloads.size(), 0u);
}
TEST_F(DownloadControllerAshTest, GetAllDownloads_MultipleBoundClients) {
// Bind `client1`.
testing::NiceMock<MockDownloadControllerClient> client1;
mojo::Receiver<mojom::DownloadControllerClient> client1_receiver{&client1};
download_controller_ash()->BindClient(
client1_receiver.BindNewPipeAndPassRemoteWithVersion());
// Mock `client1` response for `GetAllDownloads()`.
EXPECT_CALL(client1, GetAllDownloads)
.WillOnce(testing::Invoke(
[](mojom::DownloadControllerClient::GetAllDownloadsCallback
callback) {
std::vector<mojom::DownloadItemPtr> downloads;
downloads.push_back(
CreateDownloadItemWithStartTimeOffset(base::Minutes(10)));
downloads.push_back(
CreateDownloadItemWithStartTimeOffset(-base::Minutes(10)));
std::move(callback).Run(std::move(downloads));
}));
// Bind `client2`.
testing::NiceMock<MockDownloadControllerClient> client2;
mojo::Receiver<mojom::DownloadControllerClient> client2_receiver{&client2};
download_controller_ash()->BindClient(
client2_receiver.BindNewPipeAndPassRemoteWithVersion());
// Mock `client2` response for `GetAllDownloads()`.
EXPECT_CALL(client2, GetAllDownloads)
.WillOnce(testing::Invoke(
[](mojom::DownloadControllerClient::GetAllDownloadsCallback
callback) {
std::vector<mojom::DownloadItemPtr> downloads;
downloads.push_back(
CreateDownloadItemWithStartTimeOffset(base::Minutes(20)));
downloads.push_back(
CreateDownloadItemWithStartTimeOffset(-base::Minutes(20)));
std::move(callback).Run(std::move(downloads));
}));
// Invoke `GetAllDownloads()`.
const std::vector<mojom::DownloadItemPtr> downloads = GetAllDownloads();
EXPECT_EQ(downloads.size(), 4u);
EXPECT_TRUE(IsSortedChronologicallyByStartTime(downloads));
}
} // namespace crosapi

@ -22,7 +22,6 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/holding_space/holding_space_util.h"
#include "components/download/public/common/download_item.h"
#include "components/download/public/common/download_item_utils.h"
#include "components/download/public/common/simple_download_manager.h"
#include "components/vector_icons/vector_icons.h"
#include "content/public/browser/browser_context.h"

@ -26,7 +26,6 @@ mojom("mojom") {
"device_oauth2_token_service.mojom",
"diagnostics_service.mojom",
"document_scan.mojom",
"download_controller.mojom",
"drive_integration_service.mojom",
"echo_private.mojom",
"embedded_accessibility_helper.mojom",

@ -27,7 +27,6 @@ import "chromeos/crosapi/mojom/device_local_account_extension_service.mojom";
import "chromeos/crosapi/mojom/device_oauth2_token_service.mojom";
import "chromeos/crosapi/mojom/diagnostics_service.mojom";
import "chromeos/crosapi/mojom/document_scan.mojom";
import "chromeos/crosapi/mojom/download_controller.mojom";
import "chromeos/crosapi/mojom/drive_integration_service.mojom";
import "chromeos/crosapi/mojom/echo_private.mojom";
import "chromeos/crosapi/mojom/extension_info_private.mojom";
@ -219,11 +218,7 @@ interface Crosapi {
// Added in M104.
[MinVersion=77] BindDocumentScan@80(pending_receiver<DocumentScan> receiver);
// Binds the DownloadController interface, which allows Lacros download
// information to be passed into Ash Chrome.
// Added in M92.
[MinVersion=28] BindDownloadController@33(
pending_receiver<DownloadController> receiver);
// BindDownloadController@33 was removed.
// Binds the DriveIntegrationService interface for getting information about
// the local Google Drive mount.

@ -1,154 +0,0 @@
// 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.
module crosapi.mojom;
import "mojo/public/mojom/base/file_path.mojom";
import "mojo/public/mojom/base/time.mojom";
// This mirrors `download::DownloadItem::DownloadState`, anything added or
// removed here must also be added or removed there.
[Extensible]
enum DownloadState {
[Default] kUnknown = 0,
kInProgress,
kComplete,
kCancelled,
kInterrupted
};
// This mirrors `download::DownloadDangerType`, anything added or removed here
// must also be added or removed there.
[Extensible]
enum DownloadDangerType {
[Default] kDownloadDangerTypeInvalid = -1,
kDownloadDangerTypeNotDangerous = 0,
kDownloadDangerTypeDangerousFile = 1,
kDownloadDangerTypeDangerousUrl = 2,
kDownloadDangerTypeDangerousContent = 3,
kDownloadDangerTypeMaybeDangerousContent = 4,
kDownloadDangerTypeUncommonContent = 5,
kDownloadDangerTypeUserValidated = 6,
kDownloadDangerTypeDangerousHost = 7,
kDownloadDangerTypePotentiallyUnwanted = 8,
kDownloadDangerTypeAllowlistedByPolicy = 9,
kDownloadDangerTypeAsyncScanning = 10,
kDownloadDangerTypeBlockedPasswordProtected = 11,
kDownloadDangerTypeBlockedTooLarge = 12,
kDownloadDangerTypeSensitiveContentWarning = 13,
kDownloadDangerTypeSensitiveContentBlock = 14,
kDownloadDangerTypeDeepScannedSafe = 15,
kDownloadDangerTypeDeepScannedOpenedDangerous = 16,
kDownloadDangerTypePromptForScanning = 17,
kDownloadDangerTypeDeprecated18 = 18,
kDownloadDangerTypeDangerousAccountCompromise = 19,
[MinVersion=1] kDownloadDangerTypeDeepScannedFailed = 20,
[MinVersion=2] kDownloadDangerTypePromptForLocalPasswordScanning = 21,
[MinVersion=2] kDownloadDangerTypeAsyncLocalPasswordScanning = 22,
[MinVersion=3] kDownloadDangerTypeBlockedScanFailed = 23,
};
// This mirrors `download::DownloadItem::InsecureDownloadStatus`, anything
// added or removed here must also be added or removed there.
[Extensible, RenamedFrom="crosapi.mojom.DownloadMixedContentStatus"]
enum InsecureDownloadStatus {
[Default] kInvalid = -1,
kUnknown = 0,
kSafe = 1,
kValidated = 2,
kWarn = 3,
kBlock = 4,
kSilentBlock = 5,
};
// This mirrors `download::DownloadItem`. See:
// https://source.chromium.org/chromium/chromium/src/+/main:components/download/public/common/download_item.h?q=download_item.h
//
// NOTE: Starting in Version 1, `has_field` is added for every new
// non-nullable `field`. This is for backwards compatibility, so that older
// clients know when values are present or are absent by default.
//
// Next MinVersion: 5
// Next ID: 20
[RenamedFrom="crosapi.mojom.DownloadEvent"]
struct DownloadItem {
DownloadState state@0;
mojo_base.mojom.FilePath target_file_path@1;
bool is_from_incognito_profile@2;
[MinVersion=1] string? guid@3;
[MinVersion=1] mojo_base.mojom.FilePath? full_path@4;
[MinVersion=1] bool has_is_paused@5;
[MinVersion=1] bool is_paused@6;
[MinVersion=1] bool has_open_when_complete@7;
[MinVersion=1] bool open_when_complete@8;
[MinVersion=1] bool has_received_bytes@9;
[MinVersion=1] int64 received_bytes@10;
[MinVersion=1] bool has_total_bytes@11;
[MinVersion=1] int64 total_bytes@12;
[MinVersion=2] mojo_base.mojom.Time? start_time@13;
[MinVersion=3] bool has_is_dangerous@14;
[MinVersion=3] bool is_dangerous@15;
[MinVersion=3] bool has_is_insecure@16;
[MinVersion=3] bool is_insecure@17;
[MinVersion=4] DownloadDangerType danger_type@18;
[MinVersion=4] InsecureDownloadStatus insecure_download_status@19;
};
// A client implemented in lacros-chrome for the DownloadController which is
// implemented in ash-chrome.
//
// Next MinVersion: 2
// Next ID: 6
[Uuid="eccf720b-538a-4943-a6fd-d073639c4140"]
interface DownloadControllerClient {
// Returns all downloads, no matter the type or state, sorted chronologically
// by start time. This method will ultimately invoke
// `download::SimpleDownloadManager::GetAllDownloads()`.
[MinVersion=1] GetAllDownloads@5() => (array<DownloadItem> downloads);
// Pauses the download associated with the specified `download_guid`. This
// method will ultimately invoke `download::DownloadItem::Pause()`.
Pause@1(string download_guid);
// Resumes the download associated with the specified `download_guid`. If
// `user_resume` is set to `true`, it signifies that this invocation was
// triggered by an explicit user action. This method will ultimately invoke
// `download::DownloadItem::Resume()`.
Resume@2(string download_guid, bool user_resume);
// Cancels the download associated with the specified `download_guid`. If
// `user_cancel` is set to `true`, it signifies that this invocation was
// triggered by an explicit user action. This method will ultimately invoke
// `download::DownloadItem::Cancel()`.
Cancel@3(string download_guid, bool user_cancel);
// Marks the download associated with the specified `download_guid` to be
// `open_when_complete`. This method will ultimately invoke
// `download::DownloadItem::SetOpenWhenComplete()`.
SetOpenWhenComplete@4(string download_guid, bool open_when_complete);
};
// Allows lacros to pass download information to ash-chrome.
// Implemented in ash-chrome.
//
// Next MinVersion: 2
// Next ID: 4
[Uuid="c3d8bd4b-1fc9-4529-aeb2-76770b0ad1c3"]
interface DownloadController {
// Binds the DownloadControllerClient interface, which allows the
// DownloadController implemented in ash-chrome to communicate with its client
// which is implemented in lacros-chrome.
[MinVersion=1] BindClient@3(
pending_remote<DownloadControllerClient> client);
// Called when a download is created. Comes from `content::DownloadManager`,
// and will only pass events once that's initialized.
OnDownloadCreated@0(crosapi.mojom.DownloadItem download);
// Called whenever a `download::DownloadItem` is updated.
OnDownloadUpdated@1(crosapi.mojom.DownloadItem download);
// Called when a `download::DownloadItem` is destroyed.
OnDownloadDestroyed@2(crosapi.mojom.DownloadItem download);
};

@ -118,14 +118,6 @@ component("public") {
"android/auto_resumption_handler.h",
]
}
if (is_chromeos) {
sources += [
"download_item_utils.cc",
"download_item_utils.h",
]
deps += [ "//chromeos/crosapi/mojom" ]
}
}
if (is_android) {

@ -1,157 +0,0 @@
// 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.
#include "components/download/public/common/download_item_utils.h"
#include "chromeos/crosapi/mojom/download_controller.mojom.h"
namespace download {
namespace download_item_utils {
namespace {
crosapi::mojom::DownloadDangerType ConvertToMojoDownloadDangerType(
DownloadDangerType value) {
switch (value) {
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeNotDangerous;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeDangerousFile;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeDangerousUrl;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeDangerousContent;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeMaybeDangerousContent;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeUncommonContent;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_USER_VALIDATED:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeUserValidated;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeDangerousHost;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypePotentiallyUnwanted;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_ALLOWLISTED_BY_POLICY:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeAllowlistedByPolicy;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_ASYNC_SCANNING:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeAsyncScanning;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_ASYNC_LOCAL_PASSWORD_SCANNING:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeAsyncLocalPasswordScanning;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_BLOCKED_PASSWORD_PROTECTED:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeBlockedPasswordProtected;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_BLOCKED_TOO_LARGE:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeBlockedTooLarge;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_SENSITIVE_CONTENT_WARNING:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeSensitiveContentWarning;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_SENSITIVE_CONTENT_BLOCK:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeSensitiveContentBlock;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_DEEP_SCANNED_SAFE:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeDeepScannedSafe;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_DEEP_SCANNED_OPENED_DANGEROUS:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeDeepScannedOpenedDangerous;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_PROMPT_FOR_SCANNING:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypePromptForScanning;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_DANGEROUS_ACCOUNT_COMPROMISE:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeDangerousAccountCompromise;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_DEEP_SCANNED_FAILED:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeDeepScannedFailed;
case DownloadDangerType::
DOWNLOAD_DANGER_TYPE_PROMPT_FOR_LOCAL_PASSWORD_SCANNING:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypePromptForLocalPasswordScanning;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_BLOCKED_SCAN_FAILED:
return crosapi::mojom::DownloadDangerType::
kDownloadDangerTypeBlockedScanFailed;
case DownloadDangerType::DOWNLOAD_DANGER_TYPE_MAX:
NOTREACHED();
}
}
crosapi::mojom::InsecureDownloadStatus ConvertToMojoInsecureDownloadStatus(
DownloadItem::InsecureDownloadStatus value) {
switch (value) {
case DownloadItem::InsecureDownloadStatus::UNKNOWN:
return crosapi::mojom::InsecureDownloadStatus::kUnknown;
case DownloadItem::InsecureDownloadStatus::SAFE:
return crosapi::mojom::InsecureDownloadStatus::kSafe;
case DownloadItem::InsecureDownloadStatus::VALIDATED:
return crosapi::mojom::InsecureDownloadStatus::kValidated;
case DownloadItem::InsecureDownloadStatus::WARN:
return crosapi::mojom::InsecureDownloadStatus::kWarn;
case DownloadItem::InsecureDownloadStatus::BLOCK:
return crosapi::mojom::InsecureDownloadStatus::kBlock;
case DownloadItem::InsecureDownloadStatus::SILENT_BLOCK:
return crosapi::mojom::InsecureDownloadStatus::kSilentBlock;
}
}
} // namespace
crosapi::mojom::DownloadItemPtr ConvertToMojoDownloadItem(
const DownloadItem* item,
bool is_from_incognito_profile) {
auto download = crosapi::mojom::DownloadItem::New();
download->guid = item->GetGuid();
download->state = ConvertToMojoDownloadState(item->GetState());
download->full_path = item->GetFullPath();
download->target_file_path = item->GetTargetFilePath();
download->is_from_incognito_profile = is_from_incognito_profile;
download->is_paused = item->IsPaused();
download->has_is_paused = true;
download->open_when_complete = item->GetOpenWhenComplete();
download->has_open_when_complete = true;
download->received_bytes = item->GetReceivedBytes();
download->has_received_bytes = true;
download->total_bytes = item->GetTotalBytes();
download->has_total_bytes = true;
download->start_time = item->GetStartTime();
download->is_dangerous = item->IsDangerous();
download->has_is_dangerous = true;
download->is_insecure = item->IsInsecure();
download->has_is_insecure = true;
download->danger_type =
ConvertToMojoDownloadDangerType(item->GetDangerType());
download->insecure_download_status =
ConvertToMojoInsecureDownloadStatus(item->GetInsecureDownloadStatus());
return download;
}
crosapi::mojom::DownloadState ConvertToMojoDownloadState(
DownloadItem::DownloadState state) {
switch (state) {
case DownloadItem::IN_PROGRESS:
return crosapi::mojom::DownloadState::kInProgress;
case DownloadItem::COMPLETE:
return crosapi::mojom::DownloadState::kComplete;
case DownloadItem::CANCELLED:
return crosapi::mojom::DownloadState::kCancelled;
case DownloadItem::INTERRUPTED:
return crosapi::mojom::DownloadState::kInterrupted;
case DownloadItem::MAX_DOWNLOAD_STATE:
NOTREACHED();
}
}
} // namespace download_item_utils
} // namespace download

@ -1,32 +0,0 @@
// 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_DOWNLOAD_PUBLIC_COMMON_DOWNLOAD_ITEM_UTILS_H_
#define COMPONENTS_DOWNLOAD_PUBLIC_COMMON_DOWNLOAD_ITEM_UTILS_H_
#include "chromeos/crosapi/mojom/download_controller.mojom-forward.h"
#include "components/download/public/common/download_export.h"
#include "components/download/public/common/download_item.h"
namespace download {
namespace download_item_utils {
// Returns a new `crosapi::mojom::DownloadItemPtr` from the specified
// `DownloadItem*`.
COMPONENTS_DOWNLOAD_EXPORT
crosapi::mojom::DownloadItemPtr ConvertToMojoDownloadItem(
const DownloadItem* download_item,
bool is_from_incognito_profile);
// Returns the corresponding `crosapi::mojom::DownloadState` for the specified
// `DownloadItem::DownloadState`.
COMPONENTS_DOWNLOAD_EXPORT
crosapi::mojom::DownloadState ConvertToMojoDownloadState(
DownloadItem::DownloadState state);
} // namespace download_item_utils
} // namespace download
#endif // COMPONENTS_DOWNLOAD_PUBLIC_COMMON_DOWNLOAD_ITEM_UTILS_H_