This source file includes following definitions.
- Start
- weak_factory_
- Start
- Stop
- StartOnUiThread
- StopOnUiThread
- client_jid
- DisconnectSession
- OnLocalMouseMoved
- SetDisableInputs
#include "remoting/host/host_window_proxy.h"
#include "base/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/single_thread_task_runner.h"
#include "remoting/host/client_session_control.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
namespace remoting {
class HostWindowProxy::Core
: public base::RefCountedThreadSafe<Core>,
public ClientSessionControl {
public:
Core(scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
scoped_ptr<HostWindow> host_window);
void Start(const base::WeakPtr<ClientSessionControl>& client_session_control);
void Stop();
private:
friend class base::RefCountedThreadSafe<Core>;
virtual ~Core();
void StartOnUiThread(const std::string& client_jid);
void StopOnUiThread();
virtual const std::string& client_jid() const OVERRIDE;
virtual void DisconnectSession() OVERRIDE;
virtual void OnLocalMouseMoved(
const webrtc::DesktopVector& position) OVERRIDE;
virtual void SetDisableInputs(bool disable_inputs) OVERRIDE;
scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_;
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
std::string client_jid_;
base::WeakPtr<ClientSessionControl> client_session_control_;
scoped_ptr<HostWindow> host_window_;
base::WeakPtrFactory<ClientSessionControl> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(Core);
};
HostWindowProxy::HostWindowProxy(
scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
scoped_ptr<HostWindow> host_window) {
DCHECK(caller_task_runner->BelongsToCurrentThread());
host_window->DetachFromThread();
core_ = new Core(caller_task_runner, ui_task_runner, host_window.Pass());
}
HostWindowProxy::~HostWindowProxy() {
DCHECK(CalledOnValidThread());
core_->Stop();
}
void HostWindowProxy::Start(
const base::WeakPtr<ClientSessionControl>& client_session_control) {
DCHECK(CalledOnValidThread());
core_->Start(client_session_control);
}
HostWindowProxy::Core::Core(
scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
scoped_ptr<HostWindow> host_window)
: caller_task_runner_(caller_task_runner),
ui_task_runner_(ui_task_runner),
host_window_(host_window.Pass()),
weak_factory_(this) {
DCHECK(caller_task_runner->BelongsToCurrentThread());
}
void HostWindowProxy::Core::Start(
const base::WeakPtr<ClientSessionControl>& client_session_control) {
DCHECK(caller_task_runner_->BelongsToCurrentThread());
DCHECK(!client_session_control_.get());
DCHECK(client_session_control.get());
client_session_control_ = client_session_control;
ui_task_runner_->PostTask(
FROM_HERE, base::Bind(&Core::StartOnUiThread, this,
client_session_control->client_jid()));
}
void HostWindowProxy::Core::Stop() {
DCHECK(caller_task_runner_->BelongsToCurrentThread());
ui_task_runner_->PostTask(FROM_HERE, base::Bind(&Core::StopOnUiThread, this));
}
HostWindowProxy::Core::~Core() {
DCHECK(!host_window_);
}
void HostWindowProxy::Core::StartOnUiThread(const std::string& client_jid) {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
DCHECK(client_jid_.empty());
client_jid_ = client_jid;
host_window_->Start(weak_factory_.GetWeakPtr());
}
void HostWindowProxy::Core::StopOnUiThread() {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
host_window_.reset();
}
const std::string& HostWindowProxy::Core::client_jid() const {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
return client_jid_;
}
void HostWindowProxy::Core::DisconnectSession() {
if (!caller_task_runner_->BelongsToCurrentThread()) {
caller_task_runner_->PostTask(FROM_HERE,
base::Bind(&Core::DisconnectSession, this));
return;
}
if (client_session_control_.get())
client_session_control_->DisconnectSession();
}
void HostWindowProxy::Core::OnLocalMouseMoved(
const webrtc::DesktopVector& position) {
if (!caller_task_runner_->BelongsToCurrentThread()) {
caller_task_runner_->PostTask(
FROM_HERE, base::Bind(&Core::OnLocalMouseMoved, this, position));
return;
}
if (client_session_control_.get())
client_session_control_->OnLocalMouseMoved(position);
}
void HostWindowProxy::Core::SetDisableInputs(bool disable_inputs) {
if (!caller_task_runner_->BelongsToCurrentThread()) {
caller_task_runner_->PostTask(
FROM_HERE, base::Bind(&Core::SetDisableInputs, this, disable_inputs));
return;
}
if (client_session_control_.get())
client_session_control_->SetDisableInputs(disable_inputs);
}
}