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

Unified Diff: components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.cc

Issue 465823002: Data reduction proxy sessions last no more than 24 hours (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.cc
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.cc
index 79fb37e15fefa70df57da688387b600d48ea8473..3f1565684a729c2da104c692fa1197b957c28f9f 100644
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.cc
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.cc
@@ -99,6 +99,11 @@ void DataReductionProxyAuthRequestHandler::MaybeAddRequestHeader(
void DataReductionProxyAuthRequestHandler::AddAuthorizationHeader(
net::HttpRequestHeaders* headers) {
+ base::Time now = Now();
+ if (now - last_update_time_ > base::TimeDelta::FromHours(24)) {
+ last_update_time_ = now;
+ ComputeCredentials(last_update_time_, &session_, &credentials_);
+ }
const char kChromeProxyHeader[] = "Chrome-Proxy";
std::string header_value;
if (headers->HasHeader(kChromeProxyHeader)) {
@@ -115,34 +120,40 @@ void DataReductionProxyAuthRequestHandler::AddAuthorizationHeader(
void DataReductionProxyAuthRequestHandler::InitAuthenticationOnUI(
const std::string& key) {
- key_ = key;
+ network_task_runner_->PostTask(FROM_HERE, base::Bind(
+ &DataReductionProxyAuthRequestHandler::InitAuthentication,
+ base::Unretained(this),
+ key));
+}
+
+void DataReductionProxyAuthRequestHandler::ComputeCredentials(
+ const base::Time& now,
+ std::string* session,
+ std::string* credentials) {
+ DCHECK(session);
+ DCHECK(credentials);
int64 timestamp =
- (Now() - base::Time::UnixEpoch()).InMilliseconds() / 1000;
+ (now - base::Time::UnixEpoch()).InMilliseconds() / 1000;
int32 rand[3];
RandBytes(rand, 3 * sizeof(rand[0]));
- std::string session = base::StringPrintf("%lld-%u-%u-%u",
- static_cast<long long>(timestamp),
- rand[0],
- rand[1],
- rand[2]);
- std::string credentials = base::UTF16ToUTF8(AuthHashForSalt(timestamp, key_));
-
- DVLOG(1) << "session: [" << session << "] "
- << "password: [" << credentials << "]";
- network_task_runner_->PostTask(FROM_HERE, base::Bind(
- &DataReductionProxyAuthRequestHandler::InitAuthentication,
- base::Unretained(this),
- session,
- credentials));
+ *session = base::StringPrintf("%lld-%u-%u-%u",
+ static_cast<long long>(timestamp),
+ rand[0],
+ rand[1],
+ rand[2]);
+ *credentials = base::UTF16ToUTF8(AuthHashForSalt(timestamp, key_));
+
+ DVLOG(1) << "session: [" << *session << "] "
+ << "password: [" << *credentials << "]";
}
void DataReductionProxyAuthRequestHandler::InitAuthentication(
- const std::string& session,
- const std::string& credentials) {
+ const std::string& key) {
DCHECK(network_task_runner_->BelongsToCurrentThread());
- session_ = session;
- credentials_ = credentials;
+ key_ = key;
+ last_update_time_ = Now();
+ ComputeCredentials(last_update_time_, &session_, &credentials_);
}
void DataReductionProxyAuthRequestHandler::SetKeyOnUI(const std::string& key) {

Powered by Google App Engine
This is Rietveld 408576698