| # 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("//extensions/buildflags/buildflags.gni") | 
 | import("//google_apis/config.gni") | 
 | import("//testing/test.gni") | 
 | import("//third_party/protobuf/proto_library.gni") | 
 |  | 
 | declare_args() { | 
 |   # 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_internal_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_internal_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_features.cc", | 
 |     "gaia/gaia_features.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/oauth2_response.h", | 
 |     "gaia/oauth_multilogin_result.cc", | 
 |     "gaia/oauth_multilogin_result.h", | 
 |     "gaia/register_bound_session_payload.cc", | 
 |     "gaia/register_bound_session_payload.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", | 
 |     "//services/network/public/cpp", | 
 |   ] | 
 |  | 
 |   deps = [ | 
 |     ":proto", | 
 |     "//build:branding_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", | 
 |     ] | 
 |  | 
 |     if (is_ios) { | 
 |       sources += [ "gaia/gaia_id_ios.mm" ] | 
 |     } | 
 |  | 
 |     frameworks = [ "Foundation.framework" ] | 
 |   } | 
 |  | 
 |   if (is_android) { | 
 |     deps += [ "gaia/android:jni_headers" ] | 
 |   } | 
 |  | 
 |   defines = [ "IS_GOOGLE_APIS_IMPL" ] | 
 | } | 
 |  | 
 | proto_library("proto") { | 
 |   sources = [ | 
 |     "gaia/bound_oauth_token.proto", | 
 |     "gaia/list_accounts_response.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/fake_oauth2_token_response.cc", | 
 |     "gaia/fake_oauth2_token_response.h", | 
 |     "gaia/gaia_auth_test_util.cc", | 
 |     "gaia/gaia_auth_test_util.h", | 
 |     "gaia/gaia_id_literal.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/fake_oauth2_token_response_unittest.cc", | 
 |     "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", | 
 |     "gaia/register_bound_session_payload_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", | 
 |     "//build:branding_buildflags", | 
 |     "//google_apis/calendar:calendar_unittests", | 
 |     "//google_apis/common:common_unittests", | 
 |     "//testing/gmock", | 
 |     "//testing/gtest", | 
 |     "//third_party/protobuf:protobuf_lite", | 
 |   ] | 
 |  | 
 |   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", | 
 |     ] | 
 |   } | 
 |  | 
 |   # TODO(crbug.com/40031409): Fix code that adds exit-time destructors and | 
 |   # enable the diagnostic by removing this line. | 
 |   configs += [ "//build/config/compiler:no_exit_time_destructors" ] | 
 | } | 
 |  | 
 | 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}}" ] | 
 | } |