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 @@
#include "base/task/task_traits.h"
#include "chrome/browser/browser_process.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/safe_browsing/download_protection/check_client_download_request.h"
#include "chrome/grit/generated_resources.h"
......@@ -36,6 +37,11 @@ const base::Feature kDeepScanningOfUploadsUI{"DeepScanningOfUploadsUI",
namespace {
std::string* GetDMTokenForTestingStorage() {
static std::string dm_token;
return &dm_token;
}
// Global pointer of factory function (RepeatingCallback) used to create
// instances of DeepScanningDialogDelegate in tests. !is_null() only in tests.
DeepScanningDialogDelegate::Factory* GetFactoryStorage() {
......@@ -215,8 +221,8 @@ bool DeepScanningDialogDelegate::IsEnabled(Profile* profile,
if (!base::FeatureList::IsEnabled(kDeepScanningOfUploads))
return false;
// If there's no DM token, the upload will fail, so we can skip uploading now.
if (policy::BrowserDMTokenStorage::Get()->RetrieveDMToken().empty())
// If there's no DM token, the upload will fail.
if (GetDMToken().empty())
return false;
// See if content compliance checks are needed.
......@@ -309,6 +315,11 @@ void DeepScanningDialogDelegate::SetFactoryForTesting(Factory factory) {
*GetFactoryStorage() = factory;
}
// static
void DeepScanningDialogDelegate::SetDMTokenForTesting(const char* dm_token) {
*GetDMTokenForTestingStorage() = dm_token;
}
DeepScanningDialogDelegate::DeepScanningDialogDelegate(
content::WebContents* web_contents,
Data data,
......@@ -366,6 +377,25 @@ void DeepScanningDialogDelegate::FileRequestCallback(
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() {
if (data_.do_dlp_scan) {
// Create a string data source based on all the text.
......@@ -418,8 +448,7 @@ void DeepScanningDialogDelegate::PrepareRequest(
request->set_request_malware_scan(std::move(malware_request));
}
request->set_dm_token(
policy::BrowserDMTokenStorage::Get()->RetrieveDMToken());
request->set_dm_token(GetDMToken());
}
void DeepScanningDialogDelegate::FillAllResultsWith(bool status) {
......@@ -450,7 +479,8 @@ bool DeepScanningDialogDelegate::CloseTabModalDialog() {
if (!dialog_)
return false;
dialog_->AcceptTabModalDialog();
RunCallback();
dialog_->CancelTabModalDialog();
return true;
}
......
......@@ -144,6 +144,9 @@ class DeepScanningDialogDelegate : public TabModalConfirmDialogDelegate {
// DeepScanningDialogDelegates.
static void SetFactoryForTesting(Factory factory);
// Overrides the DM token used for testing purposes.
static void SetDMTokenForTesting(const char* dm_token);
protected:
DeepScanningDialogDelegate(content::WebContents* web_contents,
Data data,
......@@ -164,6 +167,9 @@ class DeepScanningDialogDelegate : public TabModalConfirmDialogDelegate {
private:
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
// the background and false if there is nothing to do.
bool UploadData();
......
......@@ -10,7 +10,6 @@
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.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_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
......@@ -110,13 +109,10 @@ class BaseTest : public testing::Test {
BaseTest() : profile_manager_(TestingBrowserProcess::GetGlobal()) {
EXPECT_TRUE(profile_manager_.SetUp());
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) {
fake_dm_token_storage_.SetDMToken(dm_token);
DeepScanningDialogDelegate::SetDMTokenForTesting(dm_token);
}
void EnableFeatures(const std::vector<base::Feature>& features) {
......@@ -149,7 +145,6 @@ class BaseTest : public testing::Test {
TestingPrefServiceSimple pref_service_;
TestingProfileManager profile_manager_;
TestingProfile* profile_;
policy::FakeBrowserDMTokenStorage fake_dm_token_storage_;
};
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