Commit 3d0d1dca authored by Nasko Oskov's avatar Nasko Oskov Committed by Commit Bot

Add IsOnline API to RenderThread and cache locally online status.

This CL adds caching of the online status in the RenderThread for each
renderer process to make it available to query on demand.
Without it, when navigation in a new process results in an error page,
the NetErrorHelper object is initialized with incorrect state, leading
to breakage of autoreload functionality when the browser is back online.

Bug: 865914
Change-Id: I9eb388ddd4f06a80f48d5c4f9c774ac4b29f5377
Reviewed-on: https://chromium-review.googlesource.com/1237143Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Commit-Queue: Nasko Oskov <nasko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593819}
parent 6f27b0a8
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "components/url_formatter/url_formatter.h" #include "components/url_formatter/url_formatter.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
#include "content/public/renderer/render_thread.h"
#include "net/base/escape.h" #include "net/base/escape.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "third_party/blink/public/platform/web_string.h" #include "third_party/blink/public/platform/web_string.h"
...@@ -523,8 +524,7 @@ NetErrorHelperCore::NetErrorHelperCore(Delegate* delegate, ...@@ -523,8 +524,7 @@ NetErrorHelperCore::NetErrorHelperCore(Delegate* delegate,
auto_reload_paused_(false), auto_reload_paused_(false),
auto_reload_in_flight_(false), auto_reload_in_flight_(false),
uncommitted_load_started_(false), uncommitted_load_started_(false),
// TODO(ellyjones): Make online_ accurate at object creation. online_(content::RenderThread::Get()->IsOnline()),
online_(true),
visible_(is_visible), visible_(is_visible),
auto_reload_count_(0), auto_reload_count_(0),
navigation_from_button_(NO_BUTTON) {} navigation_from_button_(NO_BUTTON) {}
......
...@@ -97,6 +97,10 @@ class CONTENT_EXPORT RenderThread : virtual public ChildThread { ...@@ -97,6 +97,10 @@ class CONTENT_EXPORT RenderThread : virtual public ChildThread {
// Retrieve the process ID of the browser process. // Retrieve the process ID of the browser process.
virtual int32_t GetClientId() = 0; virtual int32_t GetClientId() = 0;
// Get the online status of the browser - false when there is no network
// access.
virtual bool IsOnline() = 0;
// Set the renderer process type. // Set the renderer process type.
virtual void SetRendererProcessType( virtual void SetRendererProcessType(
blink::scheduler::RendererProcessType type) = 0; blink::scheduler::RendererProcessType type) = 0;
......
...@@ -238,6 +238,10 @@ int32_t MockRenderThread::GetClientId() { ...@@ -238,6 +238,10 @@ int32_t MockRenderThread::GetClientId() {
return 1; return 1;
} }
bool MockRenderThread::IsOnline() {
return true;
}
void MockRenderThread::SetRendererProcessType( void MockRenderThread::SetRendererProcessType(
blink::scheduler::RendererProcessType type) {} blink::scheduler::RendererProcessType type) {}
......
...@@ -79,6 +79,7 @@ class MockRenderThread : public RenderThread { ...@@ -79,6 +79,7 @@ class MockRenderThread : public RenderThread {
bool ResolveProxy(const GURL& url, std::string* proxy_list) override; bool ResolveProxy(const GURL& url, std::string* proxy_list) override;
base::WaitableEvent* GetShutdownEvent() override; base::WaitableEvent* GetShutdownEvent() override;
int32_t GetClientId() override; int32_t GetClientId() override;
bool IsOnline() override;
void SetRendererProcessType( void SetRendererProcessType(
blink::scheduler::RendererProcessType type) override; blink::scheduler::RendererProcessType type) override;
blink::WebString GetUserAgent() const override; blink::WebString GetUserAgent() const override;
......
...@@ -1495,6 +1495,10 @@ int32_t RenderThreadImpl::GetClientId() { ...@@ -1495,6 +1495,10 @@ int32_t RenderThreadImpl::GetClientId() {
return client_id_; return client_id_;
} }
bool RenderThreadImpl::IsOnline() {
return online_status_;
}
void RenderThreadImpl::SetRendererProcessType( void RenderThreadImpl::SetRendererProcessType(
blink::scheduler::RendererProcessType type) { blink::scheduler::RendererProcessType type) {
main_thread_scheduler_->SetRendererProcessType(type); main_thread_scheduler_->SetRendererProcessType(type);
...@@ -2160,12 +2164,12 @@ void RenderThreadImpl::SetUpEmbeddedWorkerChannelForServiceWorker( ...@@ -2160,12 +2164,12 @@ void RenderThreadImpl::SetUpEmbeddedWorkerChannelForServiceWorker(
void RenderThreadImpl::OnNetworkConnectionChanged( void RenderThreadImpl::OnNetworkConnectionChanged(
net::NetworkChangeNotifier::ConnectionType type, net::NetworkChangeNotifier::ConnectionType type,
double max_bandwidth_mbps) { double max_bandwidth_mbps) {
bool online = type != net::NetworkChangeNotifier::CONNECTION_NONE; online_status_ = type != net::NetworkChangeNotifier::CONNECTION_NONE;
WebNetworkStateNotifier::SetOnLine(online); WebNetworkStateNotifier::SetOnLine(online_status_);
if (url_loader_throttle_provider_) if (url_loader_throttle_provider_)
url_loader_throttle_provider_->SetOnline(online); url_loader_throttle_provider_->SetOnline(online_status_);
for (auto& observer : observers_) for (auto& observer : observers_)
observer.NetworkStateChanged(online); observer.NetworkStateChanged(online_status_);
WebNetworkStateNotifier::SetWebConnection( WebNetworkStateNotifier::SetWebConnection(
NetConnectionTypeToWebConnectionType(type), max_bandwidth_mbps); NetConnectionTypeToWebConnectionType(type), max_bandwidth_mbps);
} }
......
...@@ -217,6 +217,7 @@ class CONTENT_EXPORT RenderThreadImpl ...@@ -217,6 +217,7 @@ class CONTENT_EXPORT RenderThreadImpl
bool ResolveProxy(const GURL& url, std::string* proxy_list) override; bool ResolveProxy(const GURL& url, std::string* proxy_list) override;
base::WaitableEvent* GetShutdownEvent() override; base::WaitableEvent* GetShutdownEvent() override;
int32_t GetClientId() override; int32_t GetClientId() override;
bool IsOnline() override;
void SetRendererProcessType( void SetRendererProcessType(
blink::scheduler::RendererProcessType type) override; blink::scheduler::RendererProcessType type) override;
blink::WebString GetUserAgent() const override; blink::WebString GetUserAgent() const override;
...@@ -757,6 +758,7 @@ class CONTENT_EXPORT RenderThreadImpl ...@@ -757,6 +758,7 @@ class CONTENT_EXPORT RenderThreadImpl
bool needs_to_record_first_active_paint_; bool needs_to_record_first_active_paint_;
base::TimeTicks was_backgrounded_time_; base::TimeTicks was_backgrounded_time_;
int process_foregrounded_count_; int process_foregrounded_count_;
bool online_status_ = true;
int32_t client_id_; int32_t client_id_;
......
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