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
google_apis / BUILD.gn [blame]
# Copyright 2014 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/buildflag_header.gni")
import("//build/config/chrome_build.gni")
import("//build/config/chromeos/ui_mode.gni")
import("//build/config/features.gni")
import("//extensions/buildflags/buildflags.gni")
import("//testing/test.gni")
import("//third_party/protobuf/proto_library.gni")
declare_args() {
# Set the variable 'use_official_google_api_keys' to true
# to use the Google-internal file containing official API keys
# even in a developer build. Setting this variable explicitly to
# true will cause the build to fail if the internal file is missing.
#
# Set the variable to false to not use the internal file, even for
# Chrome-branded builds or when it exists in your checkout.
#
# Leave it set to "" to have the variable implicitly set to true for
# Chrome-branded builds or if
# //src/google_apis/internal/google_chrome_api_keys.h is present and false
# otherwise.
# This does not apply to iOS builds, which use different mechanisms and always
# evaluate to use_official_google_api_keys=false.
# See https://crbug.com/1183709.
use_official_google_api_keys = ""
# Set these to bake the specified API keys and OAuth client
# IDs/secrets into your build.
#
# If you create a build without values baked in, you can instead
# set environment variables to provide the keys at runtime (see
# src/google_apis/google_api_keys.h for details). Features that
# require server-side APIs may fail to work if no keys are
# provided.
#
# Note that if `use_official_google_api_keys` has been set to true
# (explicitly or implicitly), these values will be ignored and the official
# keys will be used instead.
google_api_key = ""
# See google_api_key.
google_default_client_id = ""
# See google_api_key.
google_default_client_secret = ""
}
if (use_official_google_api_keys == "") {
# No override set. Determine the default behavior.
if (is_chrome_branded) {
# Chrome-branded builds default to behaving as if
#`use_official_google_api_keys` was explicitly set to true and will fail to
# build if the file is missing.
use_official_google_api_keys = true
} else {
# Check if the key file exists.
check_internal_result =
exec_script("build/check_internal.py",
[ rebase_path("internal/google_chrome_api_keys.h",
root_build_dir) ],
"value")
use_official_google_api_keys = check_internal_result == 1
}
}
# Official API keys should always be used for Chrome-branded builds except on
# iOS (see https://crbug.com/1183709) and Fuchsia (see the description of
# https://crbug.com/1171510 for background).
assert(
use_official_google_api_keys || !is_chrome_branded || is_ios || is_fuchsia)
declare_args() {
# Whether the SetAPIKey() method is defined.
# iOS and Fuchsia builds that do not use the built-in key use this.
support_external_google_api_key =
is_ios || (is_fuchsia && !use_official_google_api_keys)
}
# internal:generate_metrics_key_header must be a deps when
# USE_OFFICIAL_GOOGLE_API_KEYS` is defined. Use this variable for both.
# On iOS, Chrome branding had been overriding use_official_google_api_keys.
# TODO(crbug.com/40864074): Fix this logic on iOS. Can this variable be replaced
# with just use_official_google_api_keys?
_use_official_google_keys_and_generate_metrics_key_header =
use_official_google_api_keys || (is_ios && is_chrome_branded)
buildflag_header("buildflags") {
header = "buildflags.h"
flags = [ "SUPPORT_EXTERNAL_GOOGLE_API_KEY=$support_external_google_api_key" ]
}
config("key_defines") {
defines = []
if (_use_official_google_keys_and_generate_metrics_key_header) {
defines += [ "USE_OFFICIAL_GOOGLE_API_KEYS=1" ]
}
if (google_api_key != "") {
defines += [ "GOOGLE_API_KEY=\"$google_api_key\"" ]
}
if (google_default_client_id != "") {
defines += [ "GOOGLE_DEFAULT_CLIENT_ID=\"$google_default_client_id\"" ]
}
if (google_default_client_secret != "") {
defines +=
[ "GOOGLE_DEFAULT_CLIENT_SECRET=\"$google_default_client_secret\"" ]
}
}
component("google_apis") {
sources = [
"api_key_cache.cc",
"api_key_cache.h",
"credentials_mode.cc",
"credentials_mode.h",
"default_api_keys-inc.cc",
"default_api_keys.h",
"gaia/core_account_id.cc",
"gaia/core_account_id.h",
"gaia/gaia_access_token_fetcher.cc",
"gaia/gaia_access_token_fetcher.h",
"gaia/gaia_auth_consumer.cc",
"gaia/gaia_auth_consumer.h",
"gaia/gaia_auth_fetcher.cc",
"gaia/gaia_auth_fetcher.h",
"gaia/gaia_auth_util.cc",
"gaia/gaia_auth_util.h",
"gaia/gaia_config.cc",
"gaia/gaia_config.h",
"gaia/gaia_constants.cc",
"gaia/gaia_constants.h",
"gaia/gaia_id.cc",
"gaia/gaia_id.h",
"gaia/gaia_oauth_client.cc",
"gaia/gaia_oauth_client.h",
"gaia/gaia_switches.cc",
"gaia/gaia_switches.h",
"gaia/gaia_urls.cc",
"gaia/gaia_urls.h",
"gaia/google_service_auth_error.cc",
"gaia/google_service_auth_error.h",
"gaia/oauth2_access_token_consumer.cc",
"gaia/oauth2_access_token_consumer.h",
"gaia/oauth2_access_token_fetcher.cc",
"gaia/oauth2_access_token_fetcher.h",
"gaia/oauth2_access_token_fetcher_immediate_error.cc",
"gaia/oauth2_access_token_fetcher_immediate_error.h",
"gaia/oauth2_access_token_fetcher_impl.cc",
"gaia/oauth2_access_token_fetcher_impl.h",
"gaia/oauth2_access_token_manager.cc",
"gaia/oauth2_access_token_manager.h",
"gaia/oauth2_api_call_flow.cc",
"gaia/oauth2_api_call_flow.h",
"gaia/oauth2_id_token_decoder.cc",
"gaia/oauth2_id_token_decoder.h",
"gaia/oauth2_mint_access_token_fetcher_adapter.cc",
"gaia/oauth2_mint_access_token_fetcher_adapter.h",
"gaia/oauth2_mint_token_flow.cc",
"gaia/oauth2_mint_token_flow.h",
"gaia/oauth_multilogin_result.cc",
"gaia/oauth_multilogin_result.h",
"gaia/token_binding_response_encryption_error.h",
"google_api_keys.cc",
"google_api_keys.h",
]
configs += [
":key_defines",
"//build/config/compiler:wexit_time_destructors",
]
public_deps = [
":buildflags",
"//base",
"//build:chromeos_buildflags",
"//services/network/public/cpp",
]
deps = [
":proto",
"//base/version_info:channel",
"//build:branding_buildflags",
"//build:chromeos_buildflags",
"//crypto",
"//mojo/public/cpp/bindings:struct_traits",
"//net",
"//services/network/public/mojom",
]
if (_use_official_google_keys_and_generate_metrics_key_header) {
deps += [ "internal:generate_metrics_key_header" ]
}
if (is_apple) {
sources += [
"google_api_keys_mac.h",
"google_api_keys_mac.mm",
]
frameworks = [ "Foundation.framework" ]
}
defines = [ "IS_GOOGLE_APIS_IMPL" ]
}
proto_library("proto") {
sources = [
"gaia/bound_oauth_token.proto",
"gaia/oauth2_mint_token_consent_result.proto",
]
}
static_library("test_support") {
testonly = true
sources = [
"gaia/fake_gaia.cc",
"gaia/fake_gaia.h",
"gaia/fake_oauth2_access_token_manager.cc",
"gaia/fake_oauth2_access_token_manager.h",
"gaia/gaia_auth_test_util.cc",
"gaia/gaia_auth_test_util.h",
"gaia/gaia_urls_overrider_for_testing.cc",
"gaia/gaia_urls_overrider_for_testing.h",
"gaia/oauth2_access_token_manager_test_util.cc",
"gaia/oauth2_access_token_manager_test_util.h",
]
public_deps = [
":google_apis",
":proto",
"//base",
"//base/test:test_support",
"//net:test_support",
"//services/network:network_service",
"//services/network:test_support",
"//services/network/public/cpp",
]
}
source_set("run_all_unittests") {
testonly = true
sources = [ "run_all_unittests.cc" ]
deps = [
"//base/test:test_support",
"//mojo/core/embedder",
]
}
test("google_apis_unittests") {
sources = [
"gaia/gaia_auth_fetcher_unittest.cc",
"gaia/gaia_auth_util_unittest.cc",
"gaia/gaia_config_unittest.cc",
"gaia/gaia_oauth_client_unittest.cc",
"gaia/gaia_urls_unittest.cc",
"gaia/google_service_auth_error_unittest.cc",
"gaia/oauth2_access_token_fetcher_impl_unittest.cc",
"gaia/oauth2_access_token_manager_unittest.cc",
"gaia/oauth2_api_call_flow_unittest.cc",
"gaia/oauth2_id_token_decoder_unittest.cc",
"gaia/oauth2_mint_access_token_fetcher_adapter_unittest.cc",
"gaia/oauth2_mint_token_flow_unittest.cc",
"gaia/oauth_multilogin_result_unittest.cc",
"google_api_keys_unittest.cc",
"google_api_keys_unittest.h",
]
configs += [ ":key_defines" ]
deps = [
":google_apis",
":proto",
":run_all_unittests",
":test_support",
"//base",
"//base/test:test_support",
"//base/version_info:channel",
"//build:branding_buildflags",
"//build:chromeos_buildflags",
"//google_apis/calendar:calendar_unittests",
"//google_apis/common:common_unittests",
"//testing/gmock",
"//testing/gtest",
]
if (is_ios) {
deps += [ ":google_apis_unittest_bundle_data" ]
} else {
data = [ "test/" ]
}
if (is_android) {
deps += [ "//net/android:net_java" ]
}
if (is_fuchsia) {
additional_manifest_fragments =
[ "//build/config/fuchsia/test/network.shard.test-cml" ]
}
if (enable_extensions) {
deps += [ "//google_apis/drive:drive_unittests" ]
}
if (is_apple) {
sources += [ "google_api_keys_mac_unittest.mm" ]
deps += [ "//third_party/ocmock" ]
}
if (is_chromeos) {
deps += [
"//google_apis/classroom:classroom_unittests",
"//google_apis/people:people_unittest_sources",
"//google_apis/tasks:tasks_unittests",
"//google_apis/youtube_music:youtube_music_unittests",
]
}
}
bundle_data("google_apis_unittest_bundle_data") {
testonly = true
sources = [
"test/data/calendar/calendar_list.json",
"test/data/calendar/event_self_response_statuses.json",
"test/data/calendar/event_statuses.json",
"test/data/calendar/event_with_attachments.json",
"test/data/calendar/event_with_invalid_attachments.json",
"test/data/calendar/event_with_invalid_conference_data_uri.json",
"test/data/calendar/event_with_missing_entry_point_type.json",
"test/data/calendar/events.json",
"test/data/calendar/invalid_events.json",
"test/data/gaia/all_base_urls.json",
"test/data/gaia/all_urls.json",
"test/data/gaia/api_keys.json",
"test/data/gaia/bad_url.json",
"test/data/gaia/bad_url_key.json",
"test/data/gaia/bad_urls_key.json",
"test/data/gaia/not_a_json.txt",
"test/data/gaia/one_base_url.json",
"test/data/gaia/one_url.json",
"test/data/tasks/task.json",
"test/data/tasks/task_lists.json",
"test/data/tasks/tasks.json",
]
outputs = [ "{{bundle_resources_dir}}/" +
"{{source_root_relative_dir}}/{{source_file_part}}" ]
}