summaryrefslogtreecommitdiffstats
path: root/google_apis
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-16 19:10:40 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-16 19:10:40 +0000
commite7dd789201dfe869fbba7acb06f63da58ec77f05 (patch)
tree60531f4a90c7687dfe92eae04e870654a874d522 /google_apis
parenta1c8bae3608e6c40f0258fbb780223cdae0b61d5 (diff)
downloadchromium_src-e7dd789201dfe869fbba7acb06f63da58ec77f05.zip
chromium_src-e7dd789201dfe869fbba7acb06f63da58ec77f05.tar.gz
chromium_src-e7dd789201dfe869fbba7acb06f63da58ec77f05.tar.bz2
Display an infobar on startup when Google API keys are missing.
BUG=158766 R=joi@chromium.org, pkasting@chromium.org Review URL: https://codereview.chromium.org/14766011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200599 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis')
-rw-r--r--google_apis/google_api_keys.cc15
-rw-r--r--google_apis/google_api_keys.h5
-rw-r--r--google_apis/google_api_keys_unittest.cc10
3 files changed, 29 insertions, 1 deletions
diff --git a/google_apis/google_api_keys.cc b/google_apis/google_api_keys.cc
index c05435e..034b69a 100644
--- a/google_apis/google_api_keys.cc
+++ b/google_apis/google_api_keys.cc
@@ -235,6 +235,21 @@ class APIKeyCache {
static base::LazyInstance<APIKeyCache> g_api_key_cache =
LAZY_INSTANCE_INITIALIZER;
+bool HasKeysConfigured() {
+ if (GetAPIKey() == DUMMY_API_TOKEN)
+ return false;
+
+ for (size_t client_id = 0; client_id < CLIENT_NUM_ITEMS; ++client_id) {
+ OAuth2Client client = static_cast<OAuth2Client>(client_id);
+ if (GetOAuth2ClientID(client) == DUMMY_API_TOKEN ||
+ GetOAuth2ClientSecret(client) == DUMMY_API_TOKEN) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
std::string GetAPIKey() {
return g_api_key_cache.Get().api_key();
}
diff --git a/google_apis/google_api_keys.h b/google_apis/google_api_keys.h
index 28905ac..28421e8 100644
--- a/google_apis/google_api_keys.h
+++ b/google_apis/google_api_keys.h
@@ -56,7 +56,10 @@
namespace google_apis {
-// Retrieves the API key, a.k.a. developer key, or the empty string
+// Returns true if no dummy API keys or OAuth2 tokens are set.
+bool HasKeysConfigured();
+
+// Retrieves the API key, a.k.a. developer key, or a dummy string
// if not set.
//
// Note that the key should be escaped for the context you use it in,
diff --git a/google_apis/google_api_keys_unittest.cc b/google_apis/google_api_keys_unittest.cc
index ab50d3f..4d338f5 100644
--- a/google_apis/google_api_keys_unittest.cc
+++ b/google_apis/google_api_keys_unittest.cc
@@ -132,6 +132,8 @@ namespace official_build {
TEST_F(GoogleAPIKeysTest, OfficialKeys) {
namespace testcase = official_build::google_apis;
+ EXPECT_TRUE(testcase::HasKeysConfigured());
+
std::string api_key = testcase::g_api_key_cache.Get().api_key();
std::string id_main = testcase::g_api_key_cache.Get().GetClientID(
testcase::CLIENT_MAIN);
@@ -212,6 +214,8 @@ namespace default_keys {
TEST_F(GoogleAPIKeysTest, DefaultKeys) {
namespace testcase = default_keys::google_apis;
+ EXPECT_FALSE(testcase::HasKeysConfigured());
+
std::string api_key = testcase::g_api_key_cache.Get().api_key();
std::string id_main = testcase::g_api_key_cache.Get().GetClientID(
testcase::CLIENT_MAIN);
@@ -267,6 +271,8 @@ namespace override_some_keys {
TEST_F(GoogleAPIKeysTest, OverrideSomeKeys) {
namespace testcase = override_some_keys::google_apis;
+ EXPECT_FALSE(testcase::HasKeysConfigured());
+
std::string api_key = testcase::g_api_key_cache.Get().api_key();
std::string id_main = testcase::g_api_key_cache.Get().GetClientID(
testcase::CLIENT_MAIN);
@@ -327,6 +333,8 @@ namespace override_all_keys {
TEST_F(GoogleAPIKeysTest, OverrideAllKeys) {
namespace testcase = override_all_keys::google_apis;
+ EXPECT_TRUE(testcase::HasKeysConfigured());
+
std::string api_key = testcase::g_api_key_cache.Get().api_key();
std::string id_main = testcase::g_api_key_cache.Get().GetClientID(
testcase::CLIENT_MAIN);
@@ -397,6 +405,8 @@ TEST_F(GoogleAPIKeysTest, OverrideAllKeysUsingEnvironment) {
env->SetVar("GOOGLE_CLIENT_SECRET_CLOUD_PRINT", "env-SECRET_CLOUD_PRINT");
env->SetVar("GOOGLE_CLIENT_SECRET_REMOTING", "env-SECRET_REMOTING");
+ EXPECT_TRUE(testcase::HasKeysConfigured());
+
// It's important that the first call to Get() only happen after the
// environment variables have been set.
std::string api_key = testcase::g_api_key_cache.Get().api_key();