2017-12-18 11:57:20 +00:00
|
|
|
// Copyright (c) 2017 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#ifndef SHELL_BROWSER_IO_THREAD_H_
|
|
|
|
#define SHELL_BROWSER_IO_THREAD_H_
|
2017-12-18 11:57:20 +00:00
|
|
|
|
|
|
|
#include <memory>
|
2019-06-04 03:44:12 +00:00
|
|
|
#include <set>
|
2017-12-18 11:57:20 +00:00
|
|
|
|
|
|
|
#include "base/macros.h"
|
2019-06-04 03:44:12 +00:00
|
|
|
#include "base/synchronization/lock.h"
|
2017-12-18 11:57:20 +00:00
|
|
|
#include "content/public/browser/browser_thread_delegate.h"
|
2018-11-07 14:24:05 +00:00
|
|
|
#include "services/network/public/mojom/network_service.mojom.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/net/system_network_context_manager.h"
|
2017-12-18 11:57:20 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2019-06-04 03:44:12 +00:00
|
|
|
class URLRequestContextGetter;
|
|
|
|
}
|
|
|
|
|
2017-12-18 11:57:20 +00:00
|
|
|
namespace net {
|
|
|
|
class URLRequestContext;
|
2018-11-07 14:24:05 +00:00
|
|
|
}
|
2017-12-18 11:57:20 +00:00
|
|
|
|
|
|
|
class IOThread : public content::BrowserThreadDelegate {
|
|
|
|
public:
|
2018-11-07 14:24:05 +00:00
|
|
|
explicit IOThread(
|
|
|
|
SystemNetworkContextManager* system_network_context_manager);
|
2017-12-18 11:57:20 +00:00
|
|
|
~IOThread() override;
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
void RegisterURLRequestContextGetter(
|
|
|
|
electron::URLRequestContextGetter* getter);
|
|
|
|
void DeregisterURLRequestContextGetter(
|
|
|
|
electron::URLRequestContextGetter* getter);
|
2019-06-04 03:44:12 +00:00
|
|
|
|
2017-12-18 11:57:20 +00:00
|
|
|
protected:
|
|
|
|
// BrowserThreadDelegate Implementation, runs on the IO thread.
|
|
|
|
void Init() override;
|
|
|
|
void CleanUp() override;
|
|
|
|
|
|
|
|
private:
|
2018-11-07 14:24:05 +00:00
|
|
|
// When the network service is disabled, this holds on to a
|
|
|
|
// content::NetworkContext class that owns |system_request_context_|.
|
2019-06-04 03:44:12 +00:00
|
|
|
std::unique_ptr<network::mojom::NetworkContext> system_network_context_;
|
2018-11-07 14:24:05 +00:00
|
|
|
net::URLRequestContext* system_request_context_;
|
|
|
|
|
|
|
|
// These are set on the UI thread, and then consumed during initialization on
|
|
|
|
// the IO thread.
|
|
|
|
network::mojom::NetworkContextRequest network_context_request_;
|
|
|
|
network::mojom::NetworkContextParamsPtr network_context_params_;
|
|
|
|
|
|
|
|
// Initial HTTP auth configuration used when setting up the NetworkService on
|
|
|
|
// the IO Thread. Future updates are sent using the NetworkService mojo
|
|
|
|
// interface, but initial state needs to be set non-racily.
|
|
|
|
network::mojom::HttpAuthStaticParamsPtr http_auth_static_params_;
|
|
|
|
network::mojom::HttpAuthDynamicParamsPtr http_auth_dynamic_params_;
|
2017-12-18 11:57:20 +00:00
|
|
|
|
2019-06-04 03:44:12 +00:00
|
|
|
// |lock_| protects access to |request_context_getters_|.
|
|
|
|
base::Lock lock_;
|
|
|
|
|
|
|
|
// List of all request contexts that needs to be notified when
|
|
|
|
// IO thread is shutting down.
|
2019-06-19 21:23:04 +00:00
|
|
|
std::set<electron::URLRequestContextGetter*> request_context_getters_;
|
2019-06-04 03:44:12 +00:00
|
|
|
|
2017-12-18 11:57:20 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(IOThread);
|
|
|
|
};
|
|
|
|
|
2019-06-19 20:56:58 +00:00
|
|
|
#endif // SHELL_BROWSER_IO_THREAD_H_
|