Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / remoting / host / remoting_me2me_host.cc
index b4ab023..69b505b 100644 (file)
@@ -91,7 +91,9 @@
 
 #if defined(OS_WIN)
 #include <commctrl.h>
+#include "base/win/registry.h"
 #include "base/win/scoped_handle.h"
+#include "remoting/host/pairing_registry_delegate_win.h"
 #include "remoting/host/win/session_desktop_environment.h"
 #endif  // defined(OS_WIN)
 
 #include "ui/gfx/gtk_util.h"
 #endif  // defined(TOOLKIT_GTK)
 
+using remoting::protocol::PairingRegistry;
+
+namespace {
+
 // This is used for tagging system event logs.
 const char kApplicationName[] = "chromoting";
 
@@ -116,6 +122,8 @@ const char kSignalParentSwitchName[] = "signal-parent";
 // from stdin.
 const char kStdinConfigPath[] = "-";
 
+}  // namespace
+
 namespace remoting {
 
 class HostProcess
@@ -143,6 +151,11 @@ class HostProcess
   // HostChangeNotificationListener::Listener overrides.
   virtual void OnHostDeleted() OVERRIDE;
 
+  // Initializes the pairing registry on Windows.
+  void OnInitializePairingRegistry(
+      IPC::PlatformFileForTransit privileged_key,
+      IPC::PlatformFileForTransit unprivileged_key);
+
  private:
   enum HostState {
     // Host process has just been started. Waiting for config and policies to be
@@ -274,6 +287,7 @@ class HostProcess
   bool curtain_required_;
   ThirdPartyAuthConfig third_party_auth_config_;
 
+  scoped_ptr<OAuthTokenGetter> oauth_token_getter_;
   scoped_ptr<XmppSignalStrategy> signal_strategy_;
   scoped_ptr<SignalingConnector> signaling_connector_;
   scoped_ptr<HeartbeatSender> heartbeat_sender_;
@@ -293,6 +307,8 @@ class HostProcess
 
   int* exit_code_out_;
   bool signal_parent_;
+
+  scoped_ptr<PairingRegistry::Delegate> pairing_registry_delegate_;
 };
 
 HostProcess::HostProcess(scoped_ptr<ChromotingHostContext> context,
@@ -508,9 +524,15 @@ void HostProcess::CreateAuthenticatorFactory() {
     return;
   }
 
-  scoped_refptr<protocol::PairingRegistry> pairing_registry = NULL;
+  scoped_refptr<PairingRegistry> pairing_registry = NULL;
   if (allow_pairing_) {
-    pairing_registry = CreatePairingRegistry(context_->file_task_runner());
+    if (!pairing_registry_delegate_)
+      pairing_registry_delegate_ = CreatePairingRegistryDelegate();
+
+    if (pairing_registry_delegate_) {
+      pairing_registry = new PairingRegistry(context_->file_task_runner(),
+                                             pairing_registry_delegate_.Pass());
+    }
   }
 
   scoped_ptr<protocol::AuthenticatorFactory> factory;
@@ -560,6 +582,8 @@ bool HostProcess::OnMessageReceived(const IPC::Message& message) {
     IPC_MESSAGE_HANDLER(ChromotingDaemonMsg_Crash, OnCrash)
     IPC_MESSAGE_HANDLER(ChromotingDaemonNetworkMsg_Configuration,
                         OnConfigUpdated)
+    IPC_MESSAGE_HANDLER(ChromotingDaemonNetworkMsg_InitializePairingRegistry,
+                        OnInitializePairingRegistry)
     IPC_MESSAGE_FORWARD(
         ChromotingDaemonNetworkMsg_DesktopAttached,
         desktop_session_connector_,
@@ -676,6 +700,29 @@ void HostProcess::OnHostDeleted() {
   ShutdownHost(kInvalidHostIdExitCode);
 }
 
+void HostProcess::OnInitializePairingRegistry(
+    IPC::PlatformFileForTransit privileged_key,
+    IPC::PlatformFileForTransit unprivileged_key) {
+  DCHECK(!pairing_registry_delegate_);
+
+#if defined(OS_WIN)
+  // Initialize the pairing registry delegate.
+  scoped_ptr<PairingRegistryDelegateWin> delegate(
+      new PairingRegistryDelegateWin());
+  bool result = delegate->SetRootKeys(
+      reinterpret_cast<HKEY>(
+          IPC::PlatformFileForTransitToPlatformFile(privileged_key)),
+      reinterpret_cast<HKEY>(
+          IPC::PlatformFileForTransitToPlatformFile(unprivileged_key)));
+  if (!result)
+    return;
+
+  pairing_registry_delegate_ = delegate.PassAs<PairingRegistry::Delegate>();
+#else  // !defined(OS_WIN)
+  NOTREACHED();
+#endif  // !defined(OS_WIN)
+}
+
 // Applies the host config, returning true if successful.
 bool HostProcess::ApplyConfig(scoped_ptr<JsonHostConfig> config) {
   DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
@@ -987,16 +1034,20 @@ void HostProcess::StartHost() {
 
   signaling_connector_.reset(new SignalingConnector(
       signal_strategy_.get(),
-      context_->url_request_context_getter(),
       dns_blackhole_checker.Pass(),
       base::Bind(&HostProcess::OnAuthFailed, this)));
 
   if (!oauth_refresh_token_.empty()) {
-    scoped_ptr<SignalingConnector::OAuthCredentials> oauth_credentials(
-        new SignalingConnector::OAuthCredentials(
+    scoped_ptr<OAuthTokenGetter::OAuthCredentials> oauth_credentials;
+    oauth_credentials.reset(
+        new OAuthTokenGetter::OAuthCredentials(
             xmpp_server_config_.username, oauth_refresh_token_,
             use_service_account_));
-    signaling_connector_->EnableOAuth(oauth_credentials.Pass());
+
+    oauth_token_getter_.reset(new OAuthTokenGetter(
+        oauth_credentials.Pass(), context_->url_request_context_getter()));
+
+    signaling_connector_->EnableOAuth(oauth_token_getter_.get());
   }
 
   NetworkSettings network_settings(
@@ -1114,6 +1165,7 @@ void HostProcess::ShutdownOnNetworkThread() {
   host_status_sender_.reset();
   host_change_notification_listener_.reset();
   signaling_connector_.reset();
+  oauth_token_getter_.reset();
   signal_strategy_.reset();
   network_change_notifier_.reset();