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

Add a row for Crostini in Settings>Device>Storage

- Adds row to c/b/r/settings/device_page/storage for Crostini storage.

- Fixes method ordering in device_storage_handler.

Bug: 822499
Change-Id: Ibc0d01c287bf49af639f98803257c05aa66a0d1d
Reviewed-on: https://chromium-review.googlesource.com/1077912
Commit-Queue: Renée Wright <rjwright@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567572}
parent 18d4ec4b
...@@ -3997,6 +3997,9 @@ ...@@ -3997,6 +3997,9 @@
<message name="IDS_SETTINGS_STORAGE_ITEM_ANDROID" desc="In Device Settings > Storage, label for the total size of Android apps and cache."> <message name="IDS_SETTINGS_STORAGE_ITEM_ANDROID" desc="In Device Settings > Storage, label for the total size of Android apps and cache.">
Android storage Android storage
</message> </message>
<message name="IDS_SETTINGS_STORAGE_ITEM_CROSTINI" desc="In Device Settings > Storage, label for the total size of Crostini VMs, apps and cache.">
Linux (Beta) storage
</message>
<message name="IDS_SETTINGS_STORAGE_ITEM_OTHER_USERS" desc="In Device Settings > Storage, label for the total size of other users' data directories."> <message name="IDS_SETTINGS_STORAGE_ITEM_OTHER_USERS" desc="In Device Settings > Storage, label for the total size of other users' data directories.">
Other users Other users
</message> </message>
......
...@@ -145,7 +145,9 @@ ...@@ -145,7 +145,9 @@
<template is="dom-if" if="[[showPage_(pageVisibility.device)]]" restamp> <template is="dom-if" if="[[showPage_(pageVisibility.device)]]" restamp>
<settings-section page-title="$i18n{devicePageTitle}" <settings-section page-title="$i18n{devicePageTitle}"
section="device"> section="device">
<settings-device-page prefs="{{prefs}}"></settings-device-page> <settings-device-page prefs="{{prefs}}"
show-crostini="[[showCrostini]]">
</settings-device-page>
</settings-section> </settings-section>
</template> </template>
</if> </if>
......
...@@ -21,6 +21,8 @@ Polymer({ ...@@ -21,6 +21,8 @@ Polymer({
// <if expr="chromeos"> // <if expr="chromeos">
showAndroidApps: Boolean, showAndroidApps: Boolean,
showCrostini: Boolean,
showMultidevice: Boolean, showMultidevice: Boolean,
havePlayStoreApp: Boolean, havePlayStoreApp: Boolean,
......
...@@ -108,7 +108,9 @@ ...@@ -108,7 +108,9 @@
<settings-subpage <settings-subpage
associated-control="[[$$('#storageRow')]]" associated-control="[[$$('#storageRow')]]"
page-title="$i18n{storageTitle}"> page-title="$i18n{storageTitle}">
<settings-storage></settings-storage> <settings-storage prefs="{{prefs}}"
show-crostini="[[showCrostini]]">
</settings-storage>
</settings-subpage> </settings-subpage>
</template> </template>
<template is="dom-if" route-path="/power" <template is="dom-if" route-path="/power"
......
...@@ -21,6 +21,8 @@ Polymer({ ...@@ -21,6 +21,8 @@ Polymer({
notify: true, notify: true,
}, },
showCrostini: Boolean,
/** /**
* |hasMouse_| and |hasTouchpad_| start undefined so observers don't trigger * |hasMouse_| and |hasTouchpad_| start undefined so observers don't trigger
* until they have been populated. * until they have been populated.
......
...@@ -249,6 +249,20 @@ ...@@ -249,6 +249,20 @@
</paper-icon-button-light> </paper-icon-button-light>
</div> </div>
</template> </template>
<template is="dom-if" if="[[showCrostiniStorage_]]">
<div class="settings-box two-line" on-click="onCrostiniTap_" actionable>
<div class="start">
$i18n{storageItemCrostini}
<div id="crostiniSize" class="secondary">
$i18n{storageSizeComputing}
</div>
</div>
<paper-icon-button-light class="subpage-arrow">
<button aria-label="$i18n{storageItemCrostini}"
aria-describedby="crostiniSize"></button>
</paper-icon-button-light>
</div>
</template>
<template is="dom-if" if="[[!isGuest_]]"> <template is="dom-if" if="[[!isGuest_]]">
<div class="settings-box two-line" on-click="onOtherUsersTap_" actionable> <div class="settings-box two-line" on-click="onOtherUsersTap_" actionable>
<div class="start"> <div class="start">
......
...@@ -49,6 +49,15 @@ Polymer({ ...@@ -49,6 +49,15 @@ Polymer({
value: false, value: false,
}, },
/** @private */
showCrostiniStorage_: {
type: Boolean,
value: false,
},
/** @private */
showCrostini: Boolean,
/** @private */ /** @private */
isGuest_: { isGuest_: {
type: Boolean, type: Boolean,
...@@ -67,6 +76,8 @@ Polymer({ ...@@ -67,6 +76,8 @@ Polymer({
sizeStat_: Object, sizeStat_: Object,
}, },
observers: ['handleCrostiniEnabledChanged_(prefs.crostini.enabled.value)'],
/** /**
* Timer ID for periodic update. * Timer ID for periodic update.
* @private {number} * @private {number}
...@@ -89,6 +100,9 @@ Polymer({ ...@@ -89,6 +100,9 @@ Polymer({
this.addWebUIListener( this.addWebUIListener(
'storage-android-size-changed', 'storage-android-size-changed',
this.handleAndroidSizeChanged_.bind(this)); this.handleAndroidSizeChanged_.bind(this));
this.addWebUIListener(
'storage-crostini-size-changed',
this.handleCrostiniSizeChanged_.bind(this));
if (!this.isGuest_) { if (!this.isGuest_) {
this.addWebUIListener( this.addWebUIListener(
'storage-other-users-size-changed', 'storage-other-users-size-changed',
...@@ -155,6 +169,14 @@ Polymer({ ...@@ -155,6 +169,14 @@ Polymer({
chrome.send('openArcStorage'); chrome.send('openArcStorage');
}, },
/**
* Handler for tapping the "Linux storage" item.
* @private
*/
onCrostiniTap_: function() {
settings.navigateTo(settings.routes.CROSTINI_DETAILS);
},
/** /**
* Handler for tapping the "Other users" item. * Handler for tapping the "Other users" item.
* @private * @private
...@@ -214,6 +236,16 @@ Polymer({ ...@@ -214,6 +236,16 @@ Polymer({
this.$$('#androidSize').textContent = size; this.$$('#androidSize').textContent = size;
}, },
/**
* @param {string} size Formatted string representing the size of Crostini
* storage.
* @private
*/
handleCrostiniSizeChanged_: function(size) {
if (this.showCrostiniStorage_)
this.$$('#crostiniSize').textContent = size;
},
/** /**
* @param {string} size Formatted string representing the size of Other users. * @param {string} size Formatted string representing the size of Other users.
* @private * @private
...@@ -239,6 +271,14 @@ Polymer({ ...@@ -239,6 +271,14 @@ Polymer({
this.androidEnabled_ = enabled; this.androidEnabled_ = enabled;
}, },
/**
* @param {boolean} enabled True if Crostini is enabled.
* @private
*/
handleCrostiniEnabledChanged_: function(enabled) {
this.showCrostiniStorage_ = enabled && this.showCrostini;
},
/** /**
* Starts periodic update for storage usage. * Starts periodic update for storage usage.
* @private * @private
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
#include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
#include "chrome/browser/browsing_data/browsing_data_service_worker_helper.h" #include "chrome/browser/browsing_data/browsing_data_service_worker_helper.h"
#include "chrome/browser/chromeos/arc/arc_util.h" #include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/browser/chromeos/crostini/crostini_manager.h"
#include "chrome/browser/chromeos/crostini/crostini_util.h"
#include "chrome/browser/chromeos/drive/file_system_util.h" #include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/file_manager/path_util.h" #include "chrome/browser/chromeos/file_manager/path_util.h"
#include "chrome/browser/platform_util.h" #include "chrome/browser/platform_util.h"
...@@ -73,6 +75,7 @@ StorageHandler::StorageHandler() ...@@ -73,6 +75,7 @@ StorageHandler::StorageHandler()
updating_drive_cache_size_(false), updating_drive_cache_size_(false),
updating_browsing_data_size_(false), updating_browsing_data_size_(false),
updating_android_size_(false), updating_android_size_(false),
updating_crostini_size_(false),
updating_other_users_size_(false), updating_other_users_size_(false),
weak_ptr_factory_(this) {} weak_ptr_factory_(this) {}
...@@ -108,6 +111,7 @@ void StorageHandler::HandleUpdateStorageInfo(const base::ListValue* args) { ...@@ -108,6 +111,7 @@ void StorageHandler::HandleUpdateStorageInfo(const base::ListValue* args) {
UpdateBrowsingDataSize(); UpdateBrowsingDataSize();
UpdateOtherUsersSize(); UpdateOtherUsersSize();
UpdateAndroidSize(); UpdateAndroidSize();
UpdateCrostiniSize();
} }
void StorageHandler::HandleOpenDownloads( void StorageHandler::HandleOpenDownloads(
...@@ -205,7 +209,7 @@ void StorageHandler::UpdateDriveCacheSize() { ...@@ -205,7 +209,7 @@ void StorageHandler::UpdateDriveCacheSize() {
if (!file_system) if (!file_system)
return; return;
// Shows the item "Offline cache" and start calculating size. // Shows the item "Offline cache" and starts calculating size.
FireWebUIListener("storage-drive-enabled-changed", base::Value(true)); FireWebUIListener("storage-drive-enabled-changed", base::Value(true));
updating_drive_cache_size_ = true; updating_drive_cache_size_ = true;
file_system->CalculateCacheSize(base::Bind( file_system->CalculateCacheSize(base::Bind(
...@@ -288,6 +292,29 @@ void StorageHandler::OnGetBrowsingDataSize(bool is_site_data, int64_t size) { ...@@ -288,6 +292,29 @@ void StorageHandler::OnGetBrowsingDataSize(bool is_site_data, int64_t size) {
} }
} }
void StorageHandler::UpdateCrostiniSize() {
Profile* const profile = Profile::FromWebUI(web_ui());
if (!IsCrostiniEnabled(profile)) {
return;
}
if (updating_crostini_size_)
return;
updating_crostini_size_ = true;
crostini::CrostiniManager::GetInstance()->ListVmDisks(
CryptohomeIdForProfile(profile),
base::BindOnce(&StorageHandler::OnGetCrostiniSize,
weak_ptr_factory_.GetWeakPtr()));
}
void StorageHandler::OnGetCrostiniSize(crostini::ConciergeClientResult result,
int64_t size) {
updating_crostini_size_ = false;
FireWebUIListener("storage-crostini-size-changed",
base::Value(ui::FormatBytes(size)));
}
void StorageHandler::UpdateOtherUsersSize() { void StorageHandler::UpdateOtherUsersSize() {
if (updating_other_users_size_) if (updating_other_users_size_)
return; return;
...@@ -344,8 +371,9 @@ void StorageHandler::UpdateAndroidSize() { ...@@ -344,8 +371,9 @@ void StorageHandler::UpdateAndroidSize() {
return; return;
} }
// Shows the item "Android apps and cache" and start calculating size. // Shows the item "Android apps and cache" and starts calculating size.
FireWebUIListener("storage-android-enabled-changed", base::Value(true)); FireWebUIListener("storage-android-enabled-changed", base::Value(true));
bool success = false; bool success = false;
auto* arc_storage_manager = auto* arc_storage_manager =
arc::ArcStorageManager::GetForBrowserContext(profile); arc::ArcStorageManager::GetForBrowserContext(profile);
...@@ -361,8 +389,7 @@ void StorageHandler::OnGetAndroidSize(bool succeeded, ...@@ -361,8 +389,7 @@ void StorageHandler::OnGetAndroidSize(bool succeeded,
arc::mojom::ApplicationsSizePtr size) { arc::mojom::ApplicationsSizePtr size) {
base::string16 size_string; base::string16 size_string;
if (succeeded) { if (succeeded) {
uint64_t total_bytes = size->total_code_bytes + uint64_t total_bytes = size->total_code_bytes + size->total_data_bytes +
size->total_data_bytes +
size->total_cache_bytes; size->total_cache_bytes;
size_string = ui::FormatBytes(total_bytes); size_string = ui::FormatBytes(total_bytes);
} else { } else {
......
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
#include "components/arc/storage_manager/arc_storage_manager.h" #include "components/arc/storage_manager/arc_storage_manager.h"
#include "components/user_manager/user.h" #include "components/user_manager/user.h"
namespace crostini {
enum class ConciergeClientResult;
} // namespace crostini
namespace chromeos { namespace chromeos {
namespace settings { namespace settings {
...@@ -86,6 +90,13 @@ class StorageHandler : public ::settings::SettingsPageUIHandler { ...@@ -86,6 +90,13 @@ class StorageHandler : public ::settings::SettingsPageUIHandler {
// Callback to update the UI about Android apps and cache. // Callback to update the UI about Android apps and cache.
void OnGetAndroidSize(bool succeeded, arc::mojom::ApplicationsSizePtr size); void OnGetAndroidSize(bool succeeded, arc::mojom::ApplicationsSizePtr size);
// Requests updating the space size used by Crostini VMs and their apps and
// cache.
void UpdateCrostiniSize();
// Callback to update the UI about Crostini VMs and their apps and cache.
void OnGetCrostiniSize(crostini::ConciergeClientResult result, int64_t size);
// Callback called when clearing Drive cache is done. // Callback called when clearing Drive cache is done.
void OnClearDriveCacheDone(bool success); void OnClearDriveCacheDone(bool success);
...@@ -116,6 +127,7 @@ class StorageHandler : public ::settings::SettingsPageUIHandler { ...@@ -116,6 +127,7 @@ class StorageHandler : public ::settings::SettingsPageUIHandler {
bool updating_drive_cache_size_; bool updating_drive_cache_size_;
bool updating_browsing_data_size_; bool updating_browsing_data_size_;
bool updating_android_size_; bool updating_android_size_;
bool updating_crostini_size_;
bool updating_other_users_size_; bool updating_other_users_size_;
base::WeakPtrFactory<StorageHandler> weak_ptr_factory_; base::WeakPtrFactory<StorageHandler> weak_ptr_factory_;
......
...@@ -758,6 +758,7 @@ void AddDeviceStrings(content::WebUIDataSource* html_source) { ...@@ -758,6 +758,7 @@ void AddDeviceStrings(content::WebUIDataSource* html_source) {
{"storageItemDriveCache", IDS_SETTINGS_STORAGE_ITEM_DRIVE_CACHE}, {"storageItemDriveCache", IDS_SETTINGS_STORAGE_ITEM_DRIVE_CACHE},
{"storageItemBrowsingData", IDS_SETTINGS_STORAGE_ITEM_BROWSING_DATA}, {"storageItemBrowsingData", IDS_SETTINGS_STORAGE_ITEM_BROWSING_DATA},
{"storageItemAndroid", IDS_SETTINGS_STORAGE_ITEM_ANDROID}, {"storageItemAndroid", IDS_SETTINGS_STORAGE_ITEM_ANDROID},
{"storageItemCrostini", IDS_SETTINGS_STORAGE_ITEM_CROSTINI},
{"storageItemOtherUsers", IDS_SETTINGS_STORAGE_ITEM_OTHER_USERS}, {"storageItemOtherUsers", IDS_SETTINGS_STORAGE_ITEM_OTHER_USERS},
{"storageSizeComputing", IDS_SETTINGS_STORAGE_SIZE_CALCULATING}, {"storageSizeComputing", IDS_SETTINGS_STORAGE_SIZE_CALCULATING},
{"storageSizeUnknown", IDS_SETTINGS_STORAGE_SIZE_UNKNOWN}, {"storageSizeUnknown", IDS_SETTINGS_STORAGE_SIZE_UNKNOWN},
......
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