Add autotestPrivate.bootstrapMachineLearningService
This function makes a basic call using the ML Service client library. Doing this triggers the ML Service daemon to be started (via D-Bus service activation) and the D-Bus -> Mojo IPC bootstrap to occur. The VoidCallback is invoked when the basic call (LoadModel on the test model) completes successfully. Tested: - Ran it with a Chrome OS Tast test (testing successful bootstrap) - Added a test to the test.js covering the case of failure to connect to ML Service Bug: 836102 Change-Id: I509eab4a518a933109095eec1ece811bc30e4f99 Reviewed-on: https://chromium-review.googlesource.com/1229878 Reviewed-by: Ben Wells <benwells@chromium.org> Reviewed-by: Achuith Bhandarkar <achuith@chromium.org> Reviewed-by: Joel Hockey <joelhockey@chromium.org> Commit-Queue: Andrew Moylan <amoylan@chromium.org> Cr-Commit-Position: refs/heads/master@{#593066}
This commit is contained in:

committed by
Commit Bot

parent
b85369240c
commit
d3542c5100
chrome
browser
extensions
common
extensions
test
data
extensions
api_test
autotest_private
extensions/browser
tools/metrics/histograms
@ -997,6 +997,8 @@ jumbo_static_library("extensions") {
|
||||
"//ash/public/cpp",
|
||||
"//chromeos/components/proximity_auth",
|
||||
"//chromeos/services/ime/public/mojom",
|
||||
"//chromeos/services/machine_learning/public/cpp",
|
||||
"//chromeos/services/machine_learning/public/mojom",
|
||||
"//components/arc",
|
||||
"//components/chrome_apps",
|
||||
"//components/constrained_window",
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "chrome/browser/extensions/api/autotest_private/autotest_private_api.h"
|
||||
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
#include "base/lazy_instance.h"
|
||||
@ -49,6 +50,7 @@
|
||||
#include "chromeos/dbus/dbus_thread_manager.h"
|
||||
#include "chromeos/dbus/session_manager_client.h"
|
||||
#include "chromeos/printing/printer_configuration.h"
|
||||
#include "chromeos/services/machine_learning/public/cpp/service_connection.h"
|
||||
#include "components/arc/arc_prefs.h"
|
||||
#include "components/user_manager/user_manager.h"
|
||||
#include "content/public/common/service_manager_connection.h"
|
||||
@ -806,6 +808,49 @@ void AutotestPrivateRunCrostiniInstallerFunction::CrostiniRestarted(
|
||||
}
|
||||
#endif
|
||||
|
||||
AutotestPrivateBootstrapMachineLearningServiceFunction::
|
||||
~AutotestPrivateBootstrapMachineLearningServiceFunction() = default;
|
||||
|
||||
AutotestPrivateBootstrapMachineLearningServiceFunction::
|
||||
AutotestPrivateBootstrapMachineLearningServiceFunction() {}
|
||||
|
||||
ExtensionFunction::ResponseAction
|
||||
AutotestPrivateBootstrapMachineLearningServiceFunction::Run() {
|
||||
DVLOG(1) << "AutotestPrivateBootstrapMachineLearningServiceFunction";
|
||||
#if defined(OS_CHROMEOS)
|
||||
// Load a model. This will first bootstrap the Mojo connection to ML Service.
|
||||
chromeos::machine_learning::ServiceConnection::GetInstance()->LoadModel(
|
||||
chromeos::machine_learning::mojom::ModelSpec::New(
|
||||
chromeos::machine_learning::mojom::ModelId::TEST_MODEL),
|
||||
mojo::MakeRequest(&model_),
|
||||
base::BindOnce(
|
||||
&AutotestPrivateBootstrapMachineLearningServiceFunction::ModelLoaded,
|
||||
this));
|
||||
model_.set_connection_error_handler(base::BindOnce(
|
||||
&AutotestPrivateBootstrapMachineLearningServiceFunction::ConnectionError,
|
||||
this));
|
||||
return RespondLater();
|
||||
#else
|
||||
return RespondNow(Error(kOnlyAvailableOnChromeOSError));
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(OS_CHROMEOS)
|
||||
void AutotestPrivateBootstrapMachineLearningServiceFunction::ModelLoaded(
|
||||
chromeos::machine_learning::mojom::LoadModelResult result) {
|
||||
if (result == chromeos::machine_learning::mojom::LoadModelResult::OK) {
|
||||
Respond(NoArguments());
|
||||
} else {
|
||||
Respond(Error(base::StrCat(
|
||||
{"Model load error ", (std::ostringstream() << result).str()})));
|
||||
}
|
||||
}
|
||||
|
||||
void AutotestPrivateBootstrapMachineLearningServiceFunction::ConnectionError() {
|
||||
Respond(Error("ML Service connection error"));
|
||||
}
|
||||
#endif
|
||||
|
||||
static base::LazyInstance<BrowserContextKeyedAPIFactory<AutotestPrivateAPI>>::
|
||||
DestructorAtExit g_autotest_private_api_factory = LAZY_INSTANCE_INITIALIZER;
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
#if defined(OS_CHROMEOS)
|
||||
#include "ash/public/interfaces/ash_message_center_controller.mojom.h"
|
||||
#include "chrome/browser/chromeos/printing/cups_printers_manager.h"
|
||||
#include "chromeos/services/machine_learning/public/mojom/machine_learning_service.mojom.h"
|
||||
#endif
|
||||
|
||||
namespace message_center {
|
||||
@ -335,6 +336,28 @@ class AutotestPrivateRemovePrinterFunction : public UIThreadExtensionFunction {
|
||||
DISALLOW_COPY_AND_ASSIGN(AutotestPrivateRemovePrinterFunction);
|
||||
};
|
||||
|
||||
class AutotestPrivateBootstrapMachineLearningServiceFunction
|
||||
: public UIThreadExtensionFunction {
|
||||
public:
|
||||
AutotestPrivateBootstrapMachineLearningServiceFunction();
|
||||
DECLARE_EXTENSION_FUNCTION("autotestPrivate.bootstrapMachineLearningService",
|
||||
AUTOTESTPRIVATE_BOOTSTRAPMACHINELEARNINGSERVICE)
|
||||
|
||||
private:
|
||||
~AutotestPrivateBootstrapMachineLearningServiceFunction() override;
|
||||
ResponseAction Run() override;
|
||||
#if defined(OS_CHROMEOS)
|
||||
// Callbacks for a basic Mojo call to MachineLearningService.LoadModel.
|
||||
void ModelLoaded(chromeos::machine_learning::mojom::LoadModelResult result);
|
||||
void ConnectionError();
|
||||
|
||||
chromeos::machine_learning::mojom::ModelPtr model_;
|
||||
#endif
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(
|
||||
AutotestPrivateBootstrapMachineLearningServiceFunction);
|
||||
};
|
||||
|
||||
// Don't kill the browser when we're in a browser test.
|
||||
void SetAutotestPrivateTest();
|
||||
|
||||
|
@ -201,5 +201,10 @@ namespace autotestPrivate {
|
||||
// |enabled|: Enable Crostini.
|
||||
// |callback|: Called when the operation has completed.
|
||||
static void setCrostiniEnabled(boolean enabled, VoidCallback callback);
|
||||
|
||||
// Makes a basic request to ML Service, triggering 1. ML Service
|
||||
// daemon startup, and 2. the initial D-Bus -> Mojo IPC bootstrap.
|
||||
// |callback|: Called when the operation has completed.
|
||||
static void bootstrapMachineLearningService(VoidCallback callback);
|
||||
};
|
||||
};
|
||||
|
@ -185,6 +185,10 @@ chrome.test.runTests([
|
||||
chrome.autotestPrivate.runCrostiniInstaller(chrome.test.callbackFail(
|
||||
'Crostini is not available for the current user'));
|
||||
},
|
||||
function bootstrapMachineLearningService() {
|
||||
chrome.autotestPrivate.bootstrapMachineLearningService(
|
||||
chrome.test.callbackFail('ML Service connection error'));
|
||||
},
|
||||
function getPrinterList() {
|
||||
chrome.autotestPrivate.getPrinterList(function(){
|
||||
chrome.test.succeed();
|
||||
|
@ -1341,6 +1341,7 @@ enum HistogramValue {
|
||||
FILEMANAGERPRIVATEINTERNAL_GETTHUMBNAIL = 1278,
|
||||
FILEMANAGERPRIVATEINTERNAL_GETCROSTINISHAREDPATHS = 1279,
|
||||
AUTOTESTPRIVATE_LAUNCHAPP = 1280,
|
||||
AUTOTESTPRIVATE_BOOTSTRAPMACHINELEARNINGSERVICE = 1281,
|
||||
// Last entry: Add new entries above, then run:
|
||||
// python tools/metrics/histograms/update_extension_histograms.py
|
||||
ENUM_BOUNDARY
|
||||
|
@ -16838,6 +16838,7 @@ Called by update_net_error_codes.py.-->
|
||||
<int value="1278" label="FILEMANAGERPRIVATEINTERNAL_GETTHUMBNAIL"/>
|
||||
<int value="1279" label="FILEMANAGERPRIVATEINTERNAL_GETCROSTINISHAREDPATHS"/>
|
||||
<int value="1280" label="AUTOTESTPRIVATE_LAUNCHAPP"/>
|
||||
<int value="1281" label="AUTOTESTPRIVATE_BOOTSTRAPMACHINELEARNINGSERVICE"/>
|
||||
</enum>
|
||||
|
||||
<enum name="ExtensionIconState">
|
||||
|
Reference in New Issue
Block a user