File: api_key_cache.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (87 lines) | stat: -rw-r--r-- 2,856 bytes parent folder | download | duplicates (2)
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
83
84
85
86
87
// 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 "google_apis/buildflags.h"
#include "google_apis/google_api_keys.h"

namespace google_apis {

struct DefaultApiKeys;

// 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)
  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_; }
  const std::string& api_key_cros_system_geo() const {
    return api_key_cros_system_geo_;
  }
  const std::string& api_key_cros_chrome_geo() const {
    return api_key_cros_chrome_geo_;
  }
#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)
  std::string api_key_sharing_;
  std::string api_key_read_aloud_;
  std::string api_key_fresnel_;
  std::string api_key_boca_;
  std::string api_key_cros_system_geo_;
  std::string api_key_cros_chrome_geo_;
#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_