Commit 91ed4061 authored by Xiaohui Chen's avatar Xiaohui Chen Committed by Commit Bot

Add libassistant resource provider

Bug: b/77916286
Test: locally build and test
Change-Id: I5998c4250240361e1f0c0b69ad5b9f8ddcc9464d
Reviewed-on: https://chromium-review.googlesource.com/1068260Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Xiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#562506}
parent 3ebe9eb1
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# found in the LICENSE file. # found in the LICENSE file.
import("//tools/grit/grit_rule.gni") import("//tools/grit/grit_rule.gni")
import("//chromeos/assistant/assistant.gni")
assert(is_chromeos, "Non-ChromeOS builds cannot depend on //chromeos") assert(is_chromeos, "Non-ChromeOS builds cannot depend on //chromeos")
...@@ -17,6 +18,8 @@ grit("resources") { ...@@ -17,6 +18,8 @@ grit("resources") {
] ]
output_dir = "$root_gen_dir/chromeos" output_dir = "$root_gen_dir/chromeos"
defines = [ "enable_cros_libassistant=$enable_cros_libassistant" ]
grit_flags = [ grit_flags = [
"-E", "-E",
"mojom_root=" + rebase_path(root_gen_dir, root_build_dir), "mojom_root=" + rebase_path(root_gen_dir, root_build_dir),
......
<?xml version="1.0" encoding="utf-8"?>
<grit-part>
<!-- Resources for Google Assistant. -->
<include name="IDR_ASSISTANT_HOTWORD_MODEL" file="../assistant/internal/resources/hotwords/c_20170314/hotword.data" type="BINDATA" />
<include name="IDR_ASSISTANT_SPEECH_RECOGNITION_ERROR" file="../assistant/internal/resources/sounds/en_hol_err_speech_recognition_error.opus" type="BINDATA" />
<include name="IDR_ASSISTANT_NO_INTERNET_ERROR" file="../assistant/internal/resources/sounds/en_hol_err_no_internet.opus" type="BINDATA" />
</grit-part>
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
use_base_dir="false" use_base_dir="false"
type="BINDATA" /> type="BINDATA" />
<part file="proximity_auth_resources.grdp" /> <part file="proximity_auth_resources.grdp" />
<if expr="enable_cros_libassistant">
<part file="assistant_resources.grdp" />
</if>
</includes> </includes>
</release> </release>
</grit> </grit>
...@@ -51,6 +51,8 @@ source_set("lib") { ...@@ -51,6 +51,8 @@ source_set("lib") {
"platform/file_provider_impl.h", "platform/file_provider_impl.h",
"platform/network_provider_impl.cc", "platform/network_provider_impl.cc",
"platform/network_provider_impl.h", "platform/network_provider_impl.h",
"platform/resource_provider_impl.cc",
"platform/resource_provider_impl.h",
"platform/system_provider_impl.cc", "platform/system_provider_impl.cc",
"platform/system_provider_impl.h", "platform/system_provider_impl.h",
"platform_api_impl.cc", "platform_api_impl.cc",
...@@ -69,6 +71,7 @@ source_set("lib") { ...@@ -69,6 +71,7 @@ source_set("lib") {
"//libassistant/shared/proto:assistant_proto", "//libassistant/shared/proto:assistant_proto",
"//libassistant/shared/public", "//libassistant/shared/public",
"//libassistant/shared/public:export", "//libassistant/shared/public:export",
"//ui/base",
] ]
if (enable_cros_libassistant_so) { if (enable_cros_libassistant_so) {
......
...@@ -7,4 +7,5 @@ include_rules = [ ...@@ -7,4 +7,5 @@ include_rules = [
"+services/device/public", "+services/device/public",
"+services/identity/public", "+services/identity/public",
"+services/service_manager/public", "+services/service_manager/public",
"+ui/base",
] ]
// 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.
#include "chromeos/services/assistant/platform/resource_provider_impl.h"
#include "chromeos/grit/chromeos_resources.h"
#include "ui/base/resource/resource_bundle.h"
namespace {
constexpr char kHotwordModelName[] = "ok google";
} // namespace
namespace chromeos {
namespace assistant {
ResourceProviderImpl::ResourceProviderImpl() = default;
ResourceProviderImpl::~ResourceProviderImpl() = default;
bool ResourceProviderImpl::GetResource(uint16_t resource_id, std::string* out) {
int chrome_resource_id = -1;
switch (resource_id) {
case assistant_client::resource_ids::kGeneralError:
chrome_resource_id = IDR_ASSISTANT_SPEECH_RECOGNITION_ERROR;
break;
case assistant_client::resource_ids::kWifiNeedsSetupError:
case assistant_client::resource_ids::kWifiNotConnectedError:
case assistant_client::resource_ids::kWifiCannotConnectError:
case assistant_client::resource_ids::kNetworkConnectingError:
// These above do not apply to ChromeOS, but let it fall through to get a
// generic error.
case assistant_client::resource_ids::kNetworkCannotReachServerError:
chrome_resource_id = IDR_ASSISTANT_NO_INTERNET_ERROR;
break;
case assistant_client::resource_ids::kDefaultHotwordResourceId:
return GetHotwordData(GetDefaultHotwordName(), out);
default:
break;
}
if (chrome_resource_id < 0)
return false;
auto data = ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
chrome_resource_id);
out->assign(data.data(), data.length());
return true;
}
std::vector<std::string> ResourceProviderImpl::GetHotwordNameList() {
std::vector<std::string> result;
std::string name = GetDefaultHotwordName();
if (!name.empty())
result.push_back(name);
return result;
}
std::string ResourceProviderImpl::GetDefaultHotwordName() {
return kHotwordModelName;
}
bool ResourceProviderImpl::GetHotwordData(const std::string& name,
std::string* result) {
if (name != kHotwordModelName)
return false;
auto data = ui::ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_ASSISTANT_HOTWORD_MODEL);
result->assign(data.data(), data.length());
return true;
}
} // namespace assistant
} // namespace chromeos
// 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.
#ifndef CHROMEOS_SERVICES_ASSISTANT_PLATFORM_RESOURCE_PROVIDER_IMPL_H_
#define CHROMEOS_SERVICES_ASSISTANT_PLATFORM_RESOURCE_PROVIDER_IMPL_H_
#include <string>
#include <vector>
#include "base/macros.h"
#include "libassistant/shared/public/platform_resources.h"
namespace chromeos {
namespace assistant {
class ResourceProviderImpl : public assistant_client::ResourceProvider {
public:
ResourceProviderImpl();
~ResourceProviderImpl() override;
// assistant_client::ResourceProvider implementation:
bool GetResource(uint16_t resource_id, std::string* out) override;
std::vector<std::string> GetHotwordNameList() override;
std::string GetDefaultHotwordName() override;
bool GetHotwordData(const std::string& name, std::string* result) override;
private:
DISALLOW_COPY_AND_ASSIGN(ResourceProviderImpl);
};
} // namespace assistant
} // namespace chromeos
#endif // CHROMEOS_SERVICES_ASSISTANT_PLATFORM_RESOURCE_PROVIDER_IMPL_H_
...@@ -78,7 +78,6 @@ PlatformApiImpl::PlatformApiImpl( ...@@ -78,7 +78,6 @@ PlatformApiImpl::PlatformApiImpl(
device::mojom::BatteryMonitorPtr battery_monitor) device::mojom::BatteryMonitorPtr battery_monitor)
: audio_input_provider_(std::move(audio_input)), : audio_input_provider_(std::move(audio_input)),
audio_output_provider_(config, this), audio_output_provider_(config, this),
resource_provider_(config),
system_provider_(std::move(battery_monitor)) {} system_provider_(std::move(battery_monitor)) {}
PlatformApiImpl::~PlatformApiImpl() = default; PlatformApiImpl::~PlatformApiImpl() = default;
......
...@@ -13,13 +13,13 @@ ...@@ -13,13 +13,13 @@
#include "chromeos/services/assistant/platform/audio_input_provider_impl.h" #include "chromeos/services/assistant/platform/audio_input_provider_impl.h"
#include "chromeos/services/assistant/platform/file_provider_impl.h" #include "chromeos/services/assistant/platform/file_provider_impl.h"
#include "chromeos/services/assistant/platform/network_provider_impl.h" #include "chromeos/services/assistant/platform/network_provider_impl.h"
#include "chromeos/services/assistant/platform/resource_provider_impl.h"
#include "chromeos/services/assistant/platform/system_provider_impl.h" #include "chromeos/services/assistant/platform/system_provider_impl.h"
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h" #include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
// TODO(xiaohuic): replace with "base/macros.h" once we remove // TODO(xiaohuic): replace with "base/macros.h" once we remove
// libassistant/contrib dependency. // libassistant/contrib dependency.
#include "libassistant/contrib/core/macros.h" #include "libassistant/contrib/core/macros.h"
#include "libassistant/contrib/platform/audio/output/audio_output_provider_impl.h" #include "libassistant/contrib/platform/audio/output/audio_output_provider_impl.h"
#include "libassistant/contrib/platform/resources/resource_provider.h"
#include "libassistant/shared/public/platform_api.h" #include "libassistant/shared/public/platform_api.h"
#include "libassistant/shared/public/platform_auth.h" #include "libassistant/shared/public/platform_auth.h"
#include "services/device/public/mojom/battery_monitor.mojom.h" #include "services/device/public/mojom/battery_monitor.mojom.h"
...@@ -82,7 +82,7 @@ class PlatformApiImpl : public assistant_client::PlatformApi { ...@@ -82,7 +82,7 @@ class PlatformApiImpl : public assistant_client::PlatformApi {
DummyAuthProvider auth_provider_; DummyAuthProvider auth_provider_;
FileProviderImpl file_provider_; FileProviderImpl file_provider_;
NetworkProviderImpl network_provider_; NetworkProviderImpl network_provider_;
assistant_contrib::ResourceProviderImpl resource_provider_; ResourceProviderImpl resource_provider_;
SystemProviderImpl system_provider_; SystemProviderImpl system_provider_;
DISALLOW_COPY_AND_ASSIGN(PlatformApiImpl); DISALLOW_COPY_AND_ASSIGN(PlatformApiImpl);
......
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