Commit 0993cb9f authored by bengr's avatar bengr Committed by Commit bot

Fix Data Saver test in Cronet

Task posts in Data Saver logic were delaying initialization
unnecessarily in Cronet, and consequently, the first
request after initialization wasn't necessarily proxied.
This CL makes the initialization logic synchronous when
Data Saver's UI and IO task runners are on the same thread.

BUG=461910

Review URL: https://codereview.chromium.org/1143503005

Cr-Commit-Position: refs/heads/master@{#330579}
parent 48c25c15
......@@ -139,7 +139,7 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
// server. This request will fail if the configuration logic for the
// Data Reduction Proxy is not used.
UrlRequest urlRequest = mActivity.mUrlRequestContext.createRequest(
"http://google.com/datareductionproxysuccess.txt",
"http://DomainThatDoesnt.Resolve/datareductionproxysuccess.txt",
listener, listener.getExecutor());
urlRequest.start();
listener.blockForDone();
......@@ -148,7 +148,8 @@ public class CronetUrlRequestContextTest extends CronetTestBase {
// Proxy logic configured to use the test server as its proxy.
assertEquals(200, listener.mResponseInfo.getHttpStatusCode());
assertEquals(serverHostPort, listener.mResponseInfo.getProxyServer());
assertEquals("http://www.google.com/datareductionproxysuccess.txt",
assertEquals(
"http://DomainThatDoesnt.Resolve/datareductionproxysuccess.txt",
listener.mResponseInfo.getUrl());
}
......
......@@ -172,6 +172,10 @@ void DataReductionProxyIOData::SetDataReductionProxyService(
// Using base::Unretained is safe here, unless the browser is being shut down
// before the Initialize task can be executed. The task is only created as
// part of class initialization.
if (io_task_runner_->BelongsToCurrentThread()) {
InitializeOnIOThread();
return;
}
io_task_runner_->PostTask(
FROM_HERE,
base::Bind(&DataReductionProxyIOData::InitializeOnIOThread,
......@@ -184,6 +188,10 @@ void DataReductionProxyIOData::InitializeOnIOThread() {
if (config_client_.get())
config_client_->InitializeOnIOThread(url_request_context_getter_);
experiments_stats_->InitializeOnIOThread();
if (ui_task_runner_->BelongsToCurrentThread()) {
service_->SetIOData(weak_factory_.GetWeakPtr());
return;
}
ui_task_runner_->PostTask(
FROM_HERE,
base::Bind(&DataReductionProxyService::SetIOData,
......
......@@ -115,6 +115,10 @@ void DataReductionProxyService::SetProxyPrefs(bool enabled,
bool alternative_enabled,
bool at_startup) {
DCHECK(CalledOnValidThread());
if (io_task_runner_->BelongsToCurrentThread()) {
io_data_->SetProxyPrefs(enabled, alternative_enabled, at_startup);
return;
}
io_task_runner_->PostTask(
FROM_HERE,
base::Bind(&DataReductionProxyIOData::SetProxyPrefs,
......@@ -123,6 +127,10 @@ void DataReductionProxyService::SetProxyPrefs(bool enabled,
void DataReductionProxyService::RetrieveConfig() {
DCHECK(CalledOnValidThread());
if (io_task_runner_->BelongsToCurrentThread()) {
io_data_->RetrieveConfig();
return;
}
io_task_runner_->PostTask(
FROM_HERE,
base::Bind(&DataReductionProxyIOData::RetrieveConfig, io_data_));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment