Commit 496ab358 authored by Luke Sorenson's avatar Luke Sorenson Committed by Commit Bot

Impl to add ComponentInstallationError enum to setAnalyticsComponent callback.

Bug: 1003037
Change-Id: I527dde7eff1e4e902d4bb81d94bdfec6867b2126
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1799442Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Commit-Queue: Luke Sorenson <lasoren@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704806}
parent fe022146
......@@ -39,12 +39,40 @@ std::string GetComponentNameForComponentType(
return "";
}
api::media_perception_private::ComponentInstallationError
GetComponentInstallationErrorForCrOSComponentManagerError(
const component_updater::CrOSComponentManager::Error error) {
switch (error) {
case component_updater::CrOSComponentManager::Error::ERROR_MAX:
case component_updater::CrOSComponentManager::Error::NONE:
return api::media_perception_private::COMPONENT_INSTALLATION_ERROR_NONE;
case component_updater::CrOSComponentManager::Error::UNKNOWN_COMPONENT:
return api::media_perception_private::
COMPONENT_INSTALLATION_ERROR_UNKNOWN_COMPONENT;
case component_updater::CrOSComponentManager::Error::INSTALL_FAILURE:
return api::media_perception_private::
COMPONENT_INSTALLATION_ERROR_INSTALL_FAILURE;
case component_updater::CrOSComponentManager::Error::MOUNT_FAILURE:
return api::media_perception_private::
COMPONENT_INSTALLATION_ERROR_MOUNT_FAILURE;
case component_updater::CrOSComponentManager::Error::
COMPATIBILITY_CHECK_FAILED:
return api::media_perception_private::
COMPONENT_INSTALLATION_ERROR_COMPATIBILITY_CHECK_FAILED;
case component_updater::CrOSComponentManager::Error::NOT_FOUND:
return api::media_perception_private::
COMPONENT_INSTALLATION_ERROR_NOT_FOUND;
}
NOTREACHED() << "Reached component error type not in switch.";
return api::media_perception_private::COMPONENT_INSTALLATION_ERROR_NONE;
}
void OnLoadComponent(
MediaPerceptionAPIDelegate::LoadCrOSComponentCallback load_callback,
component_updater::CrOSComponentManager::Error error,
const base::FilePath& mount_point) {
std::move(load_callback)
.Run(error == component_updater::CrOSComponentManager::Error::NONE,
.Run(GetComponentInstallationErrorForCrOSComponentManagerError(error),
mount_point);
}
......
......@@ -26,8 +26,10 @@ class MediaPerceptionAPIDelegate {
public:
// Callback for loading a CrOS component. |mount_point| will contain a path to
// the loaded component, if |success| is true (installation succeeded).
using LoadCrOSComponentCallback =
base::OnceCallback<void(bool success, const base::FilePath& mount_point)>;
using LoadCrOSComponentCallback = base::OnceCallback<void(
const api::media_perception_private::ComponentInstallationError
installation_error,
const base::FilePath& mount_point)>;
using MediaPerceptionRequestHandler = base::RepeatingCallback<void(
chromeos::media_perception::mojom::MediaPerceptionRequest request)>;
......
......@@ -194,10 +194,15 @@ void MediaPerceptionAPIManager::SetAnalyticsComponent(
void MediaPerceptionAPIManager::LoadComponentCallback(
APISetAnalyticsComponentCallback callback,
bool success,
const extensions::api::media_perception_private::ComponentInstallationError
installation_error,
const base::FilePath& mount_point) {
if (!success) {
std::move(callback).Run(GetFailedToInstallComponentState());
if (installation_error != extensions::api::media_perception_private::
COMPONENT_INSTALLATION_ERROR_NONE) {
extensions::api::media_perception_private::ComponentState component_state =
GetFailedToInstallComponentState();
component_state.installation_error_code = installation_error;
std::move(callback).Run(std::move(component_state));
return;
}
......
......@@ -131,7 +131,8 @@ class MediaPerceptionAPIManager
// Callback with the mount point for a loaded component.
void LoadComponentCallback(APISetAnalyticsComponentCallback callback,
bool success,
const extensions::api::media_perception_private::
ComponentInstallationError installation_error,
const base::FilePath& mount_point);
bool ComponentIsLoaded();
......
......@@ -36,16 +36,17 @@ class TestMediaPerceptionAPIDelegate : public MediaPerceptionAPIDelegate {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(
std::move(load_callback), true,
std::move(load_callback),
media_perception::COMPONENT_INSTALLATION_ERROR_NONE,
base::FilePath("/run/imageloader/rtanalytics-light/1.0")));
return;
}
// Firing callback with false indicates that the installation of the
// component failed.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(std::move(load_callback), false, base::FilePath()));
base::BindOnce(std::move(load_callback),
media_perception::COMPONENT_INSTALLATION_ERROR_NOT_FOUND,
base::FilePath()));
}
void BindVideoSourceProvider(
......
......@@ -5,17 +5,18 @@
function setAnalyticsComponentLight() {
chrome.mediaPerceptionPrivate.setAnalyticsComponent({
type: 'LIGHT',
}, chrome.test.callbackPass(function(component_state) {
chrome.test.assertEq('INSTALLED', component_state.status);
chrome.test.assertEq('1.0', component_state.version);
}, chrome.test.callbackPass(function(componentState) {
chrome.test.assertEq('INSTALLED', componentState.status);
chrome.test.assertEq('1.0', componentState.version);
}));
}
function setAnalyticsComponentFullExpectFailure() {
chrome.mediaPerceptionPrivate.setAnalyticsComponent({
type: 'FULL',
}, chrome.test.callbackPass(function(component_state) {
chrome.test.assertEq('FAILED_TO_INSTALL', component_state.status);
}, chrome.test.callbackPass(function(componentState) {
chrome.test.assertEq('FAILED_TO_INSTALL', componentState.status);
chrome.test.assertEq('NOT_FOUND', componentState.installationErrorCode);
}));
}
......@@ -29,9 +30,9 @@ function setAnalyticsComponentWithProcessRunningSuccess() {
chrome.mediaPerceptionPrivate.setAnalyticsComponent({
type: 'LIGHT',
}, chrome.test.callbackPass(function(component_state) {
chrome.test.assertEq('INSTALLED', component_state.status);
chrome.test.assertEq('1.0', component_state.version);
}, chrome.test.callbackPass(function(componentState) {
chrome.test.assertEq('INSTALLED', componentState.status);
chrome.test.assertEq('1.0', componentState.version);
}));
}
......
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