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

Unified Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc

Issue 1017853003: Add ClientConfig proto, and JSON generation/parsing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweak test values Created 5 years, 9 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/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc
index 985dfa5e18d901fdcefe16fccd58ba193b30209b..675b05ce0eac90242ac431572271f9fe1b62102b 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc
@@ -13,8 +13,10 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
+#include "base/values.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_client_config_parser.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.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"
@@ -69,6 +71,29 @@ bool DataReductionProxyRequestOptions::IsKeySetOnCommandLine() {
data_reduction_proxy::switches::kDataReductionProxyKey);
}
+// static
+std::string DataReductionProxyRequestOptions::CreateLocalSessionKey(
+ const std::string& session,
+ const std::string& credentials) {
+ return base::StringPrintf("%s|%s", session.c_str(), credentials.c_str());
+}
+
+// static
+bool DataReductionProxyRequestOptions::ParseLocalSessionKey(
+ const std::string& session_key,
+ std::string* session,
+ std::string* credentials) {
+ std::vector<std::string> auth_values;
+ base::SplitString(session_key, '|', &auth_values);
+ if (auth_values.size() == 2) {
+ *session = auth_values[0];
+ *credentials = auth_values[1];
+ return true;
+ }
+
+ return false;
+}
+
DataReductionProxyRequestOptions::DataReductionProxyRequestOptions(
Client client,
DataReductionProxyConfig* config,
@@ -172,7 +197,8 @@ base::Time DataReductionProxyRequestOptions::Now() const {
return base::Time::Now();
}
-void DataReductionProxyRequestOptions::RandBytes(void* output, size_t length) {
+void DataReductionProxyRequestOptions::RandBytes(void* output,
+ size_t length) const {
crypto::RandBytes(output, length);
}
@@ -200,10 +226,9 @@ void DataReductionProxyRequestOptions::MaybeAddProxyTunnelRequestHandler(
void DataReductionProxyRequestOptions::SetHeader(
net::HttpRequestHeaders* headers) {
base::Time now = Now();
- // Authorization credentials must be regenerated at least every 24 hours.
- if (now - last_credentials_update_time_ > base::TimeDelta::FromHours(24)) {
+ // Authorization credentials must be regenerated if they are expired.
+ if (now > credentials_expiration_time_)
UpdateCredentials();
- }
UpdateLoFi();
const char kChromeProxyHeader[] = "Chrome-Proxy";
std::string header_value;
@@ -219,7 +244,7 @@ void DataReductionProxyRequestOptions::SetHeader(
void DataReductionProxyRequestOptions::ComputeCredentials(
const base::Time& now,
std::string* session,
- std::string* credentials) {
+ std::string* credentials) const {
DCHECK(session);
DCHECK(credentials);
int64 timestamp =
@@ -241,8 +266,9 @@ void DataReductionProxyRequestOptions::ComputeCredentials(
void DataReductionProxyRequestOptions::UpdateCredentials() {
std::string session;
std::string credentials;
- last_credentials_update_time_ = Now();
- ComputeCredentials(last_credentials_update_time_, &session_, &credentials_);
+ base::Time now = Now();
+ ComputeCredentials(now, &session_, &credentials_);
+ credentials_expiration_time_ = now + base::TimeDelta::FromHours(24);
RegenerateRequestHeaderValue();
}
@@ -253,6 +279,20 @@ void DataReductionProxyRequestOptions::SetKeyOnIO(const std::string& key) {
}
}
+void DataReductionProxyRequestOptions::PopulateConfigResponse(
+ base::DictionaryValue* response) const {
+ DCHECK(network_task_runner_->BelongsToCurrentThread());
+ std::string session;
+ std::string credentials;
+ base::Time now = Now();
+ base::Time expiration_time = now + base::TimeDelta::FromHours(24);
+ ComputeCredentials(now, &session, &credentials);
+ response->SetString("sessionKey",
+ CreateLocalSessionKey(session, credentials));
+ response->SetString("expireTime",
+ config_parser::TimeToISO8601(expiration_time));
+}
+
std::string DataReductionProxyRequestOptions::GetDefaultKey() const {
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();

Powered by Google App Engine
This is Rietveld 408576698