| OLD | NEW |
| 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 | 9 |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| 11 | 11 |
| 12 #include <memory> | 12 #include <memory> |
| 13 | 13 |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/environment.h" | 15 #include "base/environment.h" |
| 16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/strings/stringize_macros.h" | 18 #include "base/strings/stringize_macros.h" |
| 19 #include "google_apis/gaia/gaia_switches.h" | 19 #include "google_apis/gaia/gaia_switches.h" |
| 20 | 20 |
| 21 #if defined(OS_MACOSX) |
| 22 #include "google_apis/google_api_keys_mac.h" |
| 23 #endif |
| 24 |
| 21 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) | 25 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) |
| 22 #include "google_apis/internal/google_chrome_api_keys.h" | 26 #include "google_apis/internal/google_chrome_api_keys.h" |
| 23 #endif | 27 #endif |
| 24 | 28 |
| 25 // Used to indicate an unset key/id/secret. This works better with | 29 // Used to indicate an unset key/id/secret. This works better with |
| 26 // various unit tests than leaving the token empty. | 30 // various unit tests than leaving the token empty. |
| 27 #define DUMMY_API_TOKEN "dummytoken" | 31 #define DUMMY_API_TOKEN "dummytoken" |
| 28 | 32 |
| 29 #if !defined(GOOGLE_API_KEY) | 33 #if !defined(GOOGLE_API_KEY) |
| 30 #define GOOGLE_API_KEY DUMMY_API_TOKEN | 34 #define GOOGLE_API_KEY DUMMY_API_TOKEN |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // environment variable, or finally a value baked into the build. | 233 // environment variable, or finally a value baked into the build. |
| 230 // |command_line_switch| may be NULL. | 234 // |command_line_switch| may be NULL. |
| 231 static std::string CalculateKeyValue(const char* baked_in_value, | 235 static std::string CalculateKeyValue(const char* baked_in_value, |
| 232 const char* environment_variable_name, | 236 const char* environment_variable_name, |
| 233 const char* command_line_switch, | 237 const char* command_line_switch, |
| 234 const std::string& default_if_unset, | 238 const std::string& default_if_unset, |
| 235 base::Environment* environment, | 239 base::Environment* environment, |
| 236 base::CommandLine* command_line) { | 240 base::CommandLine* command_line) { |
| 237 std::string key_value = baked_in_value; | 241 std::string key_value = baked_in_value; |
| 238 std::string temp; | 242 std::string temp; |
| 243 #if defined(OS_MACOSX) |
| 244 // macOS and iOS can also override the API key with a value from the |
| 245 // Info.plist. |
| 246 temp = ::google_apis::GetAPIKeyFromInfoPlist(environment_variable_name); |
| 247 if (!temp.empty()) { |
| 248 key_value = temp; |
| 249 VLOG(1) << "Overriding API key " << environment_variable_name |
| 250 << " with value " << key_value << " from Info.plist."; |
| 251 } |
| 252 #endif |
| 239 if (environment->GetVar(environment_variable_name, &temp)) { | 253 if (environment->GetVar(environment_variable_name, &temp)) { |
| 240 key_value = temp; | 254 key_value = temp; |
| 241 VLOG(1) << "Overriding API key " << environment_variable_name | 255 VLOG(1) << "Overriding API key " << environment_variable_name |
| 242 << " with value " << key_value << " from environment variable."; | 256 << " with value " << key_value << " from environment variable."; |
| 243 } | 257 } |
| 244 | 258 |
| 245 if (command_line_switch && command_line->HasSwitch(command_line_switch)) { | 259 if (command_line_switch && command_line->HasSwitch(command_line_switch)) { |
| 246 key_value = command_line->GetSwitchValueASCII(command_line_switch); | 260 key_value = command_line->GetSwitchValueASCII(command_line_switch); |
| 247 VLOG(1) << "Overriding API key " << environment_variable_name | 261 VLOG(1) << "Overriding API key " << environment_variable_name |
| 248 << " with value " << key_value << " from command-line switch."; | 262 << " with value " << key_value << " from command-line switch."; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 | 333 |
| 320 bool IsGoogleChromeAPIKeyUsed() { | 334 bool IsGoogleChromeAPIKeyUsed() { |
| 321 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) | 335 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) |
| 322 return true; | 336 return true; |
| 323 #else | 337 #else |
| 324 return false; | 338 return false; |
| 325 #endif | 339 #endif |
| 326 } | 340 } |
| 327 | 341 |
| 328 } // namespace google_apis | 342 } // namespace google_apis |
| OLD | NEW |