Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.

Commit fc02ba4

Browse files
Privacy Sandbox Teamcopybara-github
authored andcommitted
feat: Copy async_http_client from B&A
Note that AsyncHttpClient is a subset of AsyncClient. The AsyncClient interface in B&A actually contains two methods - one for http and one for grpc. No implementation overrides both, so it doesn't make much sense to keep both methods in one interface. Breaking out the http portion makes the clients pure interfaces. This is part of a series of CLs to copy the KV BYOS clients from B&A to common repo. Bug: 411430242 Change-Id: I1b246bfc43e2e4e1b98ed78ae2b4ff3b4701aea0 GitOrigin-RevId: eb8cc179741f446739a07b057e630b38f81c03ff
1 parent 2ca722d commit fc02ba4

7 files changed

Lines changed: 148 additions & 78 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_library")
2+
3+
cc_library(
4+
name = "async_http_client",
5+
hdrs = ["async_http_client.h"],
6+
# header only library for interface
7+
linkstatic = True,
8+
visibility = ["//visibility:public"],
9+
deps = [
10+
"@com_google_absl//absl/functional:any_invocable",
11+
"@com_google_absl//absl/status",
12+
"@com_google_absl//absl/time",
13+
],
14+
)
15+
16+
cc_library(
17+
name = "mocks",
18+
testonly = 1,
19+
hdrs = ["mocks.h"],
20+
deps = [
21+
"@com_google_absl//absl/functional:any_invocable",
22+
"@com_google_absl//absl/status",
23+
"@com_google_absl//absl/time",
24+
"@com_google_googletest//:gtest_main",
25+
],
26+
)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef SRC_CLIENTS_ASYNC_CLIENT_ASYNC_HTTP_CLIENT_H_
16+
#define SRC_CLIENTS_ASYNC_CLIENT_ASYNC_HTTP_CLIENT_H_
17+
18+
#include <memory>
19+
#include <string>
20+
21+
#include "absl/container/flat_hash_map.h"
22+
#include "absl/functional/any_invocable.h"
23+
#include "absl/status/statusor.h"
24+
#include "absl/time/time.h"
25+
26+
namespace privacy_sandbox::server_common::clients {
27+
28+
// This provides access to the Metadata Object type
29+
using RequestMetadata = absl::flat_hash_map<std::string, std::string>;
30+
31+
// Classes implementing this template and interface are able to execute
32+
// asynchronous requests.
33+
template <typename Request, typename Response, typename RawRequest = Request,
34+
typename RawResponse = Response>
35+
class AsyncHttpClient {
36+
public:
37+
virtual ~AsyncHttpClient() = default;
38+
39+
// Executes the request asynchronously.
40+
//
41+
// request: the request object to execute.
42+
// metadata: Metadata to be passed to the client.
43+
// on_done: callback called when the request is finished executing.
44+
// timeout: a timeout value for the request.
45+
virtual absl::Status Execute(
46+
std::unique_ptr<Request> request, const RequestMetadata& metadata,
47+
absl::AnyInvocable<void(absl::StatusOr<std::unique_ptr<Response>>) &&>
48+
on_done,
49+
absl::Duration timeout,
50+
privacy_sandbox::server_common::log::PSLogContext& log_context =
51+
const_cast<privacy_sandbox::server_common::log::NoOpContext&>(
52+
privacy_sandbox::server_common::log::kNoOpContext)) const = 0;
53+
};
54+
55+
} // namespace privacy_sandbox::server_common::clients
56+
57+
#endif // SRC_CLIENTS_ASYNC_CLIENT_ASYNC_HTTP_CLIENT_H_

