summaryrefslogtreecommitdiffstats
path: root/remoting/host/chromoting_host_context.cc
blob: 480de732922a9282de5dac6a984b884150f6f2ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "remoting/host/chromoting_host_context.h"

#include <string>

#include "base/bind.h"
#include "base/threading/thread.h"
#include "remoting/host/url_request_context.h"

namespace remoting {

ChromotingHostContext::ChromotingHostContext(
    scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner)
    : network_thread_("ChromotingNetworkThread"),
      capture_thread_("ChromotingCaptureThread"),
      encode_thread_("ChromotingEncodeThread"),
      desktop_thread_("ChromotingDesktopThread"),
      file_thread_("ChromotingFileIOThread"),
      ui_task_runner_(ui_task_runner) {
}

ChromotingHostContext::~ChromotingHostContext() {
}

bool ChromotingHostContext::Start() {
  // Start all the threads.
  bool started = capture_thread_.Start() && encode_thread_.Start() &&
      network_thread_.StartWithOptions(base::Thread::Options(
          MessageLoop::TYPE_IO, 0)) &&
      desktop_thread_.Start() &&
      file_thread_.StartWithOptions(
          base::Thread::Options(MessageLoop::TYPE_IO, 0));
  if (!started)
    return false;

  url_request_context_getter_ = new URLRequestContextGetter(
      ui_task_runner(), network_task_runner(),
      static_cast<MessageLoopForIO*>(file_thread_.message_loop()));
  return true;
}

base::SingleThreadTaskRunner* ChromotingHostContext::capture_task_runner() {
  return capture_thread_.message_loop_proxy();
}

base::SingleThreadTaskRunner* ChromotingHostContext::encode_task_runner() {
  return encode_thread_.message_loop_proxy();
}

base::SingleThreadTaskRunner* ChromotingHostContext::network_task_runner() {
  return network_thread_.message_loop_proxy();
}

base::SingleThreadTaskRunner* ChromotingHostContext::desktop_task_runner() {
  return desktop_thread_.message_loop_proxy();
}

base::SingleThreadTaskRunner* ChromotingHostContext::ui_task_runner() {
  return ui_task_runner_;
}

base::SingleThreadTaskRunner* ChromotingHostContext::file_task_runner() {
  return file_thread_.message_loop_proxy();
}

const scoped_refptr<net::URLRequestContextGetter>&
ChromotingHostContext::url_request_context_getter() {
  DCHECK(url_request_context_getter_.get());
  return url_request_context_getter_;
}

}  // namespace remoting