// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/safe_browsing/cloud_content_scanning/test_binary_upload_service.h"

#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"

namespace safe_browsing {

using ::enterprise_connectors::BinaryUploadRequest;
using ::enterprise_connectors::BinaryUploadService;

TestBinaryUploadService::TestBinaryUploadService() = default;
TestBinaryUploadService::~TestBinaryUploadService() = default;

base::WeakPtr<BinaryUploadService> TestBinaryUploadService::AsWeakPtr() {
  return weak_ptr_factory_.GetWeakPtr();
}

void TestBinaryUploadService::MaybeUploadForDeepScanning(
    std::unique_ptr<BinaryUploadRequest> request) {
  DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
  last_request_ = request->content_analysis_request();
  content::GetUIThreadTaskRunner({})->PostTask(
      FROM_HERE,
      base::BindOnce(&BinaryUploadRequest::FinishRequest, std::move(request),
                     saved_result_, saved_response_));
  was_called_ = true;
}

void TestBinaryUploadService::SetResponse(
    enterprise_connectors::ScanRequestUploadResult result,
    enterprise_connectors::ContentAnalysisResponse response) {
  saved_result_ = result;
  saved_response_ = response;
}

void TestBinaryUploadService::ClearWasCalled() {
  was_called_ = false;
}

}  // namespace safe_browsing
