summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-01 18:27:55 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-01 18:27:55 +0000
commitafc05ab382ebc47e88efeb1384c20f4a50326af6 (patch)
tree189d1e70b0c1cd880d5ab8f266b683c3e419cbd6
parent834a6a109409de82662d29e0495a23872050812f (diff)
downloadchromium_src-afc05ab382ebc47e88efeb1384c20f4a50326af6.zip
chromium_src-afc05ab382ebc47e88efeb1384c20f4a50326af6.tar.gz
chromium_src-afc05ab382ebc47e88efeb1384c20f4a50326af6.tar.bz2
Start Chromoting Host Process in Chrome Service
Enable chromoting host process if chrome is started with --type=service --enable-chromoting BUG=none TEST=chrome --type=service --enable-chromoting Review URL: http://codereview.chromium.org/2813038 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51393 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/chrome.gyp7
-rw-r--r--chrome/common/chrome_switches.cc4
-rw-r--r--chrome/common/chrome_switches.h1
-rw-r--r--chrome/service/DEPS4
-rw-r--r--chrome/service/service_main.cc55
-rw-r--r--chrome/service/service_process.cc44
-rw-r--r--chrome/service/service_process.h11
-rw-r--r--remoting/host/chromoting_host_context.h2
8 files changed, 128 insertions, 0 deletions
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 9972502..55a3894 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -1092,6 +1092,13 @@
'service/cloud_print/print_system_cups.cc',
],
}],
+ ['remoting==1', {
+ 'dependencies': [
+ '../remoting/remoting.gyp:chromoting_base',
+ '../remoting/remoting.gyp:chromoting_host',
+ '../remoting/remoting.gyp:chromoting_jingle_glue',
+ ],
+ }],
],
},
],
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index e77bee5..3b1625b 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -275,6 +275,10 @@ const char kEnableAuthNegotiatePort[] = "enable-auth-negotiate-port";
const char kEnableBenchmarking[] = "enable-benchmarking";
// This applies only when the process type is "service". Enables the
+// Chromoting Host Process within the service process.
+const char kEnableChromoting[] = "enable-chromoting";
+
+// This applies only when the process type is "service". Enables the
// Cloud Print Proxy component within the service process.
const char kEnableCloudPrintProxy[] = "enable-cloud-print-proxy";
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 2f43e5c..d07d2dd 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -93,6 +93,7 @@ extern const char kEnableAeroPeekTabs[];
extern const char kEnableApps[];
extern const char kEnableAuthNegotiatePort[];
extern const char kEnableBenchmarking[];
+extern const char kEnableChromoting[];
extern const char kEnableCloudPrintProxy[];
extern const char kEnableCloudPrint[];
extern const char kEnableExperimentalExtensionApis[];
diff --git a/chrome/service/DEPS b/chrome/service/DEPS
new file mode 100644
index 0000000..804d3c2
--- /dev/null
+++ b/chrome/service/DEPS
@@ -0,0 +1,4 @@
+include_rules = [
+ # For Chromoting Host Process
+ "+remoting/host",
+]
diff --git a/chrome/service/service_main.cc b/chrome/service/service_main.cc
index 35c869b..a3fcd69 100644
--- a/chrome/service/service_main.cc
+++ b/chrome/service/service_main.cc
@@ -12,6 +12,22 @@
#include "chrome/service/cloud_print/cloud_print_proxy.h"
#include "chrome/service/service_process.h"
+#if defined(ENABLE_REMOTING)
+#include "remoting/host/json_host_config.h"
+#include "remoting/host/chromoting_host.h"
+#include "remoting/host/chromoting_host_context.h"
+
+// This method is called as a signal that the Chromoting Host Process is
+// shutting down because of failure or a request made by the user.
+// We'll then post a task to |message_loop| to stop the chromoting host
+// context to finish the final cleanup.
+static void OnChromotingHostShutdown(
+ MessageLoop* message_loop, remoting::ChromotingHostContext* context) {
+ message_loop->PostTask(FROM_HERE,
+ NewRunnableMethod(context, &remoting::ChromotingHostContext::Stop));
+}
+#endif
+
// Mainline routine for running as the service process.
int ServiceProcessMain(const MainFunctionParams& parameters) {
MessageLoopForUI main_message_loop;
@@ -35,6 +51,7 @@ int ServiceProcessMain(const MainFunctionParams& parameters) {
service_process.file_thread()->message_loop_proxy()));
service_prefs->ReadPrefs();
+ // Enable Cloud Print if needed.
if (parameters.command_line_.HasSwitch(switches::kEnableCloudPrintProxy)) {
std::string lsid =
parameters.command_line_.GetSwitchValueASCII(
@@ -43,6 +60,44 @@ int ServiceProcessMain(const MainFunctionParams& parameters) {
service_process.CreateCloudPrintProxy(service_prefs.get());
cloud_print_proxy->EnableForUser(lsid);
}
+
+#if defined(ENABLE_REMOTING)
+ // Enable Chromoting Host if needed.
+ // TODO(hclam): Merge this config file with Cloud Printing.
+ // TODO(hclam): There is only start but not stop of the chromoting host
+ // process.
+ FilePath chromoting_config_path =
+ user_data_dir.Append(FILE_PATH_LITERAL(".ChromotingConfig.json"));
+ scoped_refptr<remoting::JsonHostConfig> chromoting_config;
+ scoped_ptr<remoting::ChromotingHostContext> chromoting_context;
+ scoped_refptr<remoting::ChromotingHost> chromoting_host;
+ if (parameters.command_line_.HasSwitch(switches::kEnableChromoting)) {
+ chromoting_config = new remoting::JsonHostConfig(
+ chromoting_config_path,
+ service_process.file_thread()->message_loop_proxy());
+ if (!chromoting_config->Read()) {
+ LOG(ERROR) << "Failed to read chromoting config file.";
+ } else {
+ chromoting_context.reset(new remoting::ChromotingHostContext());
+
+ // Create the Chromoting Host Process with the context and config.
+ chromoting_host = service_process.CreateChromotingHost(
+ chromoting_context.get(), chromoting_config);
+
+ // And start the context and the host process.
+ chromoting_context->Start();
+
+ // When ChromotingHost is shutdown because of failure or a request that
+ // we made. ShutdownChromotingTask() is calls.
+ // ShutdownChromotingTask() will then post a task to
+ // |main_message_loop| to shutdown the chromoting context.
+ chromoting_host->Start(
+ NewRunnableFunction(&OnChromotingHostShutdown,
+ &main_message_loop, chromoting_context.get()));
+ }
+ }
+#endif
+
MessageLoop::current()->Run();
service_prefs->WritePrefs();
service_process.Teardown();
diff --git a/chrome/service/service_process.cc b/chrome/service/service_process.cc
index 09399f0..408be65 100644
--- a/chrome/service/service_process.cc
+++ b/chrome/service/service_process.cc
@@ -8,6 +8,24 @@
#include "chrome/service/cloud_print/cloud_print_proxy.h"
#include "net/base/network_change_notifier.h"
+#if defined(ENABLE_REMOTING)
+#include "remoting/host/chromoting_host.h"
+#include "remoting/host/chromoting_host_context.h"
+#include "remoting/host/encoder_verbatim.h"
+#include "remoting/host/host_config.h"
+
+#if defined(OS_WIN)
+#include "remoting/host/capturer_gdi.h"
+#include "remoting/host/event_executor_win.h"
+#elif defined(OS_LINUX)
+#include "remoting/host/capturer_linux.h"
+#include "remoting/host/event_executor_linux.h"
+#elif defined(OS_MACOSX)
+#include "remoting/host/capturer_mac.h"
+#include "remoting/host/event_executor_mac.h"
+#endif
+#endif // defined(ENABLED_REMOTING)
+
ServiceProcess* g_service_process = NULL;
ServiceProcess::ServiceProcess() {
@@ -48,6 +66,32 @@ CloudPrintProxy* ServiceProcess::CreateCloudPrintProxy(
return cloud_print_proxy;
}
+#if defined(ENABLE_REMOTING)
+remoting::ChromotingHost* ServiceProcess::CreateChromotingHost(
+ remoting::ChromotingHostContext* context,
+ remoting::MutableHostConfig* config) {
+ scoped_ptr<remoting::Capturer> capturer;
+ scoped_ptr<remoting::Encoder> encoder;
+ scoped_ptr<remoting::EventExecutor> executor;
+
+ // Select the capturer and encoder from |config|.
+#if defined(OS_WIN)
+ capturer.reset(new remoting::CapturerGdi());
+ executor.reset(new remoting::EventExecutorWin());
+#elif defined(OS_LINUX)
+ capturer.reset(new remoting::CapturerLinux());
+ executor.reset(new remoting::EventExecutorLinux());
+#elif defined(OS_MACOSX)
+ capturer.reset(new remoting::CapturerMac());
+ executor.reset(new remoting::EventExecutorMac());
+#endif
+ encoder.reset(new remoting::EncoderVerbatim());
+
+ return new remoting::ChromotingHost(context, config, capturer.release(),
+ encoder.release(), executor.release());
+}
+#endif
+
ServiceProcess::~ServiceProcess() {
Teardown();
DCHECK(cloud_print_proxy_list_.size() == 0);
diff --git a/chrome/service/service_process.h b/chrome/service/service_process.h
index 10757fe..2dfb413 100644
--- a/chrome/service/service_process.h
+++ b/chrome/service/service_process.h
@@ -16,6 +16,12 @@ namespace net {
class NetworkChangeNotifier;
}
+namespace remoting {
+class ChromotingHost;
+class ChromotingHostContext;
+class MutableHostConfig;
+}
+
// The ServiceProcess does not inherit from ChildProcess because this
// process can live independently of the browser process.
class ServiceProcess {
@@ -48,6 +54,11 @@ class ServiceProcess {
return file_thread_.get();
}
CloudPrintProxy* CreateCloudPrintProxy(JsonPrefStore* service_prefs);
+#if defined(ENABLE_REMOTING)
+ remoting::ChromotingHost* CreateChromotingHost(
+ remoting::ChromotingHostContext* context,
+ remoting::MutableHostConfig* config);
+#endif
private:
scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
diff --git a/remoting/host/chromoting_host_context.h b/remoting/host/chromoting_host_context.h
index e336c1e..f488f74 100644
--- a/remoting/host/chromoting_host_context.h
+++ b/remoting/host/chromoting_host_context.h
@@ -48,4 +48,6 @@ class ChromotingHostContext {
} // namespace remoting
+DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::ChromotingHostContext);
+
#endif // REMOTING_HOST_CHROMOTING_HOST_CONTEXT_H_