Commit 376d5802 authored by Nikita Podguzov's avatar Nikita Podguzov Committed by Commit Bot

DLP: Replace base::NoDestructor variables

* For DlpRulesManager the variables are replaced by
base::MakeFixedFlatMap
* For DlpContentManager the variable is replaced by std::array

Bug: 1151356
Change-Id: Ibd38634040743e78178932c4bb368f99af22be72
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2550832Reviewed-by: default avatarAya Elsayed <ayaelattar@chromium.org>
Reviewed-by: default avatarSergey Poromov <poromov@chromium.org>
Commit-Queue: Nikita Podguzov <nikitapodguzov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830163}
parent a9fc978e
...@@ -227,20 +227,22 @@ DlpContentRestrictionSet DlpContentManager::GetRestrictionSetForURL( ...@@ -227,20 +227,22 @@ DlpContentRestrictionSet DlpContentManager::GetRestrictionSetForURL(
return set; return set;
DlpRulesManager* dlp_rules_manager = DlpRulesManager::Get(); DlpRulesManager* dlp_rules_manager = DlpRulesManager::Get();
static const base::NoDestructor<std::vector< const size_t kRestrictionsCount = 5;
std::pair<DlpRulesManager::Restriction, DlpContentRestriction>>> static constexpr std::array<
kRestrictionsList({{DlpRulesManager::Restriction::kScreenshot, std::pair<DlpRulesManager::Restriction, DlpContentRestriction>,
DlpContentRestriction::kScreenshot}, kRestrictionsCount>
{DlpRulesManager::Restriction::kScreenshot, kRestrictionsArray = {{{DlpRulesManager::Restriction::kScreenshot,
DlpContentRestriction::kVideoCapture}, DlpContentRestriction::kScreenshot},
{DlpRulesManager::Restriction::kPrivacyScreen, {DlpRulesManager::Restriction::kScreenshot,
DlpContentRestriction::kPrivacyScreen}, DlpContentRestriction::kVideoCapture},
{DlpRulesManager::Restriction::kPrinting, {DlpRulesManager::Restriction::kPrivacyScreen,
DlpContentRestriction::kPrint}, DlpContentRestriction::kPrivacyScreen},
{DlpRulesManager::Restriction::kScreenShare, {DlpRulesManager::Restriction::kPrinting,
DlpContentRestriction::kScreenShare}}); DlpContentRestriction::kPrint},
{DlpRulesManager::Restriction::kScreenShare,
for (const auto& restriction : *kRestrictionsList) { DlpContentRestriction::kScreenShare}}};
for (const auto& restriction : kRestrictionsArray) {
if (dlp_rules_manager->IsRestricted(url, restriction.first) == if (dlp_rules_manager->IsRestricted(url, restriction.first) ==
DlpRulesManager::Level::kBlock) { DlpRulesManager::Level::kBlock) {
set.SetRestriction(restriction.second); set.SetRestriction(restriction.second);
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
#include <utility> #include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/containers/fixed_flat_map.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/no_destructor.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/policy/dlp/data_transfer_dlp_controller.h" #include "chrome/browser/chromeos/policy/dlp/data_transfer_dlp_controller.h"
...@@ -28,27 +28,26 @@ namespace policy { ...@@ -28,27 +28,26 @@ namespace policy {
namespace dlp { namespace dlp {
const char kClipboardRestriction[] = "CLIPBOARD"; constexpr char kClipboardRestriction[] = "CLIPBOARD";
const char kScreenshotRestriction[] = "SCREENSHOT"; constexpr char kScreenshotRestriction[] = "SCREENSHOT";
const char kPrintingRestriction[] = "PRINTING"; constexpr char kPrintingRestriction[] = "PRINTING";
const char kPrivacyScreenRestriction[] = "PRIVACY_SCREEN"; constexpr char kPrivacyScreenRestriction[] = "PRIVACY_SCREEN";
const char kScreenShareRestriction[] = "SCREEN_SHARE"; constexpr char kScreenShareRestriction[] = "SCREEN_SHARE";
const char kArc[] = "ARC"; constexpr char kArc[] = "ARC";
const char kCrostini[] = "CROSTINI"; constexpr char kCrostini[] = "CROSTINI";
const char kPluginVm[] = "PLUGIN_VM"; constexpr char kPluginVm[] = "PLUGIN_VM";
const char kAllowLevel[] = "ALLOW"; constexpr char kAllowLevel[] = "ALLOW";
const char kBlockLevel[] = "BLOCK"; constexpr char kBlockLevel[] = "BLOCK";
} // namespace dlp } // namespace dlp
namespace { namespace {
DlpRulesManager::Restriction GetClassMapping(const std::string& restriction) { DlpRulesManager::Restriction GetClassMapping(const std::string& restriction) {
static const base::NoDestructor< static constexpr auto kRestrictionsMap =
std::map<std::string, DlpRulesManager::Restriction>> base::MakeFixedFlatMap<base::StringPiece, DlpRulesManager::Restriction>(
kRestrictionsMap(
{{dlp::kClipboardRestriction, {{dlp::kClipboardRestriction,
DlpRulesManager::Restriction::kClipboard}, DlpRulesManager::Restriction::kClipboard},
{dlp::kScreenshotRestriction, {dlp::kScreenshotRestriction,
...@@ -59,40 +58,42 @@ DlpRulesManager::Restriction GetClassMapping(const std::string& restriction) { ...@@ -59,40 +58,42 @@ DlpRulesManager::Restriction GetClassMapping(const std::string& restriction) {
{dlp::kScreenShareRestriction, {dlp::kScreenShareRestriction,
DlpRulesManager::Restriction::kScreenShare}}); DlpRulesManager::Restriction::kScreenShare}});
auto it = kRestrictionsMap->find(restriction); auto* it = kRestrictionsMap.find(restriction);
return (it == kRestrictionsMap->end()) return (it == kRestrictionsMap.end())
? DlpRulesManager::Restriction::kUnknownRestriction ? DlpRulesManager::Restriction::kUnknownRestriction
: it->second; : it->second;
} }
DlpRulesManager::Level GetLevelMapping(const std::string& level) { DlpRulesManager::Level GetLevelMapping(const std::string& level) {
static const base::NoDestructor<std::map<std::string, DlpRulesManager::Level>> static constexpr auto kLevelsMap =
kLevelsMap({{dlp::kAllowLevel, DlpRulesManager::Level::kAllow}, base::MakeFixedFlatMap<base::StringPiece, DlpRulesManager::Level>(
{dlp::kBlockLevel, DlpRulesManager::Level::kBlock}}); {{dlp::kAllowLevel, DlpRulesManager::Level::kAllow},
auto it = kLevelsMap->find(level); {dlp::kBlockLevel, DlpRulesManager::Level::kBlock}});
return (it == kLevelsMap->end()) ? DlpRulesManager::Level::kNotSet auto* it = kLevelsMap.find(level);
: it->second; return (it == kLevelsMap.end()) ? DlpRulesManager::Level::kNotSet
: it->second;
} }
DlpRulesManager::Component GetComponentMapping(const std::string& component) { DlpRulesManager::Component GetComponentMapping(const std::string& component) {
static const base::NoDestructor< static constexpr auto kComponentsMap =
std::map<std::string, DlpRulesManager::Component>> base::MakeFixedFlatMap<base::StringPiece, DlpRulesManager::Component>(
kComponentsMap({{dlp::kArc, DlpRulesManager::Component::kArc}, {{dlp::kArc, DlpRulesManager::Component::kArc},
{dlp::kCrostini, DlpRulesManager::Component::kCrostini}, {dlp::kCrostini, DlpRulesManager::Component::kCrostini},
{dlp::kPluginVm, DlpRulesManager::Component::kPluginVm}}); {dlp::kPluginVm, DlpRulesManager::Component::kPluginVm}});
auto it = kComponentsMap->find(component); auto* it = kComponentsMap.find(component);
return (it == kComponentsMap->end()) return (it == kComponentsMap.end())
? DlpRulesManager::Component::kUnknownComponent ? DlpRulesManager::Component::kUnknownComponent
: it->second; : it->second;
} }
uint8_t GetPriorityMapping(const DlpRulesManager::Level level) { uint8_t GetPriorityMapping(const DlpRulesManager::Level level) {
static const base::NoDestructor<std::map<DlpRulesManager::Level, uint8_t>> static constexpr auto kPrioritiesMap =
kPrioritiesMap({{DlpRulesManager::Level::kNotSet, 0}, base::MakeFixedFlatMap<DlpRulesManager::Level, uint8_t>(
{DlpRulesManager::Level::kBlock, 1}, {{DlpRulesManager::Level::kNotSet, 0},
{DlpRulesManager::Level::kAllow, 2}}); {DlpRulesManager::Level::kBlock, 1},
return kPrioritiesMap->at(level); {DlpRulesManager::Level::kAllow, 2}});
return kPrioritiesMap.at(level);
} }
DlpRulesManager::Level GetMaxLevel(const DlpRulesManager::Level& level_1, DlpRulesManager::Level GetMaxLevel(const DlpRulesManager::Level& level_1,
......
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