| 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> |
| 13 |
| 12 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 13 #include "base/environment.h" | 15 #include "base/environment.h" |
| 14 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
| 15 #include "base/logging.h" | 17 #include "base/logging.h" |
| 16 #include "base/memory/scoped_ptr.h" | |
| 17 #include "base/strings/stringize_macros.h" | 18 #include "base/strings/stringize_macros.h" |
| 18 #include "google_apis/gaia/gaia_switches.h" | 19 #include "google_apis/gaia/gaia_switches.h" |
| 19 | 20 |
| 20 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) | 21 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) |
| 21 #include "google_apis/internal/google_chrome_api_keys.h" | 22 #include "google_apis/internal/google_chrome_api_keys.h" |
| 22 #endif | 23 #endif |
| 23 | 24 |
| 24 // Used to indicate an unset key/id/secret. This works better with | 25 // Used to indicate an unset key/id/secret. This works better with |
| 25 // various unit tests than leaving the token empty. | 26 // various unit tests than leaving the token empty. |
| 26 #define DUMMY_API_TOKEN "dummytoken" | 27 #define DUMMY_API_TOKEN "dummytoken" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 87 |
| 87 namespace google_apis { | 88 namespace google_apis { |
| 88 | 89 |
| 89 const char kAPIKeysDevelopersHowToURL[] = | 90 const char kAPIKeysDevelopersHowToURL[] = |
| 90 "http://www.chromium.org/developers/how-tos/api-keys"; | 91 "http://www.chromium.org/developers/how-tos/api-keys"; |
| 91 | 92 |
| 92 // This is used as a lazy instance to determine keys once and cache them. | 93 // This is used as a lazy instance to determine keys once and cache them. |
| 93 class APIKeyCache { | 94 class APIKeyCache { |
| 94 public: | 95 public: |
| 95 APIKeyCache() { | 96 APIKeyCache() { |
| 96 scoped_ptr<base::Environment> environment(base::Environment::Create()); | 97 std::unique_ptr<base::Environment> environment(base::Environment::Create()); |
| 97 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 98 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 98 | 99 |
| 99 api_key_ = CalculateKeyValue( | 100 api_key_ = CalculateKeyValue( |
| 100 GOOGLE_API_KEY, STRINGIZE_NO_EXPANSION(GOOGLE_API_KEY), NULL, | 101 GOOGLE_API_KEY, STRINGIZE_NO_EXPANSION(GOOGLE_API_KEY), NULL, |
| 101 std::string(), environment.get(), command_line); | 102 std::string(), environment.get(), command_line); |
| 102 | 103 |
| 103 // A special non-stable key is at the moment defined only for Android Chrome. | 104 // A special non-stable key is at the moment defined only for Android Chrome. |
| 104 #if defined(OS_ANDROID) | 105 #if defined(OS_ANDROID) |
| 105 api_key_non_stable_ = CalculateKeyValue( | 106 api_key_non_stable_ = CalculateKeyValue( |
| 106 GOOGLE_API_KEY_PHYSICAL_WEB_TEST, | 107 GOOGLE_API_KEY_PHYSICAL_WEB_TEST, |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 | 319 |
| 319 bool IsGoogleChromeAPIKeyUsed() { | 320 bool IsGoogleChromeAPIKeyUsed() { |
| 320 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) | 321 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) |
| 321 return true; | 322 return true; |
| 322 #else | 323 #else |
| 323 return false; | 324 return false; |
| 324 #endif | 325 #endif |
| 325 } | 326 } |
| 326 | 327 |
| 327 } // namespace google_apis | 328 } // namespace google_apis |
| OLD | NEW |