Commit 74982d95 authored by Nicolas Ouellet-payeur's avatar Nicolas Ouellet-payeur Committed by Commit Bot

[Traffic Annotations] Make constructors private

This makes the constructors of [Partial]NetworkAnnotationTag private,
so that the new traffic_annotation_extractor won't need to locate calls
to those constructors.

Bug: 966883
Change-Id: I41559a554777cb6b5520e2dd3a940f14d60e68aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1626493
Commit-Queue: Nicolas Ouellet-Payeur <nicolaso@chromium.org>
Commit-Queue: Matt Menke <mmenke@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Reviewed-by: default avatarRamin Halavati <rhalavati@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664760}
parent 525933f1
...@@ -293,7 +293,7 @@ Entry ProtoConversions::EntryFromProto(const protodb::Entry& proto) { ...@@ -293,7 +293,7 @@ Entry ProtoConversions::EntryFromProto(const protodb::Entry& proto) {
entry.cleanup_attempt_count = proto.cleanup_attempt_count(); entry.cleanup_attempt_count = proto.cleanup_attempt_count();
entry.has_upload_data = proto.has_upload_data(); entry.has_upload_data = proto.has_upload_data();
entry.traffic_annotation = entry.traffic_annotation =
net::MutableNetworkTrafficAnnotationTag({proto.traffic_annotation()}); net::CreateMutableNetworkTrafficAnnotationTag(proto.traffic_annotation());
entry.bytes_downloaded = proto.bytes_downloaded(); entry.bytes_downloaded = proto.bytes_downloaded();
for (const auto& url : proto.url_chain()) for (const auto& url : proto.url_chain())
entry.url_chain.emplace_back(url); entry.url_chain.emplace_back(url);
......
...@@ -34,6 +34,8 @@ constexpr int TRAFFIC_ANNOTATION_UNINITIALIZED = -1; ...@@ -34,6 +34,8 @@ constexpr int TRAFFIC_ANNOTATION_UNINITIALIZED = -1;
namespace net { namespace net {
struct PartialNetworkTrafficAnnotationTag;
// Defined types for network traffic annotation tags. // Defined types for network traffic annotation tags.
struct NetworkTrafficAnnotationTag { struct NetworkTrafficAnnotationTag {
const int32_t unique_id_hash_code; const int32_t unique_id_hash_code;
...@@ -44,9 +46,36 @@ struct NetworkTrafficAnnotationTag { ...@@ -44,9 +46,36 @@ struct NetworkTrafficAnnotationTag {
static NetworkTrafficAnnotationTag NotReached() { static NetworkTrafficAnnotationTag NotReached() {
NOTREACHED(); NOTREACHED();
return net::NetworkTrafficAnnotationTag({TRAFFIC_ANNOTATION_UNINITIALIZED}); return net::NetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_UNINITIALIZED);
} }
// These functions are wrappers around the (private) constructor, so we can
// easily find the constructor's call-sites with a script.
template <size_t N1, size_t N2>
friend constexpr NetworkTrafficAnnotationTag DefineNetworkTrafficAnnotation(
const char (&unique_id)[N1],
const char (&proto)[N2]);
template <size_t N1, size_t N2>
friend NetworkTrafficAnnotationTag CompleteNetworkTrafficAnnotation(
const char (&unique_id)[N1],
const PartialNetworkTrafficAnnotationTag& partial_annotation,
const char (&proto)[N2]);
template <size_t N1, size_t N2, size_t N3>
friend NetworkTrafficAnnotationTag BranchedCompleteNetworkTrafficAnnotation(
const char (&unique_id)[N1],
const char (&group_id)[N2],
const PartialNetworkTrafficAnnotationTag& partial_annotation,
const char (&proto)[N3]);
friend struct MutableNetworkTrafficAnnotationTag;
private:
constexpr NetworkTrafficAnnotationTag(int32_t unique_id_hash_code_)
: unique_id_hash_code(unique_id_hash_code_) {}
}; };
struct PartialNetworkTrafficAnnotationTag { struct PartialNetworkTrafficAnnotationTag {
const int32_t unique_id_hash_code; const int32_t unique_id_hash_code;
...@@ -61,6 +90,27 @@ struct PartialNetworkTrafficAnnotationTag { ...@@ -61,6 +90,27 @@ struct PartialNetworkTrafficAnnotationTag {
// if an intended completing part is added to a partial network annotation. // if an intended completing part is added to a partial network annotation.
const int32_t completing_id_hash_code; const int32_t completing_id_hash_code;
#endif #endif
// This function is a wrapper around the (private) constructor, so we can
// easily find the constructor's call-sites with a script.
template <size_t N1, size_t N2, size_t N3>
friend constexpr PartialNetworkTrafficAnnotationTag
DefinePartialNetworkTrafficAnnotation(const char (&unique_id)[N1],
const char (&completing_id)[N2],
const char (&proto)[N3]);
friend struct MutablePartialNetworkTrafficAnnotationTag;
private:
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
constexpr PartialNetworkTrafficAnnotationTag(int32_t unique_id_hash_code_,
int32_t completing_id_hash_code_)
: unique_id_hash_code(unique_id_hash_code_),
completing_id_hash_code(completing_id_hash_code_) {}
#else
constexpr PartialNetworkTrafficAnnotationTag(int32_t unique_id_hash_code_)
: unique_id_hash_code(unique_id_hash_code_) {}
#endif
}; };
// Function to convert a network traffic annotation's unique id and protobuf // Function to convert a network traffic annotation's unique id and protobuf
...@@ -87,7 +137,7 @@ constexpr NetworkTrafficAnnotationTag DefineNetworkTrafficAnnotation( ...@@ -87,7 +137,7 @@ constexpr NetworkTrafficAnnotationTag DefineNetworkTrafficAnnotation(
const char (&unique_id)[N1], const char (&unique_id)[N1],
const char (&proto)[N2]) { const char (&proto)[N2]) {
return NetworkTrafficAnnotationTag( return NetworkTrafficAnnotationTag(
{COMPUTE_NETWORK_TRAFFIC_ANNOTATION_ID_HASH(unique_id)}); COMPUTE_NETWORK_TRAFFIC_ANNOTATION_ID_HASH(unique_id));
} }
// There are cases where the network traffic annotation cannot be fully // There are cases where the network traffic annotation cannot be fully
...@@ -113,11 +163,11 @@ DefinePartialNetworkTrafficAnnotation(const char (&unique_id)[N1], ...@@ -113,11 +163,11 @@ DefinePartialNetworkTrafficAnnotation(const char (&unique_id)[N1],
const char (&proto)[N3]) { const char (&proto)[N3]) {
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
return PartialNetworkTrafficAnnotationTag( return PartialNetworkTrafficAnnotationTag(
{COMPUTE_NETWORK_TRAFFIC_ANNOTATION_ID_HASH(unique_id), COMPUTE_NETWORK_TRAFFIC_ANNOTATION_ID_HASH(unique_id),
COMPUTE_NETWORK_TRAFFIC_ANNOTATION_ID_HASH(completing_id)}); COMPUTE_NETWORK_TRAFFIC_ANNOTATION_ID_HASH(completing_id));
#else #else
return PartialNetworkTrafficAnnotationTag( return PartialNetworkTrafficAnnotationTag(
{COMPUTE_NETWORK_TRAFFIC_ANNOTATION_ID_HASH(unique_id)}); COMPUTE_NETWORK_TRAFFIC_ANNOTATION_ID_HASH(unique_id));
#endif #endif
} }
...@@ -138,7 +188,7 @@ NetworkTrafficAnnotationTag CompleteNetworkTrafficAnnotation( ...@@ -138,7 +188,7 @@ NetworkTrafficAnnotationTag CompleteNetworkTrafficAnnotation(
partial_annotation.unique_id_hash_code == partial_annotation.unique_id_hash_code ==
COMPUTE_NETWORK_TRAFFIC_ANNOTATION_ID_HASH("undefined")); COMPUTE_NETWORK_TRAFFIC_ANNOTATION_ID_HASH("undefined"));
#endif #endif
return NetworkTrafficAnnotationTag({partial_annotation.unique_id_hash_code}); return NetworkTrafficAnnotationTag(partial_annotation.unique_id_hash_code);
} }
// This function can be used to define a completing partial annotation that is // This function can be used to define a completing partial annotation that is
...@@ -160,7 +210,7 @@ NetworkTrafficAnnotationTag BranchedCompleteNetworkTrafficAnnotation( ...@@ -160,7 +210,7 @@ NetworkTrafficAnnotationTag BranchedCompleteNetworkTrafficAnnotation(
COMPUTE_NETWORK_TRAFFIC_ANNOTATION_ID_HASH("undefined")); COMPUTE_NETWORK_TRAFFIC_ANNOTATION_ID_HASH("undefined"));
#endif #endif
return NetworkTrafficAnnotationTag( return NetworkTrafficAnnotationTag(
{COMPUTE_NETWORK_TRAFFIC_ANNOTATION_ID_HASH(unique_id)}); COMPUTE_NETWORK_TRAFFIC_ANNOTATION_ID_HASH(unique_id));
} }
// Example for joining N x 1 partial annotations: // Example for joining N x 1 partial annotations:
...@@ -229,7 +279,7 @@ struct MutableNetworkTrafficAnnotationTag { ...@@ -229,7 +279,7 @@ struct MutableNetworkTrafficAnnotationTag {
explicit operator NetworkTrafficAnnotationTag() const { explicit operator NetworkTrafficAnnotationTag() const {
DCHECK(is_valid()); DCHECK(is_valid());
return NetworkTrafficAnnotationTag({unique_id_hash_code}); return NetworkTrafficAnnotationTag(unique_id_hash_code);
} }
bool is_valid() const { bool is_valid() const {
...@@ -237,8 +287,22 @@ struct MutableNetworkTrafficAnnotationTag { ...@@ -237,8 +287,22 @@ struct MutableNetworkTrafficAnnotationTag {
} }
void reset() { unique_id_hash_code = TRAFFIC_ANNOTATION_UNINITIALIZED; } void reset() { unique_id_hash_code = TRAFFIC_ANNOTATION_UNINITIALIZED; }
// This function is a wrapper around the private constructor, so we can easily
// find the constructor's call-sites with a script.
friend MutableNetworkTrafficAnnotationTag
CreateMutableNetworkTrafficAnnotationTag(int32_t unique_id_hash_code);
private:
explicit MutableNetworkTrafficAnnotationTag(int32_t unique_id_hash_code_)
: unique_id_hash_code(unique_id_hash_code_) {}
}; };
inline MutableNetworkTrafficAnnotationTag
CreateMutableNetworkTrafficAnnotationTag(int32_t unique_id_hash_code) {
return MutableNetworkTrafficAnnotationTag(unique_id_hash_code);
}
struct MutablePartialNetworkTrafficAnnotationTag { struct MutablePartialNetworkTrafficAnnotationTag {
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
MutablePartialNetworkTrafficAnnotationTag() MutablePartialNetworkTrafficAnnotationTag()
...@@ -255,8 +319,8 @@ struct MutablePartialNetworkTrafficAnnotationTag { ...@@ -255,8 +319,8 @@ struct MutablePartialNetworkTrafficAnnotationTag {
explicit operator PartialNetworkTrafficAnnotationTag() const { explicit operator PartialNetworkTrafficAnnotationTag() const {
DCHECK(is_valid()); DCHECK(is_valid());
return PartialNetworkTrafficAnnotationTag( return PartialNetworkTrafficAnnotationTag(unique_id_hash_code,
{unique_id_hash_code, completing_id_hash_code}); completing_id_hash_code);
} }
bool is_valid() const { bool is_valid() const {
...@@ -278,7 +342,7 @@ struct MutablePartialNetworkTrafficAnnotationTag { ...@@ -278,7 +342,7 @@ struct MutablePartialNetworkTrafficAnnotationTag {
int32_t unique_id_hash_code; int32_t unique_id_hash_code;
explicit operator PartialNetworkTrafficAnnotationTag() const { explicit operator PartialNetworkTrafficAnnotationTag() const {
return PartialNetworkTrafficAnnotationTag({unique_id_hash_code}); return PartialNetworkTrafficAnnotationTag(unique_id_hash_code);
} }
bool is_valid() const { bool is_valid() const {
......
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