Commit a0f755db authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

AW: fix cache settings for network service

This connects the cache settings from AwSettings to the network service
code path, which fixes 2 related tests.

This creates the net_helpers file to share common logic between both the
network service and legacy code paths. Right now, this only contains
WebView's logic to translate WebView cache settings into net layer
load_flags.

Bug: 904890
Bug: 893573
Bug: 893574
Test: run_webview_instrumentation_test_apk \
Test: --enable-features=NetworkService,NetworkServiceInProcess \
Test: -f=ClientOnReceivedError*Test#test*CacheMiss
Cq-Include-Trybots: master.tryserver.chromium.android:android_mojo
Change-Id: Ic2d62dfedd5f0c1ddfa04469454aea7d43df9373
Reviewed-on: https://chromium-review.googlesource.com/c/1339720Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarTim Volodine <timvolodine@chromium.org>
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609875}
parent 942e37a1
...@@ -623,6 +623,8 @@ source_set("common") { ...@@ -623,6 +623,8 @@ source_set("common") {
"browser/net/input_stream_reader.h", "browser/net/input_stream_reader.h",
"browser/net/token_binding_manager.cc", "browser/net/token_binding_manager.cc",
"browser/net/token_binding_manager.h", "browser/net/token_binding_manager.h",
"browser/net_helpers.cc",
"browser/net_helpers.h",
"browser/parent_compositor_draw_constraints.cc", "browser/parent_compositor_draw_constraints.cc",
"browser/parent_compositor_draw_constraints.h", "browser/parent_compositor_draw_constraints.h",
"browser/parent_output_surface.cc", "browser/parent_output_surface.cc",
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <utility> #include <utility>
#include "android_webview/browser/aw_contents_client_bridge.h" #include "android_webview/browser/aw_contents_client_bridge.h"
#include "android_webview/browser/aw_contents_io_thread_client.h"
#include "android_webview/browser/net_helpers.h"
#include "android_webview/browser/renderer_host/auto_login_parser.h" #include "android_webview/browser/renderer_host/auto_login_parser.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
...@@ -16,6 +18,7 @@ ...@@ -16,6 +18,7 @@
#include "content/public/browser/resource_request_info.h" #include "content/public/browser/resource_request_info.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/url_utils.h" #include "content/public/common/url_utils.h"
#include "net/base/load_flags.h"
#include "net/http/http_util.h" #include "net/http/http_util.h"
namespace android_webview { namespace android_webview {
...@@ -68,6 +71,7 @@ class InterceptedRequest : public network::mojom::URLLoader, ...@@ -68,6 +71,7 @@ class InterceptedRequest : public network::mojom::URLLoader,
void ResumeReadingBodyFromNet() override; void ResumeReadingBodyFromNet() override;
private: private:
std::unique_ptr<AwContentsIoThreadClient> GetIoThreadClient();
void OnRequestError(const network::URLLoaderCompletionStatus& status); void OnRequestError(const network::URLLoaderCompletionStatus& status);
// TODO(timvolodine): consider factoring this out of this class. // TODO(timvolodine): consider factoring this out of this class.
...@@ -126,6 +130,8 @@ void InterceptedRequest::Restart() { ...@@ -126,6 +130,8 @@ void InterceptedRequest::Restart() {
// TODO(timvolodine): add async check shouldOverrideUrlLoading and // TODO(timvolodine): add async check shouldOverrideUrlLoading and
// shouldInterceptRequest. // shouldInterceptRequest.
request_.load_flags = GetCacheModeForClient(GetIoThreadClient().get());
if (!target_loader_ && target_factory_) { if (!target_loader_ && target_factory_) {
network::mojom::URLLoaderClientPtr proxied_client; network::mojom::URLLoaderClientPtr proxied_client;
proxied_client_binding_.Bind(mojo::MakeRequest(&proxied_client)); proxied_client_binding_.Bind(mojo::MakeRequest(&proxied_client));
...@@ -315,6 +321,16 @@ void InterceptedRequest::ResumeReadingBodyFromNet() { ...@@ -315,6 +321,16 @@ void InterceptedRequest::ResumeReadingBodyFromNet() {
target_loader_->ResumeReadingBodyFromNet(); target_loader_->ResumeReadingBodyFromNet();
} }
std::unique_ptr<AwContentsIoThreadClient>
InterceptedRequest::GetIoThreadClient() {
// |process_id_| == 0 indicates this is a navigation, and so we should use the
// frame_tree_node_id API (with request_.render_frame_id).
return process_id_
? AwContentsIoThreadClient::FromID(process_id_,
request_.render_frame_id)
: AwContentsIoThreadClient::FromID(request_.render_frame_id);
}
void InterceptedRequest::OnRequestError( void InterceptedRequest::OnRequestError(
const network::URLLoaderCompletionStatus& status) { const network::URLLoaderCompletionStatus& status) {
target_client_->OnComplete(status); target_client_->OnComplete(status);
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "android_webview/browser/net_helpers.h"
#include "android_webview/browser/aw_contents_io_thread_client.h"
#include "base/logging.h"
#include "base/macros.h"
#include "net/base/load_flags.h"
namespace android_webview {
int GetCacheModeForClient(AwContentsIoThreadClient* client) {
AwContentsIoThreadClient::CacheMode cache_mode = client->GetCacheMode();
switch (cache_mode) {
case AwContentsIoThreadClient::LOAD_CACHE_ELSE_NETWORK:
// If the resource is in the cache (even if expired), load from cache.
// Otherwise, fall back to network.
return net::LOAD_SKIP_CACHE_VALIDATION;
case AwContentsIoThreadClient::LOAD_NO_CACHE:
// Always load from the network, don't use the cache.
return net::LOAD_BYPASS_CACHE;
case AwContentsIoThreadClient::LOAD_CACHE_ONLY:
// If the resource is in the cache (even if expired), load from cache. Do
// not fall back to the network.
return net::LOAD_ONLY_FROM_CACHE | net::LOAD_SKIP_CACHE_VALIDATION;
default:
// If the resource is in the cache (and is valid), load from cache.
// Otherwise, fall back to network. This is the usual (default) case.
return 0;
}
}
} // namespace android_webview
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ANDROID_WEBVIEW_BROWSER_NET_HELPERS_H_
#define ANDROID_WEBVIEW_BROWSER_NET_HELPERS_H_
#include <memory>
namespace android_webview {
class AwContentsIoThreadClient;
// Gets the net-layer load_flags which reflect |client|'s cache mode.
int GetCacheModeForClient(AwContentsIoThreadClient* client);
} // namespace android_webview
#endif // ANDROID_WEBVIEW_BROWSER_NET_HELPERS_H_
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "android_webview/browser/aw_resource_context.h" #include "android_webview/browser/aw_resource_context.h"
#include "android_webview/browser/aw_safe_browsing_resource_throttle.h" #include "android_webview/browser/aw_safe_browsing_resource_throttle.h"
#include "android_webview/browser/net/aw_web_resource_request.h" #include "android_webview/browser/net/aw_web_resource_request.h"
#include "android_webview/browser/net_helpers.h"
#include "android_webview/browser/renderer_host/auto_login_parser.h" #include "android_webview/browser/renderer_host/auto_login_parser.h"
#include "android_webview/common/url_constants.h" #include "android_webview/common/url_constants.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
...@@ -249,20 +250,9 @@ bool IoThreadClientThrottle::ShouldBlockRequest() { ...@@ -249,20 +250,9 @@ bool IoThreadClientThrottle::ShouldBlockRequest() {
SetCacheControlFlag( SetCacheControlFlag(
request_, net::LOAD_ONLY_FROM_CACHE | net::LOAD_SKIP_CACHE_VALIDATION); request_, net::LOAD_ONLY_FROM_CACHE | net::LOAD_SKIP_CACHE_VALIDATION);
} else { } else {
AwContentsIoThreadClient::CacheMode cache_mode = io_client->GetCacheMode(); int cache_mode = GetCacheModeForClient(io_client.get());
switch (cache_mode) { if (cache_mode) {
case AwContentsIoThreadClient::LOAD_CACHE_ELSE_NETWORK: SetCacheControlFlag(request_, cache_mode);
SetCacheControlFlag(request_, net::LOAD_SKIP_CACHE_VALIDATION);
break;
case AwContentsIoThreadClient::LOAD_NO_CACHE:
SetCacheControlFlag(request_, net::LOAD_BYPASS_CACHE);
break;
case AwContentsIoThreadClient::LOAD_CACHE_ONLY:
SetCacheControlFlag(request_, net::LOAD_ONLY_FROM_CACHE |
net::LOAD_SKIP_CACHE_VALIDATION);
break;
default:
break;
} }
} }
return false; return false;
......
...@@ -115,13 +115,9 @@ ...@@ -115,13 +115,9 @@
-org.chromium.android_webview.test.ClientOnReceivedError2Test.testIframeSubresource -org.chromium.android_webview.test.ClientOnReceivedError2Test.testIframeSubresource
-org.chromium.android_webview.test.ClientOnReceivedError2Test.testImageSubresource -org.chromium.android_webview.test.ClientOnReceivedError2Test.testImageSubresource
-org.chromium.android_webview.test.ClientOnReceivedError2Test.testMainFrame -org.chromium.android_webview.test.ClientOnReceivedError2Test.testMainFrame
-org.chromium.android_webview.test.ClientOnReceivedError2Test.testOnCacheMiss
-org.chromium.android_webview.test.ClientOnReceivedError2Test.testUserGesture -org.chromium.android_webview.test.ClientOnReceivedError2Test.testUserGesture
-org.chromium.android_webview.test.ClientOnReceivedError2Test.testUserGestureForIframeSubresource -org.chromium.android_webview.test.ClientOnReceivedError2Test.testUserGestureForIframeSubresource
# https://crbug.com/893574
-org.chromium.android_webview.test.ClientOnReceivedErrorTest.testCacheMiss
# https://crbug.com/893575 # https://crbug.com/893575
-org.chromium.android_webview.test.CookieManagerStartupTest.testShouldInterceptRequestDeadlock -org.chromium.android_webview.test.CookieManagerStartupTest.testShouldInterceptRequestDeadlock
-org.chromium.android_webview.test.CookieManagerStartupTest.testStartup -org.chromium.android_webview.test.CookieManagerStartupTest.testStartup
......
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