Commit a924fbc7 authored by jeremyim's avatar jeremyim Committed by Commit bot

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}
parent f7029413
...@@ -24,8 +24,10 @@ ...@@ -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_params.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h"
#include "components/data_reduction_proxy/proto/client_config.pb.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/host_port_pair.h"
#include "net/base/load_flags.h" #include "net/base/load_flags.h"
#include "net/base/url_util.h"
#include "net/http/http_status_code.h" #include "net/http/http_status_code.h"
#include "net/proxy/proxy_server.h" #include "net/proxy/proxy_server.h"
#include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher.h"
...@@ -51,6 +53,9 @@ const char kUMAConfigServiceFetchLatency[] = ...@@ -51,6 +53,9 @@ const char kUMAConfigServiceFetchLatency[] =
// Default URL for retrieving the Data Reduction Proxy configuration. // Default URL for retrieving the Data Reduction Proxy configuration.
const char kClientConfigURL[] = ""; 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 // This is the default backoff policy used to communicate with the Data
// Reduction Proxy configuration service. // Reduction Proxy configuration service.
const net::BackoffEntry::Policy kDefaultBackoffPolicy = { const net::BackoffEntry::Policy kDefaultBackoffPolicy = {
...@@ -98,6 +103,14 @@ base::TimeDelta CalculateNextConfigRefreshTime( ...@@ -98,6 +103,14 @@ base::TimeDelta CalculateNextConfigRefreshTime(
return backoff_delay; 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 } // namespace
const net::BackoffEntry::Policy& GetBackoffPolicy() { const net::BackoffEntry::Policy& GetBackoffPolicy() {
...@@ -136,8 +149,8 @@ DataReductionProxyConfigServiceClient::DataReductionProxyConfigServiceClient( ...@@ -136,8 +149,8 @@ DataReductionProxyConfigServiceClient::DataReductionProxyConfigServiceClient(
event_creator_(event_creator), event_creator_(event_creator),
net_log_(net_log), net_log_(net_log),
backoff_entry_(&backoff_policy), backoff_entry_(&backoff_policy),
config_service_url_( config_service_url_(AddApiKeyToUrl(
GetConfigServiceURL(*base::CommandLine::ForCurrentProcess())), GetConfigServiceURL(*base::CommandLine::ForCurrentProcess()))),
use_local_config_(!config_service_url_.is_valid()), use_local_config_(!config_service_url_.is_valid()),
url_request_context_getter_(nullptr) { url_request_context_getter_(nullptr) {
DCHECK(request_options); DCHECK(request_options);
...@@ -165,7 +178,12 @@ void DataReductionProxyConfigServiceClient::RetrieveConfig() { ...@@ -165,7 +178,12 @@ void DataReductionProxyConfigServiceClient::RetrieveConfig() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
bound_net_log_ = net::BoundNetLog::Make( bound_net_log_ = net::BoundNetLog::Make(
net_log_, net::NetLog::SOURCE_DATA_REDUCTION_PROXY); 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(); config_fetch_start_time_ = base::Time::Now();
if (use_local_config_) { if (use_local_config_) {
ReadAndApplyStaticConfig(); ReadAndApplyStaticConfig();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment