Commit 06585181 authored by Christopher Gunadi's avatar Christopher Gunadi Committed by Commit Bot

Add pref watcher to CrostiniRootAccessAllowed

When policy is set on server, background and foreground of
FilesApp will listen to changes in pref and hide/show the
"Install with Linux (Beta)" context menu option

Follow up CL to http://crosreview.com/1712667

Bug: 983997, 983998, 988375
Test: compile
Change-Id: I666cb79e48e876cb222a0dead3e6cf96a5a0a28a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1730907Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Commit-Queue: Christopher Gunadi <chrisgunadi@google.com>
Cr-Commit-Position: refs/heads/master@{#683942}
parent fdd3b55c
...@@ -584,9 +584,19 @@ void EventRouter::ObserveEvents() { ...@@ -584,9 +584,19 @@ void EventRouter::ObserveEvents() {
pref_change_registrar_->Add(prefs::kUse24HourClock, callback); pref_change_registrar_->Add(prefs::kUse24HourClock, callback);
pref_change_registrar_->Add( pref_change_registrar_->Add(
crostini::prefs::kCrostiniEnabled, crostini::prefs::kCrostiniEnabled,
base::BindRepeating(&EventRouter::OnCrostiniEnabledChanged, base::BindRepeating(
weak_factory_.GetWeakPtr(), &EventRouter::OnCrostiniChanged, weak_factory_.GetWeakPtr(),
crostini::kCrostiniDefaultVmName)); crostini::kCrostiniDefaultVmName, crostini::prefs::kCrostiniEnabled,
file_manager_private::CROSTINI_EVENT_TYPE_ENABLE,
file_manager_private::CROSTINI_EVENT_TYPE_DISABLE));
pref_change_registrar_->Add(
crostini::prefs::kUserCrostiniRootAccessAllowedByPolicy,
base::BindRepeating(
&EventRouter::OnCrostiniChanged, weak_factory_.GetWeakPtr(),
crostini::kCrostiniDefaultVmName,
crostini::prefs::kUserCrostiniRootAccessAllowedByPolicy,
file_manager_private::CROSTINI_EVENT_TYPE_ROOT_ACCESS_ALLOW,
file_manager_private::CROSTINI_EVENT_TYPE_ROOT_ACCESS_DISALLOW));
pref_change_registrar_->Add(arc::prefs::kArcEnabled, callback); pref_change_registrar_->Add(arc::prefs::kArcEnabled, callback);
pref_change_registrar_->Add(arc::prefs::kArcHasAccessToRemovableMedia, pref_change_registrar_->Add(arc::prefs::kArcHasAccessToRemovableMedia,
callback); callback);
...@@ -1145,15 +1155,17 @@ void EventRouter::OnUnshare(const std::string& vm_name, ...@@ -1145,15 +1155,17 @@ void EventRouter::OnUnshare(const std::string& vm_name,
} }
} }
void EventRouter::OnCrostiniEnabledChanged(const std::string& vm_name) { void EventRouter::OnCrostiniChanged(
const std::string& vm_name,
const std::string& pref_name,
extensions::api::file_manager_private::CrostiniEventType pref_true,
extensions::api::file_manager_private::CrostiniEventType pref_false) {
for (const auto& extension_id : GetEventListenerExtensionIds( for (const auto& extension_id : GetEventListenerExtensionIds(
profile_, file_manager_private::OnCrostiniChanged::kEventName)) { profile_, file_manager_private::OnCrostiniChanged::kEventName)) {
file_manager_private::CrostiniEvent event; file_manager_private::CrostiniEvent event;
event.vm_name = vm_name; event.vm_name = vm_name;
event.event_type = event.event_type =
profile_->GetPrefs()->GetBoolean(crostini::prefs::kCrostiniEnabled) profile_->GetPrefs()->GetBoolean(pref_name) ? pref_true : pref_false;
? file_manager_private::CROSTINI_EVENT_TYPE_ENABLE
: file_manager_private::CROSTINI_EVENT_TYPE_DISABLE;
DispatchEventToExtension( DispatchEventToExtension(
profile_, extension_id, profile_, extension_id,
extensions::events::FILE_MANAGER_PRIVATE_ON_CROSTINI_CHANGED, extensions::events::FILE_MANAGER_PRIVATE_ON_CROSTINI_CHANGED,
......
...@@ -209,8 +209,12 @@ class EventRouter ...@@ -209,8 +209,12 @@ class EventRouter
const std::string& file_system_name, const std::string& file_system_name,
const std::string& full_path); const std::string& full_path);
// Called when a VM is enabled/disabled. // Called for Crostini events when the specified pref value changes.
void OnCrostiniEnabledChanged(const std::string& vm_name); void OnCrostiniChanged(
const std::string& vm_name,
const std::string& pref_name,
extensions::api::file_manager_private::CrostiniEventType pref_true,
extensions::api::file_manager_private::CrostiniEventType pref_false);
base::Time last_copy_progress_event_; base::Time last_copy_progress_event_;
......
...@@ -229,7 +229,14 @@ enum SourceRestriction { ...@@ -229,7 +229,14 @@ enum SourceRestriction {
native_or_drive_source native_or_drive_source
}; };
enum CrostiniEventType { enable, disable, share, unshare }; enum CrostiniEventType {
enable,
disable,
root_access_allow,
root_access_disallow,
share,
unshare
};
// A file task represents an action that the file manager can perform over the // A file task represents an action that the file manager can perform over the
// currently selected files. See // currently selected files. See
......
...@@ -234,6 +234,8 @@ chrome.fileManagerPrivate.InstallLinuxPackageResponse = { ...@@ -234,6 +234,8 @@ chrome.fileManagerPrivate.InstallLinuxPackageResponse = {
chrome.fileManagerPrivate.CrostiniEventType = { chrome.fileManagerPrivate.CrostiniEventType = {
ENABLE: 'enable', ENABLE: 'enable',
DISABLE: 'disable', DISABLE: 'disable',
ROOT_ACCESS_ALLOW: 'root_access_allow',
ROOT_ACCESS_DISALLOW: 'root_access_disallow',
SHARE: 'share', SHARE: 'share',
UNSHARE: 'unshare', UNSHARE: 'unshare',
}; };
......
...@@ -120,8 +120,6 @@ CrostiniImpl.prototype.isEnabled = function(vmName) { ...@@ -120,8 +120,6 @@ CrostiniImpl.prototype.isEnabled = function(vmName) {
* @param {string} vmName * @param {string} vmName
* @param {boolean} allowed * @param {boolean} allowed
*/ */
// TODO(crbug.com/988375): add dynamic pref change functionality for
// RootAccessAllowed.
CrostiniImpl.prototype.setRootAccessAllowed = function(vmName, allowed) { CrostiniImpl.prototype.setRootAccessAllowed = function(vmName, allowed) {
this.rootAccessAllowed_[vmName] = allowed; this.rootAccessAllowed_[vmName] = allowed;
}; };
...@@ -219,6 +217,12 @@ CrostiniImpl.prototype.onCrostiniChanged_ = function(event) { ...@@ -219,6 +217,12 @@ CrostiniImpl.prototype.onCrostiniChanged_ = function(event) {
case chrome.fileManagerPrivate.CrostiniEventType.DISABLE: case chrome.fileManagerPrivate.CrostiniEventType.DISABLE:
this.setEnabled(event.vmName, false); this.setEnabled(event.vmName, false);
break; break;
case chrome.fileManagerPrivate.CrostiniEventType.ROOT_ACCESS_ALLOW:
this.setRootAccessAllowed(event.vmName, true);
break;
case chrome.fileManagerPrivate.CrostiniEventType.ROOT_ACCESS_DISALLOW:
this.setRootAccessAllowed(event.vmName, false);
break;
case chrome.fileManagerPrivate.CrostiniEventType.SHARE: case chrome.fileManagerPrivate.CrostiniEventType.SHARE:
for (const entry of event.entries) { for (const entry of event.entries) {
this.registerSharedPath(event.vmName, entry); this.registerSharedPath(event.vmName, entry);
......
...@@ -1220,10 +1220,10 @@ class FileManager extends cr.EventTarget { ...@@ -1220,10 +1220,10 @@ class FileManager extends cr.EventTarget {
*/ */
async onCrostiniChanged_(event) { async onCrostiniChanged_(event) {
// The background |this.crostini_| object also listens to all crostini // The background |this.crostini_| object also listens to all crostini
// events including enable/disable and share/unshare. But to ensure we // events including enable/disable, allow/disallow and share/unshare.
// don't have any race conditions between bg and fg, we set enabled status // But to ensure we don't have any race conditions between bg and fg, we
// on it before calling |setupCrostini_| which reads enabled status from it // set enabled status on it before calling |setupCrostini_| which reads
// to determine whether 'Linux files' is shown. // enabled status from it to determine whether 'Linux files' is shown.
switch (event.eventType) { switch (event.eventType) {
case chrome.fileManagerPrivate.CrostiniEventType.ENABLE: case chrome.fileManagerPrivate.CrostiniEventType.ENABLE:
this.crostini_.setEnabled(event.vmName, true); this.crostini_.setEnabled(event.vmName, true);
......
...@@ -19,6 +19,8 @@ chrome.fileManagerPrivate = { ...@@ -19,6 +19,8 @@ chrome.fileManagerPrivate = {
CrostiniEventType: { CrostiniEventType: {
ENABLE: 'enable', ENABLE: 'enable',
DISABLE: 'disable', DISABLE: 'disable',
ROOT_ACCESS_ALLOW: 'root_access_allow',
ROOT_ACCESS_DISALLOW: 'root_access_disallow',
SHARE: 'share', SHARE: 'share',
UNSHARE: 'unshare', UNSHARE: 'unshare',
}, },
......
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