summaryrefslogtreecommitdiffstats
path: root/remoting/host/setup
diff options
context:
space:
mode:
authorweitaosu@chromium.org <weitaosu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-04 20:49:10 +0000
committerweitaosu@chromium.org <weitaosu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-04 20:49:10 +0000
commitba23e5d378762bf5e7a25f8f6591674c5d25e365 (patch)
tree5c9c921a6a39ad58f34c44ac07db169402a97f81 /remoting/host/setup
parente1d5b23a521181a3725564f7b238704b4b2efbfd (diff)
downloadchromium_src-ba23e5d378762bf5e7a25f8f6591674c5d25e365.zip
chromium_src-ba23e5d378762bf5e7a25f8f6591674c5d25e365.tar.gz
chromium_src-ba23e5d378762bf5e7a25f8f6591674c5d25e365.tar.bz2
Move NativeMessagingHostMain to me2me_native_messaging_host_main.cc
The plan is to implement a DelegatingPairingRegistryDelegate class and use it in the normal (unelevated) native messaging host process. But before I work on that I want to do this small cleanup first. BUG=325567 Review URL: https://codereview.chromium.org/100333003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238762 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host/setup')
-rw-r--r--remoting/host/setup/daemon_controller.h6
-rw-r--r--remoting/host/setup/me2me_native_messaging_host.cc79
-rw-r--r--remoting/host/setup/me2me_native_messaging_host_main.cc85
3 files changed, 88 insertions, 82 deletions
diff --git a/remoting/host/setup/daemon_controller.h b/remoting/host/setup/daemon_controller.h
index d2f771b..e342299 100644
--- a/remoting/host/setup/daemon_controller.h
+++ b/remoting/host/setup/daemon_controller.h
@@ -102,13 +102,13 @@ class DaemonController : public base::RefCountedThreadSafe<DaemonController> {
GetUsageStatsConsentCallback;
// Interface representing the platform-spacific back-end. Most of its methods
- // are blocking and should called on a background thread. There are two
+ // are blocking and should be called on a background thread. There are two
// exceptions:
// - GetState() is synchronous and called on the UI thread. It should avoid
// accessing any data members of the implementation.
// - SetConfigAndStart(), UpdateConfig() and Stop() indicate completion via
- // a callback. There methods are still can be long running and should
- // be caled on a background thread.
+ // a callback. There methods can be long running and should be caled
+ // on a background thread.
class Delegate {
public:
virtual ~Delegate() {}
diff --git a/remoting/host/setup/me2me_native_messaging_host.cc b/remoting/host/setup/me2me_native_messaging_host.cc
index d85df8e..f3bf180 100644
--- a/remoting/host/setup/me2me_native_messaging_host.cc
+++ b/remoting/host/setup/me2me_native_messaging_host.cc
@@ -9,30 +9,20 @@
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/callback.h"
-#include "base/command_line.h"
#include "base/logging.h"
-#include "base/message_loop/message_loop.h"
-#include "base/run_loop.h"
-#include "base/strings/string_number_conversions.h"
#include "base/strings/stringize_macros.h"
#include "base/threading/thread.h"
#include "base/values.h"
#include "google_apis/gaia/gaia_oauth_client.h"
#include "google_apis/google_api_keys.h"
#include "net/base/net_util.h"
-#include "net/url_request/url_fetcher.h"
#include "remoting/base/rsa_key_pair.h"
-#include "remoting/base/url_request_context.h"
-#include "remoting/host/host_exit_codes.h"
-#include "remoting/host/pairing_registry_delegate.h"
#include "remoting/host/pin_hash.h"
#include "remoting/host/setup/oauth_client.h"
#include "remoting/protocol/pairing_registry.h"
namespace {
-const char kParentWindowSwitchName[] = "parent-window";
-
// redirect_uri to use when authenticating service accounts (service account
// codes are obtained "out-of-band", i.e., not through an OAuth redirect).
const char* kServiceAccountRedirectUri = "oob";
@@ -424,73 +414,4 @@ void NativeMessagingHost::SendCredentialsResponse(
send_message_.Run(response.Pass());
}
-int NativeMessagingHostMain() {
-#if defined(OS_WIN)
- // GetStdHandle() returns pseudo-handles for stdin and stdout even if
- // the hosting executable specifies "Windows" subsystem. However the returned
- // handles are invalid in that case unless standard input and output are
- // redirected to a pipe or file.
- base::PlatformFile read_file = GetStdHandle(STD_INPUT_HANDLE);
- base::PlatformFile write_file = GetStdHandle(STD_OUTPUT_HANDLE);
-#elif defined(OS_POSIX)
- base::PlatformFile read_file = STDIN_FILENO;
- base::PlatformFile write_file = STDOUT_FILENO;
-#else
-#error Not implemented.
-#endif
-
- // Mac OS X requires that the main thread be a UI message loop in order to
- // receive distributed notifications from the System Preferences pane. An
- // IO thread is needed for the pairing registry and URL context getter.
- base::Thread io_thread("io_thread");
- io_thread.StartWithOptions(
- base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
-
- base::MessageLoopForUI message_loop;
- base::RunLoop run_loop;
-
- scoped_refptr<DaemonController> daemon_controller =
- DaemonController::Create();
-
- // Pass handle of the native view to the controller so that the UAC prompts
- // are focused properly.
- const CommandLine* command_line = CommandLine::ForCurrentProcess();
- if (command_line->HasSwitch(kParentWindowSwitchName)) {
- std::string native_view =
- command_line->GetSwitchValueASCII(kParentWindowSwitchName);
- int64 native_view_handle = 0;
- if (base::StringToInt64(native_view, &native_view_handle)) {
- daemon_controller->SetWindow(reinterpret_cast<void*>(native_view_handle));
- } else {
- LOG(WARNING) << "Invalid parameter value --" << kParentWindowSwitchName
- << "=" << native_view;
- }
- }
-
- // OAuth client (for credential requests).
- scoped_refptr<net::URLRequestContextGetter> url_request_context_getter(
- new URLRequestContextGetter(io_thread.message_loop_proxy()));
- scoped_ptr<OAuthClient> oauth_client(
- new OAuthClient(url_request_context_getter));
-
- net::URLFetcher::SetIgnoreCertificateRequests(true);
-
- // Create the pairing registry and native messaging host.
- scoped_refptr<protocol::PairingRegistry> pairing_registry =
- CreatePairingRegistry(io_thread.message_loop_proxy());
- scoped_ptr<NativeMessagingChannel::Delegate> host(
- new NativeMessagingHost(daemon_controller,
- pairing_registry,
- oauth_client.Pass()));
-
- // Set up the native messaging channel.
- scoped_ptr<NativeMessagingChannel> channel(
- new NativeMessagingChannel(host.Pass(), read_file, write_file));
- channel->Start(run_loop.QuitClosure());
-
- // Run the loop until channel is alive.
- run_loop.Run();
- return kSuccessExitCode;
-}
-
} // namespace remoting
diff --git a/remoting/host/setup/me2me_native_messaging_host_main.cc b/remoting/host/setup/me2me_native_messaging_host_main.cc
index e69abfc..91d8d9d8 100644
--- a/remoting/host/setup/me2me_native_messaging_host_main.cc
+++ b/remoting/host/setup/me2me_native_messaging_host_main.cc
@@ -4,9 +4,94 @@
#include "base/at_exit.h"
#include "base/command_line.h"
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "base/strings/string_number_conversions.h"
+#include "net/url_request/url_fetcher.h"
+#include "remoting/host/host_exit_codes.h"
#include "remoting/host/logging.h"
+#include "remoting/host/pairing_registry_delegate.h"
#include "remoting/host/setup/me2me_native_messaging_host.h"
+namespace {
+
+const char kParentWindowSwitchName[] = "parent-window";
+
+} // namespace
+
+namespace remoting {
+
+int NativeMessagingHostMain() {
+#if defined(OS_WIN)
+ // GetStdHandle() returns pseudo-handles for stdin and stdout even if
+ // the hosting executable specifies "Windows" subsystem. However the returned
+ // handles are invalid in that case unless standard input and output are
+ // redirected to a pipe or file.
+ base::PlatformFile read_file = GetStdHandle(STD_INPUT_HANDLE);
+ base::PlatformFile write_file = GetStdHandle(STD_OUTPUT_HANDLE);
+#elif defined(OS_POSIX)
+ base::PlatformFile read_file = STDIN_FILENO;
+ base::PlatformFile write_file = STDOUT_FILENO;
+#else
+#error Not implemented.
+#endif
+
+ // Mac OS X requires that the main thread be a UI message loop in order to
+ // receive distributed notifications from the System Preferences pane. An
+ // IO thread is needed for the pairing registry and URL context getter.
+ base::Thread io_thread("io_thread");
+ io_thread.StartWithOptions(
+ base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
+
+ base::MessageLoopForUI message_loop;
+ base::RunLoop run_loop;
+
+ scoped_refptr<DaemonController> daemon_controller =
+ DaemonController::Create();
+
+ // Pass handle of the native view to the controller so that the UAC prompts
+ // are focused properly.
+ const CommandLine* command_line = CommandLine::ForCurrentProcess();
+ if (command_line->HasSwitch(kParentWindowSwitchName)) {
+ std::string native_view =
+ command_line->GetSwitchValueASCII(kParentWindowSwitchName);
+ int64 native_view_handle = 0;
+ if (base::StringToInt64(native_view, &native_view_handle)) {
+ daemon_controller->SetWindow(reinterpret_cast<void*>(native_view_handle));
+ } else {
+ LOG(WARNING) << "Invalid parameter value --" << kParentWindowSwitchName
+ << "=" << native_view;
+ }
+ }
+
+ // OAuth client (for credential requests).
+ scoped_refptr<net::URLRequestContextGetter> url_request_context_getter(
+ new URLRequestContextGetter(io_thread.message_loop_proxy()));
+ scoped_ptr<OAuthClient> oauth_client(
+ new OAuthClient(url_request_context_getter));
+
+ net::URLFetcher::SetIgnoreCertificateRequests(true);
+
+ // Create the pairing registry and native messaging host.
+ scoped_refptr<protocol::PairingRegistry> pairing_registry =
+ CreatePairingRegistry(io_thread.message_loop_proxy());
+ scoped_ptr<NativeMessagingChannel::Delegate> host(
+ new NativeMessagingHost(daemon_controller,
+ pairing_registry,
+ oauth_client.Pass()));
+
+ // Set up the native messaging channel.
+ scoped_ptr<NativeMessagingChannel> channel(
+ new NativeMessagingChannel(host.Pass(), read_file, write_file));
+ channel->Start(run_loop.QuitClosure());
+
+ // Run the loop until channel is alive.
+ run_loop.Run();
+ return kSuccessExitCode;
+}
+
+} // namespace remoting
+
int main(int argc, char** argv) {
// This object instance is required by Chrome code (such as MessageLoop).
base::AtExitManager exit_manager;