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( ...@@ -39,12 +39,40 @@ std::string GetComponentNameForComponentType(
return ""; 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( void OnLoadComponent(
MediaPerceptionAPIDelegate::LoadCrOSComponentCallback load_callback, MediaPerceptionAPIDelegate::LoadCrOSComponentCallback load_callback,
component_updater::CrOSComponentManager::Error error, component_updater::CrOSComponentManager::Error error,
const base::FilePath& mount_point) { const base::FilePath& mount_point) {
std::move(load_callback) std::move(load_callback)
.Run(error == component_updater::CrOSComponentManager::Error::NONE, .Run(GetComponentInstallationErrorForCrOSComponentManagerError(error),
mount_point); mount_point);
} }
......
...@@ -26,8 +26,10 @@ class MediaPerceptionAPIDelegate { ...@@ -26,8 +26,10 @@ class MediaPerceptionAPIDelegate {
public: public:
// Callback for loading a CrOS component. |mount_point| will contain a path to // Callback for loading a CrOS component. |mount_point| will contain a path to
// the loaded component, if |success| is true (installation succeeded). // the loaded component, if |success| is true (installation succeeded).
using LoadCrOSComponentCallback = using LoadCrOSComponentCallback = base::OnceCallback<void(
base::OnceCallback<void(bool success, const base::FilePath& mount_point)>; const api::media_perception_private::ComponentInstallationError
installation_error,
const base::FilePath& mount_point)>;
using MediaPerceptionRequestHandler = base::RepeatingCallback<void( using MediaPerceptionRequestHandler = base::RepeatingCallback<void(
chromeos::media_perception::mojom::MediaPerceptionRequest request)>; chromeos::media_perception::mojom::MediaPerceptionRequest request)>;
......
...@@ -194,10 +194,15 @@ void MediaPerceptionAPIManager::SetAnalyticsComponent( ...@@ -194,10 +194,15 @@ void MediaPerceptionAPIManager::SetAnalyticsComponent(
void MediaPerceptionAPIManager::LoadComponentCallback( void MediaPerceptionAPIManager::LoadComponentCallback(
APISetAnalyticsComponentCallback callback, APISetAnalyticsComponentCallback callback,
bool success, const extensions::api::media_perception_private::ComponentInstallationError
installation_error,
const base::FilePath& mount_point) { const base::FilePath& mount_point) {
if (!success) { if (installation_error != extensions::api::media_perception_private::
std::move(callback).Run(GetFailedToInstallComponentState()); 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; return;
} }
......
...@@ -131,7 +131,8 @@ class MediaPerceptionAPIManager ...@@ -131,7 +131,8 @@ class MediaPerceptionAPIManager
// Callback with the mount point for a loaded component. // Callback with the mount point for a loaded component.
void LoadComponentCallback(APISetAnalyticsComponentCallback callback, void LoadComponentCallback(APISetAnalyticsComponentCallback callback,
bool success, const extensions::api::media_perception_private::
ComponentInstallationError installation_error,
const base::FilePath& mount_point); const base::FilePath& mount_point);
bool ComponentIsLoaded(); bool ComponentIsLoaded();
......
...@@ -36,16 +36,17 @@ class TestMediaPerceptionAPIDelegate : public MediaPerceptionAPIDelegate { ...@@ -36,16 +36,17 @@ class TestMediaPerceptionAPIDelegate : public MediaPerceptionAPIDelegate {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce( 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"))); base::FilePath("/run/imageloader/rtanalytics-light/1.0")));
return; return;
} }
// Firing callback with false indicates that the installation of the
// component failed.
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, 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( void BindVideoSourceProvider(
......
...@@ -5,17 +5,18 @@ ...@@ -5,17 +5,18 @@
function setAnalyticsComponentLight() { function setAnalyticsComponentLight() {
chrome.mediaPerceptionPrivate.setAnalyticsComponent({ chrome.mediaPerceptionPrivate.setAnalyticsComponent({
type: 'LIGHT', type: 'LIGHT',
}, chrome.test.callbackPass(function(component_state) { }, chrome.test.callbackPass(function(componentState) {
chrome.test.assertEq('INSTALLED', component_state.status); chrome.test.assertEq('INSTALLED', componentState.status);
chrome.test.assertEq('1.0', component_state.version); chrome.test.assertEq('1.0', componentState.version);
})); }));
} }
function setAnalyticsComponentFullExpectFailure() { function setAnalyticsComponentFullExpectFailure() {
chrome.mediaPerceptionPrivate.setAnalyticsComponent({ chrome.mediaPerceptionPrivate.setAnalyticsComponent({
type: 'FULL', type: 'FULL',
}, chrome.test.callbackPass(function(component_state) { }, chrome.test.callbackPass(function(componentState) {
chrome.test.assertEq('FAILED_TO_INSTALL', component_state.status); chrome.test.assertEq('FAILED_TO_INSTALL', componentState.status);
chrome.test.assertEq('NOT_FOUND', componentState.installationErrorCode);
})); }));
} }
...@@ -29,9 +30,9 @@ function setAnalyticsComponentWithProcessRunningSuccess() { ...@@ -29,9 +30,9 @@ function setAnalyticsComponentWithProcessRunningSuccess() {
chrome.mediaPerceptionPrivate.setAnalyticsComponent({ chrome.mediaPerceptionPrivate.setAnalyticsComponent({
type: 'LIGHT', type: 'LIGHT',
}, chrome.test.callbackPass(function(component_state) { }, chrome.test.callbackPass(function(componentState) {
chrome.test.assertEq('INSTALLED', component_state.status); chrome.test.assertEq('INSTALLED', componentState.status);
chrome.test.assertEq('1.0', component_state.version); 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