1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
content / browser / interest_group / trusted_signals_fetcher.cc [blame]
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/interest_group/trusted_signals_fetcher.h"
#include <stdint.h>
#include <algorithm>
#include <bit>
#include <map>
#include <set>
#include <string>
#include <string_view>
#include <vector>
#include "base/check.h"
#include "base/containers/span.h"
#include "base/containers/span_reader.h"
#include "base/containers/span_writer.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/notimplemented.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "base/types/expected.h"
#include "bidding_and_auction_server_key_fetcher.h"
#include "components/cbor/values.h"
#include "components/cbor/writer.h"
#include "content/common/content_export.h"
#include "content/services/auction_worklet/public/mojom/trusted_signals_cache.mojom.h"
#include "net/http/http_request_headers.h"
#include "net/third_party/quiche/src/quiche/oblivious_http/buffers/oblivious_http_request.h"
#include "net/third_party/quiche/src/quiche/oblivious_http/buffers/oblivious_http_response.h"
#include "net/third_party/quiche/src/quiche/oblivious_http/common/oblivious_http_header_key_config.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/data_decoder/public/cpp/data_decoder.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/fetch_api.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/boringssl/src/include/openssl/hpke.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace content {
namespace {
constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation =
net::DefineNetworkTrafficAnnotation("trusted_signals_fetcher", R"(
semantics {
sender: "TrustedSignalsFetcher"
description:
"Requests FLEDGE encrypted trusted signals for running an ad "
"auction."
trigger:
"Requested when a website runs a Protected Audiences auction. "
"The Protected Audience API allows sites to select content (such "
"as personalized ads) to display based on cross-site data in a "
"privacy preserving way."
data:
"HTTPS URL and POST body associated with an interest group or "
"seller. POST data has an additional layer of encryption, and "
"all data other than the URL is end-to-end encrypted and only "
"accessible in a Trusted Execution Environment."
destination: WEBSITE
user_data: {
type: SENSITIVE_URL
}
internal {
contacts {
email: "privacy-sandbox-dev@chromium.org"
}
}
last_reviewed: "2024-06-08"
}
policy {
cookies_allowed: NO
setting:
"Users can disable this via Settings > Privacy and Security > Ads "
"privacy > Site-suggested ads."
chrome_policy {
PrivacySandboxSiteEnabledAdsEnabled {
PrivacySandboxSiteEnabledAdsEnabled: false
}
}
})");
// Supported compression formats.
constexpr std::array<std::string_view, 2> kAcceptCompression = {"none", "gzip"};
// Lengths of various components of request and response header components.
constexpr size_t kCompressionFormatSize = 1; // bytes
constexpr size_t kCborStringLengthSize = 4; // bytes
constexpr size_t kOhttpHeaderSize = 55; // bytes
// Creates a single entry for the "arguments" array of a partition, with a
// single tag and an array of values.
cbor::Value MakeArgument(std::string_view tag, cbor::Value::ArrayValue data) {
cbor::Value::MapValue argument;
cbor::Value::ArrayValue tags;
tags.emplace_back(cbor::Value(tag));
argument.try_emplace(cbor::Value("tags"), cbor::Value(std::move(tags)));
argument.try_emplace(cbor::Value("data"), std::move(data));
return cbor::Value(std::move(argument));
}
// Creates a single entry for the "arguments" array of a partition, with a
// single tag and an array that contains the single passed-in `data` value.
cbor::Value MakeArgument(std::string_view tag, cbor::Value data) {
cbor::Value::ArrayValue cbor_array;
cbor_array.emplace_back(std::move(data));
return MakeArgument(tag, std::move(cbor_array));
}
// Creates a single entry for the "arguments" array of a partition, with a
// single tag and a variable number of string data values, from a set of
// strings.
cbor::Value MakeArgument(std::string_view tag,
const std::set<std::string>& data) {
cbor::Value::ArrayValue cbor_data;
for (const auto& element : data) {
cbor_data.emplace_back(cbor::Value(element));
}
return MakeArgument(tag, std::move(cbor_data));
}
// BiddingPartition overload of BuildMapForPartition().
cbor::Value::MapValue BuildMapForPartition(
int compression_group_id,
const TrustedSignalsFetcher::BiddingPartition& bidding_partition) {
cbor::Value::MapValue partition_cbor_map;
partition_cbor_map.try_emplace(cbor::Value("compressionGroupId"),
cbor::Value(compression_group_id));
partition_cbor_map.try_emplace(cbor::Value("id"),
cbor::Value(bidding_partition.partition_id));
if (!bidding_partition.additional_params->empty()) {
cbor::Value::MapValue metadata;
for (const auto param : *bidding_partition.additional_params) {
// TODO(crbug.com/333445540): Consider switching to taking
// `additional_params` as a cbor::Value, for greater flexibility. The
// `slotSizes` parameter, in particular, might be best represented as an
// array. cbor::Value doesn't have operator<, having a Less comparator
// instead, so would need to add that.
//
// Alternatively, could split this up into the data used to construct it.
CHECK(param.second.is_string());
metadata.try_emplace(cbor::Value(param.first),
cbor::Value(param.second.GetString()));
}
partition_cbor_map.try_emplace(cbor::Value("metadata"),
cbor::Value(std::move(metadata)));
}
cbor::Value::ArrayValue arguments;
arguments.emplace_back(MakeArgument("interestGroupNames",
*bidding_partition.interest_group_names));
arguments.emplace_back(MakeArgument("keys", *bidding_partition.keys));
partition_cbor_map.try_emplace(cbor::Value("arguments"),
cbor::Value(std::move(arguments)));
return partition_cbor_map;
}
// ScoringPartition overload of BuildMapForPartition().
cbor::Value::MapValue BuildMapForPartition(
int compression_group_id,
const TrustedSignalsFetcher::ScoringPartition& scoring_partition) {
cbor::Value::MapValue partition_cbor_map;
partition_cbor_map.try_emplace(cbor::Value("compressionGroupId"),
cbor::Value(compression_group_id));
partition_cbor_map.try_emplace(cbor::Value("id"),
cbor::Value(scoring_partition.partition_id));
if (!scoring_partition.additional_params->empty()) {
cbor::Value::MapValue metadata;
for (const auto param : *scoring_partition.additional_params) {
// TODO(crbug.com/333445540): Consider switching to taking
// `additional_params` as a cbor::Value, for greater flexibility.
//
// Alternatively, could split this up into the data used to construct it.
CHECK(param.second.is_string());
metadata.try_emplace(cbor::Value(param.first),
cbor::Value(param.second.GetString()));
}
partition_cbor_map.try_emplace(cbor::Value("metadata"),
cbor::Value(std::move(metadata)));
}
cbor::Value::ArrayValue arguments;
arguments.emplace_back(MakeArgument(
"renderUrls", cbor::Value(scoring_partition.render_url->spec())));
if (!scoring_partition.component_render_urls->empty()) {
cbor::Value::ArrayValue component_urls;
for (const GURL& component_render_urls :
*scoring_partition.component_render_urls) {
component_urls.emplace_back(cbor::Value(component_render_urls.spec()));
}
arguments.emplace_back(
MakeArgument("adComponentRenderUrls", std::move(component_urls)));
}
partition_cbor_map.try_emplace(cbor::Value("arguments"),
cbor::Value(std::move(arguments)));
return partition_cbor_map;
}
std::string CreateRequestBodyFromCbor(cbor::Value cbor_value) {
std::optional<std::vector<uint8_t>> maybe_cbor_bytes =
cbor::Writer::Write(cbor_value);
CHECK(maybe_cbor_bytes.has_value());
std::string request_body;
size_t size_before_padding = kOhttpHeaderSize + kCompressionFormatSize +
kCborStringLengthSize + maybe_cbor_bytes->size();
size_t size_with_padding = std::bit_ceil(size_before_padding);
size_t request_body_size = size_with_padding - kOhttpHeaderSize;
request_body.resize(request_body_size, 0x00);
base::SpanWriter writer(
base::as_writable_bytes(base::make_span(request_body)));
// Add framing header. First byte includes version and compression format.
// Always set first byte to 0x00 because request body is uncompressed.
writer.WriteU8BigEndian(0x00);
writer.WriteU32BigEndian(
base::checked_cast<uint32_t>(maybe_cbor_bytes->size()));
// Add CBOR string.
writer.Write(base::as_bytes(base::make_span(*maybe_cbor_bytes)));
DCHECK_EQ(writer.num_written(), size_before_padding - kOhttpHeaderSize);
// TODO(crbug.com/333445540): Add encryption.
return request_body;
}
// Builds the request body for bidding and scoring requests. The outer body is
// the same, only the data in the partitions is different, so a template works
// well for this. PartitionType is either BiddingPartition or ScoringPartition.
template <typename PartitionType>
std::string BuildSignalsRequestBody(
std::string_view hostname,
const std::map<int, std::vector<PartitionType>>& compression_groups) {
cbor::Value::MapValue request_map_value;
cbor::Value::ArrayValue accept_compression(kAcceptCompression.begin(),
kAcceptCompression.end());
request_map_value.emplace(cbor::Value("acceptCompression"),
cbor::Value(std::move(accept_compression)));
cbor::Value::MapValue metadata;
metadata.try_emplace(cbor::Value("hostname"), cbor::Value(hostname));
request_map_value.try_emplace(cbor::Value("metadata"),
cbor::Value(std::move(metadata)));
cbor::Value::ArrayValue partition_array;
for (const auto& group_pair : compression_groups) {
int compression_group_id = group_pair.first;
for (const auto& partition : group_pair.second) {
cbor::Value::MapValue partition_cbor_map =
BuildMapForPartition(compression_group_id, partition);
partition_array.emplace_back(partition_cbor_map);
}
}
request_map_value.emplace(cbor::Value("partitions"),
cbor::Value(std::move(partition_array)));
return CreateRequestBodyFromCbor(cbor::Value(std::move(request_map_value)));
}
} // namespace
TrustedSignalsFetcher::BiddingPartition::BiddingPartition(
int partition_id,
const std::set<std::string>* interest_group_names,
const std::set<std::string>* keys,
const base::Value::Dict* additional_params)
: partition_id(partition_id),
interest_group_names(*interest_group_names),
keys(*keys),
additional_params(*additional_params) {}
TrustedSignalsFetcher::BiddingPartition::BiddingPartition(BiddingPartition&&) =
default;
TrustedSignalsFetcher::BiddingPartition::~BiddingPartition() = default;
TrustedSignalsFetcher::BiddingPartition&
TrustedSignalsFetcher::BiddingPartition::operator=(BiddingPartition&&) =
default;
TrustedSignalsFetcher::ScoringPartition::ScoringPartition(
int partition_id,
const GURL* render_url,
const std::set<GURL>* component_render_urls,
const base::Value::Dict* additional_params)
: partition_id(partition_id),
render_url(*render_url),
component_render_urls(*component_render_urls),
additional_params(*additional_params) {}
TrustedSignalsFetcher::ScoringPartition::ScoringPartition(ScoringPartition&&) =
default;
TrustedSignalsFetcher::ScoringPartition::~ScoringPartition() = default;
TrustedSignalsFetcher::ScoringPartition&
TrustedSignalsFetcher::ScoringPartition::operator=(ScoringPartition&&) =
default;
TrustedSignalsFetcher::CompressionGroupResult::CompressionGroupResult() =
default;
TrustedSignalsFetcher::CompressionGroupResult::CompressionGroupResult(
CompressionGroupResult&&) = default;
TrustedSignalsFetcher::CompressionGroupResult::~CompressionGroupResult() =
default;
TrustedSignalsFetcher::CompressionGroupResult&
TrustedSignalsFetcher::CompressionGroupResult::operator=(
CompressionGroupResult&&) = default;
TrustedSignalsFetcher::TrustedSignalsFetcher() = default;
TrustedSignalsFetcher::~TrustedSignalsFetcher() = default;
void TrustedSignalsFetcher::FetchBiddingSignals(
network::mojom::URLLoaderFactory* url_loader_factory,
std::string_view hostname,
const GURL& trusted_bidding_signals_url,
const BiddingAndAuctionServerKey& bidding_and_auction_key,
const std::map<int, std::vector<BiddingPartition>>& compression_groups,
Callback callback) {
EncryptRequestBodyAndStart(
url_loader_factory, trusted_bidding_signals_url, bidding_and_auction_key,
BuildSignalsRequestBody(hostname, compression_groups),
std::move(callback));
}
void TrustedSignalsFetcher::FetchScoringSignals(
network::mojom::URLLoaderFactory* url_loader_factory,
std::string_view hostname,
const GURL& trusted_scoring_signals_url,
const BiddingAndAuctionServerKey& bidding_and_auction_key,
const std::map<int, std::vector<ScoringPartition>>& compression_groups,
Callback callback) {
EncryptRequestBodyAndStart(
url_loader_factory, trusted_scoring_signals_url, bidding_and_auction_key,
BuildSignalsRequestBody(hostname, compression_groups),
std::move(callback));
}
void TrustedSignalsFetcher::EncryptRequestBodyAndStart(
network::mojom::URLLoaderFactory* url_loader_factory,
const GURL& trusted_signals_url,
const BiddingAndAuctionServerKey& bidding_and_auction_key,
std::string plaintext_request_body,
Callback callback) {
DCHECK(!simple_url_loader_);
DCHECK(!callback_);
trusted_signals_url_ = trusted_signals_url;
callback_ = std::move(callback);
// Add encryption for request body.
auto maybe_key_config = quiche::ObliviousHttpHeaderKeyConfig::Create(
bidding_and_auction_key.id, EVP_HPKE_DHKEM_X25519_HKDF_SHA256,
EVP_HPKE_HKDF_SHA256, EVP_HPKE_AES_256_GCM);
CHECK(maybe_key_config.ok());
auto maybe_ciphertext_request_body =
quiche::ObliviousHttpRequest::CreateClientObliviousRequest(
std::move(plaintext_request_body), bidding_and_auction_key.key,
*maybe_key_config, kRequestMediaType);
CHECK(maybe_ciphertext_request_body.ok());
auto resource_request = std::make_unique<network::ResourceRequest>();
resource_request->method = net::HttpRequestHeaders::kPostMethod;
resource_request->url = trusted_signals_url;
resource_request->credentials_mode = network::mojom::CredentialsMode::kOmit;
resource_request->mode = network::mojom::RequestMode::kNoCors;
resource_request->redirect_mode = network::mojom::RedirectMode::kError;
resource_request->headers.SetHeader("Accept", kResponseMediaType);
// TODO(crbug.com/333445540): Set reasonable initiator, isolation info, client
// security state, and credentials mode, and select reasonable maximum body
// size. Also hook up to devtools.
simple_url_loader_ = network::SimpleURLLoader::Create(
std::move(resource_request), kTrafficAnnotation);
simple_url_loader_->AttachStringForUpload(
maybe_ciphertext_request_body->EncapsulateAndSerialize(),
kRequestMediaType);
// ObliviousHttpRequest::Context is a move-only type, with no default
// constructor, but ReleaseContext() return by value, so have to somewhat
// awkwardly wrap it in a unique_ptr to store it in an already-created
// TrustedSignalsFetcher.
ohttp_context_ = std::make_unique<quiche::ObliviousHttpRequest::Context>(
std::move(maybe_ciphertext_request_body).value().ReleaseContext());
simple_url_loader_->DownloadToStringOfUnboundedSizeUntilCrashAndDie(
url_loader_factory,
base::BindOnce(&TrustedSignalsFetcher::OnRequestComplete,
base::Unretained(this)));
}
void TrustedSignalsFetcher::OnRequestComplete(
std::unique_ptr<std::string> response_body) {
if (!response_body) {
std::move(callback_).Run(base::unexpected(base::StringPrintf(
"Failed to load %s error = %s.", trusted_signals_url_.spec().c_str(),
net::ErrorToString(simple_url_loader_->NetError()).c_str())));
return;
}
if (simple_url_loader_->ResponseInfo()->mime_type != kResponseMediaType) {
std::move(callback_).Run(base::unexpected(
base::StringPrintf("Rejecting load of %s due to unexpected MIME type.",
trusted_signals_url_.spec().c_str())));
return;
}
// `simple_url_loader_` is no longer needed.
simple_url_loader_.reset();
// The oblivious HTTP code returns an error on empty response bodies, so only
// try and decrypt if the body is not empty, to give an error about size
// rather than OHTTP failing in that case.
std::string plaintext_response_body;
if (response_body->size() > 0u) {
auto maybe_plaintext_response_body =
quiche::ObliviousHttpResponse::CreateClientObliviousResponse(
std::move(*response_body), *ohttp_context_, kResponseMediaType);
// `ohttp_context_` is no longer needed.
ohttp_context_.reset();
if (!maybe_plaintext_response_body.ok()) {
// Don't output OHTTP error strings, directly, as they're often not very
// user-friendly.
std::move(callback_).Run(
base::unexpected(CreateError("OHTTP decryption failed")));
return;
}
plaintext_response_body =
std::move(maybe_plaintext_response_body).value().ConsumePlaintextData();
}
base::SpanReader reader(base::as_byte_span(plaintext_response_body));
uint8_t compression_scheme_bytes;
uint32_t cbor_length;
if (!reader.ReadU8BigEndian(compression_scheme_bytes) ||
!reader.ReadU32BigEndian(cbor_length)) {
std::move(callback_).Run(base::unexpected(CreateError(
base::StringPrintf("Response body is shorter than a %s header",
kResponseMediaType.data()))));
return;
}
// Only the first to bits are used for compression format in the whole byte.
compression_scheme_bytes &= 0x03;
if (compression_scheme_bytes == 0x00) {
compression_scheme_ =
auction_worklet::mojom::TrustedSignalsCompressionScheme::kNone;
} else if (compression_scheme_bytes == 0x02) {
compression_scheme_ =
auction_worklet::mojom::TrustedSignalsCompressionScheme::kGzip;
} else {
std::move(callback_).Run(base::unexpected(CreateError(base::StringPrintf(
"Unsupported compression scheme: %u", compression_scheme_bytes))));
return;
}
base::span<const uint8_t> remaining_span = reader.remaining_span();
if (remaining_span.size() < cbor_length) {
std::move(callback_).Run(
base::unexpected(CreateError("Length header exceeds body size")));
return;
}
base::span<const uint8_t> cbor = remaining_span.subspan(0, cbor_length);
data_decoder::DataDecoder::ParseCborIsolated(
cbor, base::BindOnce(&TrustedSignalsFetcher::OnCborParsed,
weak_ptr_factory_.GetWeakPtr()));
}
void TrustedSignalsFetcher::OnCborParsed(
data_decoder::DataDecoder::ValueOrError value_or_error) {
std::move(callback_).Run(ParseDataDecoderResult(std::move(value_or_error)));
}
TrustedSignalsFetcher::SignalsFetchResult
TrustedSignalsFetcher::ParseDataDecoderResult(
data_decoder::DataDecoder::ValueOrError value_or_error) {
if (!value_or_error.has_value()) {
return base::unexpected(CreateError("Failed to parse response as CBOR"));
}
if (!value_or_error->is_dict()) {
// Since the data is CBOR, use CBOR type names in error messages ("map"
// instead of JSON "object" or Value "dict").
return base::unexpected(CreateError("Response body is not a map"));
}
base::Value::Dict& dict = value_or_error->GetDict();
// Get compression groups.
base::Value::List* compression_groups = dict.FindList("compressionGroups");
if (!compression_groups) {
return base::unexpected(
CreateError("Response is missing compressionGroups array"));
}
CompressionGroupResultMap compression_groups_out;
for (auto& compression_group : *compression_groups) {
int compression_group_id;
// This consumes each value of the list, to avoid having to copy the
// contents of each compression group.
auto compression_group_result = ParseCompressionGroup(
std::move(compression_group), compression_group_id);
if (!compression_group_result.has_value()) {
return base::unexpected(std::move(compression_group_result).error());
}
if (!compression_groups_out
.try_emplace(compression_group_id,
std::move(compression_group_result).value())
.second) {
return base::unexpected(CreateError(base::StringPrintf(
"Response contains two compression groups with id %i",
compression_group_id)));
}
}
return compression_groups_out;
}
base::expected<TrustedSignalsFetcher::CompressionGroupResult, std::string>
TrustedSignalsFetcher::ParseCompressionGroup(
base::Value compression_group_value,
int& compression_group_id) {
if (!compression_group_value.is_dict()) {
return base::unexpected(CreateError(
base::StringPrintf("Compression group is not of type map")));
}
base::Value::Dict& compression_group_dict = compression_group_value.GetDict();
std::optional<int> compression_group_id_opt =
compression_group_dict.FindInt("compressionGroupId");
if (!compression_group_id_opt.has_value() || *compression_group_id_opt < 0) {
return base::unexpected(CreateError(
base::StringPrintf("Compression group must have a non-negative integer "
"compressionGroupId")));
}
const base::Value* ttl_ms_value = compression_group_dict.Find("ttlMs");
// Default TTL is 0.
base::TimeDelta ttl;
if (ttl_ms_value) {
if (!ttl_ms_value->is_int()) {
return base::unexpected(CreateError(base::StringPrintf(
"Compression group %i ttlMs value is not an integer",
*compression_group_id_opt)));
}
// Treat negative values as 0. Using zero is more robust if these values are
// ever used to set a timer.
ttl = base::Milliseconds(std::max(0, ttl_ms_value->GetInt()));
}
auto* content = compression_group_dict.FindBlob("content");
if (!content) {
return base::unexpected(CreateError(base::StringPrintf(
"Compression group %i missing binary string \"content\"",
*compression_group_id_opt)));
}
compression_group_id = *compression_group_id_opt;
CompressionGroupResult result;
result.compression_scheme = compression_scheme_;
result.compression_group_data = std::move(*content);
result.ttl = ttl;
return result;
}
std::string TrustedSignalsFetcher::CreateError(
const std::string& error_message) {
return base::StringPrintf("Failed to load %s: %s.",
trusted_signals_url_.spec().c_str(),
error_message.c_str());
}
} // namespace content