| 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 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/environment.h" | 8 #include "base/environment.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 // Specifies custom OAuth2 client id for testing purposes. | 87 // Specifies custom OAuth2 client id for testing purposes. |
| 88 const char kOAuth2ClientID[] = "oauth2-client-id"; | 88 const char kOAuth2ClientID[] = "oauth2-client-id"; |
| 89 | 89 |
| 90 // Specifies custom OAuth2 client secret for testing purposes. | 90 // Specifies custom OAuth2 client secret for testing purposes. |
| 91 const char kOAuth2ClientSecret[] = "oauth2-client-secret"; | 91 const char kOAuth2ClientSecret[] = "oauth2-client-secret"; |
| 92 | 92 |
| 93 } // namespace switches | 93 } // namespace switches |
| 94 | 94 |
| 95 namespace google_apis { | 95 namespace google_apis { |
| 96 | 96 |
| 97 namespace { | |
| 98 | |
| 99 // This is used as a lazy instance to determine keys once and cache them. | 97 // This is used as a lazy instance to determine keys once and cache them. |
| 100 class APIKeyCache { | 98 class APIKeyCache { |
| 101 public: | 99 public: |
| 102 APIKeyCache() { | 100 APIKeyCache() { |
| 103 scoped_ptr<base::Environment> environment(base::Environment::Create()); | 101 scoped_ptr<base::Environment> environment(base::Environment::Create()); |
| 104 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 102 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 105 | 103 |
| 106 api_key_ = CalculateKeyValue(GOOGLE_API_KEY, | 104 api_key_ = CalculateKeyValue(GOOGLE_API_KEY, |
| 107 STRINGIZE_NO_EXPANSION(GOOGLE_API_KEY), | 105 STRINGIZE_NO_EXPANSION(GOOGLE_API_KEY), |
| 108 NULL, "", | 106 NULL, "", |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 } | 230 } |
| 233 | 231 |
| 234 std::string api_key_; | 232 std::string api_key_; |
| 235 std::string client_ids_[CLIENT_NUM_ITEMS]; | 233 std::string client_ids_[CLIENT_NUM_ITEMS]; |
| 236 std::string client_secrets_[CLIENT_NUM_ITEMS]; | 234 std::string client_secrets_[CLIENT_NUM_ITEMS]; |
| 237 }; | 235 }; |
| 238 | 236 |
| 239 static base::LazyInstance<APIKeyCache> g_api_key_cache = | 237 static base::LazyInstance<APIKeyCache> g_api_key_cache = |
| 240 LAZY_INSTANCE_INITIALIZER; | 238 LAZY_INSTANCE_INITIALIZER; |
| 241 | 239 |
| 242 } // namespace | |
| 243 | |
| 244 std::string GetAPIKey() { | 240 std::string GetAPIKey() { |
| 245 return g_api_key_cache.Get().api_key(); | 241 return g_api_key_cache.Get().api_key(); |
| 246 } | 242 } |
| 247 | 243 |
| 248 std::string GetOAuth2ClientID(OAuth2Client client) { | 244 std::string GetOAuth2ClientID(OAuth2Client client) { |
| 249 return g_api_key_cache.Get().GetClientID(client); | 245 return g_api_key_cache.Get().GetClientID(client); |
| 250 } | 246 } |
| 251 | 247 |
| 252 std::string GetOAuth2ClientSecret(OAuth2Client client) { | 248 std::string GetOAuth2ClientSecret(OAuth2Client client) { |
| 253 return g_api_key_cache.Get().GetClientSecret(client); | 249 return g_api_key_cache.Get().GetClientSecret(client); |
| 254 } | 250 } |
| 255 | 251 |
| 256 } // namespace google_apis | 252 } // namespace google_apis |
| OLD | NEW |