Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: google_apis/google_api_keys.cc

Issue 819193002: Make callers of CommandLine use it via the base:: namespace. (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. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « google_apis/gcm/tools/mcs_probe.cc ('k') | gpu/angle_end2end_tests_main.cc » ('j') | 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"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 #define GOOGLE_DEFAULT_CLIENT_SECRET "" 74 #define GOOGLE_DEFAULT_CLIENT_SECRET ""
75 #endif 75 #endif
76 76
77 namespace google_apis { 77 namespace google_apis {
78 78
79 // This is used as a lazy instance to determine keys once and cache them. 79 // This is used as a lazy instance to determine keys once and cache them.
80 class APIKeyCache { 80 class APIKeyCache {
81 public: 81 public:
82 APIKeyCache() { 82 APIKeyCache() {
83 scoped_ptr<base::Environment> environment(base::Environment::Create()); 83 scoped_ptr<base::Environment> environment(base::Environment::Create());
84 CommandLine* command_line = CommandLine::ForCurrentProcess(); 84 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
85 85
86 api_key_ = CalculateKeyValue(GOOGLE_API_KEY, 86 api_key_ = CalculateKeyValue(GOOGLE_API_KEY,
87 STRINGIZE_NO_EXPANSION(GOOGLE_API_KEY), 87 STRINGIZE_NO_EXPANSION(GOOGLE_API_KEY),
88 NULL, 88 NULL,
89 std::string(), 89 std::string(),
90 environment.get(), 90 environment.get(),
91 command_line); 91 command_line);
92 92
93 api_key_safesites_ = 93 api_key_safesites_ =
94 CalculateKeyValue(GOOGLE_API_KEY_SAFESITES, 94 CalculateKeyValue(GOOGLE_API_KEY_SAFESITES,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 private: 204 private:
205 // Gets a value for a key. In priority order, this will be the value 205 // Gets a value for a key. In priority order, this will be the value
206 // provided via a command-line switch, the value provided via an 206 // provided via a command-line switch, the value provided via an
207 // environment variable, or finally a value baked into the build. 207 // environment variable, or finally a value baked into the build.
208 // |command_line_switch| may be NULL. 208 // |command_line_switch| may be NULL.
209 static std::string CalculateKeyValue(const char* baked_in_value, 209 static std::string CalculateKeyValue(const char* baked_in_value,
210 const char* environment_variable_name, 210 const char* environment_variable_name,
211 const char* command_line_switch, 211 const char* command_line_switch,
212 const std::string& default_if_unset, 212 const std::string& default_if_unset,
213 base::Environment* environment, 213 base::Environment* environment,
214 CommandLine* command_line) { 214 base::CommandLine* command_line) {
215 std::string key_value = baked_in_value; 215 std::string key_value = baked_in_value;
216 std::string temp; 216 std::string temp;
217 if (environment->GetVar(environment_variable_name, &temp)) { 217 if (environment->GetVar(environment_variable_name, &temp)) {
218 key_value = temp; 218 key_value = temp;
219 VLOG(1) << "Overriding API key " << environment_variable_name 219 VLOG(1) << "Overriding API key " << environment_variable_name
220 << " with value " << key_value << " from environment variable."; 220 << " with value " << key_value << " from environment variable.";
221 } 221 }
222 222
223 if (command_line_switch && command_line->HasSwitch(command_line_switch)) { 223 if (command_line_switch && command_line->HasSwitch(command_line_switch)) {
224 key_value = command_line->GetSwitchValueASCII(command_line_switch); 224 key_value = command_line->GetSwitchValueASCII(command_line_switch);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 292
293 bool IsGoogleChromeAPIKeyUsed() { 293 bool IsGoogleChromeAPIKeyUsed() {
294 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) 294 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS)
295 return true; 295 return true;
296 #else 296 #else
297 return false; 297 return false;
298 #endif 298 #endif
299 } 299 }
300 300
301 } // namespace google_apis 301 } // namespace google_apis
OLDNEW
« no previous file with comments | « google_apis/gcm/tools/mcs_probe.cc ('k') | gpu/angle_end2end_tests_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698