File: sample_traffic_annotation.cc

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (305 lines) | stat: -rw-r--r-- 12,021 bytes parent folder | download | duplicates (5)
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
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/traffic_annotation/network_traffic_annotation.h"

// This file includes a template and some samples for text-coded
// traffic_annotation. For more description on each field, please refer to:
// chrome/browser/privacy/traffic_annotation.proto
// and
// out/Debug/gen/components/policy/proto/chrome_settings.proto
// For more information on policies, please refer to:
// https://cloud.google.com/docs/chrome-enterprise/policies

// A template for one level traffic annotation.
void network_traffic_annotation_template() {
  net::NetworkTrafficAnnotationTag traffic_annotation =
      net::DefineNetworkTrafficAnnotation("...", R"(
        semantics {
          sender: "..."
          description: "..."
          trigger: "..."
          data: "..."
          destination: WEBSITE/GOOGLE_OWNED_SERVICE/OTHER
          internal {
            contacts {
              email: "..."
            }
            contacts {
              email: "..."
            }
          }
          user_data {
            type: ...
          }
          last_reviewed: "YYYY-MM-DD"
        }
        policy {
          cookies_allowed: NO/YES
          cookies_store: "..."
          setting: "..."
          chrome_policy {
            [POLICY_NAME] {
                [POLICY_NAME]: ...
            }
          }
          policy_exception_justification = "..."
        }
        comments: "..."
      )");
}

// An example on one level traffic annotation.
void network_traffic_annotation_sample() {
  net::NetworkTrafficAnnotationTag traffic_annotation =
      net::DefineNetworkTrafficAnnotation("spellcheck_lookup", R"(
        semantics {
          sender: "Online Spellcheck"
          description:
            "Chrome can provide smarter spell-checking by sending text you "
            "type into the browser to Google's servers, allowing you to use "
            "the same spell-checking technology used by Google products, such "
            "as Docs. If the feature is enabled, Chrome will send the entire "
            "contents of text fields as you type in them to Google along with "
            "the browser’s default language. Google returns a list of "
            "suggested spellings, which will be displayed in the context menu."
          trigger: "User types text into a text field or asks to correct a "
                   "misspelled word."
          data: "Text a user has typed into a text field. No user identifier "
                "is sent along with the text."
          destination: GOOGLE_OWNED_SERVICE
          internal {
            contacts {
              email: "john-doe@chromium.org"
            }
            contacts {
              email: "spellcheck-team@google.com"
            }
          }
          user_data {
            type: USER_CONTENT
          }
          last_reviewed: "2023-01-01"
        }
        policy {
          cookies_allowed: NO
          setting:
            "You can enable or disable this feature via 'Use a web service to "
            "help resolve spelling errors.' in Chrome's settings under "
            "Advanced. The feature is disabled by default."
          chrome_policy {
            SpellCheckServiceEnabled {
                SpellCheckServiceEnabled: false
            }
          }
        })");
}

// Example for Nx1 partial annotations where the partial annotations are defined
// in PrefetchImage1 and PrefetchImage2, and the completing annotation is
// defined in GetBitmap. Partial annotations are missing cookies fields and are
// completed in GetBitmap function.
void PrefetchImage1(const GURL& url) {
  net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation =
      net::DefinePartialNetworkTrafficAnnotation("omnibox_prefetch_image",
                                                 "bitmap_fetcher",
                                                 R"(
        semantics {
          sender: "Omnibox"
          description:
            "Chromium provides answers in the suggestion list for certain "
            "queries that the user types in the omnibox. This request "
            "retrieves a small image (for example, an icon illustrating the "
            "current weather conditions) when this can add information to an "
            "answer."
          trigger:
            "Change of results for the query typed by the user in the "
            "omnibox."
          data:
            "The only data sent is the path to an image. No user data is "
            "included, although some might be inferrable (e.g. whether the "
            "weather is sunny or rainy in the user's current location) from "
            "the name of the image in the path."
          destination: WEBSITE
          internal {
            contacts {
              email: "john-doe@chromium.org"
            }
            contacts {
              email: "omnibox-team@google.com"
            }
          }
          user_data {
            type: NONE
          }
          last_reviewed: "2023-01-01"
        }
        policy {
          setting:
            "You can enable or disable this feature via 'Use a prediction "
            "service to help complete searches and URLs typed in the "
            "address bar.' in Chromium's settings under Advanced. The "
            "feature is enabled by default."
          chrome_policy {
            SearchSuggestEnabled {
                SearchSuggestEnabled: false
            }
          }
        })");
  GetBitmap(url, partial_traffic_annotation);
}

