| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/desktop_environment.h" | 5 #include "remoting/host/desktop_environment.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 8 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 9 #include "remoting/host/audio_capturer.h" | 8 #include "remoting/host/audio_capturer.h" |
| 9 #include "remoting/host/chromoting_host_context.h" |
| 10 #include "remoting/host/desktop_environment.h" |
| 11 #include "remoting/host/event_executor.h" |
| 10 #include "remoting/host/video_frame_capturer.h" | 12 #include "remoting/host/video_frame_capturer.h" |
| 11 #include "remoting/host/chromoting_host_context.h" | |
| 12 #include "remoting/host/event_executor.h" | |
| 13 | |
| 14 #if defined(OS_WIN) | |
| 15 #include "remoting/host/session_event_executor_win.h" | |
| 16 #endif | |
| 17 | 13 |
| 18 namespace remoting { | 14 namespace remoting { |
| 19 | 15 |
| 20 // static | 16 DesktopEnvironment::DesktopEnvironment( |
| 21 scoped_ptr<DesktopEnvironment> DesktopEnvironment::Create( | 17 scoped_ptr<AudioCapturer> audio_capturer, |
| 22 ChromotingHostContext* context) { | |
| 23 scoped_ptr<VideoFrameCapturer> capturer(VideoFrameCapturer::Create()); | |
| 24 scoped_ptr<EventExecutor> event_executor = EventExecutor::Create( | |
| 25 context->desktop_task_runner(), context->ui_task_runner()); | |
| 26 scoped_ptr<AudioCapturer> audio_capturer = AudioCapturer::Create(); | |
| 27 | |
| 28 if (capturer.get() == NULL || event_executor.get() == NULL) { | |
| 29 LOG(ERROR) << "Unable to create DesktopEnvironment"; | |
| 30 return scoped_ptr<DesktopEnvironment>(); | |
| 31 } | |
| 32 | |
| 33 return scoped_ptr<DesktopEnvironment>( | |
| 34 new DesktopEnvironment(context, | |
| 35 capturer.Pass(), | |
| 36 event_executor.Pass(), | |
| 37 audio_capturer.Pass())); | |
| 38 } | |
| 39 | |
| 40 // static | |
| 41 scoped_ptr<DesktopEnvironment> DesktopEnvironment::CreateForService( | |
| 42 ChromotingHostContext* context) { | |
| 43 scoped_ptr<VideoFrameCapturer> capturer(VideoFrameCapturer::Create()); | |
| 44 scoped_ptr<EventExecutor> event_executor = EventExecutor::Create( | |
| 45 context->desktop_task_runner(), context->ui_task_runner()); | |
| 46 scoped_ptr<AudioCapturer> audio_capturer = AudioCapturer::Create(); | |
| 47 | |
| 48 if (capturer.get() == NULL || event_executor.get() == NULL) { | |
| 49 LOG(ERROR) << "Unable to create DesktopEnvironment"; | |
| 50 return scoped_ptr<DesktopEnvironment>(); | |
| 51 } | |
| 52 | |
| 53 #if defined(OS_WIN) | |
| 54 event_executor.reset(new SessionEventExecutorWin( | |
| 55 context->desktop_task_runner(), | |
| 56 event_executor.Pass())); | |
| 57 #endif | |
| 58 | |
| 59 return scoped_ptr<DesktopEnvironment>( | |
| 60 new DesktopEnvironment(context, | |
| 61 capturer.Pass(), | |
| 62 event_executor.Pass(), | |
| 63 audio_capturer.Pass())); | |
| 64 } | |
| 65 | |
| 66 // static | |
| 67 scoped_ptr<DesktopEnvironment> DesktopEnvironment::CreateFake( | |
| 68 ChromotingHostContext* context, | |
| 69 scoped_ptr<VideoFrameCapturer> capturer, | |
| 70 scoped_ptr<EventExecutor> event_executor, | 18 scoped_ptr<EventExecutor> event_executor, |
| 71 scoped_ptr<AudioCapturer> audio_capturer) { | 19 scoped_ptr<VideoFrameCapturer> video_capturer) |
| 72 return scoped_ptr<DesktopEnvironment>( | 20 : audio_capturer_(audio_capturer.Pass()), |
| 73 new DesktopEnvironment(context, | 21 event_executor_(event_executor.Pass()), |
| 74 capturer.Pass(), | 22 video_capturer_(video_capturer.Pass()) { |
| 75 event_executor.Pass(), | |
| 76 audio_capturer.Pass())); | |
| 77 } | |
| 78 | |
| 79 DesktopEnvironment::DesktopEnvironment( | |
| 80 ChromotingHostContext* context, | |
| 81 scoped_ptr<VideoFrameCapturer> capturer, | |
| 82 scoped_ptr<EventExecutor> event_executor, | |
| 83 scoped_ptr<AudioCapturer> audio_capturer) | |
| 84 : context_(context), | |
| 85 capturer_(capturer.Pass()), | |
| 86 audio_capturer_(audio_capturer.Pass()), | |
| 87 event_executor_(event_executor.Pass()) { | |
| 88 } | 23 } |
| 89 | 24 |
| 90 DesktopEnvironment::~DesktopEnvironment() { | 25 DesktopEnvironment::~DesktopEnvironment() { |
| 91 } | 26 } |
| 92 | 27 |
| 93 void DesktopEnvironment::OnSessionStarted( | 28 void DesktopEnvironment::Start( |
| 94 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | 29 scoped_ptr<protocol::ClipboardStub> client_clipboard) { |
| 95 event_executor_->OnSessionStarted(client_clipboard.Pass()); | 30 event_executor_->Start(client_clipboard.Pass()); |
| 96 } | 31 } |
| 97 | 32 |
| 98 void DesktopEnvironment::OnSessionFinished() { | 33 void DesktopEnvironment::StopAndDelete() { |
| 99 event_executor_->OnSessionFinished(); | 34 event_executor_.release()->StopAndDelete(); |
| 35 delete this; |
| 100 } | 36 } |
| 101 | 37 |
| 102 } // namespace remoting | 38 } // namespace remoting |
| OLD | NEW |