Commit 80fdd0ca authored by Henrique Ferreiro's avatar Henrique Ferreiro Committed by Commit Bot

Migrate downloads.mojom to the new Mojo types

Convert the implementation and all users of the
downloads::mojom::PageHandlerFactory, PageHandler and Page interfaces.

Bug: 955171
Change-Id: I49c00905b4b3b2df318b0b0147b84bb04ca8f48a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1805642Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Reviewed-by: default avatarDan Beam <dbeam@chromium.org>
Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Henrique Ferreiro <hferreiro@igalia.com>
Cr-Commit-Position: refs/heads/master@{#698449}
parent 5325d37c
......@@ -28,7 +28,8 @@ struct Data {
};
interface PageHandlerFactory {
CreatePageHandler(Page page, PageHandler& handler);
CreatePageHandler(pending_remote<Page> page,
pending_receiver<PageHandler> handler);
};
interface PageHandler {
......
......@@ -8,6 +8,7 @@
#include <functional>
#include <memory>
#include <string>
#include <utility>
#include "base/bind.h"
#include "base/bind_helpers.h"
......@@ -30,6 +31,7 @@
#include "chrome/browser/download/drag_download_item.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/downloads/downloads.mojom.h"
#include "chrome/browser/ui/webui/fileicon_source.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
......@@ -44,6 +46,9 @@
#include "content/public/browser/url_data_source.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "net/base/filename_util.h"
#include "ui/base/l10n/time_format.h"
#include "ui/gfx/image/image.h"
......@@ -78,13 +83,13 @@ void CountDownloadsDOMEvents(DownloadsDOMEvent event) {
} // namespace
DownloadsDOMHandler::DownloadsDOMHandler(
downloads::mojom::PageHandlerRequest request,
downloads::mojom::PagePtr page,
mojo::PendingReceiver<downloads::mojom::PageHandler> receiver,
mojo::PendingRemote<downloads::mojom::Page> page,
content::DownloadManager* download_manager,
content::WebUI* web_ui)
: list_tracker_(download_manager, std::move(page)),
web_ui_(web_ui),
binding_(this, std::move(request)) {
receiver_(this, std::move(receiver)) {
// Create our fileicon data source.
content::URLDataSource::Add(
Profile::FromBrowserContext(download_manager->GetBrowserContext()),
......
......@@ -13,10 +13,12 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/download/download_danger_prompt.h"
#include "chrome/browser/ui/webui/downloads/downloads_list_tracker.h"
#include "chrome/browser/ui/webui/downloads/downloads.mojom.h"
#include "chrome/browser/ui/webui/downloads/downloads_list_tracker.h"
#include "content/public/browser/web_contents_observer.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
namespace content {
class DownloadManager;
......@@ -34,10 +36,11 @@ class DownloadItem;
class DownloadsDOMHandler : public content::WebContentsObserver,
public downloads::mojom::PageHandler {
public:
DownloadsDOMHandler(downloads::mojom::PageHandlerRequest request,
downloads::mojom::PagePtr page,
content::DownloadManager* download_manager,
content::WebUI* web_ui);
DownloadsDOMHandler(
mojo::PendingReceiver<downloads::mojom::PageHandler> receiver,
mojo::PendingRemote<downloads::mojom::Page> page,
content::DownloadManager* download_manager,
content::WebUI* web_ui);
~DownloadsDOMHandler() override;
// WebContentsObserver implementation.
......@@ -123,7 +126,7 @@ class DownloadsDOMHandler : public content::WebContentsObserver,
content::WebUI* web_ui_;
mojo::Binding<downloads::mojom::PageHandler> binding_;
mojo::Receiver<downloads::mojom::PageHandler> receiver_;
base::WeakPtrFactory<DownloadsDOMHandler> weak_ptr_factory_{this};
......
......@@ -16,6 +16,8 @@
#include "content/public/test/mock_download_manager.h"
#include "content/public/test/test_web_ui.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -23,13 +25,14 @@ namespace {
class TestDownloadsDOMHandler : public DownloadsDOMHandler {
public:
TestDownloadsDOMHandler(downloads::mojom::PagePtr page,
TestDownloadsDOMHandler(mojo::PendingRemote<downloads::mojom::Page> page,
content::DownloadManager* download_manager,
content::WebUI* web_ui)
: DownloadsDOMHandler(downloads::mojom::PageHandlerRequest(),
std::move(page),
download_manager,
web_ui) {}
: DownloadsDOMHandler(
mojo::PendingReceiver<downloads::mojom::PageHandler>(),
std::move(page),
download_manager,
web_ui) {}
using DownloadsDOMHandler::FinalizeRemovals;
using DownloadsDOMHandler::RemoveDownloads;
......@@ -66,7 +69,8 @@ class DownloadsDOMHandlerTest : public testing::Test {
TEST_F(DownloadsDOMHandlerTest, ChecksForRemovedFiles) {
EXPECT_CALL(*manager(), CheckForHistoryFilesRemoval());
TestDownloadsDOMHandler handler(page_.BindAndGetPtr(), manager(), web_ui());
TestDownloadsDOMHandler handler(page_.BindAndGetRemote(), manager(),
web_ui());
testing::Mock::VerifyAndClear(manager());
......@@ -74,7 +78,8 @@ TEST_F(DownloadsDOMHandlerTest, ChecksForRemovedFiles) {
}
TEST_F(DownloadsDOMHandlerTest, HandleGetDownloads) {
TestDownloadsDOMHandler handler(page_.BindAndGetPtr(), manager(), web_ui());
TestDownloadsDOMHandler handler(page_.BindAndGetRemote(), manager(),
web_ui());
handler.GetDownloads(std::vector<std::string>());
......@@ -110,7 +115,8 @@ TEST_F(DownloadsDOMHandlerTest, ClearAll) {
ASSERT_TRUE(DownloadItemModel(&completed).ShouldShowInShelf());
TestDownloadsDOMHandler handler(page_.BindAndGetPtr(), manager(), web_ui());
TestDownloadsDOMHandler handler(page_.BindAndGetRemote(), manager(),
web_ui());
handler.RemoveDownloads(downloads);
// Ensure |completed| has been "soft removed" (i.e. can be revived).
......
......@@ -5,6 +5,7 @@
#include "chrome/browser/ui/webui/downloads/downloads_list_tracker.h"
#include <iterator>
#include <utility>
#include <vector>
#include "base/bind.h"
......@@ -22,12 +23,15 @@
#include "chrome/browser/download/download_query.h"
#include "chrome/browser/extensions/api/downloads/downloads_api.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/downloads/downloads.mojom.h"
#include "components/download/public/common/download_danger_type.h"
#include "components/download/public/common/download_item.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/download_item_utils.h"
#include "content/public/browser/download_manager.h"
#include "extensions/browser/extension_registry.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/base/filename_util.h"
#include "third_party/icu/source/i18n/unicode/datefmt.h"
#include "ui/base/l10n/time_format.h"
......@@ -86,8 +90,9 @@ std::string TimeFormatLongDate(const base::Time& time) {
} // namespace
DownloadsListTracker::DownloadsListTracker(DownloadManager* download_manager,
downloads::mojom::PagePtr page)
DownloadsListTracker::DownloadsListTracker(
DownloadManager* download_manager,
mojo::PendingRemote<downloads::mojom::Page> page)
: main_notifier_(download_manager, this),
page_(std::move(page)),
should_show_(base::BindRepeating(&DownloadsListTracker::ShouldShow,
......@@ -181,7 +186,7 @@ void DownloadsListTracker::OnDownloadRemoved(DownloadManager* manager,
DownloadsListTracker::DownloadsListTracker(
DownloadManager* download_manager,
downloads::mojom::PagePtr page,
mojo::PendingRemote<downloads::mojom::Page> page,
base::Callback<bool(const DownloadItem&)> should_show)
: main_notifier_(download_manager, this),
page_(std::move(page)),
......
......@@ -18,6 +18,8 @@
#include "chrome/browser/ui/webui/downloads/downloads.mojom.h"
#include "components/download/content/public/all_download_item_notifier.h"
#include "components/download/public/common/download_item.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace content {
class DownloadManager;
......@@ -29,7 +31,7 @@ class DownloadsListTracker
: public download::AllDownloadItemNotifier::Observer {
public:
DownloadsListTracker(content::DownloadManager* download_manager,
downloads::mojom::PagePtr page);
mojo::PendingRemote<downloads::mojom::Page> page);
~DownloadsListTracker() override;
// Clears all downloads on the page if currently sending updates and resets
......@@ -62,7 +64,7 @@ class DownloadsListTracker
protected:
// Testing constructor.
DownloadsListTracker(content::DownloadManager* download_manager,
downloads::mojom::PagePtr page,
mojo::PendingRemote<downloads::mojom::Page> page,
base::Callback<bool(const download::DownloadItem&)>);
// Creates a dictionary value that's sent to the page as JSON.
......@@ -108,7 +110,7 @@ class DownloadsListTracker
download::AllDownloadItemNotifier main_notifier_;
std::unique_ptr<download::AllDownloadItemNotifier> original_notifier_;
downloads::mojom::PagePtr page_;
mojo::Remote<downloads::mojom::Page> page_;
// Callback used to determine if an item should show on the page. Set to
// |ShouldShow()| in default constructor, passed in while testing.
......
......@@ -8,6 +8,7 @@
#include <stdint.h>
#include <memory>
#include <utility>
#include <vector>
#include "base/bind.h"
......@@ -16,12 +17,14 @@
#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
#include "chrome/browser/download/download_item_model.h"
#include "chrome/browser/ui/webui/downloads/downloads.mojom.h"
#include "chrome/browser/ui/webui/downloads/mock_downloads_page.h"
#include "chrome/test/base/testing_profile.h"
#include "components/download/public/common/mock_download_item.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/mock_download_manager.h"
#include "content/public/test/test_web_ui.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -44,7 +47,7 @@ bool ShouldShowItem(const DownloadItem& item) {
class TestDownloadsListTracker : public DownloadsListTracker {
public:
TestDownloadsListTracker(content::DownloadManager* manager,
downloads::mojom::PagePtr page)
mojo::PendingRemote<downloads::mojom::Page> page)
: DownloadsListTracker(manager,
std::move(page),
base::BindRepeating(&ShouldShowItem)) {}
......@@ -98,7 +101,7 @@ class DownloadsListTrackerTest : public testing::Test {
void CreateTracker() {
tracker_.reset(
new TestDownloadsListTracker(manager(), page_.BindAndGetPtr()));
new TestDownloadsListTracker(manager(), page_.BindAndGetRemote()));
}
TestingProfile* profile() { return &profile_; }
......@@ -241,7 +244,7 @@ TEST_F(DownloadsListTrackerTest, Incognito) {
ON_CALL(incognito_manager, GetDownload(0)).WillByDefault(Return(&item));
testing::StrictMock<MockPage> page;
TestDownloadsListTracker tracker(&incognito_manager, page.BindAndGetPtr());
TestDownloadsListTracker tracker(&incognito_manager, page.BindAndGetRemote());
EXPECT_TRUE(tracker.IsIncognito(item));
}
......
......@@ -17,6 +17,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/advanced_protection_status_manager.h"
#include "chrome/browser/safe_browsing/advanced_protection_status_manager_factory.h"
#include "chrome/browser/ui/webui/downloads/downloads.mojom.h"
#include "chrome/browser/ui/webui/downloads/downloads_dom_handler.h"
#include "chrome/browser/ui/webui/localized_string.h"
#include "chrome/browser/ui/webui/managed_ui_handler.h"
......@@ -37,6 +38,9 @@
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
......@@ -163,7 +167,7 @@ content::WebUIDataSource* CreateDownloadsUIHTMLSource(Profile* profile) {
///////////////////////////////////////////////////////////////////////////////
DownloadsUI::DownloadsUI(content::WebUI* web_ui)
: ui::MojoWebUIController(web_ui, true), page_factory_binding_(this) {
: ui::MojoWebUIController(web_ui, true) {
Profile* profile = Profile::FromWebUI(web_ui);
web_ui->AddMessageHandler(std::make_unique<MetricsHandler>());
......@@ -187,20 +191,19 @@ base::RefCountedMemory* DownloadsUI::GetFaviconResourceBytes(
}
void DownloadsUI::BindPageHandlerFactory(
downloads::mojom::PageHandlerFactoryRequest request) {
if (page_factory_binding_.is_bound())
page_factory_binding_.Unbind();
mojo::PendingReceiver<downloads::mojom::PageHandlerFactory> receiver) {
page_factory_receiver_.reset();
page_factory_binding_.Bind(std::move(request));
page_factory_receiver_.Bind(std::move(receiver));
}
void DownloadsUI::CreatePageHandler(
downloads::mojom::PagePtr page,
downloads::mojom::PageHandlerRequest request) {
mojo::PendingRemote<downloads::mojom::Page> page,
mojo::PendingReceiver<downloads::mojom::PageHandler> receiver) {
DCHECK(page);
Profile* profile = Profile::FromWebUI(web_ui());
DownloadManager* dlm = BrowserContext::GetDownloadManager(profile);
page_handler_ = std::make_unique<DownloadsDOMHandler>(
std::move(request), std::move(page), dlm, web_ui());
std::move(receiver), std::move(page), dlm, web_ui());
}
......@@ -9,7 +9,9 @@
#include "base/macros.h"
#include "chrome/browser/ui/webui/downloads/downloads.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "ui/base/layout.h"
#include "ui/webui/mojo_web_ui_controller.h"
......@@ -30,15 +32,17 @@ class DownloadsUI : public ui::MojoWebUIController,
private:
void BindPageHandlerFactory(
downloads::mojom::PageHandlerFactoryRequest request);
mojo::PendingReceiver<downloads::mojom::PageHandlerFactory> receiver);
// downloads::mojom::PageHandlerFactory:
void CreatePageHandler(downloads::mojom::PagePtr page,
downloads::mojom::PageHandlerRequest request) override;
void CreatePageHandler(
mojo::PendingRemote<downloads::mojom::Page> page,
mojo::PendingReceiver<downloads::mojom::PageHandler> receiver) override;
std::unique_ptr<DownloadsDOMHandler> page_handler_;
mojo::Binding<downloads::mojom::PageHandlerFactory> page_factory_binding_;
mojo::Receiver<downloads::mojom::PageHandlerFactory> page_factory_receiver_{
this};
DISALLOW_COPY_AND_ASSIGN(DownloadsUI);
};
......
......@@ -4,12 +4,15 @@
#include "chrome/browser/ui/webui/downloads/mock_downloads_page.h"
MockPage::MockPage() : binding_(this) {}
#include "chrome/browser/ui/webui/downloads/downloads.mojom.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
MockPage::MockPage() = default;
MockPage::~MockPage() = default;
downloads::mojom::PagePtr MockPage::BindAndGetPtr() {
DCHECK(!binding_.is_bound());
downloads::mojom::PagePtr page;
binding_.Bind(mojo::MakeRequest(&page));
return page;
mojo::PendingRemote<downloads::mojom::Page> MockPage::BindAndGetRemote() {
DCHECK(!receiver_.is_bound());
return receiver_.BindNewPipeAndPassRemote();
}
......@@ -8,8 +8,8 @@
#include <vector>
#include "chrome/browser/ui/webui/downloads/downloads.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "testing/gmock/include/gmock/gmock.h"
class MockPage : public downloads::mojom::Page {
......@@ -17,14 +17,14 @@ class MockPage : public downloads::mojom::Page {
MockPage();
~MockPage() override;
downloads::mojom::PagePtr BindAndGetPtr();
mojo::PendingRemote<downloads::mojom::Page> BindAndGetRemote();
MOCK_METHOD1(RemoveItem, void(int));
MOCK_METHOD2(UpdateItem, void(int, downloads::mojom::DataPtr));
MOCK_METHOD2(InsertItems, void(int, std::vector<downloads::mojom::DataPtr>));
MOCK_METHOD0(ClearAll, void());
mojo::Binding<downloads::mojom::Page> binding_;
mojo::Receiver<downloads::mojom::Page> receiver_{this};
};
#endif // CHROME_BROWSER_UI_WEBUI_DOWNLOADS_MOCK_DOWNLOADS_PAGE_H_
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