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