Commit f1392886 authored by Eyor Alemayehu's avatar Eyor Alemayehu Committed by Commit Bot

Applied Libassistant Platform API change

In Libassistant, the ResourceProvider platform interface got
removed. The alternative way of getting resources is via the
FileProvider. Updated the implementation of the interfaces to
comply with API change.

Bug: b/111924222
Change-Id: I8e29a73f2db0c1bffee39357dbc7e6e4853e84f2
Reviewed-on: https://chromium-review.googlesource.com/1153563
Commit-Queue: Eyor Alemayehu <eyor@google.com>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579419}
parent 06ce866c
......@@ -53,8 +53,6 @@ source_set("lib") {
"platform/file_provider_impl.h",
"platform/network_provider_impl.cc",
"platform/network_provider_impl.h",
"platform/resource_provider_impl.cc",
"platform/resource_provider_impl.h",
"platform/system_provider_impl.cc",
"platform/system_provider_impl.h",
"platform_api_impl.cc",
......
......@@ -7,6 +7,8 @@
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "chromeos/grit/chromeos_resources.h"
#include "ui/base/resource/resource_bundle.h"
namespace chromeos {
namespace assistant {
......@@ -82,5 +84,36 @@ void FileProviderImpl::CleanAssistantData() {
base::DeleteFile(root_path_, true);
}
bool FileProviderImpl::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:
chrome_resource_id = IDR_ASSISTANT_HOTWORD_MODEL;
break;
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;
}
} // namespace assistant
} // namespace chromeos
......@@ -26,6 +26,7 @@ class FileProviderImpl : public assistant_client::FileProvider {
bool WriteSecureFile(const std::string& path,
const std::string& data) override;
void CleanAssistantData() override;
bool GetResource(uint16_t resource_id, std::string* out) override;
private:
// Root path which other paths are relative to.
......
// 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_
......@@ -18,10 +18,8 @@ using assistant_client::AudioOutputProvider;
using assistant_client::AuthProvider;
using assistant_client::FileProvider;
using assistant_client::NetworkProvider;
using assistant_client::ResourceProvider;
using assistant_client::SystemProvider;
using assistant_client::PlatformApi;
using assistant_client::ResourceProvider;
namespace chromeos {
namespace assistant {
......@@ -103,10 +101,6 @@ NetworkProvider& PlatformApiImpl::GetNetworkProvider() {
return network_provider_;
}
ResourceProvider& PlatformApiImpl::GetResourceProvider() {
return resource_provider_;
}
SystemProvider& PlatformApiImpl::GetSystemProvider() {
return system_provider_;
}
......
......@@ -13,7 +13,6 @@
#include "chromeos/services/assistant/platform/audio_input_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/resource_provider_impl.h"
#include "chromeos/services/assistant/platform/system_provider_impl.h"
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
// TODO(xiaohuic): replace with "base/macros.h" once we remove
......@@ -45,7 +44,6 @@ class PlatformApiImpl : public assistant_client::PlatformApi {
assistant_client::AuthProvider& GetAuthProvider() override;
assistant_client::FileProvider& GetFileProvider() override;
assistant_client::NetworkProvider& GetNetworkProvider() override;
assistant_client::ResourceProvider& GetResourceProvider() override;
assistant_client::SystemProvider& GetSystemProvider() override;
// Called when the mic state associated with the interaction is changed.
......@@ -89,7 +87,6 @@ class PlatformApiImpl : public assistant_client::PlatformApi {
DummyAuthProvider auth_provider_;
FileProviderImpl file_provider_;
NetworkProviderImpl network_provider_;
ResourceProviderImpl resource_provider_;
SystemProviderImpl system_provider_;
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