Commit 5a5580c7 authored by Roger Tawa's avatar Roger Tawa Committed by Commit Bot

Fix cros support in deep scanning and invocation of callback.

This changes makes sure that the deep scanning code is not invoked in cros
because it does not support CBCM.  However, it makes sure the tests still
run on cros (by getting around CBCM) so that the code does not bit rot.

This change also fixes a small bug in invoking the complete callback that
was introduced when I recfactored some code in the previous commit.

Bug: 999143, 999141
Change-Id: If51a083c22e94c422011fa75c1f3a4edcdc743da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1804503Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Commit-Queue: Roger Tawa <rogerta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#696874}
parent 44b35474
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/task/task_traits.h" #include "base/task/task_traits.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/policy/browser_dm_token_storage.h" #include "chrome/browser/policy/browser_dm_token_storage.h"
#include "chrome/browser/policy/machine_level_user_cloud_policy_controller.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/download_protection/check_client_download_request.h" #include "chrome/browser/safe_browsing/download_protection/check_client_download_request.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
...@@ -36,6 +37,11 @@ const base::Feature kDeepScanningOfUploadsUI{"DeepScanningOfUploadsUI", ...@@ -36,6 +37,11 @@ const base::Feature kDeepScanningOfUploadsUI{"DeepScanningOfUploadsUI",
namespace { namespace {
std::string* GetDMTokenForTestingStorage() {
static std::string dm_token;
return &dm_token;
}
// Global pointer of factory function (RepeatingCallback) used to create // Global pointer of factory function (RepeatingCallback) used to create
// instances of DeepScanningDialogDelegate in tests. !is_null() only in tests. // instances of DeepScanningDialogDelegate in tests. !is_null() only in tests.
DeepScanningDialogDelegate::Factory* GetFactoryStorage() { DeepScanningDialogDelegate::Factory* GetFactoryStorage() {
...@@ -215,8 +221,8 @@ bool DeepScanningDialogDelegate::IsEnabled(Profile* profile, ...@@ -215,8 +221,8 @@ bool DeepScanningDialogDelegate::IsEnabled(Profile* profile,
if (!base::FeatureList::IsEnabled(kDeepScanningOfUploads)) if (!base::FeatureList::IsEnabled(kDeepScanningOfUploads))
return false; return false;
// If there's no DM token, the upload will fail, so we can skip uploading now. // If there's no DM token, the upload will fail.
if (policy::BrowserDMTokenStorage::Get()->RetrieveDMToken().empty()) if (GetDMToken().empty())
return false; return false;
// See if content compliance checks are needed. // See if content compliance checks are needed.
...@@ -309,6 +315,11 @@ void DeepScanningDialogDelegate::SetFactoryForTesting(Factory factory) { ...@@ -309,6 +315,11 @@ void DeepScanningDialogDelegate::SetFactoryForTesting(Factory factory) {
*GetFactoryStorage() = factory; *GetFactoryStorage() = factory;
} }
// static
void DeepScanningDialogDelegate::SetDMTokenForTesting(const char* dm_token) {
*GetDMTokenForTestingStorage() = dm_token;
}
DeepScanningDialogDelegate::DeepScanningDialogDelegate( DeepScanningDialogDelegate::DeepScanningDialogDelegate(
content::WebContents* web_contents, content::WebContents* web_contents,
Data data, Data data,
...@@ -366,6 +377,25 @@ void DeepScanningDialogDelegate::FileRequestCallback( ...@@ -366,6 +377,25 @@ void DeepScanningDialogDelegate::FileRequestCallback(
MaybeCompleteScanRequest(); MaybeCompleteScanRequest();
} }
// static
std::string DeepScanningDialogDelegate::GetDMToken() {
std::string dm_token = *GetDMTokenForTestingStorage();
#if !defined(OS_CHROMEOS)
// This is not compiled on chromeos because
// MachineLevelUserCloudPolicyController does not exist. Also,
// policy::BrowserDMTokenStorage::Get()->RetrieveDMToken() does not return a
// valid token either. Once these are fixed the #if !defined can be removed.
if (dm_token.empty() && policy::MachineLevelUserCloudPolicyController::
IsMachineLevelUserCloudPolicyEnabled()) {
dm_token = policy::BrowserDMTokenStorage::Get()->RetrieveDMToken();
}
#endif
return dm_token;
}
bool DeepScanningDialogDelegate::UploadData() { bool DeepScanningDialogDelegate::UploadData() {
if (data_.do_dlp_scan) { if (data_.do_dlp_scan) {
// Create a string data source based on all the text. // Create a string data source based on all the text.
...@@ -418,8 +448,7 @@ void DeepScanningDialogDelegate::PrepareRequest( ...@@ -418,8 +448,7 @@ void DeepScanningDialogDelegate::PrepareRequest(
request->set_request_malware_scan(std::move(malware_request)); request->set_request_malware_scan(std::move(malware_request));
} }
request->set_dm_token( request->set_dm_token(GetDMToken());
policy::BrowserDMTokenStorage::Get()->RetrieveDMToken());
} }
void DeepScanningDialogDelegate::FillAllResultsWith(bool status) { void DeepScanningDialogDelegate::FillAllResultsWith(bool status) {
...@@ -450,7 +479,8 @@ bool DeepScanningDialogDelegate::CloseTabModalDialog() { ...@@ -450,7 +479,8 @@ bool DeepScanningDialogDelegate::CloseTabModalDialog() {
if (!dialog_) if (!dialog_)
return false; return false;
dialog_->AcceptTabModalDialog(); RunCallback();
dialog_->CancelTabModalDialog();
return true; return true;
} }
......
...@@ -144,6 +144,9 @@ class DeepScanningDialogDelegate : public TabModalConfirmDialogDelegate { ...@@ -144,6 +144,9 @@ class DeepScanningDialogDelegate : public TabModalConfirmDialogDelegate {
// DeepScanningDialogDelegates. // DeepScanningDialogDelegates.
static void SetFactoryForTesting(Factory factory); static void SetFactoryForTesting(Factory factory);
// Overrides the DM token used for testing purposes.
static void SetDMTokenForTesting(const char* dm_token);
protected: protected:
DeepScanningDialogDelegate(content::WebContents* web_contents, DeepScanningDialogDelegate(content::WebContents* web_contents,
Data data, Data data,
...@@ -164,6 +167,9 @@ class DeepScanningDialogDelegate : public TabModalConfirmDialogDelegate { ...@@ -164,6 +167,9 @@ class DeepScanningDialogDelegate : public TabModalConfirmDialogDelegate {
private: private:
class FileSourceRequest; class FileSourceRequest;
// Gets the device level DM token to use with deep scans.
static std::string GetDMToken();
// Uploads data for deep scanning. Returns true if uploading is occurring in // Uploads data for deep scanning. Returns true if uploading is occurring in
// the background and false if there is nothing to do. // the background and false if there is nothing to do.
bool UploadData(); bool UploadData();
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "chrome/browser/policy/fake_browser_dm_token_storage.h"
#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h" #include "chrome/test/base/testing_profile_manager.h"
...@@ -110,13 +109,10 @@ class BaseTest : public testing::Test { ...@@ -110,13 +109,10 @@ class BaseTest : public testing::Test {
BaseTest() : profile_manager_(TestingBrowserProcess::GetGlobal()) { BaseTest() : profile_manager_(TestingBrowserProcess::GetGlobal()) {
EXPECT_TRUE(profile_manager_.SetUp()); EXPECT_TRUE(profile_manager_.SetUp());
profile_ = profile_manager_.CreateTestingProfile("test-user"); profile_ = profile_manager_.CreateTestingProfile("test-user");
// Set a client id, otherwise it is not possible to set a DM token.
fake_dm_token_storage_.SetClientId("client_id");
} }
void SetDMToken(const char* dm_token) { void SetDMToken(const char* dm_token) {
fake_dm_token_storage_.SetDMToken(dm_token); DeepScanningDialogDelegate::SetDMTokenForTesting(dm_token);
} }
void EnableFeatures(const std::vector<base::Feature>& features) { void EnableFeatures(const std::vector<base::Feature>& features) {
...@@ -149,7 +145,6 @@ class BaseTest : public testing::Test { ...@@ -149,7 +145,6 @@ class BaseTest : public testing::Test {
TestingPrefServiceSimple pref_service_; TestingPrefServiceSimple pref_service_;
TestingProfileManager profile_manager_; TestingProfileManager profile_manager_;
TestingProfile* profile_; TestingProfile* profile_;
policy::FakeBrowserDMTokenStorage fake_dm_token_storage_;
}; };
using DeepScanningDialogDelegateIsEnabledTest = BaseTest; using DeepScanningDialogDelegateIsEnabledTest = BaseTest;
......
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