diff --git a/cobalt/browser/browser_module.cc b/cobalt/browser/browser_module.cc index f44b2b2672fc..f168f1b3bf45 100644 --- a/cobalt/browser/browser_module.cc +++ b/cobalt/browser/browser_module.cc @@ -1962,6 +1962,11 @@ void BrowserModule::UnfreezeInternal(SbTimeMonotonic timestamp) { FOR_EACH_OBSERVER(LifecycleObserver, lifecycle_observers_, Unfreeze(GetResourceProvider(), timestamp)); +#if defined(DIAL_SERVER) + if (network_module_) { + network_module_->RestartDialService(); + } +#endif } void BrowserModule::OnMaybeFreeze() { diff --git a/cobalt/network/dial/dial_service.cc b/cobalt/network/dial/dial_service.cc index 31e648d661df..02052b80a463 100644 --- a/cobalt/network/dial/dial_service.cc +++ b/cobalt/network/dial/dial_service.cc @@ -157,10 +157,18 @@ void DialServiceProxy::Deregister( FROM_HERE, base::Bind(&DialServiceProxy::OnDeregister, this, handler)); } +void DialServiceProxy::ReplaceDialService( + const base::WeakPtr& service) { + task_runner_->PostTask( + FROM_HERE, + base::Bind(&DialServiceProxy::OnReplaceDialService, this, service)); +} + void DialServiceProxy::OnRegister( const scoped_refptr& handler) { if (dial_service_) { dial_service_->Register(handler); + handlers_.push_back(handler); } } @@ -168,6 +176,17 @@ void DialServiceProxy::OnDeregister( const scoped_refptr& handler) { if (dial_service_) { dial_service_->Deregister(handler); + handlers_.remove(handler); + } +} + +void DialServiceProxy::OnReplaceDialService( + const base::WeakPtr& service) { + dial_service_ = service; + if (dial_service_) { + for (auto handler : handlers_) { + dial_service_->Register(handler); + } } } diff --git a/cobalt/network/dial/dial_service.h b/cobalt/network/dial/dial_service.h index 6280830cbde7..8891b415fd1b 100644 --- a/cobalt/network/dial/dial_service.h +++ b/cobalt/network/dial/dial_service.h @@ -15,6 +15,7 @@ #ifndef COBALT_NETWORK_DIAL_DIAL_SERVICE_H_ #define COBALT_NETWORK_DIAL_DIAL_SERVICE_H_ +#include #include #include #include @@ -63,7 +64,7 @@ class NET_EXPORT DialService : public base::SupportsWeakPtr { scoped_refptr http_server_; std::unique_ptr udp_server_; - typedef std::map > + typedef std::map> ServiceHandlerMap; ServiceHandlerMap handlers_; std::string http_host_address_; @@ -82,6 +83,7 @@ class NET_EXPORT DialServiceProxy explicit DialServiceProxy(const base::WeakPtr& dial_service); void Register(const scoped_refptr& handler); void Deregister(const scoped_refptr& handler); + void ReplaceDialService(const base::WeakPtr& service); std::string host_address() const { return host_address_; } private: @@ -89,10 +91,13 @@ class NET_EXPORT DialServiceProxy virtual ~DialServiceProxy(); void OnRegister(const scoped_refptr& handler); void OnDeregister(const scoped_refptr& handler); + void OnReplaceDialService(const base::WeakPtr& service); base::WeakPtr dial_service_; std::string host_address_; + std::list> handlers_; + // Message loop to call DialService methods on. scoped_refptr task_runner_; diff --git a/cobalt/network/network_module.cc b/cobalt/network/network_module.cc index 00cac1bf2dc0..09263af68ae4 100644 --- a/cobalt/network/network_module.cc +++ b/cobalt/network/network_module.cc @@ -232,6 +232,29 @@ void NetworkModule::OnCreate(base::WaitableEvent* creation_event) { creation_event->Signal(); } +#if defined(DIAL_SERVER) +void NetworkModule::RestartDialService() { + base::WaitableEvent creation_event( + base::WaitableEvent::ResetPolicy::MANUAL, + base::WaitableEvent::InitialState::NOT_SIGNALED); + // Run Network module startup on IO thread, + // so the network delegate and URL request context are + // constructed on that thread. + task_runner()->PostTask(FROM_HERE, + base::Bind(&NetworkModule::OnRestartDialService, + base::Unretained(this), &creation_event)); + // Wait for OnCreate() to run, so we can be sure our members + // have been constructed. + creation_event.Wait(); +} + +void NetworkModule::OnRestartDialService(base::WaitableEvent* creation_event) { + dial_service_.reset(new DialService()); + dial_service_proxy_->ReplaceDialService(dial_service_->AsWeakPtr()); + creation_event->Signal(); +} +#endif + void NetworkModule::AddClientHintHeaders( net::URLFetcher& url_fetcher, ClientHintHeadersCallType call_type) const { if (kEnabledClientHintHeaders & call_type) { diff --git a/cobalt/network/network_module.h b/cobalt/network/network_module.h index 80b0179bff2c..e00a5f1b9b54 100644 --- a/cobalt/network/network_module.h +++ b/cobalt/network/network_module.h @@ -142,6 +142,9 @@ class NetworkModule : public base::MessageLoop::DestructionObserver { void StartNetLog(); base::FilePath StopNetLog(); +#if defined(DIAL_SERVER) + void RestartDialService(); +#endif private: void Initialize(const std::string& user_agent_string, @@ -159,6 +162,7 @@ class NetworkModule : public base::MessageLoop::DestructionObserver { std::unique_ptr http_user_agent_settings_; std::unique_ptr cookie_jar_; #if defined(DIAL_SERVER) + void OnRestartDialService(base::WaitableEvent* creation_event); std::unique_ptr dial_service_; scoped_refptr dial_service_proxy_; #endif