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 6130eda1b94f3017ca29bfdb067696a723d74a41..a687789db44352ca566732072ed7cd4ea847cbb5 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 |
@@ -4,7 +4,9 @@ |
#include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_request_handler.h" |
+#include "base/bind.h" |
#include "base/command_line.h" |
+#include "base/message_loop/message_loop_proxy.h" |
#include "base/strings/stringprintf.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/time/time.h" |
@@ -36,19 +38,21 @@ bool DataReductionProxyAuthRequestHandler::IsKeySetOnCommandLine() { |
} |
DataReductionProxyAuthRequestHandler::DataReductionProxyAuthRequestHandler( |
- DataReductionProxyParams* params) |
- : data_reduction_proxy_params_(params) { |
- version_ = kProtocolVersion; |
-#if defined(OS_ANDROID) |
- client_ = kClientChromeAndroid; |
-#elif defined(OS_IOS) |
- client_ = kClientChromeIOS; |
-#endif |
+ DataReductionProxyParams* params, |
+ base::MessageLoopProxy* io_thread_proxy) |
+ : data_reduction_proxy_params_(params), |
+ io_thread_proxy_(io_thread_proxy) { |
Init(); |
} |
void DataReductionProxyAuthRequestHandler::Init() { |
- InitAuthentication(GetDefaultKey()); |
+ std::string client; |
+#if defined(OS_ANDROID) |
+ client = kClientChromeAndroid; |
+#elif defined(OS_IOS) |
+ client = kClientChromeIOS; |
+#endif |
+ InitAuthentication(GetDefaultKey(), client, kProtocolVersion); |
} |
@@ -82,6 +86,7 @@ void DataReductionProxyAuthRequestHandler::MaybeAddRequestHeader( |
net::URLRequest* request, |
const net::ProxyServer& proxy_server, |
net::HttpRequestHeaders* request_headers) { |
+ DCHECK(io_thread_proxy_->BelongsToCurrentThread()); |
if (!proxy_server.is_valid()) |
return; |
if (data_reduction_proxy_params_ && |
@@ -108,31 +113,50 @@ void DataReductionProxyAuthRequestHandler::AddAuthorizationHeader( |
} |
void DataReductionProxyAuthRequestHandler::InitAuthentication( |
- const std::string& key) { |
+ const std::string& key, |
+ const std::string& client, |
+ const std::string& version) { |
key_ = key; |
int64 timestamp = |
(Now() - base::Time::UnixEpoch()).InMilliseconds() / 1000; |
int32 rand[3]; |
RandBytes(rand, 3 * sizeof(rand[0])); |
- 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_ << "]"; |
+ 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 << "]"; |
+ io_thread_proxy_->PostTask(FROM_HERE, base::Bind( |
+ &DataReductionProxyAuthRequestHandler::InitAuthenticationOnIOThread, |
+ base::Unretained(this), |
+ session, |
+ credentials, |
+ client, |
+ version)); |
+} |
+ |
+void DataReductionProxyAuthRequestHandler::InitAuthenticationOnIOThread( |
+ const std::string& session, |
+ const std::string& credentials, |
+ const std::string& client, |
+ const std::string& version) { |
+ DCHECK(io_thread_proxy_->BelongsToCurrentThread()); |
+ session_ = session; |
+ credentials_ = credentials; |
+ client_ = client; |
+ version_ = version; |
} |
void DataReductionProxyAuthRequestHandler::SetKey(const std::string& key, |
const std::string& client, |
const std::string& version) { |
- client_ = client; |
- version_ = version; |
if (!key.empty()) |
- InitAuthentication(key); |
+ InitAuthentication(key, client, version); |
} |