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

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: Adding fingerprint test 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
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..e850cfa8c1643c5661379b095356afc287fac653 100644
--- a/components/copresence/rpc/http_post.cc
+++ b/components/copresence/rpc/http_post.cc
@@ -17,38 +17,40 @@
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,
- 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.
+ const std::string& rpc_name)
+ : url_context_getter_(url_context_getter),
+ url_(server_host + "/" + rpc_name) {}
+
+HttpPost::~HttpPost() {}
+
+void HttpPost::set_tracing_token(const std::string& tracing_token) {
+ if (tracing_token.empty())
+ return;
+
+ url_ = net::AppendQueryParameter(
+ url_, kTracingTokenField, "token:" + tracing_token);
+}
+
+void HttpPost::Start(const ResponseCallback& response_callback,
+ const google::protobuf::MessageLite& request_proto) {
+ response_callback_ = response_callback;
+
+ // If no API key is specified, use the Chrome API key.
+ if (api_key_.empty()) {
#ifdef GOOGLE_CHROME_BUILD
- DCHECK(google_apis::HasKeysConfigured());
- url = net::AppendQueryParameter(url, kApiKeyField, google_apis::GetAPIKey());
+ DCHECK(google_apis::HasKeysConfigured());
+ api_key_ = google_apis::GetAPIKey();
+#else
+ LOG(ERROR) << "No Copresence API key provided";
+ return;
#endif
-
- // Add the tracing token, if specified.
- if (!tracing_token.empty()) {
- url = net::AppendQueryParameter(
- url, kTracingTokenField, "token:" + tracing_token);
}
+ url_ = net::AppendQueryParameter(url_, kApiKeyField, api_key_);
// Serialize the proto for transmission.
std::string request_data;
@@ -57,20 +59,14 @@ HttpPost::HttpPost(net::URLRequestContextGetter* url_context_getter,
// Configure and send the request.
url_fetcher_.reset(net::URLFetcher::Create(
- kUrlFetcherId, url, net::URLFetcher::POST, this));
- url_fetcher_->SetRequestContext(url_context_getter);
+ kUrlFetcherId, url_, net::URLFetcher::POST, this));
+ url_fetcher_->SetRequestContext(url_context_getter_);
url_fetcher_->SetLoadFlags(net::LOAD_BYPASS_CACHE |
net::LOAD_DISABLE_CACHE |
net::LOAD_DO_NOT_SAVE_COOKIES |
net::LOAD_DO_NOT_SEND_COOKIES |
net::LOAD_DO_NOT_SEND_AUTH_DATA);
url_fetcher_->SetUploadData("application/x-protobuf", request_data);
-}
-
-HttpPost::~HttpPost() {}
-
-void HttpPost::Start(const ResponseCallback& response_callback) {
- response_callback_ = response_callback;
url_fetcher_->Start();
}

Powered by Google App Engine
This is Rietveld 408576698