Commit 38ca2d3f authored by Dominique Fauteux-Chapleau's avatar Dominique Fauteux-Chapleau Committed by Commit Bot

Migrate DeepScanningDialogueDelegate to new DM token class.

Migrates RetrieveDMToken calls and class member to use the new
BrowserDMToken class.

Bug: 1020296
Change-Id: Id86d2a41a640d27abf175434faf923b041d764e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1904273
Commit-Queue: Dominique Fauteux-Chapleau <domfc@chromium.org>
Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Reviewed-by: default avatarRoger Tawa <rogerta@chromium.org>
Reviewed-by: default avatarTien Mai <tienmai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713937}
parent 6a5c00fc
......@@ -34,6 +34,8 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/ui_base_types.h"
using BrowserDMToken = policy::BrowserDMTokenStorage::BrowserDMToken;
namespace safe_browsing {
const base::Feature kDeepScanningOfUploads{"SafeBrowsingDeepScanningOfUploads",
......@@ -45,9 +47,15 @@ const base::Feature kDeepScanningOfUploadsUI{
namespace {
std::string* GetDMTokenForTestingStorage() {
static std::string dm_token;
return &dm_token;
const char** GetDMTokenForTestingStorage() {
static const char* dm_token_storage = "";
return &dm_token_storage;
}
BrowserDMToken GetDMTokenForTesting() {
const char* dm_token = *GetDMTokenForTestingStorage();
return dm_token && dm_token[0] ? BrowserDMToken::CreateValidToken(dm_token)
: BrowserDMToken::CreateEmptyToken();
}
// Global pointer of factory function (RepeatingCallback) used to create
......@@ -298,8 +306,8 @@ bool DeepScanningDialogDelegate::IsEnabled(Profile* profile,
if (profile->IsOffTheRecord())
return false;
// If there's no DM token, the upload will fail.
if (GetDMToken().empty())
// If there's no valid DM token, the upload will fail.
if (!GetDMToken().is_valid())
return false;
// See if content compliance checks are needed.
......@@ -473,8 +481,8 @@ void DeepScanningDialogDelegate::FileRequestCallback(
}
// static
std::string DeepScanningDialogDelegate::GetDMToken() {
std::string dm_token = *GetDMTokenForTestingStorage();
BrowserDMToken DeepScanningDialogDelegate::GetDMToken() {
auto dm_token = GetDMTokenForTesting();
#if !defined(OS_CHROMEOS)
// This is not compiled on chromeos because
......@@ -482,9 +490,9 @@ std::string DeepScanningDialogDelegate::GetDMToken() {
// 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() &&
if (dm_token.is_empty() &&
policy::ChromeBrowserCloudManagementController::IsEnabled()) {
dm_token = policy::BrowserDMTokenStorage::Get()->RetrieveDMToken();
dm_token = policy::BrowserDMTokenStorage::Get()->RetrieveBrowserDMToken();
}
#endif
......@@ -550,7 +558,7 @@ void DeepScanningDialogDelegate::PrepareRequest(
request->set_request_malware_scan(std::move(malware_request));
}
request->set_dm_token(GetDMToken());
request->set_dm_token(GetDMToken().value());
}
void DeepScanningDialogDelegate::FillAllResultsWith(bool status) {
......
......@@ -15,6 +15,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
#include "chrome/browser/policy/browser_dm_token_storage.h"
#include "chrome/browser/safe_browsing/download_protection/binary_upload_service.h"
#include "chrome/browser/ui/tab_modal_confirm_dialog.h"
#include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h"
......@@ -190,7 +191,7 @@ class DeepScanningDialogDelegate : public TabModalConfirmDialogDelegate {
class FileSourceRequest;
// Gets the device level DM token to use with deep scans.
static std::string GetDMToken();
static policy::BrowserDMTokenStorage::BrowserDMToken GetDMToken();
// Uploads data for deep scanning. Returns true if uploading is occurring in
// the background and false if there is nothing to do.
......
......@@ -28,16 +28,16 @@ namespace safe_browsing {
namespace {
const char kDmToken[] = "dm_token";
const char kTestUrl[] = "http://example.com";
constexpr char kDmToken[] = "dm_token";
constexpr char kTestUrl[] = "http://example.com";
const char kTestHttpsSchemePatternUrl[] = "https://*";
const char kTestChromeSchemePatternUrl[] = "chrome://*";
const char kTestDevtoolsSchemePatternUrl[] = "devtools://*";
constexpr char kTestHttpsSchemePatternUrl[] = "https://*";
constexpr char kTestChromeSchemePatternUrl[] = "chrome://*";
constexpr char kTestDevtoolsSchemePatternUrl[] = "devtools://*";
const char kTestPathPatternUrl[] = "*/a/specific/path/";
const char kTestPortPatternUrl[] = "*:1234";
const char kTestQueryPatternUrl[] = "*?q=5678";
constexpr char kTestPathPatternUrl[] = "*/a/specific/path/";
constexpr char kTestPortPatternUrl[] = "*:1234";
constexpr char kTestQueryPatternUrl[] = "*?q=5678";
class BaseTest : public testing::Test {
public:
......
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