Commit 65679d03 authored by Daniel Rubery's avatar Daniel Rubery Committed by Commit Bot

Make BinaryUploadService return asynchronously

If the BinaryFCMService does not exist, the BinaryUploadService will
return synchronously. This leads to confusing behavior, since the
code was written with the expectation that this was an
asynchronous operation.

Bug: 1015757
Change-Id: I086529a18a2e2c97a4a6545dee89eecb51fe9dbc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1873152
Commit-Queue: Daniel Rubery <drubery@chromium.org>
Reviewed-by: default avatarVarun Khaneja <vakh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708354}
parent e893b9c4
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/safe_browsing/common/safe_browsing_prefs.h" #include "components/safe_browsing/common/safe_browsing_prefs.h"
#include "components/safe_browsing/proto/webprotect.pb.h" #include "components/safe_browsing/proto/webprotect.pb.h"
#include "content/public/browser/browser_task_traits.h"
#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"
...@@ -56,8 +57,11 @@ void BinaryUploadService::UploadForDeepScanning( ...@@ -56,8 +57,11 @@ void BinaryUploadService::UploadForDeepScanning(
active_requests_[raw_request] = std::move(request); active_requests_[raw_request] = std::move(request);
if (!binary_fcm_service_) { if (!binary_fcm_service_) {
FinishRequest(raw_request, Result::FAILED_TO_GET_TOKEN, base::PostTask(FROM_HERE, {content::BrowserThread::UI},
DeepScanningClientResponse()); base::BindOnce(&BinaryUploadService::FinishRequest,
weakptr_factory_.GetWeakPtr(), raw_request,
Result::FAILED_TO_GET_TOKEN,
DeepScanningClientResponse()));
return; return;
} }
......
...@@ -359,4 +359,26 @@ TEST_F(BinaryUploadServiceTest, OnGetSynchronousResponse) { ...@@ -359,4 +359,26 @@ TEST_F(BinaryUploadServiceTest, OnGetSynchronousResponse) {
EXPECT_EQ(scanning_result, BinaryUploadService::Result::SUCCESS); EXPECT_EQ(scanning_result, BinaryUploadService::Result::SUCCESS);
} }
TEST_F(BinaryUploadServiceTest, ReturnsAsynchronouslyWithNoFCM) {
// Instantiate a BinaryUploadService with no FCM connection.
BinaryUploadService service(nullptr,
std::unique_ptr<BinaryFCMService>(nullptr));
BinaryUploadService::Result scanning_result =
BinaryUploadService::Result::UNKNOWN;
DeepScanningClientResponse scanning_response;
std::unique_ptr<MockRequest> request =
MakeRequest(&scanning_result, &scanning_response);
request->set_request_dlp_scan(DlpDeepScanningClientRequest());
request->set_request_malware_scan(MalwareDeepScanningClientRequest());
service.UploadForDeepScanning(std::move(request));
EXPECT_EQ(scanning_result, BinaryUploadService::Result::UNKNOWN);
content::RunAllTasksUntilIdle();
EXPECT_EQ(scanning_result, BinaryUploadService::Result::FAILED_TO_GET_TOKEN);
}
} // namespace safe_browsing } // namespace safe_browsing
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