Commit e9dca222 authored by Luke Sorenson's avatar Luke Sorenson Committed by Commit Bot

Add Component version number to MPP API callback.

Bug: 794273
Change-Id: I340114ad83e2dcdd5fd2b8d0dea721d0705e53b3
Reviewed-on: https://chromium-review.googlesource.com/822820Reviewed-by: default avatarToni Barzic <tbarzic@chromium.org>
Commit-Queue: Luke Sorenson <lasoren@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524625}
parent a2b72993
......@@ -4,6 +4,7 @@
#include "extensions/browser/api/media_perception_private/media_perception_api_manager.h"
#include "base/files/file_path.h"
#include "base/lazy_instance.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/media_analytics_client.h"
......@@ -35,13 +36,21 @@ media_perception::Diagnostics GetDiagnosticsForServiceError(
return diagnostics;
}
media_perception::ComponentState GetComponentStateForComponentStatus(
const media_perception::ComponentStatus status) {
media_perception::ComponentState GetFailedToInstallComponentState() {
media_perception::ComponentState component_state;
component_state.status = status;
component_state.status = media_perception::COMPONENT_STATUS_FAILED_TO_INSTALL;
return component_state;
}
// Pulls out the version number from a mount_point location for the media
// perception component. Mount points look like
// /run/imageloader/rtanalytics-light/1.0, where 1.0 is the version string.
std::unique_ptr<std::string> ExtractVersionFromMountPoint(
const std::string& mount_point) {
return std::make_unique<std::string>(
base::FilePath(mount_point).BaseName().value());
}
} // namespace
// static
......@@ -109,8 +118,7 @@ void MediaPerceptionAPIManager::SetAnalyticsComponent(
APISetAnalyticsComponentCallback callback) {
if (analytics_process_state_ != AnalyticsProcessState::IDLE) {
LOG(WARNING) << "Analytics process is not STOPPED.";
std::move(callback).Run(GetComponentStateForComponentStatus(
media_perception::COMPONENT_STATUS_FAILED_TO_INSTALL));
std::move(callback).Run(GetFailedToInstallComponentState());
return;
}
......@@ -118,8 +126,7 @@ void MediaPerceptionAPIManager::SetAnalyticsComponent(
ExtensionsAPIClient::Get()->GetMediaPerceptionAPIDelegate();
if (!delegate) {
LOG(WARNING) << "Could not get MediaPerceptionAPIDelegate.";
std::move(callback).Run(GetComponentStateForComponentStatus(
media_perception::COMPONENT_STATUS_FAILED_TO_INSTALL));
std::move(callback).Run(GetFailedToInstallComponentState());
return;
}
......@@ -132,17 +139,17 @@ void MediaPerceptionAPIManager::SetAnalyticsComponent(
void MediaPerceptionAPIManager::LoadComponentCallback(
APISetAnalyticsComponentCallback callback,
const std::string& mount_point) {
media_perception::ComponentState component_state;
if (mount_point.empty()) {
component_state.status =
media_perception::COMPONENT_STATUS_FAILED_TO_INSTALL;
std::move(callback).Run(std::move(component_state));
std::move(callback).Run(GetFailedToInstallComponentState());
return;
}
// If the new component is loaded, override the mount point.
mount_point_ = mount_point;
media_perception::ComponentState component_state;
component_state.status = media_perception::COMPONENT_STATUS_INSTALLED;
component_state.version = ExtractVersionFromMountPoint(mount_point_);
std::move(callback).Run(std::move(component_state));
return;
}
......
......@@ -36,7 +36,7 @@ class TestMediaPerceptionAPIDelegate : public MediaPerceptionAPIDelegate {
if (type == media_perception::COMPONENT_TYPE_LIGHT) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(load_callback),
"/run/imageloader/rtanalytics-light"));
"/run/imageloader/rtanalytics-light/1.0"));
return;
}
......
......@@ -82,6 +82,9 @@ namespace mediaPerceptionPrivate {
// The state of the media analytics downloadable component.
dictionary ComponentState {
ComponentStatus status;
// The version string for the current component.
DOMString? version;
};
// The parameters for processing a particular video stream.
......
......@@ -7,6 +7,7 @@ function setAnalyticsComponentLight() {
type: 'LIGHT',
}, chrome.test.callbackPass(function(component_state) {
chrome.test.assertEq('INSTALLED', component_state.status);
chrome.test.assertEq('1.0', component_state.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