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 @@ ...@@ -4,6 +4,7 @@
#include "extensions/browser/api/media_perception_private/media_perception_api_manager.h" #include "extensions/browser/api/media_perception_private/media_perception_api_manager.h"
#include "base/files/file_path.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/media_analytics_client.h" #include "chromeos/dbus/media_analytics_client.h"
...@@ -35,13 +36,21 @@ media_perception::Diagnostics GetDiagnosticsForServiceError( ...@@ -35,13 +36,21 @@ media_perception::Diagnostics GetDiagnosticsForServiceError(
return diagnostics; return diagnostics;
} }
media_perception::ComponentState GetComponentStateForComponentStatus( media_perception::ComponentState GetFailedToInstallComponentState() {
const media_perception::ComponentStatus status) {
media_perception::ComponentState component_state; media_perception::ComponentState component_state;
component_state.status = status; component_state.status = media_perception::COMPONENT_STATUS_FAILED_TO_INSTALL;
return component_state; 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 } // namespace
// static // static
...@@ -109,8 +118,7 @@ void MediaPerceptionAPIManager::SetAnalyticsComponent( ...@@ -109,8 +118,7 @@ void MediaPerceptionAPIManager::SetAnalyticsComponent(
APISetAnalyticsComponentCallback callback) { APISetAnalyticsComponentCallback callback) {
if (analytics_process_state_ != AnalyticsProcessState::IDLE) { if (analytics_process_state_ != AnalyticsProcessState::IDLE) {
LOG(WARNING) << "Analytics process is not STOPPED."; LOG(WARNING) << "Analytics process is not STOPPED.";
std::move(callback).Run(GetComponentStateForComponentStatus( std::move(callback).Run(GetFailedToInstallComponentState());
media_perception::COMPONENT_STATUS_FAILED_TO_INSTALL));
return; return;
} }
...@@ -118,8 +126,7 @@ void MediaPerceptionAPIManager::SetAnalyticsComponent( ...@@ -118,8 +126,7 @@ void MediaPerceptionAPIManager::SetAnalyticsComponent(
ExtensionsAPIClient::Get()->GetMediaPerceptionAPIDelegate(); ExtensionsAPIClient::Get()->GetMediaPerceptionAPIDelegate();
if (!delegate) { if (!delegate) {
LOG(WARNING) << "Could not get MediaPerceptionAPIDelegate."; LOG(WARNING) << "Could not get MediaPerceptionAPIDelegate.";
std::move(callback).Run(GetComponentStateForComponentStatus( std::move(callback).Run(GetFailedToInstallComponentState());
media_perception::COMPONENT_STATUS_FAILED_TO_INSTALL));
return; return;
} }
...@@ -132,17 +139,17 @@ void MediaPerceptionAPIManager::SetAnalyticsComponent( ...@@ -132,17 +139,17 @@ void MediaPerceptionAPIManager::SetAnalyticsComponent(
void MediaPerceptionAPIManager::LoadComponentCallback( void MediaPerceptionAPIManager::LoadComponentCallback(
APISetAnalyticsComponentCallback callback, APISetAnalyticsComponentCallback callback,
const std::string& mount_point) { const std::string& mount_point) {
media_perception::ComponentState component_state;
if (mount_point.empty()) { if (mount_point.empty()) {
component_state.status = std::move(callback).Run(GetFailedToInstallComponentState());
media_perception::COMPONENT_STATUS_FAILED_TO_INSTALL;
std::move(callback).Run(std::move(component_state));
return; return;
} }
// If the new component is loaded, override the mount point. // If the new component is loaded, override the mount point.
mount_point_ = mount_point; mount_point_ = mount_point;
media_perception::ComponentState component_state;
component_state.status = media_perception::COMPONENT_STATUS_INSTALLED; component_state.status = media_perception::COMPONENT_STATUS_INSTALLED;
component_state.version = ExtractVersionFromMountPoint(mount_point_);
std::move(callback).Run(std::move(component_state)); std::move(callback).Run(std::move(component_state));
return; return;
} }
......
...@@ -36,7 +36,7 @@ class TestMediaPerceptionAPIDelegate : public MediaPerceptionAPIDelegate { ...@@ -36,7 +36,7 @@ class TestMediaPerceptionAPIDelegate : public MediaPerceptionAPIDelegate {
if (type == media_perception::COMPONENT_TYPE_LIGHT) { if (type == media_perception::COMPONENT_TYPE_LIGHT) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(load_callback), FROM_HERE, base::BindOnce(std::move(load_callback),
"/run/imageloader/rtanalytics-light")); "/run/imageloader/rtanalytics-light/1.0"));
return; return;
} }
......
...@@ -82,6 +82,9 @@ namespace mediaPerceptionPrivate { ...@@ -82,6 +82,9 @@ namespace mediaPerceptionPrivate {
// The state of the media analytics downloadable component. // The state of the media analytics downloadable component.
dictionary ComponentState { dictionary ComponentState {
ComponentStatus status; ComponentStatus status;
// The version string for the current component.
DOMString? version;
}; };
// The parameters for processing a particular video stream. // The parameters for processing a particular video stream.
......
...@@ -7,6 +7,7 @@ function setAnalyticsComponentLight() { ...@@ -7,6 +7,7 @@ function setAnalyticsComponentLight() {
type: 'LIGHT', type: 'LIGHT',
}, chrome.test.callbackPass(function(component_state) { }, chrome.test.callbackPass(function(component_state) {
chrome.test.assertEq('INSTALLED', component_state.status); 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