Commit 61c134c5 authored by Nicholas Hollingum's avatar Nicholas Hollingum Committed by Chromium LUCI CQ

borealis: Add the shutdown monitor to the borealis service

This will be used by other parts of the codebase to initiate vm shutdown
from the UI.

Relatedly, we add a method to the ContextManager to query whether a
shutdown is necessary (i.e. because we don't want to show various UI
elements if it isn't).

Bug: b/172006764
Change-Id: Ie9f2fee8995ee2b02bd1fec53ffce3cf1a0171a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2569000
Commit-Queue: Nic Hollingum <hollingum@google.com>
Reviewed-by: default avatarDaniel Ng <danielng@google.com>
Cr-Commit-Position: refs/heads/master@{#833586}
parent 3810013e
...@@ -3157,6 +3157,8 @@ static_library("test_support") { ...@@ -3157,6 +3157,8 @@ static_library("test_support") {
"attestation/mock_enrollment_certificate_uploader.h", "attestation/mock_enrollment_certificate_uploader.h",
"attestation/mock_machine_certificate_uploader.cc", "attestation/mock_machine_certificate_uploader.cc",
"attestation/mock_machine_certificate_uploader.h", "attestation/mock_machine_certificate_uploader.h",
"borealis/borealis_context_manager_mock.cc",
"borealis/borealis_context_manager_mock.h",
"borealis/borealis_service_fake.cc", "borealis/borealis_service_fake.cc",
"borealis/borealis_service_fake.h", "borealis/borealis_service_fake.h",
"cert_provisioning/mock_cert_provisioning_scheduler.cc", "cert_provisioning/mock_cert_provisioning_scheduler.cc",
......
...@@ -60,6 +60,9 @@ class BorealisContextManager : public KeyedService { ...@@ -60,6 +60,9 @@ class BorealisContextManager : public KeyedService {
// Starts the Borealis VM and/or runs the callback when it is running. // Starts the Borealis VM and/or runs the callback when it is running.
virtual void StartBorealis(ResultCallback callback) = 0; virtual void StartBorealis(ResultCallback callback) = 0;
// Returns true if the VM is currently running.
virtual bool IsRunning() = 0;
// Stop the current running state, re-initializing the context manager // Stop the current running state, re-initializing the context manager
// to the state it was in prior to being started. All pending callbacks are // to the state it was in prior to being started. All pending callbacks are
// invoked with kCancelled result. // invoked with kCancelled result.
......
...@@ -30,7 +30,7 @@ BorealisContextManagerImpl::BorealisContextManagerImpl(Profile* profile) ...@@ -30,7 +30,7 @@ BorealisContextManagerImpl::BorealisContextManagerImpl(Profile* profile)
BorealisContextManagerImpl::~BorealisContextManagerImpl() = default; BorealisContextManagerImpl::~BorealisContextManagerImpl() = default;
void BorealisContextManagerImpl::StartBorealis(ResultCallback callback) { void BorealisContextManagerImpl::StartBorealis(ResultCallback callback) {
if (context_ && task_queue_.empty()) { if (IsRunning()) {
std::move(callback).Run(GetResult()); std::move(callback).Run(GetResult());
return; return;
} }
...@@ -45,7 +45,14 @@ void BorealisContextManagerImpl::StartBorealis(ResultCallback callback) { ...@@ -45,7 +45,14 @@ void BorealisContextManagerImpl::StartBorealis(ResultCallback callback) {
} }
} }
bool BorealisContextManagerImpl::IsRunning() {
return context_ && task_queue_.empty();
}
void BorealisContextManagerImpl::ShutDownBorealis() { void BorealisContextManagerImpl::ShutDownBorealis() {
// The VM is already off.
if (!context_)
return;
// TODO(b/172178036): This could have been a task-sequence but that // TODO(b/172178036): This could have been a task-sequence but that
// abstraction is proving insufficient. // abstraction is proving insufficient.
vm_tools::concierge::StopVmRequest request; vm_tools::concierge::StopVmRequest request;
......
...@@ -29,6 +29,7 @@ class BorealisContextManagerImpl : public BorealisContextManager { ...@@ -29,6 +29,7 @@ class BorealisContextManagerImpl : public BorealisContextManager {
// BorealisContextManager: // BorealisContextManager:
void StartBorealis(ResultCallback callback) override; void StartBorealis(ResultCallback callback) override;
bool IsRunning() override;
void ShutDownBorealis() override; void ShutDownBorealis() override;
// Public due to testing. // Public due to testing.
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/borealis/borealis_context_manager_mock.h"
namespace borealis {
BorealisContextManagerMock::BorealisContextManagerMock() = default;
BorealisContextManagerMock::~BorealisContextManagerMock() = default;
} // namespace borealis
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_BOREALIS_BOREALIS_CONTEXT_MANAGER_MOCK_H_
#define CHROME_BROWSER_CHROMEOS_BOREALIS_BOREALIS_CONTEXT_MANAGER_MOCK_H_
#include "chrome/browser/chromeos/borealis/borealis_context_manager.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace borealis {
class BorealisContextManagerMock : public BorealisContextManager {
public:
BorealisContextManagerMock();
~BorealisContextManagerMock();
MOCK_METHOD(void,
StartBorealis,
(BorealisContextManager::ResultCallback),
());
MOCK_METHOD(bool, IsRunning, (), ());
MOCK_METHOD(void, ShutDownBorealis, (), ());
};
} // namespace borealis
#endif // CHROME_BROWSER_CHROMEOS_BOREALIS_BOREALIS_CONTEXT_MANAGER_MOCK_H_
...@@ -15,6 +15,7 @@ class BorealisAppLauncher; ...@@ -15,6 +15,7 @@ class BorealisAppLauncher;
class BorealisContextManager; class BorealisContextManager;
class BorealisFeatures; class BorealisFeatures;
class BorealisInstaller; class BorealisInstaller;
class BorealisShutdownMonitor;
class BorealisWindowManager; class BorealisWindowManager;
// A common location for all the interdependant components of borealis. // A common location for all the interdependant components of borealis.
...@@ -29,6 +30,7 @@ class BorealisService : public KeyedService { ...@@ -29,6 +30,7 @@ class BorealisService : public KeyedService {
virtual BorealisContextManager& ContextManager() = 0; virtual BorealisContextManager& ContextManager() = 0;
virtual BorealisFeatures& Features() = 0; virtual BorealisFeatures& Features() = 0;
virtual BorealisInstaller& Installer() = 0; virtual BorealisInstaller& Installer() = 0;
virtual BorealisShutdownMonitor& ShutdownMonitor() = 0;
virtual BorealisWindowManager& WindowManager() = 0; virtual BorealisWindowManager& WindowManager() = 0;
}; };
......
...@@ -41,6 +41,11 @@ BorealisInstaller& BorealisServiceFake::Installer() { ...@@ -41,6 +41,11 @@ BorealisInstaller& BorealisServiceFake::Installer() {
return *installer_; return *installer_;
} }
BorealisShutdownMonitor& BorealisServiceFake::ShutdownMonitor() {
DCHECK(shutdown_monitor_);
return *shutdown_monitor_;
}
BorealisWindowManager& BorealisServiceFake::WindowManager() { BorealisWindowManager& BorealisServiceFake::WindowManager() {
DCHECK(window_manager_); DCHECK(window_manager_);
return *window_manager_; return *window_manager_;
...@@ -64,6 +69,11 @@ void BorealisServiceFake::SetInstallerForTesting(BorealisInstaller* installer) { ...@@ -64,6 +69,11 @@ void BorealisServiceFake::SetInstallerForTesting(BorealisInstaller* installer) {
installer_ = installer; installer_ = installer;
} }
void BorealisServiceFake::SetShutdownMonitorForTesting(
BorealisShutdownMonitor* shutdown_monitor) {
shutdown_monitor_ = shutdown_monitor;
}
void BorealisServiceFake::SetWindowManagerForTesting( void BorealisServiceFake::SetWindowManagerForTesting(
BorealisWindowManager* window_manager) { BorealisWindowManager* window_manager) {
window_manager_ = window_manager; window_manager_ = window_manager;
......
...@@ -26,12 +26,14 @@ class BorealisServiceFake : public BorealisService { ...@@ -26,12 +26,14 @@ class BorealisServiceFake : public BorealisService {
BorealisContextManager& ContextManager() override; BorealisContextManager& ContextManager() override;
BorealisFeatures& Features() override; BorealisFeatures& Features() override;
BorealisInstaller& Installer() override; BorealisInstaller& Installer() override;
BorealisShutdownMonitor& ShutdownMonitor() override;
BorealisWindowManager& WindowManager() override; BorealisWindowManager& WindowManager() override;
void SetAppLauncherForTesting(BorealisAppLauncher* app_launcher); void SetAppLauncherForTesting(BorealisAppLauncher* app_launcher);
void SetContextManagerForTesting(BorealisContextManager* context_manager); void SetContextManagerForTesting(BorealisContextManager* context_manager);
void SetFeaturesForTesting(BorealisFeatures* features); void SetFeaturesForTesting(BorealisFeatures* features);
void SetInstallerForTesting(BorealisInstaller* installer); void SetInstallerForTesting(BorealisInstaller* installer);
void SetShutdownMonitorForTesting(BorealisShutdownMonitor* shutdown_monitor);
void SetWindowManagerForTesting(BorealisWindowManager* window_manager); void SetWindowManagerForTesting(BorealisWindowManager* window_manager);
private: private:
...@@ -39,6 +41,7 @@ class BorealisServiceFake : public BorealisService { ...@@ -39,6 +41,7 @@ class BorealisServiceFake : public BorealisService {
BorealisContextManager* context_manager_ = nullptr; BorealisContextManager* context_manager_ = nullptr;
BorealisFeatures* features_ = nullptr; BorealisFeatures* features_ = nullptr;
BorealisInstaller* installer_ = nullptr; BorealisInstaller* installer_ = nullptr;
BorealisShutdownMonitor* shutdown_monitor_ = nullptr;
BorealisWindowManager* window_manager_ = nullptr; BorealisWindowManager* window_manager_ = nullptr;
}; };
......
...@@ -12,6 +12,7 @@ BorealisServiceImpl::BorealisServiceImpl(Profile* profile) ...@@ -12,6 +12,7 @@ BorealisServiceImpl::BorealisServiceImpl(Profile* profile)
context_manager_(profile), context_manager_(profile),
features_(profile_), features_(profile_),
installer_(profile_), installer_(profile_),
shutdown_monitor_(profile_),
window_manager_(profile_) {} window_manager_(profile_) {}
BorealisServiceImpl::~BorealisServiceImpl() = default; BorealisServiceImpl::~BorealisServiceImpl() = default;
...@@ -32,6 +33,10 @@ BorealisInstaller& BorealisServiceImpl::Installer() { ...@@ -32,6 +33,10 @@ BorealisInstaller& BorealisServiceImpl::Installer() {
return installer_; return installer_;
} }
BorealisShutdownMonitor& BorealisServiceImpl::ShutdownMonitor() {
return shutdown_monitor_;
}
BorealisWindowManager& BorealisServiceImpl::WindowManager() { BorealisWindowManager& BorealisServiceImpl::WindowManager() {
return window_manager_; return window_manager_;
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "chrome/browser/chromeos/borealis/borealis_context_manager_impl.h" #include "chrome/browser/chromeos/borealis/borealis_context_manager_impl.h"
#include "chrome/browser/chromeos/borealis/borealis_features.h" #include "chrome/browser/chromeos/borealis/borealis_features.h"
#include "chrome/browser/chromeos/borealis/borealis_installer_impl.h" #include "chrome/browser/chromeos/borealis/borealis_installer_impl.h"
#include "chrome/browser/chromeos/borealis/borealis_shutdown_monitor.h"
#include "chrome/browser/chromeos/borealis/borealis_window_manager.h" #include "chrome/browser/chromeos/borealis/borealis_window_manager.h"
namespace borealis { namespace borealis {
...@@ -27,6 +28,7 @@ class BorealisServiceImpl : public BorealisService { ...@@ -27,6 +28,7 @@ class BorealisServiceImpl : public BorealisService {
BorealisContextManager& ContextManager() override; BorealisContextManager& ContextManager() override;
BorealisFeatures& Features() override; BorealisFeatures& Features() override;
BorealisInstaller& Installer() override; BorealisInstaller& Installer() override;
BorealisShutdownMonitor& ShutdownMonitor() override;
BorealisWindowManager& WindowManager() override; BorealisWindowManager& WindowManager() override;
Profile* const profile_; Profile* const profile_;
...@@ -35,6 +37,7 @@ class BorealisServiceImpl : public BorealisService { ...@@ -35,6 +37,7 @@ class BorealisServiceImpl : public BorealisService {
BorealisContextManagerImpl context_manager_; BorealisContextManagerImpl context_manager_;
BorealisFeatures features_; BorealisFeatures features_;
BorealisInstallerImpl installer_; BorealisInstallerImpl installer_;
BorealisShutdownMonitor shutdown_monitor_;
BorealisWindowManager window_manager_; BorealisWindowManager window_manager_;
}; };
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include <memory> #include <memory>
#include "chrome/browser/chromeos/borealis/borealis_context_manager.h" #include "chrome/browser/chromeos/borealis/borealis_context_manager_mock.h"
#include "chrome/browser/chromeos/borealis/borealis_features.h" #include "chrome/browser/chromeos/borealis/borealis_features.h"
#include "chrome/browser/chromeos/borealis/borealis_service_fake.h" #include "chrome/browser/chromeos/borealis/borealis_service_fake.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
...@@ -17,15 +17,6 @@ ...@@ -17,15 +17,6 @@
namespace borealis { namespace borealis {
namespace { namespace {
class BorealisContextManagerMock : public BorealisContextManager {
public:
MOCK_METHOD(void,
StartBorealis,
(BorealisContextManager::ResultCallback),
());
MOCK_METHOD(void, ShutDownBorealis, (), ());
};
class BorealisShutdownMonitorTest : public testing::Test { class BorealisShutdownMonitorTest : public testing::Test {
protected: protected:
BorealisShutdownMonitorTest() BorealisShutdownMonitorTest()
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "chrome/browser/chromeos/borealis/borealis_context.h" #include "chrome/browser/chromeos/borealis/borealis_context.h"
#include "chrome/browser/chromeos/borealis/borealis_context_manager.h" #include "chrome/browser/chromeos/borealis/borealis_context_manager_mock.h"
#include "chrome/browser/chromeos/borealis/borealis_installer.h" #include "chrome/browser/chromeos/borealis/borealis_installer.h"
#include "chrome/browser/chromeos/borealis/borealis_metrics.h" #include "chrome/browser/chromeos/borealis/borealis_metrics.h"
#include "chrome/browser/chromeos/borealis/borealis_service_fake.h" #include "chrome/browser/chromeos/borealis/borealis_service_fake.h"
...@@ -40,15 +40,6 @@ class BorealisInstallerMock : public borealis::BorealisInstaller { ...@@ -40,15 +40,6 @@ class BorealisInstallerMock : public borealis::BorealisInstaller {
MOCK_METHOD1(RemoveObserver, void(Observer*)); MOCK_METHOD1(RemoveObserver, void(Observer*));
}; };
class BorealisContextManagerMock : public borealis::BorealisContextManager {
public:
MOCK_METHOD(void,
StartBorealis,
(BorealisContextManager::ResultCallback),
());
MOCK_METHOD(void, ShutDownBorealis, (), ());
};
class BorealisInstallerViewBrowserTest : public DialogBrowserTest { class BorealisInstallerViewBrowserTest : public DialogBrowserTest {
public: public:
BorealisInstallerViewBrowserTest() = default; BorealisInstallerViewBrowserTest() = default;
......
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