Chromium Code Reviews

Side by Side Diff: google_apis/google_api_keys.cc

Issue 753683004: Revert of Supervised user SafeSites: Expose & use API key from src-internal (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « google_apis/google_api_keys.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "google_apis/google_api_keys.h" 5 #include "google_apis/google_api_keys.h"
6 6
7 // If you add more includes to this list, you also need to add them to 7 // If you add more includes to this list, you also need to add them to
8 // google_api_keys_unittest.cc. 8 // google_api_keys_unittest.cc.
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/stringize_macros.h" 14 #include "base/strings/stringize_macros.h"
15 #include "google_apis/gaia/gaia_switches.h" 15 #include "google_apis/gaia/gaia_switches.h"
16 16
17 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) 17 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS)
18 #include "google_apis/internal/google_chrome_api_keys.h" 18 #include "google_apis/internal/google_chrome_api_keys.h"
19 #endif 19 #endif
20 20
21 // Used to indicate an unset key/id/secret. This works better with 21 // Used to indicate an unset key/id/secret. This works better with
22 // various unit tests than leaving the token empty. 22 // various unit tests than leaving the token empty.
23 #define DUMMY_API_TOKEN "dummytoken" 23 #define DUMMY_API_TOKEN "dummytoken"
24 24
25 #if !defined(GOOGLE_API_KEY) 25 #if !defined(GOOGLE_API_KEY)
26 #define GOOGLE_API_KEY DUMMY_API_TOKEN 26 #define GOOGLE_API_KEY DUMMY_API_TOKEN
27 #endif 27 #endif
28 28
29 #if !defined(GOOGLE_API_KEY_SAFESITES)
30 #define GOOGLE_API_KEY_SAFESITES DUMMY_API_TOKEN
31 #endif
32
33 #if !defined(GOOGLE_CLIENT_ID_MAIN) 29 #if !defined(GOOGLE_CLIENT_ID_MAIN)
34 #define GOOGLE_CLIENT_ID_MAIN DUMMY_API_TOKEN 30 #define GOOGLE_CLIENT_ID_MAIN DUMMY_API_TOKEN
35 #endif 31 #endif
36 32
37 #if !defined(GOOGLE_CLIENT_SECRET_MAIN) 33 #if !defined(GOOGLE_CLIENT_SECRET_MAIN)
38 #define GOOGLE_CLIENT_SECRET_MAIN DUMMY_API_TOKEN 34 #define GOOGLE_CLIENT_SECRET_MAIN DUMMY_API_TOKEN
39 #endif 35 #endif
40 36
41 #if !defined(GOOGLE_CLIENT_ID_CLOUD_PRINT) 37 #if !defined(GOOGLE_CLIENT_ID_CLOUD_PRINT)
42 #define GOOGLE_CLIENT_ID_CLOUD_PRINT DUMMY_API_TOKEN 38 #define GOOGLE_CLIENT_ID_CLOUD_PRINT DUMMY_API_TOKEN
(...skipping 40 matching lines...)
83 scoped_ptr<base::Environment> environment(base::Environment::Create()); 79 scoped_ptr<base::Environment> environment(base::Environment::Create());
84 CommandLine* command_line = CommandLine::ForCurrentProcess(); 80 CommandLine* command_line = CommandLine::ForCurrentProcess();
85 81
86 api_key_ = CalculateKeyValue(GOOGLE_API_KEY, 82 api_key_ = CalculateKeyValue(GOOGLE_API_KEY,
87 STRINGIZE_NO_EXPANSION(GOOGLE_API_KEY), 83 STRINGIZE_NO_EXPANSION(GOOGLE_API_KEY),
88 NULL, 84 NULL,
89 std::string(), 85 std::string(),
90 environment.get(), 86 environment.get(),
91 command_line); 87 command_line);
92 88
93 api_key_safesites_ =
94 CalculateKeyValue(GOOGLE_API_KEY_SAFESITES,
95 STRINGIZE_NO_EXPANSION(GOOGLE_API_KEY_SAFESITES),
96 NULL,
97 std::string(),
98 environment.get(),
99 command_line);
100
101 std::string default_client_id = 89 std::string default_client_id =
102 CalculateKeyValue(GOOGLE_DEFAULT_CLIENT_ID, 90 CalculateKeyValue(GOOGLE_DEFAULT_CLIENT_ID,
103 STRINGIZE_NO_EXPANSION(GOOGLE_DEFAULT_CLIENT_ID), 91 STRINGIZE_NO_EXPANSION(GOOGLE_DEFAULT_CLIENT_ID),
104 NULL, 92 NULL,
105 std::string(), 93 std::string(),
106 environment.get(), 94 environment.get(),
107 command_line); 95 command_line);
108 std::string default_client_secret = 96 std::string default_client_secret =
109 CalculateKeyValue(GOOGLE_DEFAULT_CLIENT_SECRET, 97 CalculateKeyValue(GOOGLE_DEFAULT_CLIENT_SECRET,
110 STRINGIZE_NO_EXPANSION(GOOGLE_DEFAULT_CLIENT_SECRET), 98 STRINGIZE_NO_EXPANSION(GOOGLE_DEFAULT_CLIENT_SECRET),
(...skipping 63 matching lines...)
174 client_secrets_[CLIENT_REMOTING_HOST] = CalculateKeyValue( 162 client_secrets_[CLIENT_REMOTING_HOST] = CalculateKeyValue(
175 GOOGLE_CLIENT_SECRET_REMOTING_HOST, 163 GOOGLE_CLIENT_SECRET_REMOTING_HOST,
176 STRINGIZE_NO_EXPANSION(GOOGLE_CLIENT_SECRET_REMOTING_HOST), 164 STRINGIZE_NO_EXPANSION(GOOGLE_CLIENT_SECRET_REMOTING_HOST),
177 NULL, 165 NULL,
178 default_client_secret, 166 default_client_secret,
179 environment.get(), 167 environment.get(),
180 command_line); 168 command_line);
181 } 169 }
182 170
183 std::string api_key() const { return api_key_; } 171 std::string api_key() const { return api_key_; }
184 std::string api_key_safesites() const { return api_key_safesites_; }
185 172
186 std::string GetClientID(OAuth2Client client) const { 173 std::string GetClientID(OAuth2Client client) const {
187 DCHECK_LT(client, CLIENT_NUM_ITEMS); 174 DCHECK_LT(client, CLIENT_NUM_ITEMS);
188 return client_ids_[client]; 175 return client_ids_[client];
189 } 176 }
190 177
191 std::string GetClientSecret(OAuth2Client client) const { 178 std::string GetClientSecret(OAuth2Client client) const {
192 DCHECK_LT(client, CLIENT_NUM_ITEMS); 179 DCHECK_LT(client, CLIENT_NUM_ITEMS);
193 return client_secrets_[client]; 180 return client_secrets_[client];
194 } 181 }
(...skipping 45 matching lines...)
240 } 227 }
241 } 228 }
242 229
243 // This should remain a debug-only log. 230 // This should remain a debug-only log.
244 DVLOG(1) << "API key " << environment_variable_name << "=" << key_value; 231 DVLOG(1) << "API key " << environment_variable_name << "=" << key_value;
245 232
246 return key_value; 233 return key_value;
247 } 234 }
248 235
249 std::string api_key_; 236 std::string api_key_;
250 std::string api_key_safesites_;
251 std::string client_ids_[CLIENT_NUM_ITEMS]; 237 std::string client_ids_[CLIENT_NUM_ITEMS];
252 std::string client_secrets_[CLIENT_NUM_ITEMS]; 238 std::string client_secrets_[CLIENT_NUM_ITEMS];
253 }; 239 };
254 240
255 static base::LazyInstance<APIKeyCache> g_api_key_cache = 241 static base::LazyInstance<APIKeyCache> g_api_key_cache =
256 LAZY_INSTANCE_INITIALIZER; 242 LAZY_INSTANCE_INITIALIZER;
257 243
258 bool HasKeysConfigured() { 244 bool HasKeysConfigured() {
259 if (GetAPIKey() == DUMMY_API_TOKEN) 245 if (GetAPIKey() == DUMMY_API_TOKEN)
260 return false; 246 return false;
261 247
262 for (size_t client_id = 0; client_id < CLIENT_NUM_ITEMS; ++client_id) { 248 for (size_t client_id = 0; client_id < CLIENT_NUM_ITEMS; ++client_id) {
263 OAuth2Client client = static_cast<OAuth2Client>(client_id); 249 OAuth2Client client = static_cast<OAuth2Client>(client_id);
264 if (GetOAuth2ClientID(client) == DUMMY_API_TOKEN || 250 if (GetOAuth2ClientID(client) == DUMMY_API_TOKEN ||
265 GetOAuth2ClientSecret(client) == DUMMY_API_TOKEN) { 251 GetOAuth2ClientSecret(client) == DUMMY_API_TOKEN) {
266 return false; 252 return false;
267 } 253 }
268 } 254 }
269 255
270 return true; 256 return true;
271 } 257 }
272 258
273 std::string GetAPIKey() { 259 std::string GetAPIKey() {
274 return g_api_key_cache.Get().api_key(); 260 return g_api_key_cache.Get().api_key();
275 } 261 }
276 262
277 std::string GetSafeSitesAPIKey() {
278 return g_api_key_cache.Get().api_key_safesites();
279 }
280
281 std::string GetOAuth2ClientID(OAuth2Client client) { 263 std::string GetOAuth2ClientID(OAuth2Client client) {
282 return g_api_key_cache.Get().GetClientID(client); 264 return g_api_key_cache.Get().GetClientID(client);
283 } 265 }
284 266
285 std::string GetOAuth2ClientSecret(OAuth2Client client) { 267 std::string GetOAuth2ClientSecret(OAuth2Client client) {
286 return g_api_key_cache.Get().GetClientSecret(client); 268 return g_api_key_cache.Get().GetClientSecret(client);
287 } 269 }
288 270
289 std::string GetSpdyProxyAuthValue() { 271 std::string GetSpdyProxyAuthValue() {
290 return g_api_key_cache.Get().GetSpdyProxyAuthValue(); 272 return g_api_key_cache.Get().GetSpdyProxyAuthValue();
291 } 273 }
292 274
293 bool IsGoogleChromeAPIKeyUsed() { 275 bool IsGoogleChromeAPIKeyUsed() {
294 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) 276 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS)
295 return true; 277 return true;
296 #else 278 #else
297 return false; 279 return false;
298 #endif 280 #endif
299 } 281 }
300 282
301 } // namespace google_apis 283 } // namespace google_apis
OLDNEW
« no previous file with comments | « google_apis/google_api_keys.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine