Commit 86b22e5a authored by Varun Khaneja's avatar Varun Khaneja Committed by Commit Bot

Protego: Add version and os_type in the request proto.

See go/protego-versioned-proto for more details about the motivation.

TODOs:
1. Add UMA metrics. Will do that seprately to keep this CL small and
   the reviewer list short.
3. Add the response_provider field in the proto

Bug: 1119928
Change-Id: Ie15d59b7f4e0b4c0fd236d9c665ad82f02ae2cdd
Fixed: 1119928
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2367443Reviewed-by: default avatarVarun Khaneja <vakh@chromium.org>
Reviewed-by: default avatarXinghui Lu <xinghuilu@chromium.org>
Commit-Queue: Varun Khaneja <vakh@chromium.org>
Auto-Submit: Varun Khaneja <vakh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800387}
parent e04ca87d
......@@ -1286,9 +1286,40 @@ std::string SerializeRTLookupPing(const RTLookupRequestAndToken& ping) {
lookupType = "DOWNLOAD";
break;
}
request_dict.SetKey("lookup_type", base::Value(lookupType));
request_dict.SetKey("version", base::Value(request.version()));
std::string os;
switch (request.os_type()) {
case RTLookupRequest::OS_TYPE_UNSPECIFIED:
DCHECK(false) << "RTLookupRequest::os_type is undefined.";
os = "UNSPECIFIED";
break;
case RTLookupRequest::OS_TYPE_LINUX:
os = "LINUX";
break;
case RTLookupRequest::OS_TYPE_WINDOWS:
os = "WINDOWS";
break;
case RTLookupRequest::OS_TYPE_MAC:
os = "MAC";
break;
case RTLookupRequest::OS_TYPE_ANDROID:
os = "ANDROID";
break;
case RTLookupRequest::OS_TYPE_IOS:
os = "IOS";
break;
case RTLookupRequest::OS_TYPE_CHROME_OS:
os = "CHROME_OS";
break;
case RTLookupRequest::OS_TYPE_FUCHSIA:
os = "FUCHSIA";
break;
}
request_dict.SetKey("os", base::Value(os));
std::string request_serialized;
JSONStringValueSerializer serializer(&request_serialized);
serializer.set_pretty_print(true);
......
......@@ -35,6 +35,28 @@ message RTLookupRequest {
// The DM Token for Enterprise-enrolled devices (go/uss-dmtoken).
optional string dm_token = 5;
// |version| helps the Safe Browsing server understand what verison of the
// proto Chrome understands, and also what kinds of behaviours it supports.
// It should be incremented when adding new fields and/or when making changes
// to how existing fields may be interpreted.
// Version 1:
// * Client supports caching with |COVERING_MATCH| verdicts.
// * Client supports the |os_type| field.
optional int32 version = 6 [default = 0];
// The operating system of the client.
enum OSType {
OS_TYPE_UNSPECIFIED = 0;
OS_TYPE_ANDROID = 1;
OS_TYPE_CHROME_OS = 2;
OS_TYPE_FUCHSIA = 3;
OS_TYPE_IOS = 4;
OS_TYPE_LINUX = 5;
OS_TYPE_MAC = 6;
OS_TYPE_WINDOWS = 7;
}
optional OSType os_type = 7;
}
message RTLookupResponse {
......
......@@ -11,6 +11,7 @@
#include "base/strings/string_piece.h"
#include "base/task/post_task.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/safe_browsing/core/common/thread_utils.h"
......@@ -38,6 +39,9 @@ const size_t kURLLookupTimeoutDurationInSeconds = 10; // 10 seconds.
constexpr char kAuthHeaderBearer[] = "Bearer ";
// Represents the value stored in the |version| field of |RTLookupRequest|.
const int kRTLookupRequestVersion = 1;
// UMA helper functions.
void RecordBooleanWithAndWithoutSuffix(const std::string& metric,
const std::string& suffix,
......@@ -87,6 +91,25 @@ void RecordNetworkResultWithAndWithoutSuffix(const std::string& metric,
(metric + suffix).c_str(), net_error, response_code);
}
RTLookupRequest::OSType GetRTLookupRequestOSType() {
#if defined(OS_ANDROID)
return RTLookupRequest::OS_TYPE_ANDROID;
#elif defined(OS_CHROMEOS)
return RTLookupRequest::OS_TYPE_CHROME_OS;
#elif defined(OS_FUCHSIA)
return RTLookupRequest::OS_TYPE_FUCHSIA;
#elif defined(OS_IOS)
return RTLookupRequest::OS_TYPE_IOS;
#elif defined(OS_LINUX)
return RTLookupRequest::OS_TYPE_LINUX;
#elif defined(OS_MAC)
return RTLookupRequest::OS_TYPE_MAC;
#elif defined(OS_WIN)
return RTLookupRequest::OS_TYPE_WINDOWS;
#endif
return RTLookupRequest::OS_TYPE_UNSPECIFIED;
}
} // namespace
RealTimeUrlLookupServiceBase::RealTimeUrlLookupServiceBase(
......@@ -416,6 +439,8 @@ std::unique_ptr<RTLookupRequest> RealTimeUrlLookupServiceBase::FillRequestProto(
auto request = std::make_unique<RTLookupRequest>();
request->set_url(SanitizeURL(url).spec());
request->set_lookup_type(RTLookupRequest::NAVIGATION);
request->set_version(kRTLookupRequestVersion);
request->set_os_type(GetRTLookupRequestOSType());
base::Optional<std::string> dm_token_string = GetDMTokenString();
if (dm_token_string.has_value()) {
request->set_dm_token(dm_token_string.value());
......
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