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
google_apis / api_key_cache.h [blame]
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef GOOGLE_APIS_API_KEY_CACHE_H_
#define GOOGLE_APIS_API_KEY_CACHE_H_
#include <string>
#include "base/feature_list.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "google_apis/buildflags.h"
#include "google_apis/google_api_keys.h"
namespace google_apis {
struct DefaultApiKeys;
COMPONENT_EXPORT(GOOGLE_APIS) BASE_DECLARE_FEATURE(kOverrideAPIKeyFeature);
// This is used as a lazy instance to determine keys once and cache them.
class COMPONENT_EXPORT(GOOGLE_APIS) ApiKeyCache {
public:
explicit ApiKeyCache(const DefaultApiKeys& default_api_keys);
ApiKeyCache(const ApiKeyCache&) = delete;
ApiKeyCache& operator=(const ApiKeyCache&) = delete;
~ApiKeyCache();
const std::string& api_key() const { return api_key_; }
const std::string& api_key_non_stable() const { return api_key_non_stable_; }
const std::string& api_key_remoting() const { return api_key_remoting_; }
const std::string& api_key_soda() const { return api_key_soda_; }
#if !BUILDFLAG(IS_ANDROID)
const std::string& api_key_hats() const { return api_key_hats_; }
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
const std::string& api_key_sharing() const { return api_key_sharing_; }
const std::string& api_key_read_aloud() const { return api_key_read_aloud_; }
const std::string& api_key_fresnel() const { return api_key_fresnel_; }
const std::string& api_key_boca() const { return api_key_boca_; }
#endif
const std::string& metrics_key() const { return metrics_key_; }
const std::string& GetClientID(OAuth2Client client) const;
const std::string& GetClientSecret(OAuth2Client client) const;
bool HasAPIKeyConfigured() const;
bool HasOAuthClientConfigured() const;
#if BUILDFLAG(SUPPORT_EXTERNAL_GOOGLE_API_KEY)
void set_api_key(const std::string& api_key) { api_key_ = api_key; }
void SetClientID(OAuth2Client client, const std::string& client_id);
void SetClientSecret(OAuth2Client client, const std::string& client_secret);
#endif
private:
std::string api_key_;
std::string api_key_non_stable_;
std::string api_key_remoting_;
std::string api_key_soda_;
#if !BUILDFLAG(IS_ANDROID)
std::string api_key_hats_;
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
std::string api_key_sharing_;
std::string api_key_read_aloud_;
std::string api_key_fresnel_;
std::string api_key_boca_;
#endif
std::string metrics_key_;
std::array<std::string, CLIENT_NUM_ITEMS> client_ids_;
std::array<std::string, CLIENT_NUM_ITEMS> client_secrets_;
};
} // namespace google_apis
#endif // GOOGLE_APIS_API_KEY_CACHE_H_