Commit 125c51c7 authored by Bailey Berro's avatar Bailey Berro Committed by Commit Bot

Do not start SmbService if disallowed by policy

This change adds a check for the NetworkFileSharesAllowed policy
when starting up SmbService. If the policy is set to false, meaning
that Network File Shares should not be allowed, SmbService will not
be registered with the FSP, removing the entry point from the
"Add new services" menu in the Files App.

Additionally, since the Settings UI picks up policy changes on the fly
but the NetworkFileSharesAllowed policy does not support dynamic
refresh, SmbService respects the state of the policy at login.

Bug: 757625
Test: verified by setting policy locally.
Change-Id: I2d7cc147e51b584255679a00f233750f1b8cb4fe
Reviewed-on: https://chromium-review.googlesource.com/1153488Reviewed-by: default avatarScott Chen <scottchen@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Commit-Queue: Bailey Berro <baileyberro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585192}
parent a11e54f7
......@@ -24,6 +24,7 @@
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/smb_provider_client.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/storage_partition.h"
#include "net/base/network_interfaces.h"
......@@ -54,6 +55,10 @@ std::unique_ptr<NetBiosClientInterface> GetNetBiosClient(Profile* profile) {
return std::make_unique<NetBiosClient>(network_context);
}
bool IsEnabledByFlag() {
return base::FeatureList::IsEnabled(features::kNativeSmb);
}
// Metric recording functions.
void RecordMountResult(SmbMountResult result) {
DCHECK_LE(result, SmbMountResult::kMaxValue);
......@@ -67,9 +72,12 @@ void RecordRemountResult(SmbMountResult result) {
} // namespace
bool SmbService::service_should_run_ = false;
SmbService::SmbService(Profile* profile)
: provider_id_(ProviderId::CreateFromNativeId("smb")), profile_(profile) {
if (base::FeatureList::IsEnabled(features::kNativeSmb)) {
service_should_run_ = IsEnabledByFlag() && IsAllowedByPolicy();
if (service_should_run_) {
StartSetup();
}
}
......@@ -78,7 +86,10 @@ SmbService::~SmbService() {}
// static
SmbService* SmbService::Get(content::BrowserContext* context) {
return SmbServiceFactory::Get(context);
if (service_should_run_) {
return SmbServiceFactory::Get(context);
}
return nullptr;
}
// static
......@@ -326,6 +337,10 @@ void SmbService::SetUpNetBiosHostLocator() {
share_finder_->RegisterHostLocator(std::move(netbios_host_locator));
}
bool SmbService::IsAllowedByPolicy() const {
return profile_->GetPrefs()->GetBoolean(prefs::kNetworkFileSharesAllowed);
}
void SmbService::RecordMountCount() const {
const std::vector<ProvidedFileSystemInfo> file_systems =
GetProviderService()->GetProvidedFileSystemInfoList(provider_id_);
......
......@@ -135,9 +135,13 @@ class SmbService : public KeyedService,
// Set up NetBios host locator.
void SetUpNetBiosHostLocator();
// Whether Network File Shares are allowed to be used. Controlled via policy.
bool IsAllowedByPolicy() const;
// Records metrics on the number of SMB mounts a user has.
void RecordMountCount() const;
static bool service_should_run_;
const ProviderId provider_id_;
Profile* profile_;
std::unique_ptr<TempFileManager> temp_file_manager_;
......
......@@ -20,8 +20,6 @@ namespace {
smb_client::SmbService* GetSmbService(Profile* profile) {
smb_client::SmbService* const service = smb_client::SmbService::Get(profile);
DCHECK(service);
return service;
}
......@@ -62,6 +60,9 @@ void SmbHandler::HandleSmbMount(const base::ListValue* args) {
CHECK(args->GetString(3, &password));
smb_client::SmbService* const service = GetSmbService(profile_);
if (!service) {
return;
}
chromeos::file_system_provider::MountOptions mo;
mo.display_name = mount_name.empty() ? mount_url : mount_name;
......@@ -87,6 +88,9 @@ void SmbHandler::HandleSmbMountResponse(SmbMountResult result) {
void SmbHandler::HandleStartDiscovery(const base::ListValue* args) {
smb_client::SmbService* const service = GetSmbService(profile_);
if (!service) {
return;
}
service->GatherSharesInNetwork(base::BindRepeating(
&SmbHandler::HandleGatherSharesResponse, weak_ptr_factory_.GetWeakPtr()));
......
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