Commit 0343895c authored by John Abd-El-Malek's avatar John Abd-El-Malek Committed by Commit Bot

Fix crash when Chrome switches to full mode from reduced mode.

The problem was that NetworkConnectionNotifier was created by the in-process Network Service.
BrowserMainLoop then tries to create it again which isn't supported as it's a singleton.

Fix this by adding similar logic to BrowsrMainLoop as in Network Service, which is to only create it
if it's not already created. Since BrowserMainLoop may not own the object in all cases, mark the
methods that ChromeOS needs to call on NetworkChangeNotifierPosix as static as, similar to how the
public methods on NetworkChangeNotifier are static.

Bug: 962479
Change-Id: Icb6d0053d445778e6d8b1ee75233f435257ba935
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1613721
Commit-Queue: Xi Han <hanxi@chromium.org>
Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660629}
parent b71abdf4
...@@ -695,7 +695,10 @@ void BrowserMainLoop::PostMainMessageLoopStart() { ...@@ -695,7 +695,10 @@ void BrowserMainLoop::PostMainMessageLoopStart() {
} }
{ {
TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:NetworkChangeNotifier"); TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:NetworkChangeNotifier");
network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); // On Android if reduced mode started network service this would already be
// created.
if (!net::NetworkChangeNotifier::HasNetworkChangeNotifier())
network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
} }
{ {
TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:ScreenlockMonitor"); TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:ScreenlockMonitor");
......
...@@ -175,14 +175,16 @@ class CONTENT_EXPORT BrowserMainLoop { ...@@ -175,14 +175,16 @@ class CONTENT_EXPORT BrowserMainLoop {
media::UserInputMonitor* user_input_monitor() const { media::UserInputMonitor* user_input_monitor() const {
return user_input_monitor_.get(); return user_input_monitor_.get();
} }
net::NetworkChangeNotifier* network_change_notifier() const {
return network_change_notifier_.get();
}
MediaKeysListenerManagerImpl* media_keys_listener_manager() const { MediaKeysListenerManagerImpl* media_keys_listener_manager() const {
return media_keys_listener_manager_.get(); return media_keys_listener_manager_.get();
} }
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// Only expose this on ChromeOS since it's only needed there. On Android this
// be null if this process started in reduced mode.
net::NetworkChangeNotifier* network_change_notifier() const {
return network_change_notifier_.get();
}
KeyboardMicRegistration* keyboard_mic_registration() { KeyboardMicRegistration* keyboard_mic_registration() {
return &keyboard_mic_registration_; return &keyboard_mic_registration_;
} }
......
...@@ -243,9 +243,11 @@ network::NetworkService* GetNetworkServiceImpl() { ...@@ -243,9 +243,11 @@ network::NetworkService* GetNetworkServiceImpl() {
return g_network_service; return g_network_service;
} }
#if defined(OS_CHROMEOS)
net::NetworkChangeNotifier* GetNetworkChangeNotifier() { net::NetworkChangeNotifier* GetNetworkChangeNotifier() {
return BrowserMainLoop::GetInstance()->network_change_notifier(); return BrowserMainLoop::GetInstance()->network_change_notifier();
} }
#endif
void FlushNetworkServiceInstanceForTesting() { void FlushNetworkServiceInstanceForTesting() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/callback_list.h" #include "base/callback_list.h"
#include "build/build_config.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "services/network/public/cpp/network_connection_tracker.h" #include "services/network/public/cpp/network_connection_tracker.h"
...@@ -63,8 +64,11 @@ RegisterNetworkServiceCrashHandler(base::RepeatingClosure handler); ...@@ -63,8 +64,11 @@ RegisterNetworkServiceCrashHandler(base::RepeatingClosure handler);
// service is enabled. // service is enabled.
CONTENT_EXPORT network::NetworkService* GetNetworkServiceImpl(); CONTENT_EXPORT network::NetworkService* GetNetworkServiceImpl();
// Only on ChromeOS since it's only used there.
#if defined(OS_CHROMEOS)
// Returns the global NetworkChangeNotifier instance. // Returns the global NetworkChangeNotifier instance.
CONTENT_EXPORT net::NetworkChangeNotifier* GetNetworkChangeNotifier(); CONTENT_EXPORT net::NetworkChangeNotifier* GetNetworkChangeNotifier();
#endif
// Call |FlushForTesting()| on cached |NetworkServicePtr|. For testing only. // Call |FlushForTesting()| on cached |NetworkServicePtr|. For testing only.
// Must only be called on the UI thread. // Must only be called on the UI thread.
......
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