Commit 39a1cd86 authored by Renee Wright's avatar Renee Wright Committed by Commit Bot

Crostini: only show spinner if container is not running

Change-Id: I0a0dd5bbc6d61b82015827e2a19f526f069412ed
Reviewed-on: https://chromium-review.googlesource.com/1128789
Commit-Queue: Renée Wright <rjwright@chromium.org>
Reviewed-by: default avatarNicholas Verne <nverne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#574124}
parent 41d5b933
......@@ -4,6 +4,7 @@
#include "chrome/browser/chromeos/crostini/crostini_manager.h"
#include <algorithm>
#include <string>
#include <vector>
......@@ -421,6 +422,19 @@ bool CrostiniManager::IsVmRunning(Profile* profile, std::string vm_name) {
running_vms_.end();
}
bool CrostiniManager::IsContainerRunning(Profile* profile,
std::string vm_name,
std::string container_name) {
auto range = running_containers_.equal_range(
std::make_pair(CryptohomeIdForProfile(profile), std::move(vm_name)));
for (auto it = range.first; it != range.second; ++it) {
if (it->second == container_name) {
return true;
}
}
return false;
}
CrostiniManager::CrostiniManager() : weak_ptr_factory_(this) {
// Cicerone/ConciergeClient and its observer_list_ will be destroyed together.
// We add, but don't need to remove the observer. (Doing so would force a
......@@ -977,8 +991,10 @@ void CrostiniManager::OnStopVm(
}
}
// Remove from running_vms_.
running_vms_.erase(std::make_pair(std::move(owner_id), std::move(vm_name)));
auto key = std::make_pair(std::move(owner_id), std::move(vm_name));
running_vms_.erase(key);
// Remove containers from running_containers_
running_containers_.erase(key);
std::move(callback).Run(ConciergeClientResult::SUCCESS);
}
......@@ -1018,6 +1034,9 @@ void CrostiniManager::OnContainerStarted(
std::move(it->second).Run(ConciergeClientResult::SUCCESS);
}
start_container_callbacks_.erase(range.first, range.second);
running_containers_.emplace(
std::make_pair(signal.owner_id(), signal.vm_name()),
signal.container_name());
}
void CrostiniManager::OnContainerStartupFailed(
......
......@@ -278,6 +278,9 @@ class CrostiniManager : public chromeos::ConciergeClient::Observer,
static CrostiniManager* GetInstance();
bool IsVmRunning(Profile* profile, std::string vm_name);
bool IsContainerRunning(Profile* profile,
std::string vm_name,
std::string container_name);
private:
friend struct base::DefaultSingletonTraits<CrostiniManager>;
......@@ -377,6 +380,10 @@ class CrostiniManager : public chromeos::ConciergeClient::Observer,
// Running vms as <owner_id, vm_name> pairs.
std::set<std::pair<std::string, std::string>> running_vms_;
// Running containers as keyed by <owner_id, vm_name> string pairs.
std::multimap<std::pair<std::string, std::string>, std::string>
running_containers_;
// Note: This should remain the last member so it'll be destroyed and
// invalidate its weak pointers before any other members are destroyed.
base::WeakPtrFactory<CrostiniManager> weak_ptr_factory_;
......
......@@ -30,6 +30,7 @@ namespace {
constexpr char kCrostiniAppLaunchHistogram[] = "Crostini.AppLaunch";
constexpr char kCrostiniAppNamePrefix[] = "_crostini_";
constexpr int64_t kDelayBeforeSpinnerMs = 400;
// If true then override IsCrostiniUIAllowedForProfile and related methods to
// turn on Crostini.
......@@ -160,6 +161,20 @@ void LaunchCrostiniApp(Profile* profile,
LaunchCrostiniApp(profile, app_id, display_id, std::vector<std::string>());
}
void AddSpinner(const std::string& app_id,
Profile* profile,
std::string vm_name,
std::string container_name) {
ChromeLauncherController* chrome_controller =
ChromeLauncherController::instance();
if (chrome_controller &&
!crostini::CrostiniManager::GetInstance()->IsContainerRunning(
profile, vm_name, container_name)) {
chrome_controller->GetShelfSpinnerController()->AddSpinnerToShelf(
app_id, std::make_unique<ShelfSpinnerItemController>(app_id));
}
}
void LaunchCrostiniApp(Profile* profile,
const std::string& app_id,
int64_t display_id,
......@@ -211,13 +226,10 @@ void LaunchCrostiniApp(Profile* profile,
// Update the last launched time.
registry_service->AppLaunched(app_id);
// Show a spinner as it may take a while for the app window to appear.
ChromeLauncherController* chrome_controller =
ChromeLauncherController::instance();
DCHECK(chrome_controller);
chrome_controller->GetShelfSpinnerController()->AddSpinnerToShelf(
app_id, std::make_unique<ShelfSpinnerItemController>(app_id));
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&AddSpinner, app_id, profile, vm_name, container_name),
base::TimeDelta::FromMilliseconds(kDelayBeforeSpinnerMs));
crostini_manager->RestartCrostini(
profile, vm_name, container_name,
base::BindOnce(OnCrostiniRestarted, app_id, browser,
......
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