Commit 1ad6e764 authored by Jeroen Dhollander's avatar Jeroen Dhollander Committed by Commit Bot

Add BloomController skeleton

This is the main controller for the Bloom feature.

In this CL I simply:
   * Introduce the |BloomController| class, and an (mostly) empty
    |BloomControllerImpl|.
   * Create the |BloomController| inside the |AssistantClient|, by means
    of a |BloomControllerFactory|.

In later CLs this will actually start doing something.

Bug: b/165356952
Change-Id: Ib4d22016bd60ae27e940807e9bb47a2d317eaf96
Tests: Compiled
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2363399Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Jeroen Dhollander <jeroendh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801390}
parent 388e66ef
...@@ -2525,6 +2525,8 @@ static_library("ui") { ...@@ -2525,6 +2525,8 @@ static_library("ui") {
"//chromeos/assistant:buildflags", "//chromeos/assistant:buildflags",
"//chromeos/audio", "//chromeos/audio",
"//chromeos/components/account_manager", "//chromeos/components/account_manager",
"//chromeos/components/bloom/public/cpp",
"//chromeos/components/bloom/public/cpp:bloom_controller_factory",
"//chromeos/components/camera_app_ui", "//chromeos/components/camera_app_ui",
"//chromeos/components/help_app_ui", "//chromeos/components/help_app_ui",
"//chromeos/components/local_search_service:local_search_service", "//chromeos/components/local_search_service:local_search_service",
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <utility> #include <utility>
#include "ash/public/cpp/assistant/assistant_interface_binder.h" #include "ash/public/cpp/assistant/assistant_interface_binder.h"
#include "ash/public/cpp/assistant/controller/assistant_interaction_controller.h"
#include "ash/public/cpp/network_config_service.h" #include "ash/public/cpp/network_config_service.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/assistant/assistant_util.h" #include "chrome/browser/chromeos/assistant/assistant_util.h"
...@@ -18,6 +19,8 @@ ...@@ -18,6 +19,8 @@
#include "chrome/browser/ui/ash/assistant/assistant_web_view_factory_impl.h" #include "chrome/browser/ui/ash/assistant/assistant_web_view_factory_impl.h"
#include "chrome/browser/ui/ash/assistant/conversation_starters_client_impl.h" #include "chrome/browser/ui/ash/assistant/conversation_starters_client_impl.h"
#include "chrome/browser/ui/ash/assistant/device_actions_delegate_impl.h" #include "chrome/browser/ui/ash/assistant/device_actions_delegate_impl.h"
#include "chromeos/components/bloom/public/cpp/bloom_controller.h"
#include "chromeos/components/bloom/public/cpp/bloom_controller_factory.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
#include "chromeos/constants/chromeos_switches.h" #include "chromeos/constants/chromeos_switches.h"
#include "chromeos/services/assistant/public/cpp/features.h" #include "chromeos/services/assistant/public/cpp/features.h"
...@@ -85,6 +88,13 @@ void AssistantClientImpl::MaybeInit(Profile* profile) { ...@@ -85,6 +88,13 @@ void AssistantClientImpl::MaybeInit(Profile* profile) {
conversation_starters_client_ = conversation_starters_client_ =
std::make_unique<ConversationStartersClientImpl>(profile_); std::make_unique<ConversationStartersClientImpl>(profile_);
} }
if (chromeos::assistant::features::IsBloomEnabled()) {
bloom_controller_ = chromeos::bloom::BloomControllerFactory::Create(
profile->GetURLLoaderFactory(),
IdentityManagerFactory::GetForProfile(profile),
ash::AssistantInteractionController::Get());
}
} }
void AssistantClientImpl::MaybeStartAssistantOptInFlow() { void AssistantClientImpl::MaybeStartAssistantOptInFlow() {
......
...@@ -23,6 +23,12 @@ ...@@ -23,6 +23,12 @@
#include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
namespace chromeos {
namespace bloom {
class BloomController;
} // namespace bloom
} // namespace chromeos
class AssistantSetup; class AssistantSetup;
class AssistantWebViewFactoryImpl; class AssistantWebViewFactoryImpl;
class ConversationStartersClientImpl; class ConversationStartersClientImpl;
...@@ -100,6 +106,7 @@ class AssistantClientImpl : public ash::AssistantClient, ...@@ -100,6 +106,7 @@ class AssistantClientImpl : public ash::AssistantClient,
std::unique_ptr<AssistantSetup> assistant_setup_; std::unique_ptr<AssistantSetup> assistant_setup_;
std::unique_ptr<AssistantWebViewFactoryImpl> assistant_web_view_factory_; std::unique_ptr<AssistantWebViewFactoryImpl> assistant_web_view_factory_;
std::unique_ptr<ConversationStartersClientImpl> conversation_starters_client_; std::unique_ptr<ConversationStartersClientImpl> conversation_starters_client_;
std::unique_ptr<chromeos::bloom::BloomController> bloom_controller_;
bool initialized_ = false; bool initialized_ = false;
......
# Copyright 2020 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.
source_set("bloom") {
sources = [
"bloom_controller_impl.cc",
"bloom_controller_impl.h",
]
deps = [
"//ash/public/cpp",
"//base",
"//chromeos/components/bloom/public/cpp",
"//components/signin/public/identity_manager",
"//services/network/public/cpp",
]
}
include_rules = [
"+ash/public",
"+components/signin/public/identity_manager",
"+services/network/public",
]
file://chromeos/assistant/OWNERS
# COMPONENT: UI>Shell>Assistant
// Copyright 2020 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 "chromeos/components/bloom/bloom_controller_impl.h"
#include "ash/public/cpp/assistant/controller/assistant_interaction_controller.h"
namespace chromeos {
namespace bloom {
BloomControllerImpl::BloomControllerImpl(
signin::IdentityManager* identity_manager,
ash::AssistantInteractionController* assistant_interaction_controller)
: identity_manager_(identity_manager),
assistant_interaction_controller_(assistant_interaction_controller) {
DCHECK(identity_manager_);
DCHECK(assistant_interaction_controller_);
}
BloomControllerImpl::~BloomControllerImpl() = default;
void BloomControllerImpl::StartInteraction() {
// TODO(jeroendh): Implement
}
bool BloomControllerImpl::HasInteraction() const {
// TODO(jeroendh): Implement
return true;
}
void BloomControllerImpl::StopInteraction(
BloomInteractionResolution resolution) {
// TODO(jeroendh): Implement
last_interaction_resolution_ = resolution;
}
BloomInteractionResolution BloomControllerImpl::GetLastInteractionResolution()
const {
return last_interaction_resolution_;
}
} // namespace bloom
} // namespace chromeos
// Copyright 2020 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 CHROMEOS_COMPONENTS_BLOOM_BLOOM_CONTROLLER_IMPL_H_
#define CHROMEOS_COMPONENTS_BLOOM_BLOOM_CONTROLLER_IMPL_H_
#include "chromeos/components/bloom/public/cpp/bloom_controller.h"
namespace ash {
class AssistantInteractionController;
} // namespace ash
namespace signin {
class IdentityManager;
} // namespace signin
namespace chromeos {
namespace bloom {
class BloomInteraction;
class ScreenshotGrabber;
class BloomControllerImpl : public BloomController {
public:
BloomControllerImpl(
signin::IdentityManager* identity_manager,
ash::AssistantInteractionController* assistant_interaction_controller);
BloomControllerImpl(const BloomControllerImpl&) = delete;
BloomControllerImpl& operator=(const BloomControllerImpl&) = delete;
~BloomControllerImpl() override;
// BloomController implementation:
void StartInteraction() override;
BloomInteractionResolution GetLastInteractionResolution() const override;
bool HasInteraction() const;
void StopInteraction(BloomInteractionResolution resolution);
signin::IdentityManager* identity_manager() { return identity_manager_; }
ash::AssistantInteractionController* assistant_interaction_controller() {
return assistant_interaction_controller_;
}
private:
signin::IdentityManager* const identity_manager_;
ash::AssistantInteractionController* const assistant_interaction_controller_;
BloomInteractionResolution last_interaction_resolution_ =
BloomInteractionResolution::kNormal;
};
} // namespace bloom
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_BLOOM_BLOOM_CONTROLLER_IMPL_H_
# Copyright 2020 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.
assert(is_chromeos, "Non-Chrome-OS builds must not depend on //chromeos")
component("cpp") {
sources = [
"bloom_controller.cc",
"bloom_controller.h",
"bloom_interaction_resolution.cc",
"bloom_interaction_resolution.h",
]
deps = [ "//base" ]
defines = [ "IS_BLOOM_IMPL" ]
# Prevent conflict with other targets called 'cpp'.
output_name = "bloom_public"
}
component("bloom_controller_factory") {
sources = [
"bloom_controller_factory.cc",
"bloom_controller_factory.h",
]
deps = [
"//base",
"//chromeos/components/bloom",
]
defines = [ "IS_BLOOM_IMPL" ]
}
// Copyright 2020 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 "chromeos/components/bloom/public/cpp/bloom_controller.h"
#include "base/check_op.h"
namespace chromeos {
namespace bloom {
namespace {
BloomController* g_instance = nullptr;
} // namespace
// static
BloomController* BloomController::Get() {
return g_instance;
}
BloomController::BloomController() {
DCHECK_EQ(g_instance, nullptr);
g_instance = this;
}
BloomController::~BloomController() {
DCHECK_EQ(g_instance, this);
g_instance = nullptr;
}
} // namespace bloom
} // namespace chromeos
// Copyright 2020 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 CHROMEOS_COMPONENTS_BLOOM_PUBLIC_CPP_BLOOM_CONTROLLER_H_
#define CHROMEOS_COMPONENTS_BLOOM_PUBLIC_CPP_BLOOM_CONTROLLER_H_
#include <memory>
#include "base/component_export.h"
#include "chromeos/components/bloom/public/cpp/bloom_interaction_resolution.h"
namespace chromeos {
namespace bloom {
// Main controller for the Bloom integration.
class COMPONENT_EXPORT(BLOOM) BloomController {
public:
BloomController();
BloomController(const BloomController&) = delete;
BloomController& operator=(const BloomController&) = delete;
virtual ~BloomController();
// Access the existing Bloom controller.
static BloomController* Get();
// Starts an interaction. This will ask the user for a screenshot, analyze the
// content and display the result.
virtual void StartInteraction() = 0;
// Returns the result of the last interaction.
virtual BloomInteractionResolution GetLastInteractionResolution() const = 0;
};
} // namespace bloom
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_BLOOM_PUBLIC_CPP_BLOOM_CONTROLLER_H_
// Copyright 2020 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 "chromeos/components/bloom/public/cpp/bloom_controller_factory.h"
#include "base/callback.h"
#include "chromeos/components/bloom/bloom_controller_impl.h"
namespace chromeos {
namespace bloom {
// static
std::unique_ptr<BloomController> BloomControllerFactory::Create(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
signin::IdentityManager* identity_manager,
ash::AssistantInteractionController* assistant_interaction_controller) {
return std::make_unique<BloomControllerImpl>(
identity_manager, assistant_interaction_controller);
}
} // namespace bloom
} // namespace chromeos
// Copyright 2020 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 CHROMEOS_COMPONENTS_BLOOM_PUBLIC_CPP_BLOOM_CONTROLLER_FACTORY_H_
#define CHROMEOS_COMPONENTS_BLOOM_PUBLIC_CPP_BLOOM_CONTROLLER_FACTORY_H_
#include <memory>
#include "base/component_export.h"
#include "base/memory/scoped_refptr.h"
namespace ash {
class AssistantInteractionController;
} // namespace ash
namespace network {
class SharedURLLoaderFactory;
} // namespace network
namespace signin {
class IdentityManager;
} // namespace signin
namespace chromeos {
namespace bloom {
class BloomController;
class COMPONENT_EXPORT(BLOOM) BloomControllerFactory {
public:
// Create the Bloom controller. Can only be invoked once.
static std::unique_ptr<BloomController> Create(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
signin::IdentityManager* identity_manager,
ash::AssistantInteractionController* assistant_interaction_controller);
};
} // namespace bloom
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_BLOOM_PUBLIC_CPP_BLOOM_CONTROLLER_FACTORY_H_
// Copyright 2020 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 "chromeos/components/bloom/public/cpp/bloom_interaction_resolution.h"
namespace chromeos {
namespace bloom {
#define CASE(name) \
case BloomInteractionResolution::name: \
return #name;
std::string ToString(BloomInteractionResolution resolution) {
switch (resolution) {
CASE(kNormal);
CASE(kNoAccessToken);
CASE(kNoScreenshot);
}
}
} // namespace bloom
} // namespace chromeos
// Copyright 2020 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 CHROMEOS_COMPONENTS_BLOOM_PUBLIC_CPP_BLOOM_INTERACTION_RESOLUTION_H_
#define CHROMEOS_COMPONENTS_BLOOM_PUBLIC_CPP_BLOOM_INTERACTION_RESOLUTION_H_
#include <string>
namespace chromeos {
namespace bloom {
enum class BloomInteractionResolution {
// Bloom interaction completed normally.
kNormal = 0,
// Bloom interaction failed to fetch an access token.
kNoAccessToken = 1,
// Bloom interaction failed to take a screenshot
// (or the user aborted while taking a screenshot).
kNoScreenshot = 2,
};
std::string ToString(BloomInteractionResolution resolution);
} // namespace bloom
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_BLOOM_PUBLIC_CPP_BLOOM_INTERACTION_RESOLUTION_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