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

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

Issue 412143009: Moved data reduction proxy initialization logic to ProfileImplIOData (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments from willchan and sgurun Created 6 years, 5 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 6130eda1b94f3017ca29bfdb067696a723d74a41..fcd58fc1cd521a2c3a6853bf79b83a4168050d55 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/single_thread_task_runner.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,
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner)
+ : data_reduction_proxy_params_(params),
+ network_task_runner_(network_task_runner) {
Init();
}
void DataReductionProxyAuthRequestHandler::Init() {
- InitAuthentication(GetDefaultKey());
+ std::string client;
+#if defined(OS_ANDROID)
+ client = kClientChromeAndroid;
+#elif defined(OS_IOS)
+ client = kClientChromeIOS;
+#endif
+ InitAuthenticationOnUI(GetDefaultKey(), client, kProtocolVersion);
}
@@ -82,6 +86,7 @@ void DataReductionProxyAuthRequestHandler::MaybeAddRequestHeader(
net::URLRequest* request,
const net::ProxyServer& proxy_server,
net::HttpRequestHeaders* request_headers) {
+ DCHECK(network_task_runner_->BelongsToCurrentThread());
if (!proxy_server.is_valid())
return;
if (data_reduction_proxy_params_ &&
@@ -107,32 +112,51 @@ void DataReductionProxyAuthRequestHandler::AddAuthorizationHeader(
headers->SetHeader(kChromeProxyHeader, header_value);
}
-void DataReductionProxyAuthRequestHandler::InitAuthentication(
- const std::string& key) {
+void DataReductionProxyAuthRequestHandler::InitAuthenticationOnUI(
+ 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 << "]";
+ network_task_runner_->PostTask(FROM_HERE, base::Bind(
+ &DataReductionProxyAuthRequestHandler::InitAuthentication,
+ base::Unretained(this),
+ session,
+ credentials,
+ client,
+ version));
}
-void DataReductionProxyAuthRequestHandler::SetKey(const std::string& key,
- const std::string& client,
- const std::string& version) {
+void DataReductionProxyAuthRequestHandler::InitAuthentication(
+ const std::string& session,
+ const std::string& credentials,
+ const std::string& client,
+ const std::string& version) {
+ DCHECK(network_task_runner_->BelongsToCurrentThread());
+ session_ = session;
+ credentials_ = credentials;
client_ = client;
version_ = version;
+}
+
+void DataReductionProxyAuthRequestHandler::SetKeyOnUI(const std::string& key,
+ const std::string& client,
+ const std::string& version) {
if (!key.empty())
- InitAuthentication(key);
+ InitAuthenticationOnUI(key, client, version);
}

Powered by Google App Engine
This is Rietveld 408576698