src/clients/async_client/mocks.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef SRC_CLIENTS_ASYNC_CLIENT_MOCKS_H_
18+
#define SRC_CLIENTS_ASYNC_CLIENT_MOCKS_H_
19+
20+
#include <gmock/gmock.h>
21+
22+
#include <memory>
23+
24+
#include "absl/container/flat_hash_map.h"
25+
#include "absl/functional/any_invocable.h"
26+
#include "absl/status/statusor.h"
27+
#include "absl/time/time.h"
28+
#include "src/clients/async_client/async_http_client.h"
29+
30+
namespace privacy_sandbox::server_common::clients {
31+
32+
template <typename Request, typename Response, typename RawRequest = Request,
33+
typename RawResponse = Response>
34+
class AsyncClientMock
35+
: public AsyncClient<Request, Response, RawRequest, RawResponse> {
36+
public:
37+
MOCK_METHOD(
38+
absl::Status, Execute,
39+
(std::unique_ptr<Request> request, const RequestMetadata& metadata,
40+
absl::AnyInvocable<void(absl::StatusOr<std::unique_ptr<Response>>) &&>
41+
on_done,
42+
absl::Duration timeout, RequestContext context),
43+
(const, override));
44+
45+
using OnDoneCallbackType =
46+
absl::AnyInvocable<void(absl::StatusOr<std::unique_ptr<RawResponse>>,
47+
ResponseMetadata) &&>;
48+
MOCK_METHOD(absl::Status, ExecuteInternal,
49+
(std::unique_ptr<RawRequest> raw_request,
50+
grpc::ClientContext* context, OnDoneCallbackType on_done,
51+
absl::Duration timeout, RequestConfig request_config),
52+
(override));
53+
};
54+
55+
} // namespace privacy_sandbox::server_common::clients
56+
57+
#endif // SRC_CLIENTS_ASYNC_CLIENT_MOCKS_H_

src/core/kv_client/BUILD.bazel

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,24 @@ cc_library(
1212

1313
cc_library(
1414
name = "buyer_key_value_async_http_client",
15-
srcs = [
16-
],
1715
hdrs = [
1816
"buyer_key_value_async_http_client.h",
1917
],
18+
visibility = ["//visibility:public"],
2019
deps = [
2120
":common",
22-
],
23-
)
24-
25-
cc_library(
26-
name = "byos_client",
27-
srcs = [
28-
],
29-
hdrs = [
30-
"byos_client.h",
31-
],
32-
deps = [
33-
"@com_google_absl//absl/functional:any_invocable",
34-
"@com_google_absl//absl/status",
35-
"@com_google_absl//absl/time",
21+
"//src/clients/async_client:async_http_client",
3622
],
3723
)
3824

3925
cc_library(
4026
name = "seller_key_value_async_http_client",
41-
srcs = [
42-
],
4327
hdrs = [
4428
"seller_key_value_async_http_client.h",
4529
],
30+
visibility = ["//visibility:public"],
4631
deps = [
4732
":common",
33+
"//src/clients/async_client:async_http_client",
4834
],
4935
)

src/core/kv_client/buyer_key_value_async_http_client.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <memory>
2121
#include <string>
2222

23-
#include "src/core/kv_client/byos_client.h"
23+
#include "src/clients/async_client/async_http_client.h"
2424
#include "src/core/kv_client/common.h"
2525

2626
namespace privacy_sandbox::server_common::kv_client {
@@ -72,7 +72,7 @@ struct GetBuyerValuesOutput {
7272
// TODO(b/411430242): Move actual implementation from B&A repo. This is
7373
// currently no-op
7474
class BuyerKeyValuesAsyncHttpClient
75-
: public ByosClient<GetBuyerValuesInput, GetBuyerValuesOutput> {
75+
: public AsyncHttpClient<GetBuyerValuesInput, GetBuyerValuesOutput> {
7676
public:
7777
explicit BuyerKeyValueAsyncHttpClient(std::string_view kv_server_base_address)
7878
: kv_server_base_address_(kv_server_base_address) {}

src/core/kv_client/byos_client.h

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/core/kv_client/seller_key_value_async_http_client.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <memory>
2121
#include <string>
2222

23+
#include "src/clients/async_client/async_http_client.h"
2324
#include "src/core/kv_client/common.h"
2425

2526
namespace privacy_sandbox::server_common::kv_client {
@@ -56,7 +57,7 @@ struct GetSellerValuesOutput {
5657
// TODO(b/411430242): Move actual implementation from B&A repo. This is
5758
// currently no-op
5859
class SellerKeyValuesAsyncHttpClient
59-
: public ByosClient<GetSellerValuesInput, GetSellerValuesOutput> {
60+
: public AsyncHttpClient<GetSellerValuesInput, GetSellerValuesOutput> {
6061
public:
6162
explicit SellerKeyValueAsyncHttpClient(
6263
std::string_view kv_server_base_address)

0 commit comments

Comments
 (0)