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/chromeos/ui_mode.gni")
8 import("//build/config/features.gni")
9 import("//extensions/buildflags/buildflags.gni")
10 import("//testing/test.gni")
11 import("//third_party/protobuf/proto_library.gni")
14 # Set the variable 'use_official_google_api_keys' to true
15 # to use the Google-internal file containing official API keys
16 # even in a developer build. Setting this variable explicitly to
17 # true will cause the build to fail if the internal file is missing.
19 # Set the variable to false to not use the internal file, even for
20 # Chrome-branded builds or when it exists in your checkout.
22 # Leave it set to "" to have the variable implicitly set to true for
23 # Chrome-branded builds or if
24 # //src/google_apis/internal/google_chrome_api_keys.h is present and false
26 # This does not apply to iOS builds, which use different mechanisms and always
27 # evaluate to use_official_google_api_keys=false.
28 # See https://crbug.com/1183709.
29 use_official_google_api_keys = ""
31 # Set these to bake the specified API keys and OAuth client
32 # IDs/secrets into your build.
34 # If you create a build without values baked in, you can instead
35 # set environment variables to provide the keys at runtime (see
36 # src/google_apis/google_api_keys.h for details). Features that
37 # require server-side APIs may fail to work if no keys are
40 # Note that if `use_official_google_api_keys` has been set to true
41 # (explicitly or implicitly), these values will be ignored and the official
42 # keys will be used instead.
46 google_default_client_id = ""
49 google_default_client_secret = ""
52 if (use_official_google_api_keys == "") {
53 # No override set. Determine the default behavior.
54 if (is_chrome_branded) {
55 # Chrome-branded builds default to behaving as if
56 #`use_official_google_api_keys` was explicitly set to true and will fail to
57 # build if the file is missing.
58 use_official_google_api_keys = true
60 # Check if the key file exists.
61 check_internal_result =
62 exec_script("build/check_internal.py",
63 [ rebase_path("internal/google_chrome_api_keys.h",
66 use_official_google_api_keys = check_internal_result == 1
70 # Official API keys should always be used for Chrome-branded builds except on
71 # iOS (see https://crbug.com/1183709) and Fuchsia (see the description of
72 # https://crbug.com/1171510 for background).
74 use_official_google_api_keys || !is_chrome_branded || is_ios || is_fuchsia)
77 # Whether the SetAPIKey() method is defined.
78 # iOS and Fuchsia builds that do not use the built-in key use this.
79 support_external_google_api_key =
80 is_ios || (is_fuchsia && !use_official_google_api_keys)
83 # internal:generate_metrics_key_header must be a deps when
84 # USE_OFFICIAL_GOOGLE_API_KEYS` is defined. Use this variable for both.
85 # On iOS, Chrome branding had been overriding use_official_google_api_keys.
86 # TODO(crbug.com/1362160): Fix this logic on iOS. Can this variable be replaced
87 # with just use_official_google_api_keys?
88 _use_official_google_keys_and_generate_metrics_key_header =
89 use_official_google_api_keys || (is_ios && is_chrome_branded)
91 buildflag_header("buildflags") {
92 header = "buildflags.h"
93 flags = [ "SUPPORT_EXTERNAL_GOOGLE_API_KEY=$support_external_google_api_key" ]
96 config("key_defines") {
99 if (_use_official_google_keys_and_generate_metrics_key_header) {
100 defines += [ "USE_OFFICIAL_GOOGLE_API_KEYS=1" ]
102 if (google_api_key != "") {
103 defines += [ "GOOGLE_API_KEY=\"$google_api_key\"" ]
105 if (google_default_client_id != "") {
106 defines += [ "GOOGLE_DEFAULT_CLIENT_ID=\"$google_default_client_id\"" ]
108 if (google_default_client_secret != "") {
110 [ "GOOGLE_DEFAULT_CLIENT_SECRET=\"$google_default_client_secret\"" ]
114 component("google_apis") {
116 "credentials_mode.cc",
117 "credentials_mode.h",
118 "gaia/core_account_id.cc",
119 "gaia/core_account_id.h",
120 "gaia/gaia_access_token_fetcher.cc",
121 "gaia/gaia_access_token_fetcher.h",
122 "gaia/gaia_auth_consumer.cc",
123 "gaia/gaia_auth_consumer.h",
124 "gaia/gaia_auth_fetcher.cc",
125 "gaia/gaia_auth_fetcher.h",
126 "gaia/gaia_auth_util.cc",
127 "gaia/gaia_auth_util.h",
128 "gaia/gaia_config.cc",
129 "gaia/gaia_config.h",
130 "gaia/gaia_constants.cc",
131 "gaia/gaia_constants.h",
132 "gaia/gaia_oauth_client.cc",
133 "gaia/gaia_oauth_client.h",
134 "gaia/gaia_switches.cc",
135 "gaia/gaia_switches.h",
138 "gaia/google_service_auth_error.cc",
139 "gaia/google_service_auth_error.h",
140 "gaia/oauth2_access_token_consumer.cc",
141 "gaia/oauth2_access_token_consumer.h",
142 "gaia/oauth2_access_token_fetcher.cc",
143 "gaia/oauth2_access_token_fetcher.h",
144 "gaia/oauth2_access_token_fetcher_immediate_error.cc",
145 "gaia/oauth2_access_token_fetcher_immediate_error.h",
146 "gaia/oauth2_access_token_fetcher_impl.cc",
147 "gaia/oauth2_access_token_fetcher_impl.h",
148 "gaia/oauth2_access_token_manager.cc",
149 "gaia/oauth2_access_token_manager.h",
150 "gaia/oauth2_api_call_flow.cc",
151 "gaia/oauth2_api_call_flow.h",
152 "gaia/oauth2_id_token_decoder.cc",
153 "gaia/oauth2_id_token_decoder.h",
154 "gaia/oauth2_mint_access_token_fetcher_adapter.cc",
155 "gaia/oauth2_mint_access_token_fetcher_adapter.h",
156 "gaia/oauth2_mint_token_flow.cc",
157 "gaia/oauth2_mint_token_flow.h",
158 "gaia/oauth_multilogin_result.cc",
159 "gaia/oauth_multilogin_result.h",
160 "gaia/oauth_request_signer.cc",
161 "gaia/oauth_request_signer.h",
162 "google_api_keys.cc",
168 "//build/config/compiler:wexit_time_destructors",
174 "//build:chromeos_buildflags",
175 "//services/network/public/cpp",
179 ":oauth2_mint_token_consent_result_proto",
180 "//base/third_party/dynamic_annotations",
181 "//build:branding_buildflags",
182 "//build:chromeos_buildflags",
184 "//mojo/public/cpp/bindings:struct_traits",
186 "//services/network/public/mojom",
189 if (_use_official_google_keys_and_generate_metrics_key_header) {
190 deps += [ "internal:generate_metrics_key_header" ]
195 "google_api_keys_mac.h",
196 "google_api_keys_mac.mm",
199 frameworks = [ "Foundation.framework" ]
202 defines = [ "IS_GOOGLE_APIS_IMPL" ]
205 proto_library("oauth2_mint_token_consent_result_proto") {
206 sources = [ "gaia/oauth2_mint_token_consent_result.proto" ]
209 static_library("test_support") {
214 "gaia/fake_oauth2_access_token_manager.cc",
215 "gaia/fake_oauth2_access_token_manager.h",
216 "gaia/gaia_auth_test_util.cc",
217 "gaia/gaia_auth_test_util.h",
218 "gaia/gaia_urls_overrider_for_testing.cc",
219 "gaia/gaia_urls_overrider_for_testing.h",
220 "gaia/oauth2_access_token_manager_test_util.cc",
221 "gaia/oauth2_access_token_manager_test_util.h",
226 ":oauth2_mint_token_consent_result_proto",
228 "//base/test:test_support",
229 "//net:test_support",
230 "//services/network:network_service",
231 "//services/network:test_support",
232 "//services/network/public/cpp",
236 source_set("run_all_unittests") {
238 sources = [ "run_all_unittests.cc" ]
241 "//base/test:test_support",
242 "//mojo/core/embedder",
246 test("google_apis_unittests") {
248 "gaia/gaia_auth_fetcher_unittest.cc",
249 "gaia/gaia_auth_util_unittest.cc",
250 "gaia/gaia_config_unittest.cc",
251 "gaia/gaia_oauth_client_unittest.cc",
252 "gaia/gaia_urls_unittest.cc",
253 "gaia/google_service_auth_error_unittest.cc",
254 "gaia/oauth2_access_token_fetcher_impl_unittest.cc",
255 "gaia/oauth2_access_token_manager_unittest.cc",
256 "gaia/oauth2_api_call_flow_unittest.cc",
257 "gaia/oauth2_id_token_decoder_unittest.cc",
258 "gaia/oauth2_mint_access_token_fetcher_adapter_unittest.cc",
259 "gaia/oauth2_mint_token_flow_unittest.cc",
260 "gaia/oauth_multilogin_result_unittest.cc",
261 "gaia/oauth_request_signer_unittest.cc",
262 "google_api_keys_unittest.cc",
263 "google_api_keys_unittest.h",
266 configs += [ ":key_defines" ]
270 ":oauth2_mint_token_consent_result_proto",
271 ":run_all_unittests",
274 "//base/test:test_support",
275 "//build:branding_buildflags",
276 "//build:chromeos_buildflags",
277 "//google_apis/calendar:calendar_unittests",
278 "//google_apis/common:common_unittests",
284 deps += [ ":google_apis_unittest_bundle_data" ]
290 deps += [ "//net/android:net_java" ]
294 additional_manifest_fragments =
295 [ "//build/config/fuchsia/test/network.shard.test-cml" ]
298 if (enable_extensions) {
299 deps += [ "//google_apis/drive:drive_unittests" ]
303 sources += [ "google_api_keys_mac_unittest.mm" ]
305 deps += [ "//third_party/ocmock" ]
310 "//google_apis/classroom:classroom_unittests",
311 "//google_apis/tasks:tasks_unittests",
316 bundle_data("google_apis_unittest_bundle_data") {
319 "test/data/calendar/event_self_response_statuses.json",
320 "test/data/calendar/event_statuses.json",
321 "test/data/calendar/event_with_invalid_conference_data_uri.json",
322 "test/data/calendar/event_with_missing_entry_point_type.json",
323 "test/data/calendar/events.json",
324 "test/data/calendar/invalid_events.json",
325 "test/data/gaia/all_base_urls.json",
326 "test/data/gaia/all_urls.json",
327 "test/data/gaia/api_keys.json",
328 "test/data/gaia/bad_url.json",
329 "test/data/gaia/bad_url_key.json",
330 "test/data/gaia/bad_urls_key.json",
331 "test/data/gaia/not_a_json.txt",
332 "test/data/gaia/one_base_url.json",
333 "test/data/gaia/one_url.json",
334 "test/data/tasks/task.json",
335 "test/data/tasks/task_lists.json",
336 "test/data/tasks/tasks.json",
338 outputs = [ "{{bundle_resources_dir}}/" +
339 "{{source_root_relative_dir}}/{{source_file_part}}" ]