summaryrefslogtreecommitdiffstats
path: root/remoting/host/desktop_environment.cc
blob: 179a8e3ad1540a7d10e2634a0c8e4ba90390e219 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// 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/desktop_environment.h"

#include "base/bind.h"
#include "base/compiler_specific.h"
#include "remoting/host/audio_capturer.h"
#include "remoting/host/video_frame_capturer.h"
#include "remoting/host/chromoting_host_context.h"
#include "remoting/host/event_executor.h"

#if defined(OS_WIN)
#include "remoting/host/session_event_executor_win.h"
#endif

namespace remoting {

// static
scoped_ptr<DesktopEnvironment> DesktopEnvironment::Create(
    ChromotingHostContext* context) {
  scoped_ptr<VideoFrameCapturer> capturer(VideoFrameCapturer::Create());
  scoped_ptr<EventExecutor> event_executor = EventExecutor::Create(
      context->desktop_task_runner(), context->ui_task_runner());
  scoped_ptr<AudioCapturer> audio_capturer = AudioCapturer::Create();

  if (capturer.get() == NULL || event_executor.get() == NULL) {
    LOG(ERROR) << "Unable to create DesktopEnvironment";
    return scoped_ptr<DesktopEnvironment>();
  }

  return scoped_ptr<DesktopEnvironment>(
      new DesktopEnvironment(context,
                             capturer.Pass(),
                             event_executor.Pass(),
                             audio_capturer.Pass()));
}

// static
scoped_ptr<DesktopEnvironment> DesktopEnvironment::CreateForService(
    ChromotingHostContext* context) {
  scoped_ptr<VideoFrameCapturer> capturer(VideoFrameCapturer::Create());
  scoped_ptr<EventExecutor> event_executor = EventExecutor::Create(
      context->desktop_task_runner(), context->ui_task_runner());
  scoped_ptr<AudioCapturer> audio_capturer = AudioCapturer::Create();

  if (capturer.get() == NULL || event_executor.get() == NULL) {
    LOG(ERROR) << "Unable to create DesktopEnvironment";
    return scoped_ptr<DesktopEnvironment>();
  }

#if defined(OS_WIN)
  event_executor.reset(new SessionEventExecutorWin(
      context->desktop_task_runner(),
      context->file_task_runner(),
      event_executor.Pass()));
#endif

  return scoped_ptr<DesktopEnvironment>(
      new DesktopEnvironment(context,
                             capturer.Pass(),
                             event_executor.Pass(),
                             audio_capturer.Pass()));
}

// static
scoped_ptr<DesktopEnvironment> DesktopEnvironment::CreateFake(
    ChromotingHostContext* context,
    scoped_ptr<VideoFrameCapturer> capturer,
    scoped_ptr<EventExecutor> event_executor,
    scoped_ptr<AudioCapturer> audio_capturer) {
  return scoped_ptr<DesktopEnvironment>(
      new DesktopEnvironment(context,
                             capturer.Pass(),
                             event_executor.Pass(),
                             audio_capturer.Pass()));
}

DesktopEnvironment::DesktopEnvironment(
    ChromotingHostContext* context,
    scoped_ptr<VideoFrameCapturer> capturer,
    scoped_ptr<EventExecutor> event_executor,
    scoped_ptr<AudioCapturer> audio_capturer)
    : context_(context),
      capturer_(capturer.Pass()),
      audio_capturer_(audio_capturer.Pass()),
      event_executor_(event_executor.Pass()) {
}

DesktopEnvironment::~DesktopEnvironment() {
}

void DesktopEnvironment::OnSessionStarted(
    scoped_ptr<protocol::ClipboardStub> client_clipboard) {
  event_executor_->OnSessionStarted(client_clipboard.Pass());
}

void DesktopEnvironment::OnSessionFinished() {
  event_executor_->OnSessionFinished();
}

}  // namespace remoting