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..1bb07a64d52282849f4de4b6937478f2c3d72b34 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/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()); |
bengr
2015/03/19 16:31:14
Can session or credentials be empty?
jeremyim
2015/03/20 16:21:11
Not if they are valid session/credentials.
|
+} |
+ |
+// static |
+bool DataReductionProxyRequestOptions::ParseLocalSessionKey( |
+ const std::string& session_key, |
+ std::string* session, |
+ std::string* credentials) { |
bengr
2015/03/19 16:31:14
Can session or credentials be NULL?
jeremyim
2015/03/20 16:21:11
Done.
|
+ std::vector<std::string> auth_values; |
+ base::SplitString(session_key, '|', &auth_values); |
+ if (auth_values.size() == 2) { |
bengr
2015/03/19 16:31:14
Shouldn't this always be 2? Maybe DCHECK instead a
jeremyim
2015/03/20 16:21:11
Even with a DCHECK, we would have to evaluate the
|
+ *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,8 +226,8 @@ 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_) { |
bengr
2015/03/19 16:31:14
Remove curly braces
jeremyim
2015/03/20 16:21:11
Done.
|
UpdateCredentials(); |
} |
UpdateLoFi(); |
@@ -219,7 +245,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 +267,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 +280,19 @@ 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", TimeToISO8601(expiration_time)); |
+} |
+ |
std::string DataReductionProxyRequestOptions::GetDefaultKey() const { |
const base::CommandLine& command_line = |
*base::CommandLine::ForCurrentProcess(); |