Index: remoting/host/remoting_me2me_host.cc |
diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc |
index 32f3f18a4f123af05967456f563157366cbe2724..401aba04db8ed2f1a8190d569ec05ab0356f4d43 100644 |
--- a/remoting/host/remoting_me2me_host.cc |
+++ b/remoting/host/remoting_me2me_host.cc |
@@ -171,7 +171,8 @@ class HostProcess |
// HostChangeNotificationListener::Listener overrides. |
void OnHostDeleted() override; |
- // Initializes the pairing registry on Windows. |
+ // Handler of the ChromotingDaemonNetworkMsg_InitializePairingRegistry IPC |
+ // message. |
void OnInitializePairingRegistry( |
IPC::PlatformFileForTransit privileged_key, |
IPC::PlatformFileForTransit unprivileged_key); |
@@ -271,6 +272,14 @@ class HostProcess |
void OnPolicyWatcherShutdown(); |
+#if defined(OS_WIN) |
+ // Initializes the pairing registry on Windows. This should be invoked on the |
+ // network thread. |
+ void InitializePairingRegistry( |
+ IPC::PlatformFileForTransit privileged_key, |
+ IPC::PlatformFileForTransit unprivileged_key); |
+#endif // defined(OS_WIN) |
+ |
// Crashes the process in response to a daemon's request. The daemon passes |
// the location of the code that detected the fatal error resulted in this |
// request. |
@@ -352,7 +361,7 @@ class HostProcess |
int* exit_code_out_; |
bool signal_parent_; |
- scoped_ptr<PairingRegistry::Delegate> pairing_registry_delegate_; |
+ scoped_refptr<PairingRegistry> pairing_registry_; |
ShutdownWatchdog* shutdown_watchdog_; |
}; |
@@ -608,24 +617,31 @@ void HostProcess::CreateAuthenticatorFactory() { |
return; |
} |
- scoped_refptr<PairingRegistry> pairing_registry = NULL; |
- if (allow_pairing_) { |
- 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; |
if (third_party_auth_config_.is_empty()) { |
+ scoped_refptr<PairingRegistry> pairing_registry; |
+ if (allow_pairing_) { |
+ // On Windows |pairing_registry_| is initialized in |
+ // InitializePairingRegistry(). |
+#if !defined(OS_WIN) |
+ if (!pairing_registry_) { |
+ scoped_ptr<PairingRegistry::Delegate> delegate( |
+ CreatePairingRegistryDelegate()); |
Sergey Ulanov
2015/01/08 17:34:02
nit: this would be more readable with assignment:
weitao
2015/01/08 17:56:29
Done.
|
+ |
+ pairing_registry_ = new PairingRegistry(context_->file_task_runner(), |
+ delegate.Pass()); |
Sergey Ulanov
2015/01/08 17:34:02
nit: indentation.
weitao
2015/01/08 17:56:29
Done.
|
+ } |
+#endif // defined(OS_WIN) |
+ |
+ pairing_registry = pairing_registry_; |
+ } |
+ |
factory = protocol::Me2MeHostAuthenticatorFactory::CreateWithSharedSecret( |
use_service_account_, host_owner_, local_certificate, key_pair_, |
host_secret_hash_, pairing_registry); |
+ host_->set_pairing_registry(pairing_registry); |
} else if (third_party_auth_config_.is_valid()) { |
scoped_ptr<protocol::TokenValidatorFactory> token_validator_factory( |
new TokenValidatorFactoryImpl( |
@@ -652,8 +668,6 @@ void HostProcess::CreateAuthenticatorFactory() { |
factory.reset(new PamAuthorizationFactory(factory.Pass())); |
#endif |
host_->SetAuthenticatorFactory(factory.Pass()); |
- |
- host_->set_pairing_registry(pairing_registry); |
} |
// IPC::Listener implementation. |
@@ -803,26 +817,45 @@ void HostProcess::OnHostDeleted() { |
void HostProcess::OnInitializePairingRegistry( |
IPC::PlatformFileForTransit privileged_key, |
IPC::PlatformFileForTransit unprivileged_key) { |
- DCHECK(!pairing_registry_delegate_); |
+ DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
#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.Pass(); |
+ context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( |
+ &HostProcess::InitializePairingRegistry, |
+ this, privileged_key, unprivileged_key)); |
#else // !defined(OS_WIN) |
NOTREACHED(); |
#endif // !defined(OS_WIN) |
} |
+#if defined(OS_WIN) |
+void HostProcess::InitializePairingRegistry( |
+ IPC::PlatformFileForTransit privileged_key, |
+ IPC::PlatformFileForTransit unprivileged_key) { |
+ DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
+ // |privileged_key| can be NULL but not |unprivileged_key|. |
+ DCHECK(unprivileged_key); |
+ // |pairing_registry_| should only be initialized once. |
+ DCHECK(!pairing_registry_); |
+ |
+ HKEY privileged_hkey = reinterpret_cast<HKEY>( |
+ IPC::PlatformFileForTransitToPlatformFile(privileged_key)); |
+ HKEY unprivileged_hkey = reinterpret_cast<HKEY>( |
+ IPC::PlatformFileForTransitToPlatformFile(unprivileged_key)); |
+ |
+ scoped_ptr<PairingRegistryDelegateWin> delegate( |
+ new PairingRegistryDelegateWin()); |
+ delegate->SetRootKeys(privileged_hkey, unprivileged_hkey); |
+ |
+ pairing_registry_ = new PairingRegistry(context_->file_task_runner(), |
+ delegate.Pass()); |
+ |
+ // (Re)Create the authenticator factory now that |pairing_registry_| has been |
+ // initialized. |
+ CreateAuthenticatorFactory(); |
+} |
+#endif // !defined(OS_WIN) |
+ |
// Applies the host config, returning true if successful. |
bool HostProcess::ApplyConfig(const base::DictionaryValue& config) { |
DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |