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() {
pref_change_registrar_->Add(prefs::kUse24HourClock, callback);
pref_change_registrar_->Add(
crostini::prefs::kCrostiniEnabled,
base::BindRepeating(&EventRouter::OnCrostiniEnabledChanged,
weak_factory_.GetWeakPtr(),
crostini::kCrostiniDefaultVmName));
base::BindRepeating(
&EventRouter::OnCrostiniChanged, weak_factory_.GetWeakPtr(),
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::kArcHasAccessToRemovableMedia,
callback);
......@@ -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(
profile_, file_manager_private::OnCrostiniChanged::kEventName)) {
file_manager_private::CrostiniEvent event;
event.vm_name = vm_name;
event.event_type =
profile_->GetPrefs()->GetBoolean(crostini::prefs::kCrostiniEnabled)
? file_manager_private::CROSTINI_EVENT_TYPE_ENABLE
: file_manager_private::CROSTINI_EVENT_TYPE_DISABLE;
profile_->GetPrefs()->GetBoolean(pref_name) ? pref_true : pref_false;
DispatchEventToExtension(
profile_, extension_id,
extensions::events::FILE_MANAGER_PRIVATE_ON_CROSTINI_CHANGED,
......
......@@ -209,8 +209,12 @@ class EventRouter
const std::string& file_system_name,
const std::string& full_path);
// Called when a VM is enabled/disabled.
void OnCrostiniEnabledChanged(const std::string& vm_name);
// Called for Crostini events when the specified pref value changes.
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_;
......
......@@ -229,7 +229,14 @@ enum SourceRestriction {
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
// currently selected files. See
......
......@@ -234,6 +234,8 @@ chrome.fileManagerPrivate.InstallLinuxPackageResponse = {
chrome.fileManagerPrivate.CrostiniEventType = {
ENABLE: 'enable',
DISABLE: 'disable',
ROOT_ACCESS_ALLOW: 'root_access_allow',
ROOT_ACCESS_DISALLOW: 'root_access_disallow',
SHARE: 'share',
UNSHARE: 'unshare',
};
......
......@@ -120,8 +120,6 @@ CrostiniImpl.prototype.isEnabled = function(vmName) {
* @param {string} vmName
* @param {boolean} allowed
*/
// TODO(crbug.com/988375): add dynamic pref change functionality for
// RootAccessAllowed.
CrostiniImpl.prototype.setRootAccessAllowed = function(vmName, allowed) {
this.rootAccessAllowed_[vmName] = allowed;
};
......@@ -219,6 +217,12 @@ CrostiniImpl.prototype.onCrostiniChanged_ = function(event) {
case chrome.fileManagerPrivate.CrostiniEventType.DISABLE:
this.setEnabled(event.vmName, false);
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:
for (const entry of event.entries) {
this.registerSharedPath(event.vmName, entry);
......
......@@ -1220,10 +1220,10 @@ class FileManager extends cr.EventTarget {
*/
async onCrostiniChanged_(event) {
// The background |this.crostini_| object also listens to all crostini
// events including enable/disable and share/unshare. But to ensure we
// don't have any race conditions between bg and fg, we set enabled status
// on it before calling |setupCrostini_| which reads enabled status from it
// to determine whether 'Linux files' is shown.
// events including enable/disable, allow/disallow and share/unshare.
// But to ensure we don't have any race conditions between bg and fg, we
// set enabled status on it before calling |setupCrostini_| which reads
// enabled status from it to determine whether 'Linux files' is shown.
switch (event.eventType) {
case chrome.fileManagerPrivate.CrostiniEventType.ENABLE:
this.crostini_.setEnabled(event.vmName, true);
......
......@@ -19,6 +19,8 @@ chrome.fileManagerPrivate = {
CrostiniEventType: {
ENABLE: 'enable',
DISABLE: 'disable',
ROOT_ACCESS_ALLOW: 'root_access_allow',
ROOT_ACCESS_DISALLOW: 'root_access_disallow',
SHARE: 'share',
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