1 # Copyright 2014 The Chromium Authors
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import("//build/buildflag_header.gni")
6 import("//build/config/chrome_build.gni")
7 import("//build/config/features.gni")
8 import("//extensions/buildflags/buildflags.gni")
9 import("//testing/test.gni")
10 import("//third_party/protobuf/proto_library.gni")
13 # Set the variable 'use_official_google_api_keys' to true
14 # to use the Google-internal file containing official API keys
15 # even in a developer build. Setting this variable explicitly to
16 # true will cause the build to fail if the internal file is missing.
18 # Set the variable to false to not use the internal file, even for
19 # Chrome-branded builds or when it exists in your checkout.
21 # Leave it set to "" to have the variable implicitly set to true for
22 # Chrome-branded builds or if
23 # //src/google_apis/internal/google_chrome_api_keys.h is present and false
25 # This does not apply to iOS builds, which use different mechanisms and always
26 # evaluate to use_official_google_api_keys=false.
27 # See https://crbug.com/1183709.
28 use_official_google_api_keys = ""
30 # Set these to bake the specified API keys and OAuth client
31 # IDs/secrets into your build.
33 # If you create a build without values baked in, you can instead
34 # set environment variables to provide the keys at runtime (see
35 # src/google_apis/google_api_keys.h for details). Features that
36 # require server-side APIs may fail to work if no keys are
39 # Note that if `use_official_google_api_keys` has been set to true
40 # (explicitly or implicitly), these values will be ignored and the official
41 # keys will be used instead.
45 google_default_client_id = ""
48 google_default_client_secret = ""
51 if (use_official_google_api_keys == "") {
52 # No override set. Determine the default behavior.
53 if (is_chrome_branded) {
54 # Chrome-branded builds default to behaving as if
55 #`use_official_google_api_keys` was explicitly set to true and will fail to
56 # build if the file is missing.
57 use_official_google_api_keys = true
59 # TODO(crbug.com/1294931): Remove this override when fixing the issue.
61 use_official_google_api_keys = false
64 # Check if the key file exists.
65 check_internal_result =
66 exec_script("build/check_internal.py",
67 [ rebase_path("internal/google_chrome_api_keys.h",
70 use_official_google_api_keys = check_internal_result == 1
74 # Official API keys should always be used for Chrome-branded builds except on
75 # iOS (see https://crbug.com/1183709) and Fuchsia (see the description of
76 # https://crbug.com/1171510 for background).
78 use_official_google_api_keys || !is_chrome_branded || is_ios || is_fuchsia)
81 # Whether the SetAPIKey() method is defined.
82 # iOS and Fuchsia builds that do not use the built-in key use this.
83 support_external_google_api_key =
84 is_ios || (is_fuchsia && !use_official_google_api_keys)
87 # internal:generate_metrics_key_header must be a deps when
88 # USE_OFFICIAL_GOOGLE_API_KEYS` is defined. Use this variable for both.
89 # On iOS, Chrome branding had been overriding use_official_google_api_keys.
90 # TODO(crbug.com/1362160): Fix this logic on iOS. Can this variable be replaced
91 # with just use_official_google_api_keys?
92 _use_official_google_keys_and_generate_metrics_key_header =
93 use_official_google_api_keys || (is_ios && is_chrome_branded)
95 buildflag_header("buildflags") {
96 header = "buildflags.h"
97 flags = [ "SUPPORT_EXTERNAL_GOOGLE_API_KEY=$support_external_google_api_key" ]
100 config("key_defines") {
103 if (_use_official_google_keys_and_generate_metrics_key_header) {
104 defines += [ "USE_OFFICIAL_GOOGLE_API_KEYS=1" ]
106 if (google_api_key != "") {
107 defines += [ "GOOGLE_API_KEY=\"$google_api_key\"" ]
109 if (google_default_client_id != "") {
110 defines += [ "GOOGLE_DEFAULT_CLIENT_ID=\"$google_default_client_id\"" ]
112 if (google_default_client_secret != "") {
114 [ "GOOGLE_DEFAULT_CLIENT_SECRET=\"$google_default_client_secret\"" ]
119 # deps: Extra dependencies
120 template("google_apis_tmpl") {
121 source_set(target_name) {
123 "gaia/core_account_id.cc",
124 "gaia/core_account_id.h",
125 "gaia/gaia_access_token_fetcher.cc",
126 "gaia/gaia_access_token_fetcher.h",
127 "gaia/gaia_auth_consumer.cc",
128 "gaia/gaia_auth_consumer.h",
129 "gaia/gaia_auth_fetcher.cc",
130 "gaia/gaia_auth_fetcher.h",
131 "gaia/gaia_auth_util.cc",
132 "gaia/gaia_auth_util.h",
133 "gaia/gaia_config.cc",
134 "gaia/gaia_config.h",
135 "gaia/gaia_constants.cc",
136 "gaia/gaia_constants.h",
137 "gaia/gaia_oauth_client.cc",
138 "gaia/gaia_oauth_client.h",
139 "gaia/gaia_switches.cc",
140 "gaia/gaia_switches.h",
143 "gaia/google_service_auth_error.cc",
144 "gaia/google_service_auth_error.h",
145 "gaia/oauth2_access_token_consumer.cc",
146 "gaia/oauth2_access_token_consumer.h",
147 "gaia/oauth2_access_token_fetcher.cc",
148 "gaia/oauth2_access_token_fetcher.h",
149 "gaia/oauth2_access_token_fetcher_immediate_error.cc",
150 "gaia/oauth2_access_token_fetcher_immediate_error.h",
151 "gaia/oauth2_access_token_fetcher_impl.cc",
152 "gaia/oauth2_access_token_fetcher_impl.h",
153 "gaia/oauth2_access_token_manager.cc",
154 "gaia/oauth2_access_token_manager.h",
155 "gaia/oauth2_api_call_flow.cc",
156 "gaia/oauth2_api_call_flow.h",
157 "gaia/oauth2_id_token_decoder.cc",
158 "gaia/oauth2_id_token_decoder.h",
159 "gaia/oauth2_mint_token_flow.cc",
160 "gaia/oauth2_mint_token_flow.h",
161 "gaia/oauth_multilogin_result.cc",
162 "gaia/oauth_multilogin_result.h",
163 "gaia/oauth_request_signer.cc",
164 "gaia/oauth_request_signer.h",
165 "google_api_keys.cc",
169 configs += [ ":key_defines" ]
171 public_deps = [ ":buildflags" ]
174 ":oauth2_mint_token_consent_result_proto",
176 "//base/third_party/dynamic_annotations",
177 "//build:branding_buildflags",
178 "//build:chromeos_buildflags",
180 "//mojo/public/cpp/bindings:struct_traits",
181 "//services/network/public/cpp",
184 if (_use_official_google_keys_and_generate_metrics_key_header) {
185 deps += [ "internal:generate_metrics_key_header" ]
188 if (defined(invoker.deps)) {
194 "google_api_keys_mac.h",
195 "google_api_keys_mac.mm",
198 frameworks = [ "Foundation.framework" ]
203 google_apis_tmpl("google_apis") {
206 "//services/network/public/cpp",
207 "//services/network/public/mojom",
211 proto_library("oauth2_mint_token_consent_result_proto") {
212 sources = [ "gaia/oauth2_mint_token_consent_result.proto" ]
215 static_library("test_support") {
218 "gaia/core_account_id_for_testing.cc",
221 "gaia/fake_oauth2_access_token_manager.cc",
222 "gaia/fake_oauth2_access_token_manager.h",
223 "gaia/oauth2_access_token_manager_test_util.cc",
224 "gaia/oauth2_access_token_manager_test_util.h",
230 "//base/test:test_support",
231 "//net:test_support",
232 "//services/network:network_service",
233 "//services/network:test_support",
234 "//services/network/public/cpp",
238 source_set("run_all_unittests") {
240 sources = [ "run_all_unittests.cc" ]
243 "//base/test:test_support",
244 "//mojo/core/embedder",
248 test("google_apis_unittests") {
250 "gaia/gaia_auth_fetcher_unittest.cc",
251 "gaia/gaia_auth_util_unittest.cc",
252 "gaia/gaia_config_unittest.cc",
253 "gaia/gaia_oauth_client_unittest.cc",
254 "gaia/gaia_urls_unittest.cc",
255 "gaia/google_service_auth_error_unittest.cc",
256 "gaia/oauth2_access_token_fetcher_impl_unittest.cc",
257 "gaia/oauth2_access_token_manager_unittest.cc",
258 "gaia/oauth2_api_call_flow_unittest.cc",
259 "gaia/oauth2_id_token_decoder_unittest.cc",
260 "gaia/oauth2_mint_token_flow_unittest.cc",
261 "gaia/oauth_multilogin_result_unittest.cc",
262 "gaia/oauth_request_signer_unittest.cc",
263 "google_api_keys_unittest.cc",
264 "google_api_keys_unittest.h",
267 configs += [ ":key_defines" ]
271 ":oauth2_mint_token_consent_result_proto",
272 ":run_all_unittests",
275 "//base/test:test_support",
276 "//build:branding_buildflags",
277 "//build:chromeos_buildflags",
278 "//google_apis/calendar:calendar_unittests",
279 "//google_apis/common:common_unittests",
285 deps += [ ":google_apis_unittest_bundle_data" ]
291 deps += [ "//net/android:net_java" ]
295 additional_manifest_fragments =
296 [ "//build/config/fuchsia/test/network.shard.test-cml" ]
299 if (enable_extensions) {
300 deps += [ "//google_apis/drive:drive_unittests" ]
304 sources += [ "google_api_keys_mac_unittest.mm" ]
306 deps += [ "//third_party/ocmock" ]
310 bundle_data("google_apis_unittest_bundle_data") {
313 "test/data/calendar/event_self_response_statuses.json",
314 "test/data/calendar/event_statuses.json",
315 "test/data/calendar/events.json",
316 "test/data/calendar/invalid_events.json",
317 "test/data/gaia/all_base_urls.json",
318 "test/data/gaia/all_urls.json",
319 "test/data/gaia/api_keys.json",
320 "test/data/gaia/bad_url.json",
321 "test/data/gaia/bad_url_key.json",
322 "test/data/gaia/bad_urls_key.json",
323 "test/data/gaia/not_a_json.txt",
324 "test/data/gaia/one_base_url.json",
325 "test/data/gaia/one_url.json",
327 outputs = [ "{{bundle_resources_dir}}/" +
328 "{{source_root_relative_dir}}/{{source_file_part}}" ]