Commit 88260843 authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

Add GetVmInfo

Change running_vms_ to be a map rather than set and store VmInfos for
running VMs..

Bug: 878324
Change-Id: I159a0c201a9f35ba64d81b57e0687cb95f2eec6f
Reviewed-on: https://chromium-review.googlesource.com/1193386
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Reviewed-by: default avatarNicholas Verne <nverne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#588283}
parent 33b46183
...@@ -515,6 +515,24 @@ bool CrostiniManager::IsVmRunning(Profile* profile, std::string vm_name) { ...@@ -515,6 +515,24 @@ bool CrostiniManager::IsVmRunning(Profile* profile, std::string vm_name) {
running_vms_.end(); running_vms_.end();
} }
base::Optional<vm_tools::concierge::VmInfo> CrostiniManager::GetVmInfo(
Profile* profile,
std::string vm_name) {
auto it = running_vms_.find(
std::make_pair(CryptohomeIdForProfile(profile), std::move(vm_name)));
if (it != running_vms_.end())
return it->second;
return base::nullopt;
}
void CrostiniManager::AddRunningVmForTesting(
std::string owner_id,
std::string vm_name,
vm_tools::concierge::VmInfo vm_info) {
auto key = std::make_pair(std::move(owner_id), std::move(vm_name));
running_vms_[key] = std::move(vm_info);
}
bool CrostiniManager::IsContainerRunning(Profile* profile, bool CrostiniManager::IsContainerRunning(Profile* profile,
std::string vm_name, std::string vm_name,
std::string container_name) { std::string container_name) {
...@@ -1314,6 +1332,9 @@ void CrostiniManager::OnStartTerminaVm( ...@@ -1314,6 +1332,9 @@ void CrostiniManager::OnStartTerminaVm(
tremplin_started_callbacks_.emplace( tremplin_started_callbacks_.emplace(
std::make_pair(std::move(owner_id), std::move(vm_name)), std::make_pair(std::move(owner_id), std::move(vm_name)),
base::BindOnce(std::move(callback), ConciergeClientResult::SUCCESS)); base::BindOnce(std::move(callback), ConciergeClientResult::SUCCESS));
// Record the running vm.
auto key = std::make_pair(std::move(owner_id), std::move(vm_name));
running_vms_[key] = std::move(response.vm_info());
return; return;
} }
std::move(callback).Run(ConciergeClientResult::SUCCESS); std::move(callback).Run(ConciergeClientResult::SUCCESS);
...@@ -1534,8 +1555,6 @@ void CrostiniManager::OnTremplinStarted( ...@@ -1534,8 +1555,6 @@ void CrostiniManager::OnTremplinStarted(
std::move(it->second).Run(); std::move(it->second).Run();
} }
tremplin_started_callbacks_.erase(range.first, range.second); tremplin_started_callbacks_.erase(range.first, range.second);
// Record the running vm.
running_vms_.emplace(signal.owner_id(), signal.vm_name());
} }
void CrostiniManager::OnLaunchContainerApplication( void CrostiniManager::OnLaunchContainerApplication(
......
...@@ -361,6 +361,12 @@ class CrostiniManager : public chromeos::ConciergeClient::Observer, ...@@ -361,6 +361,12 @@ class CrostiniManager : public chromeos::ConciergeClient::Observer,
static CrostiniManager* GetInstance(); static CrostiniManager* GetInstance();
bool IsVmRunning(Profile* profile, std::string vm_name); bool IsVmRunning(Profile* profile, std::string vm_name);
// Returns null if VM is not running.
base::Optional<vm_tools::concierge::VmInfo> GetVmInfo(Profile* profile,
std::string vm_name);
void AddRunningVmForTesting(std::string owner_id,
std::string vm_name,
vm_tools::concierge::VmInfo vm_info);
bool IsContainerRunning(Profile* profile, bool IsContainerRunning(Profile* profile,
std::string vm_name, std::string vm_name,
std::string container_name); std::string container_name);
...@@ -522,7 +528,8 @@ class CrostiniManager : public chromeos::ConciergeClient::Observer, ...@@ -522,7 +528,8 @@ class CrostiniManager : public chromeos::ConciergeClient::Observer,
tremplin_started_callbacks_; tremplin_started_callbacks_;
// Running vms as <owner_id, vm_name> pairs. // Running vms as <owner_id, vm_name> pairs.
std::set<std::pair<std::string, std::string>> running_vms_; std::map<std::pair<std::string, std::string>, vm_tools::concierge::VmInfo>
running_vms_;
// Running containers as keyed by <owner_id, vm_name> string pairs. // Running containers as keyed by <owner_id, vm_name> string pairs.
std::multimap<std::pair<std::string, std::string>, std::string> std::multimap<std::pair<std::string, std::string>, std::string>
......
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