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

Unified Diff: components/copresence/rpc/http_post.cc

Issue 469883002: Using API key specified from js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing API build Created 6 years, 4 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/copresence/rpc/http_post.h ('k') | components/copresence/rpc/http_post_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/copresence/rpc/http_post.cc
diff --git a/components/copresence/rpc/http_post.cc b/components/copresence/rpc/http_post.cc
index da6baae58bfb3154849c83d32ef93b2fe3b32f15..0e2b40f17ece8c02cd6063f484641d73997b6bb4 100644
--- a/components/copresence/rpc/http_post.cc
+++ b/components/copresence/rpc/http_post.cc
@@ -14,42 +14,39 @@
#include "net/http/http_status_code.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_context_getter.h"
+#include "url/gurl.h"
namespace copresence {
-// TODO(ckehoe): Come up with a better fix for Chromium.
-#ifdef GOOGLE_CHROME_BUILD
-namespace {
-
-const char kApiKeyField[] = "key";
-
-} // namespace
-#endif
-
+const char HttpPost::kApiKeyField[] = "key";
const char HttpPost::kTracingTokenField[] = "trace";
HttpPost::HttpPost(net::URLRequestContextGetter* url_context_getter,
const std::string& server_host,
const std::string& rpc_name,
const std::string& tracing_token,
+ std::string api_key,
const google::protobuf::MessageLite& request_proto) {
// Create the base URL to call.
GURL url(server_host + "/" + rpc_name);
- // Add the Chrome API key.
- // TODO(ckehoe): Replace this with an app-specific key once the
- // server API supports it. Also fix the Chromium case.
-#ifdef GOOGLE_CHROME_BUILD
- DCHECK(google_apis::HasKeysConfigured());
- url = net::AppendQueryParameter(url, kApiKeyField, google_apis::GetAPIKey());
-#endif
-
// Add the tracing token, if specified.
if (!tracing_token.empty()) {
url = net::AppendQueryParameter(
url, kTracingTokenField, "token:" + tracing_token);
}
+ // If no API key is specified, use the Chrome API key.
+ if (api_key.empty()) {
+#ifdef GOOGLE_CHROME_BUILD
+ DCHECK(google_apis::HasKeysConfigured());
+ api_key = google_apis::GetAPIKey();
+#else
+ LOG(ERROR) << "No Copresence API key provided";
+#endif
+ }
+ url = net::AppendQueryParameter(url, kApiKeyField, api_key);
+
// Serialize the proto for transmission.
std::string request_data;
bool serialize_success = request_proto.SerializeToString(&request_data);
« no previous file with comments | « components/copresence/rpc/http_post.h ('k') | components/copresence/rpc/http_post_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698