Skip to content

Commit

Permalink
Add DataControlsRule parsing to ChromeDlpRulesManager
Browse files Browse the repository at this point in the history
This CL adds parsing for the "DataControlsRule" policy, and creates
a vectors of `data_control::Rule`s in `ChromeDlpRulesManager`. This CL
is done in preparation of implementing the `ChromeDlpRulesManager`
public methods to work with that new policy, and as such no new tests
are added as existing behavior shouldn't change.

This CL also applies the following refactors to work:
- `DlpRulesManagerImpl::profile_` is moved to `ChromeDlpRulesManager`
- `OnPolicyUpdate` is split into `OnDataControlsRulesUpdate` and
  `OnDataLeakPreventionRulesUpdate` to independently update the two
  DLP policies as they change dynamically.
- The ctor of `DlpRulesManager` is changed to include a Profile ptr
  to pass to `ChromeDlpRulesManager`. Several tests and mocks are
  updated to reflect this.

Bug: b/302340176
Change-Id: I7744e5e64347f832c066be202a22d620c18d5cde
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4935878
Reviewed-by: Sergey Poromov <poromov@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Dominique Fauteux-Chapleau <domfc@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1210494}
  • Loading branch information
dominiquefc authored and Chromium LUCI CQ committed Oct 16, 2023
1 parent 4617b22 commit 1ee7f71
Show file tree
Hide file tree
Showing 28 changed files with 258 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,8 @@ class FileManagerPrivateApiDlpTest : public FileManagerPrivateApiTest {

std::unique_ptr<KeyedService> SetDlpRulesManager(
content::BrowserContext* context) {
auto dlp_rules_manager = std::make_unique<policy::MockDlpRulesManager>();
auto dlp_rules_manager = std::make_unique<policy::MockDlpRulesManager>(
Profile::FromBrowserContext(context));
mock_rules_manager_ = dlp_rules_manager.get();
ON_CALL(*mock_rules_manager_, IsFilesPolicyEnabled)
.WillByDefault(testing::Return(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,8 @@ class AppServiceFileTasksPolicyTest : public AppServiceFileTasksTestEnabled {
std::unique_ptr<KeyedService> SetDlpRulesManager(
content::BrowserContext* context) {
auto dlp_rules_manager =
std::make_unique<testing::NiceMock<policy::MockDlpRulesManager>>();
std::make_unique<testing::NiceMock<policy::MockDlpRulesManager>>(
Profile::FromBrowserContext(context));
rules_manager_ = dlp_rules_manager.get();
return dlp_rules_manager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,8 @@ class CopyOrMoveIOTaskWithDLPTest : public testing::Test {
std::unique_ptr<KeyedService> SetDlpRulesManager(
content::BrowserContext* context) {
auto dlp_rules_manager =
std::make_unique<testing::NiceMock<policy::MockDlpRulesManager>>();
std::make_unique<testing::NiceMock<policy::MockDlpRulesManager>>(
Profile::FromBrowserContext(context));
mock_rules_manager_ = dlp_rules_manager.get();
ON_CALL(*mock_rules_manager_, IsFilesPolicyEnabled)
.WillByDefault(testing::Return(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class DlpFilesAppBrowserTestBase {
std::unique_ptr<KeyedService> SetDlpRulesManager(
content::BrowserContext* context) {
auto dlp_rules_manager =
std::make_unique<testing::NiceMock<policy::MockDlpRulesManager>>();
std::make_unique<testing::NiceMock<policy::MockDlpRulesManager>>(
Profile::FromBrowserContext(context));
mock_rules_manager_ = dlp_rules_manager.get();
ON_CALL(*mock_rules_manager_, IsFilesPolicyEnabled)
.WillByDefault(testing::Return(true));
Expand Down Expand Up @@ -352,7 +353,6 @@ class DlpFilesAppBrowserTestBase {
chromeos::DlpClient::GetFilesSourcesCallback callback) {
std::move(callback).Run(response);
}

};

constexpr char kFileTransferConnectorSettingsForDlp[] = R"(
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/ash/file_manager/file_tasks_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,8 @@ class FileTasksPolicyBrowserTest : public FileTasksBrowserTest {
std::unique_ptr<KeyedService> SetDlpRulesManager(
content::BrowserContext* context) {
auto dlp_rules_manager =
std::make_unique<testing::NiceMock<policy::MockDlpRulesManager>>();
std::make_unique<testing::NiceMock<policy::MockDlpRulesManager>>(
Profile::FromBrowserContext(context));
rules_manager_ = dlp_rules_manager.get();
return dlp_rules_manager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ class RestoreToDestinationIOTaskWithDLPTest
private:
std::unique_ptr<KeyedService> SetDlpRulesManager(
content::BrowserContext* context) {
auto dlp_rules_manager = std::make_unique<policy::MockDlpRulesManager>();
auto dlp_rules_manager = std::make_unique<policy::MockDlpRulesManager>(
Profile::FromBrowserContext(context));
mock_rules_manager_ = dlp_rules_manager.get();
EXPECT_CALL(*mock_rules_manager_, IsFilesPolicyEnabled)
.WillRepeatedly(testing::Return(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ class DlpContentManagerAshBrowserTest : public InProcessBrowserTest {

std::unique_ptr<KeyedService> SetDlpRulesManager(
content::BrowserContext* context) {
auto dlp_rules_manager = std::make_unique<MockDlpRulesManager>();
auto dlp_rules_manager = std::make_unique<MockDlpRulesManager>(
Profile::FromBrowserContext(context));
mock_rules_manager_ = dlp_rules_manager.get();
return dlp_rules_manager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ class DlpContentManagerAshTest : public testing::Test {

std::unique_ptr<KeyedService> SetDlpRulesManager(
content::BrowserContext* context) {
auto dlp_rules_manager = std::make_unique<MockDlpRulesManager>();
auto dlp_rules_manager = std::make_unique<MockDlpRulesManager>(
Profile::FromBrowserContext(context));
mock_rules_manager_ = dlp_rules_manager.get();
return dlp_rules_manager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ class DlpFilesControllerAshBrowserTest : public InProcessBrowserTest {
std::unique_ptr<KeyedService> SetDlpRulesManager(
content::BrowserContext* context) {
auto dlp_rules_manager =
std::make_unique<testing::StrictMock<MockDlpRulesManager>>();
std::make_unique<testing::StrictMock<MockDlpRulesManager>>(
Profile::FromBrowserContext(context));
mock_rules_manager_ = dlp_rules_manager.get();
ON_CALL(*mock_rules_manager_, IsFilesPolicyEnabled)
.WillByDefault(testing::Return(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,8 @@ class IOTaskBrowserTest
std::unique_ptr<KeyedService> SetDlpRulesManager(
content::BrowserContext* context) {
auto dlp_rules_manager =
std::make_unique<testing::NiceMock<policy::MockDlpRulesManager>>();
std::make_unique<testing::NiceMock<policy::MockDlpRulesManager>>(
Profile::FromBrowserContext(context));
mock_rules_manager_ = dlp_rules_manager.get();
ON_CALL(*mock_rules_manager_, IsFilesPolicyEnabled)
.WillByDefault(testing::Return(true));
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/chromeos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ source_set("chromeos") {
"policy/dlp/dlp_policy_constants.h",
"policy/dlp/dlp_reporting_manager.cc",
"policy/dlp/dlp_reporting_manager.h",
"policy/dlp/dlp_rules_manager.cc",
"policy/dlp/dlp_rules_manager.h",
"policy/dlp/dlp_rules_manager_factory.cc",
"policy/dlp/dlp_rules_manager_factory.h",
Expand Down

0 comments on commit 1ee7f71

Please sign in to comment.