#include "remoting/host/chromoting_host_context.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/message_loop/message_pump_type.h"
#include "base/notreached.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "remoting/base/auto_thread.h"
#include "remoting/base/url_request_context_getter.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/transitional_url_loader_factory_owner.h"
namespace remoting {
namespace {
#if BUILDFLAG(IS_CHROMEOS_ASH)
class ChromotingHostContextChromeOs : public ChromotingHostContext {
public:
ChromotingHostContextChromeOs(
scoped_refptr<AutoThreadTaskRunner> ui_task_runner,
scoped_refptr<AutoThreadTaskRunner> audio_task_runner,
scoped_refptr<AutoThreadTaskRunner> file_task_runner,
scoped_refptr<AutoThreadTaskRunner> input_task_runner,
scoped_refptr<AutoThreadTaskRunner> network_task_runner,
scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner,
scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner,
scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory);
ChromotingHostContextChromeOs(const ChromotingHostContextChromeOs&) = delete;
ChromotingHostContextChromeOs& operator=(
const ChromotingHostContextChromeOs&) = delete;
~ChromotingHostContextChromeOs() override;
std::unique_ptr<ChromotingHostContext> Copy() override;
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter()
const override;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory() override;
private:
scoped_refptr<network::SharedURLLoaderFactory> ui_shared_url_loader_factory_;
std::unique_ptr<network::PendingSharedURLLoaderFactory> pending_factory_;
scoped_refptr<network::SharedURLLoaderFactory>
network_shared_url_loader_factory_;
};
ChromotingHostContextChromeOs::ChromotingHostContextChromeOs(
scoped_refptr<AutoThreadTaskRunner> ui_task_runner,
scoped_refptr<AutoThreadTaskRunner> audio_task_runner,
scoped_refptr<AutoThreadTaskRunner> file_task_runner,
scoped_refptr<AutoThreadTaskRunner> input_task_runner,
scoped_refptr<AutoThreadTaskRunner> network_task_runner,
scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner,
scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner,
scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory)
: ChromotingHostContext(ui_task_runner,
audio_task_runner,
file_task_runner,
input_task_runner,
network_task_runner,
video_capture_task_runner,
video_encode_task_runner),
ui_shared_url_loader_factory_(shared_url_loader_factory),
pending_factory_(ui_shared_url_loader_factory_->Clone()) {}
ChromotingHostContextChromeOs::~ChromotingHostContextChromeOs() {
ui_task_runner()->ReleaseSoon(FROM_HERE,
std::move(ui_shared_url_loader_factory_));
if (network_shared_url_loader_factory_) {
network_task_runner()->ReleaseSoon(
FROM_HERE, std::move(network_shared_url_loader_factory_));
}
}
std::unique_ptr<ChromotingHostContext> ChromotingHostContextChromeOs::Copy() {
DCHECK(ui_task_runner()->BelongsToCurrentThread());
return std::make_unique<ChromotingHostContextChromeOs>(
ui_task_runner(), audio_task_runner(), file_task_runner(),
input_task_runner(), network_task_runner(), video_capture_task_runner(),
video_encode_task_runner(), ui_shared_url_loader_factory_);
}
scoped_refptr<net::URLRequestContextGetter>
ChromotingHostContextChromeOs::url_request_context_getter() const {
NOTREACHED_IN_MIGRATION();
return nullptr;
}
scoped_refptr<network::SharedURLLoaderFactory>
ChromotingHostContextChromeOs::url_loader_factory() {
DCHECK(network_task_runner()->BelongsToCurrentThread());
if (!network_shared_url_loader_factory_) {
network_shared_url_loader_factory_ =
network::SharedURLLoaderFactory::Create(std::move(pending_factory_));
}
return network_shared_url_loader_factory_;
}
#else
void DisallowBlockingOperations() { … }
class ChromotingHostContextDesktop : public ChromotingHostContext { … };
ChromotingHostContextDesktop::ChromotingHostContextDesktop(
scoped_refptr<AutoThreadTaskRunner> ui_task_runner,
scoped_refptr<AutoThreadTaskRunner> audio_task_runner,
scoped_refptr<AutoThreadTaskRunner> file_task_runner,
scoped_refptr<AutoThreadTaskRunner> input_task_runner,
scoped_refptr<AutoThreadTaskRunner> network_task_runner,
scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner,
scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner,
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter)
: … { … }
ChromotingHostContextDesktop::~ChromotingHostContextDesktop() { … }
std::unique_ptr<ChromotingHostContext> ChromotingHostContextDesktop::Copy() { … }
scoped_refptr<net::URLRequestContextGetter>
ChromotingHostContextDesktop::url_request_context_getter() const { … }
scoped_refptr<network::SharedURLLoaderFactory>
ChromotingHostContextDesktop::url_loader_factory() { … }
#endif
}
ChromotingHostContext::ChromotingHostContext(
scoped_refptr<AutoThreadTaskRunner> ui_task_runner,
scoped_refptr<AutoThreadTaskRunner> audio_task_runner,
scoped_refptr<AutoThreadTaskRunner> file_task_runner,
scoped_refptr<AutoThreadTaskRunner> input_task_runner,
scoped_refptr<AutoThreadTaskRunner> network_task_runner,
scoped_refptr<AutoThreadTaskRunner> video_capture_task_runner,
scoped_refptr<AutoThreadTaskRunner> video_encode_task_runner)
: … { … }
ChromotingHostContext::~ChromotingHostContext() = default;
scoped_refptr<AutoThreadTaskRunner> ChromotingHostContext::audio_task_runner()
const { … }
scoped_refptr<AutoThreadTaskRunner> ChromotingHostContext::file_task_runner()
const { … }
scoped_refptr<AutoThreadTaskRunner> ChromotingHostContext::input_task_runner()
const { … }
scoped_refptr<AutoThreadTaskRunner> ChromotingHostContext::network_task_runner()
const { … }
scoped_refptr<AutoThreadTaskRunner> ChromotingHostContext::ui_task_runner()
const { … }
scoped_refptr<AutoThreadTaskRunner>
ChromotingHostContext::video_capture_task_runner() const { … }
scoped_refptr<AutoThreadTaskRunner>
ChromotingHostContext::video_encode_task_runner() const { … }
policy::ManagementService* ChromotingHostContext::management_service() { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH)
std::unique_ptr<ChromotingHostContext> ChromotingHostContext::Create(
scoped_refptr<AutoThreadTaskRunner> ui_task_runner) { … }
#else
std::unique_ptr<ChromotingHostContext> ChromotingHostContext::CreateForChromeOS(
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory) {
scoped_refptr<AutoThreadTaskRunner> io_auto_task_runner =
new AutoThreadTaskRunner(io_task_runner);
scoped_refptr<AutoThreadTaskRunner> file_auto_task_runner =
new AutoThreadTaskRunner(file_task_runner);
scoped_refptr<AutoThreadTaskRunner> ui_auto_task_runner =
new AutoThreadTaskRunner(ui_task_runner);
return std::make_unique<ChromotingHostContextChromeOs>(
ui_auto_task_runner,
AutoThread::Create("ChromotingAudioThread", file_auto_task_runner),
file_auto_task_runner,
ui_auto_task_runner,
io_auto_task_runner,
ui_auto_task_runner,
AutoThread::Create("ChromotingEncodeThread", file_auto_task_runner),
shared_url_loader_factory);
}
#endif
std::unique_ptr<ChromotingHostContext> ChromotingHostContext::CreateForTesting(
scoped_refptr<AutoThreadTaskRunner> ui_task_runner,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory) { … }
}