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

Migrate download_protection code to new DM token class.

Migrates RetrieveDMToken calls to use the new BrowserDMToken class.

Bug: 1020296
Change-Id: Icef580e243430d73b6c1c42b273a8540277481d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1904234
Commit-Queue: Dominique Fauteux-Chapleau <domfc@chromium.org>
Reviewed-by: default avatarTien Mai <tienmai@chromium.org>
Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714196}
parent fa9f018e
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "net/http/http_status_code.h" #include "net/http/http_status_code.h"
using BrowserDMToken = policy::BrowserDMTokenStorage::BrowserDMToken;
namespace safe_browsing { namespace safe_browsing {
namespace { namespace {
...@@ -38,13 +40,19 @@ const int kScanningTimeoutSeconds = 5 * 60; // 5 minutes ...@@ -38,13 +40,19 @@ const int kScanningTimeoutSeconds = 5 * 60; // 5 minutes
// here. // here.
const char kSbBinaryUploadUrl[] = ""; const char kSbBinaryUploadUrl[] = "";
std::string* GetTestingDMToken() { const char** GetTestingDMTokenStorage() {
static std::string dm_token; static const char* dm_token = "";
return &dm_token; return &dm_token;
} }
std::string GetDMToken() { BrowserDMToken GetTestingDMToken() {
std::string dm_token = *GetTestingDMToken(); const char* dm_token = *GetTestingDMTokenStorage();
return dm_token && dm_token[0] ? BrowserDMToken::CreateValidToken(dm_token)
: BrowserDMToken::CreateEmptyToken();
}
policy::BrowserDMTokenStorage::BrowserDMToken GetDMToken() {
auto dm_token = GetTestingDMToken();
#if !defined(OS_CHROMEOS) #if !defined(OS_CHROMEOS)
// This is not compiled on chromeos because // This is not compiled on chromeos because
...@@ -52,9 +60,9 @@ std::string GetDMToken() { ...@@ -52,9 +60,9 @@ std::string GetDMToken() {
// policy::BrowserDMTokenStorage::Get()->RetrieveDMToken() does not return a // policy::BrowserDMTokenStorage::Get()->RetrieveDMToken() does not return a
// valid token either. Once these are fixed the #if !defined can be removed. // 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()) { policy::ChromeBrowserCloudManagementController::IsEnabled()) {
dm_token = policy::BrowserDMTokenStorage::Get()->RetrieveDMToken(); dm_token = policy::BrowserDMTokenStorage::Get()->RetrieveBrowserDMToken();
} }
#endif #endif
...@@ -412,8 +420,8 @@ void BinaryUploadService::IsAuthorized(AuthorizationCallback callback) { ...@@ -412,8 +420,8 @@ void BinaryUploadService::IsAuthorized(AuthorizationCallback callback) {
if (!can_upload_data_.has_value()) { if (!can_upload_data_.has_value()) {
// Send a request to check if the browser can upload data. // Send a request to check if the browser can upload data.
if (!pending_validate_data_upload_request_) { if (!pending_validate_data_upload_request_) {
std::string dm_token = GetDMToken(); auto dm_token = GetDMToken();
if (dm_token.empty()) { if (!dm_token.is_valid()) {
std::move(callback).Run(false); std::move(callback).Run(false);
return; return;
} }
...@@ -422,7 +430,7 @@ void BinaryUploadService::IsAuthorized(AuthorizationCallback callback) { ...@@ -422,7 +430,7 @@ void BinaryUploadService::IsAuthorized(AuthorizationCallback callback) {
auto request = std::make_unique<ValidateDataUploadRequest>(base::BindOnce( auto request = std::make_unique<ValidateDataUploadRequest>(base::BindOnce(
&BinaryUploadService::ValidateDataUploadRequestCallback, &BinaryUploadService::ValidateDataUploadRequestCallback,
weakptr_factory_.GetWeakPtr())); weakptr_factory_.GetWeakPtr()));
request->set_dm_token(dm_token); request->set_dm_token(dm_token.value());
UploadForDeepScanning(std::move(request)); UploadForDeepScanning(std::move(request));
} }
authorization_callbacks_.push_back(std::move(callback)); authorization_callbacks_.push_back(std::move(callback));
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
namespace safe_browsing { namespace safe_browsing {
using content::BrowserThread; using content::BrowserThread;
using policy::BrowserDMTokenStorage;
namespace { namespace {
...@@ -359,8 +360,9 @@ void CheckClientDownloadRequest::UploadBinary( ...@@ -359,8 +360,9 @@ void CheckClientDownloadRequest::UploadBinary(
request->set_request_malware_scan(std::move(malware_request)); request->set_request_malware_scan(std::move(malware_request));
} }
request->set_dm_token( auto dm_token = BrowserDMTokenStorage::Get()->RetrieveBrowserDMToken();
policy::BrowserDMTokenStorage::Get()->RetrieveDMToken()); DCHECK(dm_token.is_valid());
request->set_dm_token(dm_token.value());
service()->UploadForDeepScanning(profile, std::move(request)); service()->UploadForDeepScanning(profile, std::move(request));
} }
...@@ -389,8 +391,9 @@ bool CheckClientDownloadRequest::ShouldUploadForDlpScan() { ...@@ -389,8 +391,9 @@ bool CheckClientDownloadRequest::ShouldUploadForDlpScan() {
CheckContentComplianceValues::CHECK_UPLOADS_AND_DOWNLOADS) CheckContentComplianceValues::CHECK_UPLOADS_AND_DOWNLOADS)
return false; return false;
// If there's no DM token, the upload will fail, so we can skip uploading now. // If there's no valid DM token, the upload will fail, so we can skip
if (policy::BrowserDMTokenStorage::Get()->RetrieveDMToken().empty()) // uploading now.
if (!BrowserDMTokenStorage::Get()->RetrieveBrowserDMToken().is_valid())
return false; return false;
const base::ListValue* domains = g_browser_process->local_state()->GetList( const base::ListValue* domains = g_browser_process->local_state()->GetList(
...@@ -428,8 +431,9 @@ bool CheckClientDownloadRequest::ShouldUploadForMalwareScan( ...@@ -428,8 +431,9 @@ bool CheckClientDownloadRequest::ShouldUploadForMalwareScan(
SendFilesForMalwareCheckValues::SEND_UPLOADS_AND_DOWNLOADS) SendFilesForMalwareCheckValues::SEND_UPLOADS_AND_DOWNLOADS)
return false; return false;
// If there's no DM token, the upload will fail, so we can skip uploading now. // If there's no valid DM token, the upload will fail, so we can skip
return !policy::BrowserDMTokenStorage::Get()->RetrieveDMToken().empty(); // uploading now.
return BrowserDMTokenStorage::Get()->RetrieveBrowserDMToken().is_valid();
} }
void CheckClientDownloadRequest::OnDeepScanningComplete( void CheckClientDownloadRequest::OnDeepScanningComplete(
......
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