diff options
author | bengr <bengr@chromium.org> | 2015-05-19 12:00:38 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-19 19:00:35 +0000 |
commit | 0993cb9f8f775a7c4b40525c55785f389acde1a5 (patch) | |
tree | e76a7e9cb9259c477aed12d633c88bbf93660b50 | |
parent | 48c25c15f0c882cac698bf06759a270a3f2d3b5c (diff) | |
download | chromium_src-0993cb9f8f775a7c4b40525c55785f389acde1a5.zip chromium_src-0993cb9f8f775a7c4b40525c55785f389acde1a5.tar.gz chromium_src-0993cb9f8f775a7c4b40525c55785f389acde1a5.tar.bz2 |
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}
3 files changed, 19 insertions, 2 deletions
diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java b/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java index d4c4a6b..2576dbb 100644 --- a/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java +++ b/components/cronet/android/test/javatests/src/org/chromium/net/CronetUrlRequestContextTest.java @@ -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()); } diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc index 9c12d24..29b3408 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.cc @@ -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, diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc index 9f6b4b0..20faab1 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_service.cc @@ -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_)); |