Skip to content

Commit

Permalink
Make //google_apis a component
Browse files Browse the repository at this point in the history
Multiple components depend on build target //google_apis which is
against recommended practices in [1] and specifically runs into issues
when new singleton-like state, include base::Feature instances, are
added to //google_apis.

Following recommended practices, this patch makes //google_apis a
component itself, as all targets it depends on are already components.

[1] https://chromium.googlesource.com/chromium/src/+/main/docs/component_build.md#dependencies-between-targets

Change-Id: I9c14050314b208791d7d5773ab76a7913c422bd9
Fixed: 1417961
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4272614
Reviewed-by: Jamie Walch <jamiewalch@chromium.org>
Reviewed-by: Alex Ilin <alexilin@chromium.org>
Commit-Queue: Mikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1107876}
  • Loading branch information
Mikel Astiz authored and Chromium LUCI CQ committed Feb 21, 2023
1 parent e2f91c6 commit a08ea66
Show file tree
Hide file tree
Showing 25 changed files with 243 additions and 187 deletions.
160 changes: 74 additions & 86 deletions google_apis/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -110,100 +110,88 @@ config("key_defines") {
}
}

# Variables:
# deps: Extra dependencies
template("google_apis_tmpl") {
source_set(target_name) {
sources = [
"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_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_token_flow.cc",
"gaia/oauth2_mint_token_flow.h",
"gaia/oauth_multilogin_result.cc",
"gaia/oauth_multilogin_result.h",
"gaia/oauth_request_signer.cc",
"gaia/oauth_request_signer.h",
"google_api_keys.cc",
"google_api_keys.h",
]

configs += [ ":key_defines" ]

public_deps = [
":buildflags",
"//build:chromeos_buildflags",
]

deps = [
":oauth2_mint_token_consent_result_proto",
"//base",
"//base/third_party/dynamic_annotations",
"//build:branding_buildflags",
"//build:chromeos_buildflags",
"//crypto",
"//mojo/public/cpp/bindings:struct_traits",
"//services/network/public/cpp",
]

if (_use_official_google_keys_and_generate_metrics_key_header) {
deps += [ "internal:generate_metrics_key_header" ]
}

if (defined(invoker.deps)) {
deps += invoker.deps
}
component("google_apis") {
sources = [
"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_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_token_flow.cc",
"gaia/oauth2_mint_token_flow.h",
"gaia/oauth_multilogin_result.cc",
"gaia/oauth_multilogin_result.h",
"gaia/oauth_request_signer.cc",
"gaia/oauth_request_signer.h",
"google_api_keys.cc",
"google_api_keys.h",
]

if (is_apple) {
sources += [
"google_api_keys_mac.h",
"google_api_keys_mac.mm",
]
configs += [ ":key_defines" ]

frameworks = [ "Foundation.framework" ]
}
}
}
public_deps = [
":buildflags",
"//base",
"//build:chromeos_buildflags",
]

google_apis_tmpl("google_apis") {
deps = [
":oauth2_mint_token_consent_result_proto",
"//base/third_party/dynamic_annotations",
"//build:branding_buildflags",
"//build:chromeos_buildflags",
"//crypto",
"//mojo/public/cpp/bindings:struct_traits",
"//net",
"//services/network/public/cpp",
"//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("oauth2_mint_token_consent_result_proto") {
Expand Down
8 changes: 7 additions & 1 deletion google_apis/gaia/core_account_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>
#include <vector>

#include "base/component_export.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"

Expand All @@ -24,7 +25,7 @@
// change on start-up.
// --------------------------------------------------------------------------

struct CoreAccountId {
struct COMPONENT_EXPORT(GOOGLE_APIS) CoreAccountId {
CoreAccountId();
CoreAccountId(const CoreAccountId&);
CoreAccountId(CoreAccountId&&) noexcept;
Expand Down Expand Up @@ -96,16 +97,21 @@ struct CoreAccountId {
std::string id_;
};

COMPONENT_EXPORT(GOOGLE_APIS)
bool operator<(const CoreAccountId& lhs, const CoreAccountId& rhs);

COMPONENT_EXPORT(GOOGLE_APIS)
bool operator==(const CoreAccountId& lhs, const CoreAccountId& rhs);

COMPONENT_EXPORT(GOOGLE_APIS)
bool operator!=(const CoreAccountId& lhs, const CoreAccountId& rhs);

COMPONENT_EXPORT(GOOGLE_APIS)
std::ostream& operator<<(std::ostream& out, const CoreAccountId& a);

// Returns the values of the account ids in a vector. Useful especially for
// logs.
COMPONENT_EXPORT(GOOGLE_APIS)
std::vector<std::string> ToStringList(
const std::vector<CoreAccountId>& account_ids);

Expand Down
4 changes: 3 additions & 1 deletion google_apis/gaia/gaia_access_token_fetcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <memory>
#include <string>

#include "base/component_export.h"
#include "base/memory/ref_counted.h"
#include "google_apis/gaia/oauth2_access_token_fetcher_impl.h"

Expand All @@ -21,7 +22,8 @@ class SharedURLLoaderFactory;
// tokens from Google's authorization server. See "Refreshing an access token"
// for more Google specific info:
// https://developers.google.com/identity/protocols/oauth2/web-server?csw=1#obtainingaccesstokens
class GaiaAccessTokenFetcher : public OAuth2AccessTokenFetcherImpl {
class COMPONENT_EXPORT(GOOGLE_APIS) GaiaAccessTokenFetcher
: public OAuth2AccessTokenFetcherImpl {
public:
static const char kOAuth2NetResponseCodeHistogramName[];
static const char kOAuth2ResponseHistogramName[];
Expand Down
6 changes: 4 additions & 2 deletions google_apis/gaia/gaia_auth_consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
#include <string>
#include <vector>

#include "base/component_export.h"

class GoogleServiceAuthError;
class OAuthMultiloginResult;

// An interface that defines the callbacks for objects that
// GaiaAuthFetcher can return data to.
class GaiaAuthConsumer {
class COMPONENT_EXPORT(GOOGLE_APIS) GaiaAuthConsumer {
public:
struct ClientOAuthResult {
struct COMPONENT_EXPORT(GOOGLE_APIS) ClientOAuthResult {
ClientOAuthResult(const std::string& new_refresh_token,
const std::string& new_access_token,
int new_expires_in_secs,
Expand Down
7 changes: 4 additions & 3 deletions google_apis/gaia/gaia_auth_fetcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>
#include <vector>

#include "base/component_export.h"
#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
Expand Down Expand Up @@ -43,7 +44,7 @@ enum class MultiloginMode {
};

// Specifies the "source" parameter for Gaia calls.
class GaiaSource {
class COMPONENT_EXPORT(GOOGLE_APIS) GaiaSource {
public:
enum Type {
kChrome,
Expand Down Expand Up @@ -72,9 +73,9 @@ class SimpleURLLoader;
class SharedURLLoaderFactory;
} // namespace network

class GaiaAuthFetcher {
class COMPONENT_EXPORT(GOOGLE_APIS) GaiaAuthFetcher {
public:
struct MultiloginTokenIDPair {
struct COMPONENT_EXPORT(GOOGLE_APIS) MultiloginTokenIDPair {
std::string token_;
std::string gaia_id_;

Expand Down
14 changes: 12 additions & 2 deletions google_apis/gaia/gaia_auth_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
#include <utility>
#include <vector>

#include "base/component_export.h"
#include "google_apis/gaia/core_account_id.h"

class GURL;

namespace gaia {

struct ListedAccount {
struct COMPONENT_EXPORT(GOOGLE_APIS) ListedAccount {
// The account's ID, as per Chrome, will be determined in the
// CookieManagerService.
CoreAccountId id;
Expand All @@ -35,41 +36,49 @@ struct ListedAccount {
// gmail does not consider '.' or caps inside a username to matter.
// If |email_address| is not a valid, returns it in lower case without
// additional canonicalization.
COMPONENT_EXPORT(GOOGLE_APIS)
std::string CanonicalizeEmail(const std::string& email_address);

// Returns the canonical form of the given domain.
COMPONENT_EXPORT(GOOGLE_APIS)
std::string CanonicalizeDomain(const std::string& domain);

// Sanitize emails. Currently, it only ensures all emails have a domain by
// adding gmail.com if no domain is present.
COMPONENT_EXPORT(GOOGLE_APIS)
std::string SanitizeEmail(const std::string& email_address);

// Returns true if the two specified email addresses are the same. Both
// addresses are first sanitized and then canonicalized before comparing.
COMPONENT_EXPORT(GOOGLE_APIS)
bool AreEmailsSame(const std::string& email1, const std::string& email2);

// Extract the domain part from the canonical form of the given email.
COMPONENT_EXPORT(GOOGLE_APIS)
std::string ExtractDomainName(const std::string& email);

// Returns whether the user's email is Google internal. This check is meant
// to be used sparingly since it ship Googler-only code to all users.
COMPONENT_EXPORT(GOOGLE_APIS)
bool IsGoogleInternalAccountEmail(const std::string& email);

// Returns true if |email| correspnds to the email of a robot account.
COMPONENT_EXPORT(GOOGLE_APIS)
bool IsGoogleRobotAccountEmail(const std::string& email);

// Mechanically compares the scheme, host, and port of the |url| against the
// GAIA url in GaiaUrls. This means that this function will *not* work for
// determining whether a frame with an "about:blank" URL or "blob:..." URL has
// a GAIA origin and will in that case return false.
bool HasGaiaSchemeHostPort(const GURL& url);
COMPONENT_EXPORT(GOOGLE_APIS) bool HasGaiaSchemeHostPort(const GURL& url);

// Parses JSON data returned by /ListAccounts call, returning a vector of
// email/valid pairs. An email addresses is considered valid if a passive
// login would succeed (i.e. the user does not need to reauthenticate).
// If there an error parsing the JSON, then false is returned.
// If either |accounts| or |signed_out_accounts| is null, the corresponding
// accounts returned from /ListAccounts will be ignored.
COMPONENT_EXPORT(GOOGLE_APIS)
bool ParseListAccountsData(const std::string& data,
std::vector<ListedAccount>* accounts,
std::vector<ListedAccount>* signed_out_accounts);
Expand All @@ -79,6 +88,7 @@ bool ParseListAccountsData(const std::string& data,
// that was shown the consent page.
// Returns false if the method failed to decode the protobuf.
// |approved| and |gaia_id| must not be null.
COMPONENT_EXPORT(GOOGLE_APIS)
bool ParseOAuth2MintTokenConsentResult(const std::string& consent_result,
bool* approved,
std::string* gaia_id);
Expand Down
3 changes: 2 additions & 1 deletion google_apis/gaia/gaia_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <memory>
#include <string>

#include "base/component_export.h"
#include "base/gtest_prod_util.h"
#include "base/strings/string_piece_forward.h"
#include "base/values.h"
Expand Down Expand Up @@ -38,7 +39,7 @@ class FilePath;
// ...
// }
// }
class GaiaConfig {
class COMPONENT_EXPORT(GOOGLE_APIS) GaiaConfig {
public:
// Returns a global instance of GaiaConfig.
// This may return nullptr if the config file was not specified by a command
Expand Down
Loading

0 comments on commit a08ea66

Please sign in to comment.