From 410e82c08dda3b708e639e00ca4f0dacfbd7395a Mon Sep 17 00:00:00 2001 From: w00818794 Date: Mon, 30 Dec 2024 01:31:05 +0000 Subject: [PATCH] 304CodeCache Signed-off-by: w00818794 --- net/http/http_cache_transaction.cc | 18 ++++++++++++++++++ net/http/http_response_headers.h | 4 ++++ net/http/http_response_info.h | 5 +++++ net/url_request/url_request.h | 5 +++++ .../public/mojom/url_response_head.mojom | 3 +++ services/network/url_loader.cc | 1 + 6 files changed, 36 insertions(+) diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc index ce5ca68394..6397c6c382 100644 --- a/net/http/http_cache_transaction.cc +++ b/net/http/http_cache_transaction.cc @@ -63,6 +63,11 @@ #include "net/ssl/ssl_cert_request_info.h" #include "net/ssl/ssl_config_service.h" +#if BUILDFLAG(IS_OHOS) +#include "base/logging.h" +#include "ohos_adapter_helper.h" +#endif + using base::Time; using base::TimeTicks; @@ -2110,6 +2115,19 @@ int HttpCache::Transaction::DoUpdateCachedResponse() { response_.ssl_info = new_response_->ssl_info; response_.dns_aliases = new_response_->dns_aliases; +#if BUILDFLAG(IS_OHOS) + if (new_response_->headers->response_code() == HTTP_NOT_MODIFIED) { + static bool res = OHOS::NWeb::OhosAdapterHelper::GetInstance() + .GetSystemPropertiesInstance() + .GetBoolParameter("web.304CodeCache.enable", false); + if (res) { + LOG(DEBUG) << "HttpCache::Transaction::DoUpdateCachedResponse set " + "response code: HTTP_NOT_MODIFIED"; + response_.code_cache_valid = true; + } + } +#endif + // Be careful never to set single_keyed_cache_entry_unusable back to false // from true. if (mark_single_keyed_cache_entry_unusable_) { diff --git a/net/http/http_response_headers.h b/net/http/http_response_headers.h index dea8bd2153..ba1621125e 100644 --- a/net/http/http_response_headers.h +++ b/net/http/http_response_headers.h @@ -341,6 +341,10 @@ class NET_EXPORT HttpResponseHeaders // Write a representation of this object into tracing proto. void WriteIntoTrace(perfetto::TracedValue context) const; +#if BUILDFLAG(IS_OHOS) + void SetResponseCode(int code) { response_code_ = code; } +#endif + private: friend class base::RefCountedThreadSafe; diff --git a/net/http/http_response_info.h b/net/http/http_response_info.h index 1455d3771b..7cd74107ed 100644 --- a/net/http/http_response_info.h +++ b/net/http/http_response_info.h @@ -273,6 +273,11 @@ class NET_EXPORT HttpResponseInfo { absl::optional browser_run_id; static std::string ConnectionInfoToString(ConnectionInfo connection_info); + +#if BUILDFLAG(IS_OHOS) + // Valid when response status code is 304 + bool code_cache_valid = false; +#endif }; } // namespace net diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h index 1a588e14ab..03729f9dfa 100644 --- a/net/url_request/url_request.h +++ b/net/url_request/url_request.h @@ -880,6 +880,11 @@ class NET_EXPORT URLRequest : public base::SupportsUserData { std::shared_ptr preload_info() const { return preload_info_; } #endif +#if BUILDFLAG(IS_OHOS) + void set_code_cache_valid(bool valid) { response_info_.code_cache_valid = valid; } + bool is_code_cache_valid() { return response_info_.code_cache_valid; } +#endif + static bool DefaultCanUseCookies(); base::WeakPtr GetWeakPtr(); diff --git a/services/network/public/mojom/url_response_head.mojom b/services/network/public/mojom/url_response_head.mojom index f232e84621..814937c3d4 100644 --- a/services/network/public/mojom/url_response_head.mojom +++ b/services/network/public/mojom/url_response_head.mojom @@ -291,4 +291,7 @@ struct URLResponseHead { // TODO(https://crbug.com/1268378): Remove this once preflights are enforced. PrivateNetworkAccessPreflightResult private_network_access_preflight_result = PrivateNetworkAccessPreflightResult.kNone; + + [EnableIf=is_ohos] + bool code_cache_valid = false; }; diff --git a/services/network/url_loader.cc b/services/network/url_loader.cc index e553763d01..30d687ffb0 100644 --- a/services/network/url_loader.cc +++ b/services/network/url_loader.cc @@ -1410,6 +1410,7 @@ mojom::URLResponseHeadPtr URLLoader::BuildResponseHead() const { PopulateParsedHeaders(response->headers.get(), url_request_->url()); #if BUILDFLAG(IS_OHOS) + response->code_cache_valid = url_request_->is_code_cache_valid(); std::string http_version; if (url_request_->was_fetched_via_spdy()) { http_version = "http/2.0"; -- Gitee