summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/message_loop.cc12
-rw-r--r--base/message_loop.h5
-rw-r--r--chrome/service/remoting/chromoting_host_manager.cc5
-rw-r--r--chrome/service/remoting/chromoting_host_manager.h4
-rw-r--r--chrome/service/service_process.cc9
-rw-r--r--chrome/service/service_process.h3
-rw-r--r--remoting/host/chromoting_host.cc2
-rw-r--r--remoting/host/chromoting_host_context.cc9
-rw-r--r--remoting/host/chromoting_host_context.h9
-rw-r--r--remoting/host/chromoting_host_context_unittest.cc2
-rw-r--r--remoting/host/event_executor.h4
-rw-r--r--remoting/host/event_executor_linux.cc50
-rw-r--r--remoting/host/event_executor_linux.h4
-rw-r--r--remoting/host/event_executor_mac.cc4
-rw-r--r--remoting/host/event_executor_mac.h4
-rw-r--r--remoting/host/event_executor_win.cc4
-rw-r--r--remoting/host/event_executor_win.h4
-rw-r--r--remoting/host/host_mock_objects.cc3
-rw-r--r--remoting/host/simple_host_process.cc15
19 files changed, 82 insertions, 70 deletions
diff --git a/base/message_loop.cc b/base/message_loop.cc
index d83adcc..453172b 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -4,6 +4,11 @@
#include "base/message_loop.h"
+#if defined(OS_POSIX) && !defined(OS_MACOSX)
+#include <gdk/gdk.h>
+#include <gdk/gdkx.h>
+#endif
+
#include <algorithm>
#include "base/compiler_specific.h"
@@ -664,6 +669,13 @@ void MessageLoopForUI::DidProcessMessage(const MSG& message) {
}
#endif // defined(OS_WIN)
+#if defined(OS_POSIX) && !defined(OS_MACOSX)
+Display* MessageLoopForUI::get_display()
+{
+ return gdk_x11_get_default_xdisplay();
+}
+#endif
+
#if !defined(OS_MACOSX) && !defined(OS_NACL)
void MessageLoopForUI::AddObserver(Observer* observer) {
pump_ui()->AddObserver(observer);
diff --git a/base/message_loop.h b/base/message_loop.h
index d238997..58306a7 100644
--- a/base/message_loop.h
+++ b/base/message_loop.h
@@ -24,6 +24,7 @@
#include "base/message_pump_libevent.h"
#if !defined(OS_MACOSX)
#include "base/message_pump_glib.h"
+typedef struct _XDisplay Display;
#endif
#endif
#if defined(TOUCH_UI)
@@ -508,6 +509,10 @@ class MessageLoopForUI : public MessageLoop {
void DidProcessMessage(const MSG& message);
#endif // defined(OS_WIN)
+#if defined(OS_POSIX) && !defined(OS_MACOSX)
+ Display* get_display();
+#endif
+
#if !defined(OS_MACOSX)
// Please see message_pump_win/message_pump_glib for definitions of these
// methods.
diff --git a/chrome/service/remoting/chromoting_host_manager.cc b/chrome/service/remoting/chromoting_host_manager.cc
index c2621b9..b24eb4b 100644
--- a/chrome/service/remoting/chromoting_host_manager.cc
+++ b/chrome/service/remoting/chromoting_host_manager.cc
@@ -20,7 +20,7 @@ ChromotingHostManager::ChromotingHostManager(Observer* observer)
}
void ChromotingHostManager::Initialize(
- MessageLoop* main_message_loop,
+ MessageLoopForUI* main_message_loop,
base::MessageLoopProxy* file_message_loop) {
FilePath user_data_dir;
PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
@@ -170,7 +170,8 @@ void ChromotingHostManager::Start() {
return;
// Start the chromoting context first.
- chromoting_context_.reset(new remoting::ChromotingHostContext());
+ chromoting_context_.reset(
+ new remoting::ChromotingHostContext(main_message_loop_));
chromoting_context_->Start();
// Create a chromoting host object.
diff --git a/chrome/service/remoting/chromoting_host_manager.h b/chrome/service/remoting/chromoting_host_manager.h
index 4ca1d6f..70cf4e9 100644
--- a/chrome/service/remoting/chromoting_host_manager.h
+++ b/chrome/service/remoting/chromoting_host_manager.h
@@ -41,7 +41,7 @@ class ChromotingHostManager
// destroyed while this object exists.
explicit ChromotingHostManager(Observer* observer);
- void Initialize(MessageLoop* main_message_loop,
+ void Initialize(MessageLoopForUI* main_message_loop,
base::MessageLoopProxy* file_message_loop);
// Shutdown ChromotingHostManager. |done_task| will be executed when done.
@@ -83,7 +83,7 @@ class ChromotingHostManager
scoped_ptr<remoting::ChromotingHostContext> chromoting_context_;
scoped_refptr<remoting::ChromotingHost> chromoting_host_;
- MessageLoop* main_message_loop_;
+ MessageLoopForUI* main_message_loop_;
scoped_ptr<Task> shutdown_task_;
};
diff --git a/chrome/service/service_process.cc b/chrome/service/service_process.cc
index c46bb97..b49bdb1 100644
--- a/chrome/service/service_process.cc
+++ b/chrome/service/service_process.cc
@@ -33,6 +33,10 @@
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_switches.h"
+#if defined(TOOLKIT_USES_GTK)
+#include "ui/gfx/gtk_util.h"
+#endif
+
#if defined(ENABLE_REMOTING)
#include "chrome/service/remoting/chromoting_host_manager.h"
#if defined(OS_MACOSX)
@@ -119,8 +123,11 @@ ServiceProcess::ServiceProcess()
g_service_process = this;
}
-bool ServiceProcess::Initialize(MessageLoop* message_loop,
+bool ServiceProcess::Initialize(MessageLoopForUI* message_loop,
const CommandLine& command_line) {
+#if defined(TOOLKIT_USES_GTK)
+ gfx::GtkInitFromCommandLine(command_line);
+#endif
main_message_loop_ = message_loop;
network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
base::Thread::Options options;
diff --git a/chrome/service/service_process.h b/chrome/service/service_process.h
index ac3a1286..8a84efd 100644
--- a/chrome/service/service_process.h
+++ b/chrome/service/service_process.h
@@ -34,7 +34,8 @@ class ServiceProcess : public CloudPrintProxy::Client,
~ServiceProcess();
// Initialize the ServiceProcess with the message loop that it should run on.
- bool Initialize(MessageLoop* message_loop, const CommandLine& command_line);
+ bool Initialize(MessageLoopForUI* message_loop,
+ const CommandLine& command_line);
bool Teardown();
// TODO(sanjeevr): Change various parts of the code such as
// net::ProxyService::CreateSystemProxyConfigService to take in
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc
index 317e5b0..41eb5a0 100644
--- a/remoting/host/chromoting_host.cc
+++ b/remoting/host/chromoting_host.cc
@@ -35,7 +35,7 @@ namespace remoting {
ChromotingHost* ChromotingHost::Create(ChromotingHostContext* context,
MutableHostConfig* config) {
Capturer* capturer = Capturer::Create(context->main_message_loop());
- InputStub* input_stub = CreateEventExecutor(context->main_message_loop(),
+ InputStub* input_stub = CreateEventExecutor(context->ui_message_loop(),
capturer);
return Create(context, config, capturer, input_stub);
}
diff --git a/remoting/host/chromoting_host_context.cc b/remoting/host/chromoting_host_context.cc
index 053f411..3e426f7 100644
--- a/remoting/host/chromoting_host_context.cc
+++ b/remoting/host/chromoting_host_context.cc
@@ -11,9 +11,10 @@
namespace remoting {
-ChromotingHostContext::ChromotingHostContext()
+ChromotingHostContext::ChromotingHostContext(MessageLoopForUI* ui_message_loop)
: main_thread_("ChromotingMainThread"),
- encode_thread_("ChromotingEncodeThread") {
+ encode_thread_("ChromotingEncodeThread"),
+ ui_message_loop_(ui_message_loop) {
}
ChromotingHostContext::~ChromotingHostContext() {
@@ -49,4 +50,8 @@ MessageLoop* ChromotingHostContext::network_message_loop() {
return jingle_thread_.message_loop();
}
+MessageLoopForUI* ChromotingHostContext::ui_message_loop() {
+ return ui_message_loop_;
+}
+
} // namespace remoting
diff --git a/remoting/host/chromoting_host_context.h b/remoting/host/chromoting_host_context.h
index 17b57ff..3b3c14f 100644
--- a/remoting/host/chromoting_host_context.h
+++ b/remoting/host/chromoting_host_context.h
@@ -17,7 +17,10 @@ namespace remoting {
// process.
class ChromotingHostContext {
public:
- ChromotingHostContext();
+ // Create a context attached to the specified ui message loop. Since there
+ // can only be one such loop on UNIX platforms, it has to be passed into
+ // this object rather than being owned by it.
+ explicit ChromotingHostContext(MessageLoopForUI* ui_message_loop);
virtual ~ChromotingHostContext();
// TODO(ajwong): Move the Start/Stop methods out of this class. Then
@@ -32,6 +35,7 @@ class ChromotingHostContext {
virtual MessageLoop* main_message_loop();
virtual MessageLoop* encode_message_loop();
virtual MessageLoop* network_message_loop();
+ MessageLoopForUI* ui_message_loop();
private:
FRIEND_TEST_ALL_PREFIXES(ChromotingHostContextTest, StartAndStop);
@@ -45,6 +49,9 @@ class ChromotingHostContext {
// A thread that hosts all encode operations.
base::Thread encode_thread_;
+ // The main message loop.
+ MessageLoopForUI* ui_message_loop_;
+
DISALLOW_COPY_AND_ASSIGN(ChromotingHostContext);
};
diff --git a/remoting/host/chromoting_host_context_unittest.cc b/remoting/host/chromoting_host_context_unittest.cc
index 827ad37..6fdda75 100644
--- a/remoting/host/chromoting_host_context_unittest.cc
+++ b/remoting/host/chromoting_host_context_unittest.cc
@@ -11,7 +11,7 @@ namespace remoting {
// A simple test that starts and stop the context. This tests the context
// operates properly and all threads and message loops are valid.
TEST(ChromotingHostContextTest, StartAndStop) {
- ChromotingHostContext context;
+ ChromotingHostContext context(NULL);
context.Start();
EXPECT_TRUE(context.jingle_thread());
EXPECT_TRUE(context.main_message_loop());
diff --git a/remoting/host/event_executor.h b/remoting/host/event_executor.h
index 13fe511..f99339b 100644
--- a/remoting/host/event_executor.h
+++ b/remoting/host/event_executor.h
@@ -5,7 +5,7 @@
#ifndef REMOTING_HOST_EVENT_EXECUTOR_H_
#define REMOTING_HOST_EVENT_EXECUTOR_H_
-class MessageLoop;
+class MessageLoopForUI;
namespace remoting {
@@ -16,7 +16,7 @@ class InputStub;
} // namespace protocol
// Creates default event executor for the current platform.
-protocol::InputStub* CreateEventExecutor(MessageLoop* message_loop,
+protocol::InputStub* CreateEventExecutor(MessageLoopForUI* message_loop,
Capturer* capturer);
} // namespace remoting
diff --git a/remoting/host/event_executor_linux.cc b/remoting/host/event_executor_linux.cc
index fddcab9..1e82fc9 100644
--- a/remoting/host/event_executor_linux.cc
+++ b/remoting/host/event_executor_linux.cc
@@ -13,33 +13,6 @@
#include "base/task.h"
#include "remoting/proto/internal.pb.h"
-// TODO(jamiewalch): Class to ensure that XFlush is called regardless of what
-// fields are set in the MouseEvent. It's not worth refactoring HandleMouse to
-// avoid the early returns because calling XFlush is not really the correct
-// way of flushing the XTest requests; instead we should dispatch the requests
-// to a suitable UI thread.
-namespace {
-class ScopedXFlusher {
- public:
- explicit ScopedXFlusher(Display* display)
- : display_(display), needs_flush_(false) {
- }
-
- ~ScopedXFlusher() {
- if (needs_flush_)
- XFlush(display_);
- }
-
- void SignalFlush() {
- needs_flush_ = true;
- }
-
- private:
- Display* display_;
- bool needs_flush_;
-};
-}
-
namespace remoting {
using protocol::MouseEvent;
@@ -229,7 +202,8 @@ static int ChromotocolKeycodeToX11Keysym(int32_t keycode) {
class EventExecutorLinuxPimpl {
public:
- explicit EventExecutorLinuxPimpl(EventExecutorLinux* executor);
+ explicit EventExecutorLinuxPimpl(EventExecutorLinux* executor,
+ Display* display);
~EventExecutorLinuxPimpl();
bool Init(); // TODO(ajwong): Do we really want this to be synchronous?
@@ -254,9 +228,10 @@ class EventExecutorLinuxPimpl {
int test_error_base_;
};
-EventExecutorLinuxPimpl::EventExecutorLinuxPimpl(EventExecutorLinux* executor)
+EventExecutorLinuxPimpl::EventExecutorLinuxPimpl(EventExecutorLinux* executor,
+ Display* display)
: executor_(executor),
- display_(NULL),
+ display_(display),
root_window_(BadValue),
width_(0),
height_(0) {
@@ -267,9 +242,6 @@ EventExecutorLinuxPimpl::~EventExecutorLinuxPimpl() {
}
bool EventExecutorLinuxPimpl::Init() {
- // TODO(ajwong): We should specify the display string we are attaching to
- // in the constructor.
- display_ = XOpenDisplay(NULL);
if (!display_) {
LOG(ERROR) << "Unable to open display";
return false;
@@ -329,13 +301,9 @@ void EventExecutorLinuxPimpl::HandleKey(const KeyEvent* key_event) {
<< " sending keysym: " << keysym
<< " to keycode: " << keycode;
XTestFakeKeyEvent(display_, keycode, key_event->pressed(), CurrentTime);
-
- // TODO(jamiewalch): Get rid of this once we're dispatching to the UI thread.
- XFlush(display_);
}
void EventExecutorLinuxPimpl::HandleMouse(const MouseEvent* event) {
- ScopedXFlusher flusher(display_);
if (event->has_x() && event->has_y()) {
if (event->x() < 0 || event->y() < 0 ||
event->x() > width_ || event->y() > height_) {
@@ -347,7 +315,6 @@ void EventExecutorLinuxPimpl::HandleMouse(const MouseEvent* event) {
VLOG(3) << "Moving mouse to " << event->x()
<< "," << event->y();
- flusher.SignalFlush();
XTestFakeMotionEvent(display_, DefaultScreen(display_),
event->x(), event->y(),
CurrentTime);
@@ -364,7 +331,6 @@ void EventExecutorLinuxPimpl::HandleMouse(const MouseEvent* event) {
VLOG(3) << "Button " << event->button()
<< " received, sending down " << button_number;
- flusher.SignalFlush();
XTestFakeButtonEvent(display_, button_number, event->button_down(),
CurrentTime);
}
@@ -385,10 +351,10 @@ void EventExecutorLinuxPimpl::DeinitXlib() {
}
EventExecutorLinux::EventExecutorLinux(
- MessageLoop* message_loop, Capturer* capturer)
+ MessageLoopForUI* message_loop, Capturer* capturer)
: message_loop_(message_loop),
capturer_(capturer),
- pimpl_(new EventExecutorLinuxPimpl(this)) {
+ pimpl_(new EventExecutorLinuxPimpl(this, message_loop->get_display())) {
CHECK(pimpl_->Init());
}
@@ -422,7 +388,7 @@ void EventExecutorLinux::InjectMouseEvent(const MouseEvent* event,
delete done;
}
-protocol::InputStub* CreateEventExecutor(MessageLoop* message_loop,
+protocol::InputStub* CreateEventExecutor(MessageLoopForUI* message_loop,
Capturer* capturer) {
return new EventExecutorLinux(message_loop, capturer);
}
diff --git a/remoting/host/event_executor_linux.h b/remoting/host/event_executor_linux.h
index c20b06f..8b61dd0 100644
--- a/remoting/host/event_executor_linux.h
+++ b/remoting/host/event_executor_linux.h
@@ -20,7 +20,7 @@ class EventExecutorLinuxPimpl;
// A class to generate events on Linux.
class EventExecutorLinux : public protocol::InputStub {
public:
- EventExecutorLinux(MessageLoop* message_loop,
+ EventExecutorLinux(MessageLoopForUI* message_loop,
Capturer* capturer);
virtual ~EventExecutorLinux();
@@ -28,7 +28,7 @@ class EventExecutorLinux : public protocol::InputStub {
virtual void InjectMouseEvent(const protocol::MouseEvent* event, Task* done);
private:
- MessageLoop* message_loop_;
+ MessageLoopForUI* message_loop_;
Capturer* capturer_;
scoped_ptr<EventExecutorLinuxPimpl> pimpl_;
diff --git a/remoting/host/event_executor_mac.cc b/remoting/host/event_executor_mac.cc
index 37041a8..71a9eda 100644
--- a/remoting/host/event_executor_mac.cc
+++ b/remoting/host/event_executor_mac.cc
@@ -14,7 +14,7 @@ using protocol::MouseEvent;
using protocol::KeyEvent;
EventExecutorMac::EventExecutorMac(
- MessageLoop* message_loop, Capturer* capturer)
+ MessageLoopForUI* message_loop, Capturer* capturer)
: message_loop_(message_loop),
capturer_(capturer) {
}
@@ -32,7 +32,7 @@ void EventExecutorMac::InjectMouseEvent(const MouseEvent* event, Task* done) {
delete done;
}
-protocol::InputStub* CreateEventExecutor(MessageLoop* message_loop,
+protocol::InputStub* CreateEventExecutor(MessageLoopForUI* message_loop,
Capturer* capturer) {
return new EventExecutorMac(message_loop, capturer);
}
diff --git a/remoting/host/event_executor_mac.h b/remoting/host/event_executor_mac.h
index 758ccc0..66288a0 100644
--- a/remoting/host/event_executor_mac.h
+++ b/remoting/host/event_executor_mac.h
@@ -16,14 +16,14 @@ namespace remoting {
// A class to generate events on Mac.
class EventExecutorMac : public protocol::InputStub {
public:
- EventExecutorMac(MessageLoop* message_loop, Capturer* capturer);
+ EventExecutorMac(MessageLoopForUI* message_loop, Capturer* capturer);
virtual ~EventExecutorMac();
virtual void InjectKeyEvent(const protocol::KeyEvent* event, Task* done);
virtual void InjectMouseEvent(const protocol::MouseEvent* event, Task* done);
private:
- MessageLoop* message_loop_;
+ MessageLoopForUI* message_loop_;
Capturer* capturer_;
DISALLOW_COPY_AND_ASSIGN(EventExecutorMac);
diff --git a/remoting/host/event_executor_win.cc b/remoting/host/event_executor_win.cc
index 980b1ad..e9229b2 100644
--- a/remoting/host/event_executor_win.cc
+++ b/remoting/host/event_executor_win.cc
@@ -18,7 +18,7 @@ using protocol::MouseEvent;
using protocol::KeyEvent;
EventExecutorWin::EventExecutorWin(
- MessageLoop* message_loop, Capturer* capturer)
+ MessageLoopForUI* message_loop, Capturer* capturer)
: message_loop_(message_loop),
capturer_(capturer) {
}
@@ -82,7 +82,7 @@ void EventExecutorWin::HandleKey(const KeyEvent* event) {
SendInput(1, &input, sizeof(INPUT));
}
-protocol::InputStub* CreateEventExecutor(MessageLoop* message_loop,
+protocol::InputStub* CreateEventExecutor(MessageLoopForUI* message_loop,
Capturer* capturer) {
return new EventExecutorWin(message_loop, capturer);
}
diff --git a/remoting/host/event_executor_win.h b/remoting/host/event_executor_win.h
index 4ba4aad..1eebf33 100644
--- a/remoting/host/event_executor_win.h
+++ b/remoting/host/event_executor_win.h
@@ -20,7 +20,7 @@ class EventExecutorWinPimpl;
// A class to generate events on Windows.
class EventExecutorWin : public protocol::InputStub {
public:
- EventExecutorWin(MessageLoop* message_loop, Capturer* capturer);
+ EventExecutorWin(MessageLoopForUI* message_loop, Capturer* capturer);
virtual ~EventExecutorWin();
virtual void InjectKeyEvent(const protocol::KeyEvent* event, Task* done);
@@ -30,7 +30,7 @@ class EventExecutorWin : public protocol::InputStub {
void HandleKey(const protocol::KeyEvent* event);
void HandleMouse(const protocol::MouseEvent* event);
- MessageLoop* message_loop_;
+ MessageLoopForUI* message_loop_;
Capturer* capturer_;
DISALLOW_COPY_AND_ASSIGN(EventExecutorWin);
diff --git a/remoting/host/host_mock_objects.cc b/remoting/host/host_mock_objects.cc
index 8cfddec..d4d51a5 100644
--- a/remoting/host/host_mock_objects.cc
+++ b/remoting/host/host_mock_objects.cc
@@ -10,7 +10,8 @@ MockCapturer::MockCapturer() : Capturer(NULL) {}
MockCapturer::~MockCapturer() {}
-MockChromotingHostContext::MockChromotingHostContext() {}
+MockChromotingHostContext::MockChromotingHostContext()
+ : ChromotingHostContext(NULL) {}
MockChromotingHostContext::~MockChromotingHostContext() {}
diff --git a/remoting/host/simple_host_process.cc b/remoting/host/simple_host_process.cc
index 289da0f..5903489 100644
--- a/remoting/host/simple_host_process.cc
+++ b/remoting/host/simple_host_process.cc
@@ -36,6 +36,10 @@
#include "remoting/host/json_host_config.h"
#include "remoting/proto/video.pb.h"
+#if defined(TOOLKIT_USES_GTK)
+#include "ui/gfx/gtk_util.h"
+#endif
+
using remoting::ChromotingHost;
using remoting::protocol::CandidateSessionConfig;
using remoting::protocol::ChannelConfig;
@@ -78,7 +82,11 @@ int main(int argc, char** argv) {
base::EnsureNSPRInit();
// Allocate a chromoting context and starts it.
- remoting::ChromotingHostContext context;
+#if defined(TOOLKIT_USES_GTK)
+ gfx::GtkInitFromCommandLine(*cmd_line);
+#endif
+ MessageLoopForUI message_loop;
+ remoting::ChromotingHostContext context(&message_loop);
context.Start();
@@ -120,7 +128,7 @@ int main(int argc, char** argv) {
remoting::Capturer* capturer =
new remoting::CapturerFake(context.main_message_loop());
remoting::protocol::InputStub* input_stub =
- CreateEventExecutor(context.main_message_loop(), capturer);
+ CreateEventExecutor(context.ui_message_loop(), capturer);
host = ChromotingHost::Create(
&context, config, capturer, input_stub);
} else {
@@ -155,9 +163,8 @@ int main(int argc, char** argv) {
}
// Let the chromoting host run until the shutdown task is executed.
- MessageLoop message_loop(MessageLoop::TYPE_UI);
host->Start(NewRunnableFunction(&ShutdownTask, &message_loop));
- message_loop.Run();
+ message_loop.MessageLoop::Run();
// And then stop the chromoting context.
context.Stop();