Commit ba3467b5 authored by Renee Wright's avatar Renee Wright Committed by Commit Bot

Fix crostini value in Storage Settings so it always shows a value

This change fixes a bug where the value for
Settings > Device > Storage Management > Linux (Beta) storage
shows as 0 when the Termina container is not running.

Bug: 888795
Change-Id: I6ab468bc6cca5cdf786e226517ecc25c971061ec
Reviewed-on: https://chromium-review.googlesource.com/c/1260608
Commit-Queue: Renée Wright <rjwright@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597019}
parent 5a4205f3
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/time/default_clock.h" #include "base/time/default_clock.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/crostini/crostini_manager_factory.h" #include "chrome/browser/chromeos/crostini/crostini_manager_factory.h"
#include "chrome/browser/chromeos/crostini/crostini_pref_names.h"
#include "chrome/browser/chromeos/crostini/crostini_remover.h" #include "chrome/browser/chromeos/crostini/crostini_remover.h"
#include "chrome/browser/chromeos/crostini/crostini_reporting_util.h" #include "chrome/browser/chromeos/crostini/crostini_reporting_util.h"
#include "chrome/browser/chromeos/crostini/crostini_share_path.h" #include "chrome/browser/chromeos/crostini/crostini_share_path.h"
...@@ -1190,17 +1191,23 @@ void CrostiniManager::OnListVmDisks( ...@@ -1190,17 +1191,23 @@ void CrostiniManager::OnListVmDisks(
base::Optional<vm_tools::concierge::ListVmDisksResponse> reply) { base::Optional<vm_tools::concierge::ListVmDisksResponse> reply) {
if (!reply.has_value()) { if (!reply.has_value()) {
LOG(ERROR) << "Failed to get list of VM disks. Empty response."; LOG(ERROR) << "Failed to get list of VM disks. Empty response.";
std::move(callback).Run(ConciergeClientResult::LIST_VM_DISKS_FAILED, 0); std::move(callback).Run(
ConciergeClientResult::LIST_VM_DISKS_FAILED,
profile_->GetPrefs()->GetInt64(prefs::kCrostiniLastDiskSize));
return; return;
} }
vm_tools::concierge::ListVmDisksResponse response = std::move(reply).value(); vm_tools::concierge::ListVmDisksResponse response = std::move(reply).value();
if (!response.success()) { if (!response.success()) {
LOG(ERROR) << "Failed to list VM disks: " << response.failure_reason(); LOG(ERROR) << "Failed to list VM disks: " << response.failure_reason();
std::move(callback).Run(ConciergeClientResult::LIST_VM_DISKS_FAILED, 0); std::move(callback).Run(
ConciergeClientResult::LIST_VM_DISKS_FAILED,
profile_->GetPrefs()->GetInt64(prefs::kCrostiniLastDiskSize));
return; return;
} }
profile_->GetPrefs()->SetInt64(prefs::kCrostiniLastDiskSize,
response.total_size());
std::move(callback).Run(ConciergeClientResult::SUCCESS, std::move(callback).Run(ConciergeClientResult::SUCCESS,
response.total_size()); response.total_size());
} }
......
...@@ -28,6 +28,8 @@ const char kCrostiniLastLaunchVersion[] = "crostini.last_launch.version"; ...@@ -28,6 +28,8 @@ const char kCrostiniLastLaunchVersion[] = "crostini.last_launch.version";
// stored as Java time (ms since epoch). // stored as Java time (ms since epoch).
const char kCrostiniLastLaunchTimeWindowStart[] = const char kCrostiniLastLaunchTimeWindowStart[] =
"crostini.last_launch.time_window_start"; "crostini.last_launch.time_window_start";
// The value of the last sample of the disk space used by Crostini.
const char kCrostiniLastDiskSize[] = "crostini.last_disk_size";
void RegisterProfilePrefs(PrefRegistrySimple* registry) { void RegisterProfilePrefs(PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(kCrostiniEnabled, false); registry->RegisterBooleanPref(kCrostiniEnabled, false);
...@@ -38,6 +40,7 @@ void RegisterProfilePrefs(PrefRegistrySimple* registry) { ...@@ -38,6 +40,7 @@ void RegisterProfilePrefs(PrefRegistrySimple* registry) {
false); false);
registry->RegisterStringPref(kCrostiniLastLaunchVersion, std::string()); registry->RegisterStringPref(kCrostiniLastLaunchVersion, std::string());
registry->RegisterInt64Pref(kCrostiniLastLaunchTimeWindowStart, 0u); registry->RegisterInt64Pref(kCrostiniLastLaunchTimeWindowStart, 0u);
registry->RegisterInt64Pref(kCrostiniLastDiskSize, 0u);
registry->RegisterBooleanPref(kUserCrostiniAllowedByPolicy, true); registry->RegisterBooleanPref(kUserCrostiniAllowedByPolicy, true);
} }
......
...@@ -19,6 +19,7 @@ extern const char kUserCrostiniAllowedByPolicy[]; ...@@ -19,6 +19,7 @@ extern const char kUserCrostiniAllowedByPolicy[];
extern const char kReportCrostiniUsageEnabled[]; extern const char kReportCrostiniUsageEnabled[];
extern const char kCrostiniLastLaunchVersion[]; extern const char kCrostiniLastLaunchVersion[];
extern const char kCrostiniLastLaunchTimeWindowStart[]; extern const char kCrostiniLastLaunchTimeWindowStart[];
extern const char kCrostiniLastDiskSize[];
void RegisterProfilePrefs(PrefRegistrySimple* registry); void RegisterProfilePrefs(PrefRegistrySimple* registry);
......
...@@ -98,6 +98,7 @@ void CrostiniRemover::StopConciergeFinished(bool is_successful) { ...@@ -98,6 +98,7 @@ void CrostiniRemover::StopConciergeFinished(bool is_successful) {
if (cros_component_manager) { if (cros_component_manager) {
if (cros_component_manager->Unload("cros-termina")) { if (cros_component_manager->Unload("cros-termina")) {
profile_->GetPrefs()->SetBoolean(prefs::kCrostiniEnabled, false); profile_->GetPrefs()->SetBoolean(prefs::kCrostiniEnabled, false);
profile_->GetPrefs()->ClearPref(prefs::kCrostiniLastDiskSize);
} }
} }
std::move(callback_).Run(ConciergeClientResult::SUCCESS); std::move(callback_).Run(ConciergeClientResult::SUCCESS);
......
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