summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorjeremyim <jeremyim@chromium.org>2015-05-19 14:30:13 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-19 21:30:20 +0000
commita924fbc722dc9ab048180bf77d80ee216f370d6a (patch)
treec94832ddb2d5579ceef5953b93b4d921b03a3373 /components
parentf70294138acf31b83a1db00798ba523c69333c56 (diff)
downloadchromium_src-a924fbc722dc9ab048180bf77d80ee216f370d6a.zip
chromium_src-a924fbc722dc9ab048180bf77d80ee216f370d6a.tar.gz
chromium_src-a924fbc722dc9ab048180bf77d80ee216f370d6a.tar.bz2
Add the API key to the config service request.
Also store a version of the GURL with no query string for purposes of displaying on the net-internals#bandwidth page. BUG=466753 Review URL: https://codereview.chromium.org/1139923004 Cr-Commit-Position: refs/heads/master@{#330609}
Diffstat (limited to 'components')
-rw-r--r--components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc24
1 files changed, 21 insertions, 3 deletions
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc
index 1f42bea..81c9f39 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.cc
@@ -24,8 +24,10 @@
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h"
#include "components/data_reduction_proxy/proto/client_config.pb.h"
+#include "google_apis/google_api_keys.h"
#include "net/base/host_port_pair.h"
#include "net/base/load_flags.h"
+#include "net/base/url_util.h"
#include "net/http/http_status_code.h"
#include "net/proxy/proxy_server.h"
#include "net/url_request/url_fetcher.h"
@@ -51,6 +53,9 @@ const char kUMAConfigServiceFetchLatency[] =
// Default URL for retrieving the Data Reduction Proxy configuration.
const char kClientConfigURL[] = "";
+// Used in all Data Reduction Proxy URLs to specify API Key.
+const char kApiKeyName[] = "key";
+
// This is the default backoff policy used to communicate with the Data
// Reduction Proxy configuration service.
const net::BackoffEntry::Policy kDefaultBackoffPolicy = {
@@ -98,6 +103,14 @@ base::TimeDelta CalculateNextConfigRefreshTime(
return backoff_delay;
}
+GURL AddApiKeyToUrl(const GURL& url) {
+ std::string api_key = google_apis::GetAPIKey();
+ if (api_key.empty())
+ return url;
+
+ return net::AppendQueryParameter(url, kApiKeyName, api_key);
+}
+
} // namespace
const net::BackoffEntry::Policy& GetBackoffPolicy() {
@@ -136,8 +149,8 @@ DataReductionProxyConfigServiceClient::DataReductionProxyConfigServiceClient(
event_creator_(event_creator),
net_log_(net_log),
backoff_entry_(&backoff_policy),
- config_service_url_(
- GetConfigServiceURL(*base::CommandLine::ForCurrentProcess())),
+ config_service_url_(AddApiKeyToUrl(
+ GetConfigServiceURL(*base::CommandLine::ForCurrentProcess()))),
use_local_config_(!config_service_url_.is_valid()),
url_request_context_getter_(nullptr) {
DCHECK(request_options);
@@ -165,7 +178,12 @@ void DataReductionProxyConfigServiceClient::RetrieveConfig() {
DCHECK(thread_checker_.CalledOnValidThread());
bound_net_log_ = net::BoundNetLog::Make(
net_log_, net::NetLog::SOURCE_DATA_REDUCTION_PROXY);
- event_creator_->BeginConfigRequest(bound_net_log_, config_service_url_);
+ // Strip off query string parameters
+ GURL::Replacements replacements;
+ replacements.ClearQuery();
+ GURL base_config_service_url =
+ config_service_url_.ReplaceComponents(replacements);
+ event_creator_->BeginConfigRequest(bound_net_log_, base_config_service_url);
config_fetch_start_time_ = base::Time::Now();
if (use_local_config_) {
ReadAndApplyStaticConfig();