Index: remoting/host/desktop_process.cc |
diff --git a/remoting/host/desktop_process.cc b/remoting/host/desktop_process.cc |
index e333e717bfc495c67e60af59120dea5add68be93..d2d25ac9550519b1b6dd1117aaf665d50d1b8d0f 100644 |
--- a/remoting/host/desktop_process.cc |
+++ b/remoting/host/desktop_process.cc |
@@ -7,56 +7,21 @@ |
#include "remoting/host/desktop_process.h" |
-#include "base/at_exit.h" |
-#include "base/command_line.h" |
-#include "base/file_path.h" |
+#include "base/bind.h" |
+#include "base/bind_helpers.h" |
+#include "base/logging.h" |
#include "base/memory/ref_counted.h" |
#include "base/message_loop.h" |
#include "base/run_loop.h" |
-#include "base/scoped_native_library.h" |
-#include "base/stringprintf.h" |
-#include "base/utf_string_conversions.h" |
-#include "base/win/windows_version.h" |
#include "ipc/ipc_channel_proxy.h" |
#include "remoting/base/auto_thread.h" |
#include "remoting/base/auto_thread_task_runner.h" |
+#include "remoting/host/chromoting_messages.h" |
+#include "remoting/host/desktop_session_agent.h" |
#include "remoting/host/host_exit_codes.h" |
-#include "remoting/host/logging.h" |
-#include "remoting/host/usage_stats_consent.h" |
- |
-#if defined(OS_MACOSX) |
-#include "base/mac/scoped_nsautorelease_pool.h" |
-#endif // defined(OS_MACOSX) |
- |
-#if defined(OS_WIN) |
-#include <commctrl.h> |
-#endif // defined(OS_WIN) |
- |
-namespace { |
- |
-// The command line switch specifying the name of the daemon IPC endpoint. |
-const char kDaemonIpcSwitchName[] = "daemon-pipe"; |
const char kIoThreadName[] = "I/O thread"; |
-// "--help" or "--?" prints the usage message. |
-const char kHelpSwitchName[] = "help"; |
-const char kQuestionSwitchName[] = "?"; |
- |
-const wchar_t kUsageMessage[] = |
- L"\n" |
- L"Usage: %ls [options]\n" |
- L"\n" |
- L"Options:\n" |
- L" --help, --? - Print this message.\n"; |
- |
-void usage(const FilePath& program_name) { |
- LOG(INFO) << StringPrintf(kUsageMessage, |
- UTF16ToWide(program_name.value()).c_str()); |
-} |
- |
-} // namespace |
- |
namespace remoting { |
DesktopProcess::DesktopProcess(const std::string& daemon_channel_name) |
@@ -67,115 +32,80 @@ DesktopProcess::~DesktopProcess() { |
} |
bool DesktopProcess::OnMessageReceived(const IPC::Message& message) { |
- return false; |
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP(DesktopProcess, message) |
+ IPC_MESSAGE_HANDLER(ChromotingDaemonDesktopMsg_Crash, OnCrash) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ return handled; |
} |
void DesktopProcess::OnChannelConnected(int32 peer_pid) { |
+ VLOG(1) << "IPC: desktop <- daemon (" << peer_pid << ")"; |
+ |
NOTIMPLEMENTED(); |
} |
void DesktopProcess::OnChannelError() { |
- LOG(ERROR) << "Failed to connect to '" << daemon_channel_name_ << "'"; |
+ // Shutdown the desktop process. |
daemon_channel_.reset(); |
+ desktop_agent_.reset(); |
} |
int DesktopProcess::Run() { |
- // Create the UI message loop. |
- MessageLoop message_loop(MessageLoop::TYPE_UI); |
+ DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI); |
{ |
scoped_refptr<AutoThreadTaskRunner> ui_task_runner = |
- new remoting::AutoThreadTaskRunner(message_loop.message_loop_proxy(), |
- MessageLoop::QuitClosure()); |
+ new remoting::AutoThreadTaskRunner( |
+ MessageLoop::current()->message_loop_proxy(), |
+ MessageLoop::QuitClosure()); |
// Launch the I/O thread. |
scoped_refptr<AutoThreadTaskRunner> io_task_runner = |
AutoThread::CreateWithType(kIoThreadName, ui_task_runner, |
MessageLoop::TYPE_IO); |
+ // Create a desktop agent. |
+ desktop_agent_ = DesktopSessionAgent::Create(ui_task_runner, |
+ io_task_runner); |
+ |
+ // Start the agent and create an IPC channel to talk to it. It is safe to |
+ // use base::Unretained(this) here because the message loop below will run |
+ // until |desktop_agent_| is completely destroyed. |
+ IPC::PlatformFileForTransit desktop_pipe; |
+ if (!desktop_agent_->Start(base::Bind(&DesktopProcess::OnChannelError, |
+ base::Unretained(this)), |
+ &desktop_pipe)) { |
+ desktop_agent_.reset(); |
+ return kInitializationFailed; |
+ } |
+ |
// Connect to the daemon. |
daemon_channel_.reset(new IPC::ChannelProxy(daemon_channel_name_, |
IPC::Channel::MODE_CLIENT, |
this, |
io_task_runner)); |
+ |
+ // Pass |desktop_pipe| to the daemon. |
+ daemon_channel_->Send( |
+ new ChromotingDesktopDaemonMsg_DesktopAttached(desktop_pipe)); |
} |
// Run the UI message loop. |
base::RunLoop run_loop; |
run_loop.Run(); |
- return 0; |
-} |
- |
-} // namespace remoting |
-int main(int argc, char** argv) { |
-#if defined(OS_MACOSX) |
- // Needed so we don't leak objects when threads are created. |
- base::mac::ScopedNSAutoreleasePool pool; |
-#endif |
- |
- CommandLine::Init(argc, argv); |
- |
- // This object instance is required by Chrome code (for example, |
- // LazyInstance, MessageLoop). |
- base::AtExitManager exit_manager; |
- |
- remoting::InitHostLogging(); |
- |
- const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
- if (command_line->HasSwitch(kHelpSwitchName) || |
- command_line->HasSwitch(kQuestionSwitchName)) { |
- usage(command_line->GetProgram()); |
- return remoting::kSuccessExitCode; |
- } |
- |
- std::string channel_name = |
- command_line->GetSwitchValueASCII(kDaemonIpcSwitchName); |
- |
- if (channel_name.empty()) { |
- usage(command_line->GetProgram()); |
- return remoting::kUsageExitCode; |
- } |
- |
- remoting::DesktopProcess desktop_process(channel_name); |
- return desktop_process.Run(); |
+ DCHECK(!daemon_channel_); |
+ DCHECK(!desktop_agent_); |
+ return kSuccessExitCode; |
} |
-#if defined(OS_WIN) |
- |
-int CALLBACK WinMain(HINSTANCE instance, |
- HINSTANCE previous_instance, |
- LPSTR raw_command_line, |
- int show_command) { |
-#ifdef OFFICIAL_BUILD |
- if (remoting::IsUsageStatsAllowed()) { |
- remoting::InitializeCrashReporting(); |
- } |
-#endif // OFFICIAL_BUILD |
- |
- // Register and initialize common controls. |
- INITCOMMONCONTROLSEX info; |
- info.dwSize = sizeof(info); |
- info.dwICC = ICC_STANDARD_CLASSES; |
- InitCommonControlsEx(&info); |
- |
- // Mark the process as DPI-aware, so Windows won't scale coordinates in APIs. |
- // N.B. This API exists on Vista and above. |
- if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
- FilePath path(base::GetNativeLibraryName(UTF8ToUTF16("user32"))); |
- base::ScopedNativeLibrary user32(path); |
- CHECK(user32.is_valid()); |
- |
- typedef BOOL (WINAPI * SetProcessDPIAwareFn)(); |
- SetProcessDPIAwareFn set_process_dpi_aware = |
- static_cast<SetProcessDPIAwareFn>( |
- user32.GetFunctionPointer("SetProcessDPIAware")); |
- set_process_dpi_aware(); |
- } |
- |
- // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
- // the command line from GetCommandLineW(), so we can safely pass NULL here. |
- return main(0, NULL); |
+void DesktopProcess::OnCrash(const std::string& function_name, |
+ const std::string& file_name, |
+ const int& line_number) { |
+ // The daemon requested us to crash the process. |
+ CHECK(false); |
} |
-#endif // defined(OS_WIN) |
+} // namespace remoting |