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

Remove legacy protos support from BinaryUploadService

This should not change deep scanning behaviour with Connectors.

Bug: 1103390
Change-Id: I8f45972d7649eae31d7c3e9024f925c059ad68d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2427427Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Commit-Queue: Dominique Fauteux-Chapleau <domfc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810833}
parent e7c7018d
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include "components/enterprise/common/proto/connectors.pb.h" #include "components/enterprise/common/proto/connectors.pb.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "components/safe_browsing/core/proto/csd.pb.h" #include "components/safe_browsing/core/proto/csd.pb.h"
#include "components/safe_browsing/core/proto/webprotect.pb.h"
#include "services/network/public/cpp/shared_url_loader_factory.h" #include "services/network/public/cpp/shared_url_loader_factory.h"
class Profile; class Profile;
...@@ -97,7 +96,6 @@ class BinaryUploadService : public KeyedService { ...@@ -97,7 +96,6 @@ class BinaryUploadService : public KeyedService {
class Request { class Request {
public: public:
// |callback| will run on the UI thread. // |callback| will run on the UI thread.
Request(Callback callback, GURL url);
Request(ContentAnalysisCallback, GURL url); Request(ContentAnalysisCallback, GURL url);
virtual ~Request(); virtual ~Request();
Request(const Request&) = delete; Request(const Request&) = delete;
...@@ -132,11 +130,6 @@ class BinaryUploadService : public KeyedService { ...@@ -132,11 +130,6 @@ class BinaryUploadService : public KeyedService {
using DataCallback = base::OnceCallback<void(Result, const Data&)>; using DataCallback = base::OnceCallback<void(Result, const Data&)>;
virtual void GetRequestData(DataCallback callback) = 0; virtual void GetRequestData(DataCallback callback) = 0;
// Returns the metadata to upload, as a DeepScanningClientRequest.
const DeepScanningClientRequest& deep_scanning_request() const {
return deep_scanning_request_;
}
// Returns the URL to send the request to. // Returns the URL to send the request to.
GURL GetUrlWithParams() const; GURL GetUrlWithParams() const;
...@@ -146,17 +139,9 @@ class BinaryUploadService : public KeyedService { ...@@ -146,17 +139,9 @@ class BinaryUploadService : public KeyedService {
return content_analysis_request_; return content_analysis_request_;
} }
bool use_legacy_proto() const { return use_legacy_proto_; }
void set_tab_url(const GURL& tab_url); void set_tab_url(const GURL& tab_url);
const GURL& tab_url() const; const GURL& tab_url() const;
// Methods for modifying the DeepScanningClientRequest.
void set_request_dlp_scan(DlpDeepScanningClientRequest dlp_request);
void set_request_malware_scan(
MalwareDeepScanningClientRequest malware_request);
void set_request_token(const std::string& token);
// Methods for modifying the ContentAnalysisRequest. // Methods for modifying the ContentAnalysisRequest.
void set_analysis_connector( void set_analysis_connector(
enterprise_connectors::AnalysisConnector connector); enterprise_connectors::AnalysisConnector connector);
...@@ -164,15 +149,14 @@ class BinaryUploadService : public KeyedService { ...@@ -164,15 +149,14 @@ class BinaryUploadService : public KeyedService {
void set_csd(ClientDownloadRequest csd); void set_csd(ClientDownloadRequest csd);
void add_tag(const std::string& tag); void add_tag(const std::string& tag);
void set_email(const std::string& email); void set_email(const std::string& email);
void set_request_token(const std::string& token);
// Methods for modifying either internal proto requests.
void set_fcm_token(const std::string& token); void set_fcm_token(const std::string& token);
void set_device_token(const std::string& token); void set_device_token(const std::string& token);
void set_filename(const std::string& filename); void set_filename(const std::string& filename);
void set_digest(const std::string& digest); void set_digest(const std::string& digest);
void clear_dlp_scan_request(); void clear_dlp_scan_request();
// Methods for accessing either internal proto requests. // Methods for accessing the ContentAnalysisRequest.
const std::string& device_token() const; const std::string& device_token() const;
const std::string& request_token() const; const std::string& request_token() const;
const std::string& fcm_notification_token() const; const std::string& fcm_notification_token() const;
...@@ -181,26 +165,19 @@ class BinaryUploadService : public KeyedService { ...@@ -181,26 +165,19 @@ class BinaryUploadService : public KeyedService {
// Finish the request, with the given |result| and |response| from the // Finish the request, with the given |result| and |response| from the
// server. // server.
void FinishRequest(Result result); void FinishRequest(Result result,
void FinishConnectorRequest( enterprise_connectors::ContentAnalysisResponse response);
Result result,
enterprise_connectors::ContentAnalysisResponse response);
void FinishLegacyRequest(Result result,
DeepScanningClientResponse response);
// Calls SerializeToString on the appropriate proto request. // Calls SerializeToString on the appropriate proto request.
void SerializeToString(std::string* destination) const; void SerializeToString(std::string* destination) const;
private: private:
const bool use_legacy_proto_;
DeepScanningClientRequest deep_scanning_request_;
Callback callback_;
enterprise_connectors::ContentAnalysisRequest content_analysis_request_; enterprise_connectors::ContentAnalysisRequest content_analysis_request_;
ContentAnalysisCallback content_analysis_callback_; ContentAnalysisCallback content_analysis_callback_;
// The URL to send the data to for scanning.
GURL url_; GURL url_;
// The URL of the page that initially triggered the scan. // The URL of the page that initially triggered the scan.
GURL tab_url_; GURL tab_url_;
}; };
...@@ -230,14 +207,9 @@ class BinaryUploadService : public KeyedService { ...@@ -230,14 +207,9 @@ class BinaryUploadService : public KeyedService {
static GURL GetUploadUrl(bool is_advanced_protection_request); static GURL GetUploadUrl(bool is_advanced_protection_request);
protected: protected:
void FinishRequest(Request* request, Result result); void FinishRequest(Request* request,
void FinishConnectorRequest( Result result,
Request* request, enterprise_connectors::ContentAnalysisResponse response);
Result result,
enterprise_connectors::ContentAnalysisResponse response);
void FinishLegacyRequest(Request* request,
Result result,
DeepScanningClientResponse response);
private: private:
friend class BinaryUploadServiceTest; friend class BinaryUploadServiceTest;
...@@ -257,14 +229,10 @@ class BinaryUploadService : public KeyedService { ...@@ -257,14 +229,10 @@ class BinaryUploadService : public KeyedService {
bool success, bool success,
const std::string& response_data); const std::string& response_data);
void OnGetConnectorResponse( void OnGetResponse(Request* request,
Request* request, enterprise_connectors::ContentAnalysisResponse response);
enterprise_connectors::ContentAnalysisResponse response);
void OnGetLegacyResponse(Request* request,
DeepScanningClientResponse response);
void MaybeFinishConnectorRequest(Request* request); void MaybeFinishRequest(Request* request);
void MaybeFinishLegacyRequest(Request* request);
void OnTimeout(Request* request); void OnTimeout(Request* request);
...@@ -292,7 +260,7 @@ class BinaryUploadService : public KeyedService { ...@@ -292,7 +260,7 @@ class BinaryUploadService : public KeyedService {
Result result, Result result,
const DeepScanningClientResponse& response); const DeepScanningClientResponse& response);
// Called at the end of either Finish{Connector|Legacy}Request methods. // Called at the end of the FinishRequest method.
void FinishRequestCleanup(Request* request, const std::string& instance_id); void FinishRequestCleanup(Request* request, const std::string& instance_id);
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_; scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
......
...@@ -71,9 +71,6 @@ DeepScanningDialogDelegate::Factory* GetFactoryStorage() { ...@@ -71,9 +71,6 @@ DeepScanningDialogDelegate::Factory* GetFactoryStorage() {
// from a string. // from a string.
class StringSourceRequest : public BinaryUploadService::Request { class StringSourceRequest : public BinaryUploadService::Request {
public: public:
StringSourceRequest(GURL analysis_url,
std::string text,
BinaryUploadService::Callback callback);
StringSourceRequest(GURL analysis_url, StringSourceRequest(GURL analysis_url,
std::string text, std::string text,
BinaryUploadService::ContentAnalysisCallback callback); BinaryUploadService::ContentAnalysisCallback callback);
...@@ -91,17 +88,6 @@ class StringSourceRequest : public BinaryUploadService::Request { ...@@ -91,17 +88,6 @@ class StringSourceRequest : public BinaryUploadService::Request {
BinaryUploadService::Result::FILE_TOO_LARGE; BinaryUploadService::Result::FILE_TOO_LARGE;
}; };
StringSourceRequest::StringSourceRequest(GURL analysis_url,
std::string text,
BinaryUploadService::Callback callback)
: Request(std::move(callback), analysis_url) {
// Only remember strings less than the maximum allowed.
if (text.size() < BinaryUploadService::kMaxUploadSizeBytes) {
data_.contents = std::move(text);
result_ = BinaryUploadService::Result::SUCCESS;
}
}
StringSourceRequest::StringSourceRequest( StringSourceRequest::StringSourceRequest(
GURL analysis_url, GURL analysis_url,
std::string text, std::string text,
...@@ -632,7 +618,8 @@ void DeepScanningDialogDelegate::OnGotFileInfo( ...@@ -632,7 +618,8 @@ void DeepScanningDialogDelegate::OnGotFileInfo(
// property (too large, unsupported file type, encrypted, ...) that make its // property (too large, unsupported file type, encrypted, ...) that make its
// upload pointless, so the request should finish early. // upload pointless, so the request should finish early.
if (result != BinaryUploadService::Result::SUCCESS) { if (result != BinaryUploadService::Result::SUCCESS) {
request->FinishRequest(result); request->FinishRequest(result,
enterprise_connectors::ContentAnalysisResponse());
return; return;
} }
......
...@@ -52,7 +52,8 @@ class FakeBinaryUploadService : public BinaryUploadService { ...@@ -52,7 +52,8 @@ class FakeBinaryUploadService : public BinaryUploadService {
// Finish the authentication request. Called after ShowForWebContents to // Finish the authentication request. Called after ShowForWebContents to
// simulate an async callback. // simulate an async callback.
void ReturnAuthorizedResponse() { void ReturnAuthorizedResponse() {
FinishRequest(authorization_request_.get(), authorization_result_); FinishRequest(authorization_request_.get(), authorization_result_,
enterprise_connectors::ContentAnalysisResponse());
} }
void SetResponseForText( void SetResponseForText(
...@@ -87,13 +88,12 @@ class FakeBinaryUploadService : public BinaryUploadService { ...@@ -87,13 +88,12 @@ class FakeBinaryUploadService : public BinaryUploadService {
} else { } else {
std::string file = request->filename(); std::string file = request->filename();
if (file.empty()) { if (file.empty()) {
request->FinishConnectorRequest(prepared_text_result_, request->FinishRequest(prepared_text_result_, prepared_text_response_);
prepared_text_response_);
} else { } else {
ASSERT_TRUE(prepared_file_results_.count(file)); ASSERT_TRUE(prepared_file_results_.count(file));
ASSERT_TRUE(prepared_file_responses_.count(file)); ASSERT_TRUE(prepared_file_responses_.count(file));
request->FinishConnectorRequest(prepared_file_results_[file], request->FinishRequest(prepared_file_results_[file],
prepared_file_responses_[file]); prepared_file_responses_[file]);
} }
} }
} }
......
...@@ -18,17 +18,9 @@ TestBinaryUploadService::TestBinaryUploadService() ...@@ -18,17 +18,9 @@ TestBinaryUploadService::TestBinaryUploadService()
void TestBinaryUploadService::MaybeUploadForDeepScanning( void TestBinaryUploadService::MaybeUploadForDeepScanning(
std::unique_ptr<Request> request) { std::unique_ptr<Request> request) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (request->use_legacy_proto()) { content::GetUIThreadTaskRunner({})->PostTask(
content::GetUIThreadTaskRunner({})->PostTask( FROM_HERE, base::BindOnce(&Request::FinishRequest, std::move(request),
FROM_HERE, saved_result_, saved_response_));
base::BindOnce(&Request::FinishLegacyRequest, std::move(request),
saved_result_, saved_response_));
} else {
content::GetUIThreadTaskRunner({})->PostTask(
FROM_HERE,
base::BindOnce(&Request::FinishConnectorRequest, std::move(request),
saved_result_, saved_content_analysis_response_));
}
was_called_ = true; was_called_ = true;
} }
...@@ -36,12 +28,6 @@ void TestBinaryUploadService::SetResponse( ...@@ -36,12 +28,6 @@ void TestBinaryUploadService::SetResponse(
Result result, Result result,
enterprise_connectors::ContentAnalysisResponse response) { enterprise_connectors::ContentAnalysisResponse response) {
saved_result_ = result; saved_result_ = result;
saved_content_analysis_response_ = response;
}
void TestBinaryUploadService::SetResponse(Result result,
DeepScanningClientResponse response) {
saved_result_ = result;
saved_response_ = response; saved_response_ = response;
} }
......
...@@ -21,16 +21,13 @@ class TestBinaryUploadService : public BinaryUploadService { ...@@ -21,16 +21,13 @@ class TestBinaryUploadService : public BinaryUploadService {
void MaybeUploadForDeepScanning(std::unique_ptr<Request> request) override; void MaybeUploadForDeepScanning(std::unique_ptr<Request> request) override;
void SetResponse(Result result, void SetResponse(Result result,
enterprise_connectors::ContentAnalysisResponse response); enterprise_connectors::ContentAnalysisResponse response);
void SetResponse(Result result, DeepScanningClientResponse response);
bool was_called() { return was_called_; } bool was_called() { return was_called_; }
void ClearWasCalled(); void ClearWasCalled();
private: private:
Result saved_result_ = Result::UNKNOWN; Result saved_result_ = Result::UNKNOWN;
DeepScanningClientResponse saved_response_ = DeepScanningClientResponse(); enterprise_connectors::ContentAnalysisResponse saved_response_;
enterprise_connectors::ContentAnalysisResponse
saved_content_analysis_response_;
bool was_called_ = false; bool was_called_ = false;
}; };
......
...@@ -68,7 +68,7 @@ class FakeBinaryUploadService : public BinaryUploadService { ...@@ -68,7 +68,7 @@ class FakeBinaryUploadService : public BinaryUploadService {
void MaybeUploadForDeepScanning(std::unique_ptr<Request> request) override { void MaybeUploadForDeepScanning(std::unique_ptr<Request> request) override {
last_request_ = request->content_analysis_request(); last_request_ = request->content_analysis_request();
request->FinishConnectorRequest(saved_result_, saved_response_); request->FinishRequest(saved_result_, saved_response_);
} }
void SetResponse(BinaryUploadService::Result result, void SetResponse(BinaryUploadService::Result result,
......
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