void PrefetchImage2(const GURL& url) {
  net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation =
      net::DefinePartialNetworkTrafficAnnotation("credential_avatar",
                                                 "bitmap_fetcher",
                                                 R"(
        semantics {
          sender: "Chrome Password Manager"
          description:
            "Every credential saved in Chromium via the Credential Management "
            "API can have an avatar URL. The URL is essentially provided by "
            "the site calling the API. The avatar is used in the account "
            "chooser UI and auto signin toast which appear when a site calls "
            "navigator.credentials.get(). The avatar is retrieved before "
            "showing the UI."
          trigger:
            "User visits a site that calls navigator.credentials.get(). "
            "Assuming there are matching credentials in the Chromium password "
            "store, the avatars are retrieved."
          destination: WEBSITE
          internal {
            contacts {
              email: "john-doe@chromium.org"
            }
            contacts {
              email: "password-manager-team@google.com"
            }
          }
          user_data {
            type: SENSITIVE_URL
            type: ACCESS_TOKEN
          }
          last_reviewed: "2023-01-01"
        }
        policy {
          setting:
            "One can disable saving new credentials in the settings (see "
            "'Passwords and forms'). There is no setting to disable the API."
          chrome_policy {
            PasswordManagerEnabled {
                PasswordManagerEnabled: false
            }
          }
        })");
  GetBitmap(url, partial_traffic_annotation);
}

void GetBitmap(
    const GURL& url,
    const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) {
  net::NetworkTrafficAnnotationTag traffic_annotation =
      net::CompleteNetworkTrafficAnnotation("bitmap_fetcher",
                                            partial_traffic_annotation,
                                            R"(
              policy {
                cookies_allowed: YES
                cookies_store: "user"
              })");
  url_fetcher_ = net::URLFetcher::Create(url, net::URLFetcher::GET, this,
                                         traffic_annotation);
  ...
}

// Example for 1xN partial annoations where the partial annotation is defined in
// UploadLog and two completing annotations are defined
// in GetNetworkTrafficAnnotation. The partial annotation is missing |sender|
// and |description| fields and is completed in GetNetworkTrafficAnnotation.
net::NetworkTrafficAnnotationTag GetNetworkTrafficAnnotation(
    const bool& uma_service_type,
    const net::PartialNetworkTrafficAnnotationTag& partial_traffic_annotation) {
  if (uma_service_type) {
    return net::BranchedCompleteNetworkTrafficAnnotation(
        "metrics_report_uma", "metrics_report_based_on_service_type",
        partial_traffic_annotation, R"(
        semantics {
          sender: "Metrics UMA Log Uploader"
          description:
            "Report of usage statistics and crash-related data about Chromium. "
            "Usage statistics contain information such as preferences, button "
            "clicks, and memory usage and do not include web page URLs or "
            "personal information. See more at "
            "https://www.google.com/chrome/browser/privacy/ under 'Usage "
            "statistics and crash reports'. Usage statistics are tied to a "
            "pseudonymous machine identifier and not to your email address."
        })");
  } else {
    return net::BranchedCompleteNetworkTrafficAnnotation(
        "metrics_report_ukm", "metrics_report_based_on_service_type",
        partial_traffic_annotation, R"(
        semantics {
          sender: "Metrics UKM Log Uploader"
          description:
            "Report of usage statistics that are keyed by URLs to Chromium, "
            "sent only if the profile has History Sync. This includes "
            "information about the web pages you visit and your usage of them, "
            "such as page load speed. This will also include URLs and "
            "statistics related to downloaded files. If Extension Sync is "
            "enabled, these statistics will also include information about "
            "the extensions that have been installed from Chrome Web Store. "
            "Google only stores usage statistics associated with published "
            "extensions, and URLs that are known by Google’s search index. "
            "Usage statistics are tied to a pseudonymous machine identifier "
            "and not to your email address."
        })");
  }
}

void UploadLog(const bool& uma_service_type) {
  const GURL &url,
      net::PartialNetworkTrafficAnnotationTag partial_traffic_annotation =
          net::DefinePartialNetworkTrafficAnnotation(
              "net_metrics_report", "metrics_report_based_on_service_type",
              R"(
        semantics {
          trigger:
            "Reports are automatically generated on startup and at intervals "
            "while Chromium is running."
          data:
            "A protocol buffer with usage statistics and crash related data."
          destination: GOOGLE_OWNED_SERVICE
          internal {
            contacts {
              email: "john-doe@chromium.org"
            }
            contacts {
              email: "metrics-team@google.com"
            }
          }
          user_data {
            type: OTHER
          }
          last_reviewed: "2023-01-01"
        }
        policy {
          cookies_allowed: NO
          setting:
            "Users can enable or disable this feature by disabling "
            "'Automatically send usage statistics and crash reports to Google' "
            "in Chromium's settings under Advanced Settings, Privacy. The "
            "feature is enabled by default."
          chrome_policy {
            MetricsReportingEnabled {
              MetricsReportingEnabled: false
            }
          }
        })");

  current_fetch_ = net::URLFetcher::Create(
      url, net::URLFetcher::POST, this,
      GetNetworkTrafficAnnotation(uma_service_type,
                                  partial_traffic_annotation));

  ...
}