Commit 3585ba0b authored by Jun Mukai's avatar Jun Mukai Committed by Commit Bot

Replace assistant_image_downloader.mojom by C++ interface

This is only used for the communication between ash and browser.
It doesn't have to be mojo interface anymore.

Bug: 958193
Test: trybot
Change-Id: Ic250567f37a2d9da7e213b6f96abcdaee449f9b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1633110Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Jun Mukai <mukai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664477}
parent 2ba3df26
......@@ -102,11 +102,6 @@ void AssistantController::SetAssistant(
observer.OnAssistantReady();
}
void AssistantController::SetAssistantImageDownloader(
mojom::AssistantImageDownloaderPtr assistant_image_downloader) {
assistant_image_downloader_ = std::move(assistant_image_downloader);
}
void AssistantController::OpenAssistantSettings() {
// Launch Assistant settings via deeplink.
OpenUrl(assistant::util::CreateAssistantSettingsDeepLink());
......@@ -147,9 +142,7 @@ void AssistantController::StartSpeakerIdEnrollmentFlow() {
void AssistantController::DownloadImage(
const GURL& url,
mojom::AssistantImageDownloader::DownloadCallback callback) {
DCHECK(assistant_image_downloader_);
AssistantImageDownloader::DownloadCallback callback) {
const UserSession* user_session =
Shell::Get()->session_controller()->GetUserSession(0);
......@@ -160,7 +153,8 @@ void AssistantController::DownloadImage(
}
AccountId account_id = user_session->user_info.account_id;
assistant_image_downloader_->Download(account_id, url, std::move(callback));
AssistantImageDownloader::GetInstance()->Download(account_id, url,
std::move(callback));
}
void AssistantController::OnDeepLinkReceived(
......
......@@ -22,9 +22,9 @@
#include "ash/assistant/assistant_ui_controller.h"
#include "ash/assistant/assistant_view_delegate_impl.h"
#include "ash/assistant/ui/assistant_view_delegate.h"
#include "ash/public/cpp/assistant/assistant_image_downloader.h"
#include "ash/public/cpp/assistant/default_voice_interaction_observer.h"
#include "ash/public/interfaces/assistant_controller.mojom.h"
#include "ash/public/interfaces/assistant_image_downloader.mojom.h"
#include "ash/public/interfaces/assistant_setup.mojom.h"
#include "ash/public/interfaces/assistant_volume_control.mojom.h"
#include "ash/public/interfaces/voice_interaction_controller.mojom.h"
......@@ -73,16 +73,13 @@ class ASH_EXPORT AssistantController
// Downloads the image found at the specified |url|. On completion, the
// supplied |callback| will be run with the downloaded image. If the download
// attempt is unsuccessful, a NULL image is returned.
void DownloadImage(
const GURL& url,
mojom::AssistantImageDownloader::DownloadCallback callback);
void DownloadImage(const GURL& url,
AssistantImageDownloader::DownloadCallback callback);
// mojom::AssistantController:
// TODO(updowndota): Refactor Set() calls to use a factory pattern.
void SetAssistant(
chromeos::assistant::mojom::AssistantPtr assistant) override;
void SetAssistantImageDownloader(
mojom::AssistantImageDownloaderPtr assistant_image_downloader) override;
void OpenAssistantSettings() override;
void StartSpeakerIdEnrollmentFlow() override;
void SendAssistantFeedback(bool assistant_debug_info_allowed,
......@@ -172,7 +169,6 @@ class ASH_EXPORT AssistantController
chromeos::assistant::mojom::AssistantPtr assistant_;
mojom::AssistantImageDownloaderPtr assistant_image_downloader_;
chromeos::assistant::mojom::DeviceActionsPtr device_actions_;
// Assistant sub-controllers.
......
......@@ -107,7 +107,7 @@ CaptionBarDelegate* AssistantViewDelegateImpl::GetCaptionBarDelegate() {
void AssistantViewDelegateImpl::DownloadImage(
const GURL& url,
mojom::AssistantImageDownloader::DownloadCallback callback) {
AssistantImageDownloader::DownloadCallback callback) {
assistant_controller_->DownloadImage(url, std::move(callback));
}
......
......@@ -48,7 +48,7 @@ class AssistantViewDelegateImpl : public AssistantViewDelegate {
CaptionBarDelegate* GetCaptionBarDelegate() override;
void DownloadImage(
const GURL& url,
mojom::AssistantImageDownloader::DownloadCallback callback) override;
AssistantImageDownloader::DownloadCallback callback) override;
mojom::ConsentStatus GetConsentStatus() const override;
::wm::CursorManager* GetCursorManager() override;
void GetNavigableContentsFactoryForView(
......
......@@ -20,8 +20,8 @@
#include "ash/assistant/ui/caption_bar.h"
#include "ash/assistant/ui/dialog_plate/dialog_plate.h"
#include "ash/assistant/ui/main_stage/assistant_opt_in_view.h"
#include "ash/public/cpp/assistant/assistant_image_downloader.h"
#include "ash/public/cpp/assistant/default_voice_interaction_observer.h"
#include "ash/public/interfaces/assistant_image_downloader.mojom.h"
#include "base/component_export.h"
#include "base/observer_list_types.h"
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
......@@ -127,7 +127,7 @@ class COMPONENT_EXPORT(ASSISTANT_UI) AssistantViewDelegate {
// attempt is unsuccessful, a NULL image is returned.
virtual void DownloadImage(
const GURL& url,
mojom::AssistantImageDownloader::DownloadCallback callback) = 0;
AssistantImageDownloader::DownloadCallback callback) = 0;
// Returns the status of the user's consent.
virtual mojom::ConsentStatus GetConsentStatus() const = 0;
......
......@@ -44,6 +44,8 @@ component("cpp") {
"ash_typography.cc",
"ash_typography.h",
"ash_view_ids.h",
"assistant/assistant_image_downloader.cc",
"assistant/assistant_image_downloader.h",
"assistant/assistant_state_base.cc",
"assistant/assistant_state_base.h",
"assistant/assistant_state_proxy.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/public/cpp/assistant/assistant_image_downloader.h"
#include "base/logging.h"
namespace ash {
namespace {
AssistantImageDownloader* g_assistant_image_downloader = nullptr;
}
// static
AssistantImageDownloader* AssistantImageDownloader::GetInstance() {
return g_assistant_image_downloader;
}
AssistantImageDownloader::AssistantImageDownloader() {
DCHECK(!g_assistant_image_downloader);
g_assistant_image_downloader = this;
}
AssistantImageDownloader::~AssistantImageDownloader() {
DCHECK_EQ(g_assistant_image_downloader, this);
g_assistant_image_downloader = nullptr;
}
} // namespace ash
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_PUBLIC_CPP_ASSISTANT_ASSISTANT_IMAGE_DOWNLOADER_H_
#define ASH_PUBLIC_CPP_ASSISTANT_ASSISTANT_IMAGE_DOWNLOADER_H_
#include "ash/public/cpp/ash_public_export.h"
#include "base/callback_forward.h"
#include "base/macros.h"
class AccountId;
class GURL;
namespace gfx {
class ImageSkia;
}
namespace ash {
// Interface for a class which is responsible for downloading images on behalf
// of the Assistant UI in ash.
class ASH_PUBLIC_EXPORT AssistantImageDownloader {
public:
static AssistantImageDownloader* GetInstance();
using DownloadCallback = base::OnceCallback<void(const gfx::ImageSkia&)>;
// Downloads the image found at |url| for the profile associated with
// |account_id|. On completion, |callback| is run with the
// downloaded |image|. In the event that the download attempt fails, a NULL
// image will be returned.
virtual void Download(const AccountId& account_id,
const GURL& url,
DownloadCallback callback) = 0;
protected:
AssistantImageDownloader();
virtual ~AssistantImageDownloader();
private:
DISALLOW_COPY_AND_ASSIGN(AssistantImageDownloader);
};
} // namespace ash
#endif // ASH_PUBLIC_CPP_ASSISTANT_ASSISTANT_IMAGE_DOWNLOADER_H_
......@@ -21,7 +21,6 @@ mojom("interfaces_internal") {
"accessibility_focus_ring_controller.mojom",
"ash_message_center_controller.mojom",
"assistant_controller.mojom",
"assistant_image_downloader.mojom",
"assistant_setup.mojom",
"assistant_volume_control.mojom",
"constants.mojom",
......
......@@ -4,7 +4,6 @@
module ash.mojom;
import "ash/public/interfaces/assistant_image_downloader.mojom";
import "ash/public/interfaces/assistant_setup.mojom";
import "chromeos/services/assistant/public/mojom/assistant.mojom";
import "ui/gfx/geometry/mojo/geometry.mojom";
......@@ -18,11 +17,6 @@ interface AssistantController {
// Provides a reference to the underlying |assistant| service.
SetAssistant(chromeos.assistant.mojom.Assistant assistant);
// Provides an interface to the |assistant_image_downloader| owned by
// AssistantClient.
SetAssistantImageDownloader(
AssistantImageDownloader assistant_image_downloader);
// Opens Google Assistant settings.
OpenAssistantSettings();
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module ash.mojom;
import "components/account_id/interfaces/account_id.mojom";
import "ui/gfx/image/mojo/image.mojom";
import "url/mojom/url.mojom";
// Interface for a class which is responsible for downloading images on behalf
// of the Assistant UI in ash.
interface AssistantImageDownloader {
// Downloads the image found at |url| for the profile associated with
// |account_id|. On completion, the supplied callback is run with the
// downloaded |image|. In the event that the download attempt fails, a NULL
// image will be returned.
Download(signin.mojom.AccountId account_id, url.mojom.Url url)
=> (gfx.mojom.ImageSkia image);
};
......@@ -75,8 +75,7 @@ void AssistantClient::MaybeInit(Profile* profile) {
assistant_connection_->Init(std::move(client_ptr),
device_actions_.AddBinding());
assistant_image_downloader_ =
std::make_unique<AssistantImageDownloader>(connector);
assistant_image_downloader_ = std::make_unique<AssistantImageDownloader>();
assistant_setup_ = std::make_unique<AssistantSetup>(connector);
}
......
......@@ -4,14 +4,11 @@
#include "chrome/browser/ui/ash/assistant/assistant_image_downloader.h"
#include "ash/public/interfaces/assistant_controller.mojom.h"
#include "ash/public/interfaces/constants.mojom.h"
#include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h"
#include "chrome/browser/bitmap_fetcher/bitmap_fetcher_delegate.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "content/public/browser/storage_partition.h"
#include "net/base/load_flags.h"
#include "services/service_manager/public/cpp/connector.h"
namespace {
......@@ -42,7 +39,7 @@ class DownloadTask : public BitmapFetcherDelegate {
public:
DownloadTask(Profile* profile,
const GURL& url,
ash::mojom::AssistantImageDownloader::DownloadCallback callback)
ash::AssistantImageDownloader::DownloadCallback callback)
: callback_(std::move(callback)) {
StartTask(profile, url);
}
......@@ -73,7 +70,7 @@ class DownloadTask : public BitmapFetcherDelegate {
.get());
}
ash::mojom::AssistantImageDownloader::DownloadCallback callback_;
ash::AssistantImageDownloader::DownloadCallback callback_;
std::unique_ptr<BitmapFetcher> bitmap_fetcher_;
DISALLOW_COPY_AND_ASSIGN(DownloadTask);
......@@ -83,23 +80,14 @@ class DownloadTask : public BitmapFetcherDelegate {
// AssistantImageDownloader ----------------------------------------------------
AssistantImageDownloader::AssistantImageDownloader(
service_manager::Connector* connector)
: binding_(this) {
// Bind to the Assistant controller in ash.
ash::mojom::AssistantControllerPtr assistant_controller;
connector->BindInterface(ash::mojom::kServiceName, &assistant_controller);
ash::mojom::AssistantImageDownloaderPtr ptr;
binding_.Bind(mojo::MakeRequest(&ptr));
assistant_controller->SetAssistantImageDownloader(std::move(ptr));
}
AssistantImageDownloader::AssistantImageDownloader() = default;
AssistantImageDownloader::~AssistantImageDownloader() = default;
void AssistantImageDownloader::Download(
const AccountId& account_id,
const GURL& url,
ash::mojom::AssistantImageDownloader::DownloadCallback callback) {
ash::AssistantImageDownloader::DownloadCallback callback) {
Profile* profile =
chromeos::ProfileHelper::Get()->GetProfileByAccountId(account_id);
......
......@@ -5,32 +5,25 @@
#ifndef CHROME_BROWSER_UI_ASH_ASSISTANT_ASSISTANT_IMAGE_DOWNLOADER_H_
#define CHROME_BROWSER_UI_ASH_ASSISTANT_ASSISTANT_IMAGE_DOWNLOADER_H_
#include "ash/public/interfaces/assistant_image_downloader.mojom.h"
#include "ash/public/cpp/assistant/assistant_image_downloader.h"
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding.h"
class AccountId;
namespace service_manager {
class Connector;
} // namespace service_manager
// AssistantImageDownloader is the class responsible for downloading images on
// behalf of Assistant UI in ash.
class AssistantImageDownloader : public ash::mojom::AssistantImageDownloader {
class AssistantImageDownloader : public ash::AssistantImageDownloader {
public:
explicit AssistantImageDownloader(service_manager::Connector* connector);
AssistantImageDownloader();
~AssistantImageDownloader() override;
// ash::mojom::AssistantImageDownloader:
// ash::AssistantImageDownloader:
void Download(
const AccountId& account_id,
const GURL& url,
ash::mojom::AssistantImageDownloader::DownloadCallback callback) override;
ash::AssistantImageDownloader::DownloadCallback callback) override;
private:
mojo::Binding<ash::mojom::AssistantImageDownloader> binding_;
DISALLOW_COPY_AND_ASSIGN(AssistantImageDownloader);
};
......
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