diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-23 19:31:40 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-23 19:31:40 +0000 |
commit | 809e10f57b8bbfb1b780e3963a7466b15aef45bf (patch) | |
tree | 00b8867d566bf0c968b519bac4f036846d0c1612 /chrome | |
parent | 1edeeaf2c02be8d62dd57a348b6a4d0e57604448 (diff) | |
download | chromium_src-809e10f57b8bbfb1b780e3963a7466b15aef45bf.zip chromium_src-809e10f57b8bbfb1b780e3963a7466b15aef45bf.tar.gz chromium_src-809e10f57b8bbfb1b780e3963a7466b15aef45bf.tar.bz2 |
Remove chromoting host registration from service process. More IPCs to control
host state.
BUG=None
TEST=Unittests.
Review URL: http://codereview.chromium.org/5955001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70081 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/remoting/remoting_setup_flow.cc | 4 | ||||
-rw-r--r-- | chrome/browser/service/service_process_control.cc | 43 | ||||
-rw-r--r-- | chrome/browser/service/service_process_control.h | 25 | ||||
-rw-r--r-- | chrome/chrome.gyp | 4 | ||||
-rw-r--r-- | chrome/common/remoting/chromoting_host_info.h | 23 | ||||
-rw-r--r-- | chrome/common/service_messages.cc | 41 | ||||
-rw-r--r-- | chrome/common/service_messages.h | 17 | ||||
-rw-r--r-- | chrome/common/service_messages_internal.h | 21 | ||||
-rw-r--r-- | chrome/service/cloud_print/cloud_print_proxy.cc | 1 | ||||
-rw-r--r-- | chrome/service/remoting/chromoting_host_manager.cc | 173 | ||||
-rw-r--r-- | chrome/service/remoting/chromoting_host_manager.h | 81 | ||||
-rw-r--r-- | chrome/service/service_ipc_server.cc | 40 | ||||
-rw-r--r-- | chrome/service/service_ipc_server.h | 13 | ||||
-rw-r--r-- | chrome/service/service_process.cc | 169 | ||||
-rw-r--r-- | chrome/service/service_process.h | 76 | ||||
-rw-r--r-- | chrome/service/service_process_unittest.cc | 14 |
16 files changed, 480 insertions, 265 deletions
diff --git a/chrome/browser/remoting/remoting_setup_flow.cc b/chrome/browser/remoting/remoting_setup_flow.cc index 6255c50..05c7590 100644 --- a/chrome/browser/remoting/remoting_setup_flow.cc +++ b/chrome/browser/remoting/remoting_setup_flow.cc @@ -262,8 +262,8 @@ void RemotingSetupFlow::OnUserSubmittedAuth(const std::string& user, void RemotingSetupFlow::OnProcessLaunched() { DCHECK(process_control_->is_connected()); // TODO(hclam): Need to wait for an ACK to be sure that it is actually active. - process_control_->EnableRemotingWithTokens(login_, remoting_token_, - sync_token_); + process_control_->SetRemotingHostCredentials(login_, sync_token_); + process_control_->EnableRemotingHost(); // Save the preference that we have completed the setup of remoting. profile_->GetPrefs()->SetBoolean(prefs::kRemotingHasSetupCompleted, true); diff --git a/chrome/browser/service/service_process_control.cc b/chrome/browser/service/service_process_control.cc index bd98319..dfba80a 100644 --- a/chrome/browser/service/service_process_control.cc +++ b/chrome/browser/service/service_process_control.cc @@ -243,6 +243,8 @@ void ServiceProcessControl::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ServiceHostMsg_GoodDay, OnGoodDay) IPC_MESSAGE_HANDLER(ServiceHostMsg_CloudPrintProxy_IsEnabled, OnCloudPrintProxyIsEnabled) + IPC_MESSAGE_HANDLER(ServiceHostMsg_RemotingHost_HostInfo, + OnRemotingHostInfo) IPC_END_MESSAGE_MAP() } @@ -273,7 +275,6 @@ void ServiceProcessControl::Observe(NotificationType type, } } - void ServiceProcessControl::OnGoodDay() { if (!message_handler_) return; @@ -290,6 +291,22 @@ void ServiceProcessControl::OnCloudPrintProxyIsEnabled(bool enabled, } } +void ServiceProcessControl::OnRemotingHostInfo( + remoting::ChromotingHostInfo host_info) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + if (remoting_host_status_callback_ != NULL) { + remoting_host_status_callback_->Run(host_info); + remoting_host_status_callback_.reset(); + } +} + +bool ServiceProcessControl::GetCloudPrintProxyStatus( + Callback2<bool, std::string>::Type* cloud_print_status_callback) { + DCHECK(cloud_print_status_callback); + cloud_print_status_callback_.reset(cloud_print_status_callback); + return Send(new ServiceMsg_IsCloudPrintProxyEnabled); +} + bool ServiceProcessControl::SendHello() { return Send(new ServiceMsg_Hello()); } @@ -300,20 +317,26 @@ bool ServiceProcessControl::Shutdown() { return ret; } -bool ServiceProcessControl::EnableRemotingWithTokens( +bool ServiceProcessControl::SetRemotingHostCredentials( const std::string& user, - const std::string& remoting_token, const std::string& talk_token) { return Send( - new ServiceMsg_EnableRemotingWithTokens(user, remoting_token, - talk_token)); + new ServiceMsg_SetRemotingHostCredentials(user, talk_token)); } -bool ServiceProcessControl::GetCloudPrintProxyStatus( - Callback2<bool, std::string>::Type* cloud_print_status_callback) { - DCHECK(cloud_print_status_callback); - cloud_print_status_callback_.reset(cloud_print_status_callback); - return Send(new ServiceMsg_IsCloudPrintProxyEnabled); +bool ServiceProcessControl::EnableRemotingHost() { + return Send(new ServiceMsg_EnableRemotingHost()); +} + +bool ServiceProcessControl::DisableRemotingHost() { + return Send(new ServiceMsg_DisableRemotingHost()); +} + +bool ServiceProcessControl::GetRemotingHostStatus( + GetRemotingHostStatusCallback* status_callback) { + DCHECK(status_callback); + remoting_host_status_callback_.reset(status_callback); + return Send(new ServiceMsg_GetRemotingHostInfo); } DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcessControl); diff --git a/chrome/browser/service/service_process_control.h b/chrome/browser/service/service_process_control.h index ff22eb3..efbd545 100644 --- a/chrome/browser/service/service_process_control.h +++ b/chrome/browser/service/service_process_control.h @@ -20,6 +20,10 @@ class Profile; +namespace remoting { +struct ChromotingHostInfo; +} // namespace remoting + // A ServiceProcessControl works as a portal between the service process and // the browser process. // @@ -36,6 +40,8 @@ class ServiceProcessControl : public IPC::Channel::Sender, public: typedef IDMap<ServiceProcessControl>::iterator iterator; typedef std::queue<IPC::Message> MessageQueue; + typedef Callback1<const remoting::ChromotingHostInfo&>::Type + GetRemotingHostStatusCallback; // An interface for handling messages received from the service process. class MessageHandler { @@ -86,6 +92,7 @@ class ServiceProcessControl : public IPC::Channel::Sender, // Message handlers void OnGoodDay(); void OnCloudPrintProxyIsEnabled(bool enabled, std::string email); + void OnRemotingHostInfo(remoting::ChromotingHostInfo host_info); // Send a hello message to the service process for testing purpose. // Return true if the message was sent. @@ -96,12 +103,6 @@ class ServiceProcessControl : public IPC::Channel::Sender, // Return true if the message was sent. bool Shutdown(); - // Send a message to enable the remoting service in the service process. - // Return true if the message was sent. - bool EnableRemotingWithTokens(const std::string& user, - const std::string& remoting_token, - const std::string& talk_token); - // Send a message to the service process to request a response // containing the enablement status of the cloud print proxy and the // registered email address. The callback gets the information when @@ -109,6 +110,17 @@ class ServiceProcessControl : public IPC::Channel::Sender, bool GetCloudPrintProxyStatus( Callback2<bool, std::string>::Type* cloud_print_status_callback); + // Send a message to enable the remoting service in the service process. + // Return true if the message was sent. + bool SetRemotingHostCredentials(const std::string& user, + const std::string& auth_token); + + bool EnableRemotingHost(); + bool DisableRemotingHost(); + + bool GetRemotingHostStatus( + GetRemotingHostStatusCallback* status_callback); + // Set the message handler for receiving messages from the service process. // TODO(hclam): Allow more than 1 handler. void SetMessageHandler(MessageHandler* message_handler) { @@ -149,6 +161,7 @@ class ServiceProcessControl : public IPC::Channel::Sender, // Callback that gets invoked when a status message is received from // the cloud print proxy. scoped_ptr<Callback2<bool, std::string>::Type> cloud_print_status_callback_; + scoped_ptr<GetRemotingHostStatusCallback> remoting_host_status_callback_; // Handler for messages from service process. MessageHandler* message_handler_; diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index a87b798..b58992af 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1159,8 +1159,8 @@ 'service/gaia/service_gaia_authenticator.h', 'service/net/service_url_request_context.cc', 'service/net/service_url_request_context.h', - 'service/remoting/remoting_directory_service.cc', - 'service/remoting/remoting_directory_service.h', + 'service/remoting/chromoting_host_manager.cc', + 'service/remoting/chromoting_host_manager.h', ], 'include_dirs': [ '..', diff --git a/chrome/common/remoting/chromoting_host_info.h b/chrome/common/remoting/chromoting_host_info.h new file mode 100644 index 0000000..e803eef --- /dev/null +++ b/chrome/common/remoting/chromoting_host_info.h @@ -0,0 +1,23 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_COMMON_REMOTING_CHROMOTING_HOST_INFO_H_ +#define CHROME_COMMON_REMOTING_CHROMOTING_HOST_INFO_H_ + +#include <string> + +namespace remoting { + +// This struct is used for ServiceHostMsg_ChromotingHost_Info IPC message. +struct ChromotingHostInfo { + std::string host_id; + std::string hostname; + std::string public_key; + std::string login; + bool enabled; +}; + +} // namespace remoting + +#endif // CHROME_COMMON_REMOTING_CHROMOTING_HOST_INFO_H_ diff --git a/chrome/common/service_messages.cc b/chrome/common/service_messages.cc index 98f8923..b221881 100644 --- a/chrome/common/service_messages.cc +++ b/chrome/common/service_messages.cc @@ -2,5 +2,46 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/common/remoting/chromoting_host_info.h" +#include "ipc/ipc_channel_handle.h" + #define IPC_MESSAGE_IMPL #include "chrome/common/service_messages.h" + +namespace IPC { + +void ParamTraits<remoting::ChromotingHostInfo> ::Write( + Message* m, const param_type& p) { + WriteParam(m, p.host_id); + WriteParam(m, p.hostname); + WriteParam(m, p.public_key); + WriteParam(m, p.enabled); + WriteParam(m, p.login); +} + +bool ParamTraits<remoting::ChromotingHostInfo> ::Read( + const Message* m, void** iter, param_type* p) { + bool ret = ReadParam(m, iter, &p->host_id); + ret = ret && ReadParam(m, iter, &p->hostname); + ret = ret && ReadParam(m, iter, &p->public_key); + ret = ret && ReadParam(m, iter, &p->enabled); + ret = ret && ReadParam(m, iter, &p->login); + return ret; +} + +void ParamTraits<remoting::ChromotingHostInfo> ::Log( + const param_type& p, std::string* l) { + l->append("("); + LogParam(p.host_id, l); + l->append(", "); + LogParam(p.hostname, l); + l->append(", "); + LogParam(p.public_key, l); + l->append(", "); + LogParam(p.enabled, l); + l->append(", "); + LogParam(p.login, l); + l->append(")"); +} + +} // namespace IPC diff --git a/chrome/common/service_messages.h b/chrome/common/service_messages.h index 1c23ead..1f8d75e 100644 --- a/chrome/common/service_messages.h +++ b/chrome/common/service_messages.h @@ -7,5 +7,20 @@ #include "chrome/common/service_messages_internal.h" -#endif // CHROME_COMMON_SERVICE_MESSAGES_H_ +namespace remoting { +struct ChromotingHostInfo; +} // namespace remoting + +namespace IPC { + +template <> +struct ParamTraits<remoting::ChromotingHostInfo> { + typedef remoting::ChromotingHostInfo param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, void** iter, param_type* p); + static void Log(const param_type& p, std::string* l); +}; +} // namespace IPC + +#endif // CHROME_COMMON_SERVICE_MESSAGES_H_ diff --git a/chrome/common/service_messages_internal.h b/chrome/common/service_messages_internal.h index e5ae7b3..94a0215 100644 --- a/chrome/common/service_messages_internal.h +++ b/chrome/common/service_messages_internal.h @@ -6,6 +6,8 @@ #include "ipc/ipc_message_macros.h" +#include "chrome/common/remoting/chromoting_host_info.h" + #define IPC_MESSAGE_START ServiceMsgStart //------------------------------------------------------------------------------ @@ -30,11 +32,19 @@ IPC_MESSAGE_CONTROL0(ServiceMsg_IsCloudPrintProxyEnabled) // This message is for testing purpose. IPC_MESSAGE_CONTROL0(ServiceMsg_Hello) -// This message is for enabling the remoting process. -IPC_MESSAGE_CONTROL3(ServiceMsg_EnableRemotingWithTokens, +// Set credentials used by the RemotingHost. +IPC_MESSAGE_CONTROL2(ServiceMsg_SetRemotingHostCredentials, std::string, /* username */ - std::string, /* Token for remoting */ - std::string /* Token for Google Talk */) + std::string /* token for XMPP */) + +// Enabled remoting host. +IPC_MESSAGE_CONTROL0(ServiceMsg_EnableRemotingHost) + +// Disable remoting host. +IPC_MESSAGE_CONTROL0(ServiceMsg_DisableRemotingHost) + +// Get remoting host status information. +IPC_MESSAGE_CONTROL0(ServiceMsg_GetRemotingHostInfo) // Tell the service process to shutdown. IPC_MESSAGE_CONTROL0(ServiceMsg_Shutdown) @@ -53,5 +63,8 @@ IPC_MESSAGE_CONTROL2(ServiceHostMsg_CloudPrintProxy_IsEnabled, bool, /* Is the proxy enabled? */ std::string /* Email address of account */) +IPC_MESSAGE_CONTROL1(ServiceHostMsg_RemotingHost_HostInfo, + remoting::ChromotingHostInfo /* host_info */) + // Sent from the service process in response to a Hello message. IPC_MESSAGE_CONTROL0(ServiceHostMsg_GoodDay) diff --git a/chrome/service/cloud_print/cloud_print_proxy.cc b/chrome/service/cloud_print/cloud_print_proxy.cc index d2fb73c..9bb789d 100644 --- a/chrome/service/cloud_print/cloud_print_proxy.cc +++ b/chrome/service/cloud_print/cloud_print_proxy.cc @@ -14,6 +14,7 @@ #include "chrome/service/cloud_print/print_system.h" #include "chrome/service/service_process.h" #include "chrome/service/service_process_prefs.h" +#include "googleurl/src/gurl.h" // This method is invoked on the IO thread to launch the browser process to // display a desktop notification that the Cloud Print token is invalid and diff --git a/chrome/service/remoting/chromoting_host_manager.cc b/chrome/service/remoting/chromoting_host_manager.cc new file mode 100644 index 0000000..1fb369f --- /dev/null +++ b/chrome/service/remoting/chromoting_host_manager.cc @@ -0,0 +1,173 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/service/remoting/chromoting_host_manager.h" + +#include "base/path_service.h" +#include "chrome/common/chrome_paths.h" +#include "chrome/common/guid.h" +#include "chrome/common/remoting/chromoting_host_info.h" +#include "net/base/net_util.h" +#include "remoting/base/constants.h" +#include "remoting/host/chromoting_host_context.h" +#include "remoting/host/json_host_config.h" + +namespace remoting { + +ChromotingHostManager::ChromotingHostManager(Observer* observer) + : observer_(observer) { +} + +void ChromotingHostManager::Initialize( + base::MessageLoopProxy* file_message_loop) { + FilePath user_data_dir; + PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); + FilePath chromoting_config_path = + user_data_dir.Append(FILE_PATH_LITERAL(".ChromotingConfig.json")); + remoting::JsonHostConfig* config = new remoting::JsonHostConfig( + chromoting_config_path, file_message_loop); + if (!config->Read()) { + VLOG(1) << "Failed to read chromoting config file."; + } + + chromoting_config_ = config; + + if (!IsConfigInitialized()) { + InitializeConfig(); + } + + if (IsEnabled()) { + Start(); + } +} + +void ChromotingHostManager::Teardown() { + Stop(); +} + +bool ChromotingHostManager::IsConfigInitialized() { + std::string host_id; + if (!chromoting_config_->GetString(remoting::kHostIdConfigPath, &host_id)) + return false; + + return guid::IsValidGUID(host_id); +} + +void ChromotingHostManager::InitializeConfig() { + VLOG(1) << "Initializing static chromoting host parameters."; + + // TODO(hclam): This is a time consuming operation so we should run it on + // a separate thread. + remoting::HostKeyPair host_key_pair; + host_key_pair.Generate(); + std::string host_id(guid::GenerateGUID()); + std::string hostname(net::GetHostName()); + + chromoting_config_->SetBoolean(remoting::kHostEnabledConfigPath, false); + chromoting_config_->SetString(remoting::kHostIdConfigPath, host_id); + chromoting_config_->SetString(remoting::kHostNameConfigPath, hostname); + host_key_pair.Save(chromoting_config_); + + // Save updated values on the disk. + chromoting_config_->Save(); +} + +void ChromotingHostManager::SetCredentials(const std::string& login, + const std::string& token) { + chromoting_config_->SetString(remoting::kXmppLoginConfigPath, login); + chromoting_config_->SetString(remoting::kXmppAuthTokenConfigPath, token); + + // Save updated values on the disk. + chromoting_config_->Save(); +} + +void ChromotingHostManager::Enable() { + // We have already started. + if (IsEnabled()) + return; + + SetEnabled(true); + observer_->OnChromotingHostEnabled(); + + Start(); +} + +void ChromotingHostManager::Disable() { + if (IsEnabled()) { + SetEnabled(false); + observer_->OnChromotingHostDisabled(); + } + + Stop(); +} + +void ChromotingHostManager::GetHostInfo(ChromotingHostInfo* host_info) { + chromoting_config_->GetString(remoting::kHostIdConfigPath, + &host_info->host_id); + chromoting_config_->GetString(remoting::kHostNameConfigPath, + &host_info->hostname); + HostKeyPair key_pair; + if (key_pair.Load(chromoting_config_)) { + host_info->public_key = key_pair.GetPublicKey(); + } + + host_info->enabled = IsEnabled(); + + chromoting_config_->GetString(remoting::kXmppLoginConfigPath, + &host_info->login); +} + +void ChromotingHostManager::Stop() { + // Stop the host if it is started. + if (chromoting_host_) { + // Shutdown the chromoting host asynchronously. This will signal the host to + // shutdown, we'll actually wait for all threads to stop when we destroy + // the chromoting context. + chromoting_host_->Shutdown(); + chromoting_host_ = NULL; + + chromoting_context_->Stop(); + chromoting_context_.reset(); + } +} + +bool ChromotingHostManager::IsEnabled() { + bool enabled; + if (!chromoting_config_->GetBoolean(remoting::kHostEnabledConfigPath, + &enabled)) { + enabled = false; + } + return enabled; +} + +void ChromotingHostManager::SetEnabled(bool enabled) { + chromoting_config_->SetBoolean(remoting::kHostEnabledConfigPath, + enabled); + chromoting_config_->Save(); +} + +void ChromotingHostManager::Start() { + // Don't do anything if we already started. + if (chromoting_host_.get()) + return; + + // Start the chromoting context first. + chromoting_context_.reset(new remoting::ChromotingHostContext()); + chromoting_context_->Start(); + + // Create a chromoting host object. + chromoting_host_ = remoting::ChromotingHost::Create(chromoting_context_.get(), + chromoting_config_); + + // Then start the chromoting host. + // When ChromotingHost is shutdown because of failure or a request that + // we made OnChromotingShutdown() is calls. + chromoting_host_->Start( + NewRunnableMethod(this, &ChromotingHostManager::OnShutdown)); +} + +void ChromotingHostManager::OnShutdown() { +} + +} // namespace remoting diff --git a/chrome/service/remoting/chromoting_host_manager.h b/chrome/service/remoting/chromoting_host_manager.h new file mode 100644 index 0000000..6c510e8 --- /dev/null +++ b/chrome/service/remoting/chromoting_host_manager.h @@ -0,0 +1,81 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_SERVICE_REMOTING_CHROMOTING_HOST_MANAGER_H_ +#define CHROME_SERVICE_REMOTING_CHROMOTING_HOST_MANAGER_H_ + +#include <string> + +#include "base/ref_counted.h" +#include "base/scoped_ptr.h" +#include "remoting/host/chromoting_host.h" +#include "remoting/host/chromoting_host_context.h" +#include "remoting/host/host_config.h" + +namespace base { +class MessageLoopProxy; +} // namespace base + +namespace remoting { + +struct ChromotingHostInfo; + +// ChromotingHostManager manages chromoting host. It loads config and updates +// config when necessary, and starts and stops the chromoting host. +class ChromotingHostManager + : public base::RefCountedThreadSafe<ChromotingHostManager> { + public: + + // Interface for observer that is notified about the host being + // enabled/disabled. Observer is specified in the constructor. + class Observer { + public: + virtual ~Observer() {} + virtual void OnChromotingHostEnabled() {} + virtual void OnChromotingHostDisabled() {} + }; + + // Caller keeps ownership of |observer|. |observer| must not be + // destroyed while this object exists. + ChromotingHostManager(Observer* observer); + + void Initialize(base::MessageLoopProxy* file_message_loop); + void Teardown(); + + // Return the reference to the chromoting host only if it has started. + remoting::ChromotingHost* GetChromotingHost() { return chromoting_host_; } + + // Updates credentials used for XMPP connection. + void SetCredentials(const std::string& login, const std::string& token); + + bool IsEnabled(); + + // Start running the chromoting host asynchronously. + void Enable(); + + // Stop chromoting host. The shutdown process will happen asynchronously. + void Disable(); + + void GetHostInfo(ChromotingHostInfo* host_info); + + private: + bool IsConfigInitialized(); + void InitializeConfig(); + + void SetEnabled(bool enabled); + void Start(); + void Stop(); + + void OnShutdown(); + + Observer* observer_; + + scoped_refptr<remoting::MutableHostConfig> chromoting_config_; + scoped_ptr<remoting::ChromotingHostContext> chromoting_context_; + scoped_refptr<remoting::ChromotingHost> chromoting_host_; +}; + +} // namespace remoting + +#endif // CHROME_SERVICE_REMOTING_CHROMOTING_HOST_MANAGER_H_ diff --git a/chrome/service/service_ipc_server.cc b/chrome/service/service_ipc_server.cc index 71ae5d7..c7280c3 100644 --- a/chrome/service/service_ipc_server.cc +++ b/chrome/service/service_ipc_server.cc @@ -83,12 +83,20 @@ void ServiceIPCServer::OnMessageReceived(const IPC::Message& msg) { OnEnableCloudPrintProxy) IPC_MESSAGE_HANDLER(ServiceMsg_EnableCloudPrintProxyWithTokens, OnEnableCloudPrintProxyWithTokens) - IPC_MESSAGE_HANDLER(ServiceMsg_EnableRemotingWithTokens, - OnEnableRemotingWithTokens) IPC_MESSAGE_HANDLER(ServiceMsg_DisableCloudPrintProxy, OnDisableCloudPrintProxy) IPC_MESSAGE_HANDLER(ServiceMsg_IsCloudPrintProxyEnabled, OnIsCloudPrintProxyEnabled) +#if defined(ENABLE_REMOTING) + IPC_MESSAGE_HANDLER(ServiceMsg_SetRemotingHostCredentials, + OnSetRemotingHostCredentials) + IPC_MESSAGE_HANDLER(ServiceMsg_EnableRemotingHost, + OnEnableRemotingHost) + IPC_MESSAGE_HANDLER(ServiceMsg_DisableRemotingHost, + OnDisableRemotingHost) + IPC_MESSAGE_HANDLER(ServiceMsg_GetRemotingHostInfo, + OnGetRemotingHostInfo) +#endif // defined(ENABLE_REMOTING) IPC_MESSAGE_HANDLER(ServiceMsg_Hello, OnHello); IPC_MESSAGE_HANDLER(ServiceMsg_Shutdown, OnShutdown); IPC_MESSAGE_HANDLER(ServiceMsg_UpdateAvailable, OnUpdateAvailable); @@ -112,16 +120,29 @@ void ServiceIPCServer::OnIsCloudPrintProxyEnabled() { email)); } -void ServiceIPCServer::OnEnableRemotingWithTokens( - const std::string& login, - const std::string& remoting_token, - const std::string& talk_token) { #if defined(ENABLE_REMOTING) - g_service_process->EnableChromotingHostWithTokens(login, remoting_token, - talk_token); -#endif +void ServiceIPCServer::OnSetRemotingHostCredentials( + const std::string& login, + const std::string& auth_token) { + g_service_process->remoting_host_manager()->SetCredentials( + login, auth_token); +} + +void ServiceIPCServer::OnEnableRemotingHost() { + g_service_process->remoting_host_manager()->Enable(); } +void ServiceIPCServer:: OnDisableRemotingHost() { + g_service_process->remoting_host_manager()->Disable(); +} + +void ServiceIPCServer:: OnGetRemotingHostInfo() { + remoting::ChromotingHostInfo host_info; + g_service_process->remoting_host_manager()->GetHostInfo(&host_info); + channel_->Send(new ServiceHostMsg_RemotingHost_HostInfo(host_info)); +} +#endif // defined(ENABLE_REMOTING) + void ServiceIPCServer::OnDisableCloudPrintProxy() { g_service_process->GetCloudPrintProxy()->DisableForUser(); } @@ -137,4 +158,3 @@ void ServiceIPCServer::OnShutdown() { void ServiceIPCServer::OnUpdateAvailable() { g_service_process->SetUpdateAvailable(); } - diff --git a/chrome/service/service_ipc_server.h b/chrome/service/service_ipc_server.h index 79416a5..af19f7b 100644 --- a/chrome/service/service_ipc_server.h +++ b/chrome/service/service_ipc_server.h @@ -44,11 +44,16 @@ class ServiceIPCServer : public IPC::Channel::Listener, void OnEnableCloudPrintProxyWithTokens(const std::string& cloud_print_token, const std::string& talk_token); void OnIsCloudPrintProxyEnabled(); - - void OnEnableRemotingWithTokens(const std::string& login, - const std::string& remoting_token, - const std::string& talk_token); void OnDisableCloudPrintProxy(); + +#if defined(ENABLE_REMOTING) + void OnSetRemotingHostCredentials(const std::string& login, + const std::string& talk_token); + void OnEnableRemotingHost(); + void OnDisableRemotingHost(); + void OnGetRemotingHostInfo(); +#endif // defined(ENABLE_REMOTING) + void OnHello(); void OnShutdown(); void OnUpdateAvailable(); diff --git a/chrome/service/service_process.cc b/chrome/service/service_process.cc index 517ccfcc..c2f43f2 100644 --- a/chrome/service/service_process.cc +++ b/chrome/service/service_process.cc @@ -16,6 +16,7 @@ #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/net/url_fetcher.h" #include "chrome/common/pref_names.h" #include "chrome/common/service_process_util.h" #include "chrome/service/cloud_print/cloud_print_proxy.h" @@ -24,10 +25,7 @@ #include "net/base/network_change_notifier.h" #if defined(ENABLE_REMOTING) -#include "remoting/base/constants.h" -#include "remoting/host/chromoting_host.h" -#include "remoting/host/chromoting_host_context.h" -#include "remoting/host/json_host_config.h" +#include "chrome/service/remoting/chromoting_host_manager.h" #endif // defined(ENABLED_REMOTING) ServiceProcess* g_service_process = NULL; @@ -99,22 +97,10 @@ bool ServiceProcess::Initialize(MessageLoop* message_loop, new ServiceProcessPrefs(pref_path, file_thread_->message_loop_proxy())); service_prefs_->ReadPrefs(); - bool remoting_host_enabled = false; - - // For development, we allow forcing the enabling of the host daemon via a - // commandline flag, regardless of the preference setting. - // - // TODO(ajwong): When we've gotten the preference setting workflow more - // stable, we should remove the command-line flag force-enable. - service_prefs_->GetBoolean(prefs::kRemotingHostEnabled, - &remoting_host_enabled); - remoting_host_enabled |= command_line.HasSwitch(switches::kEnableRemoting); - #if defined(ENABLE_REMOTING) - // Check if remoting host is already enabled. - if (remoting_host_enabled) { - StartChromotingHost(); - } + // Initialize chromoting host manager. + remoting_host_manager_ = new remoting::ChromotingHostManager(this); + remoting_host_manager_->Initialize(file_thread_->message_loop_proxy()); #endif // Enable Cloud Print if needed. First check the command-line. @@ -149,7 +135,7 @@ bool ServiceProcess::Teardown() { cloud_print_proxy_.reset(); #if defined(ENABLE_REMOTING) - ShutdownChromotingHost(); + remoting_host_manager_->Teardown(); #endif ipc_server_.reset(); @@ -204,6 +190,14 @@ void ServiceProcess::OnCloudPrintProxyDisabled() { OnServiceDisabled(); } +void ServiceProcess::OnRemotingHostEnabled() { + OnServiceEnabled(); +} + +void ServiceProcess::OnRemotingHostDisabled() { + OnServiceDisabled(); +} + void ServiceProcess::OnServiceEnabled() { enabled_services_++; if (1 == enabled_services_) { @@ -242,141 +236,6 @@ void ServiceProcess::ShutdownIfNeeded() { } } -#if defined(ENABLE_REMOTING) -bool ServiceProcess::EnableChromotingHostWithTokens( - const std::string& login, - const std::string& remoting_token, - const std::string& talk_token) { - // Save the login info and tokens. - remoting_login_ = login; - remoting_token_ = remoting_token; - talk_token_ = talk_token; - - // Use the remoting directory to register the host. - if (remoting_directory_.get()) - remoting_directory_->CancelRequest(); - remoting_directory_.reset(new RemotingDirectoryService(this)); - remoting_directory_->AddHost(remoting_token); - return true; -} - -bool ServiceProcess::StartChromotingHost() { - // We have already started. - if (chromoting_context_.get()) - return true; - - // Load chromoting config from the disk. - LoadChromotingConfig(); - - // Start the chromoting context first. - chromoting_context_.reset(new remoting::ChromotingHostContext()); - chromoting_context_->Start(); - - // Create a chromoting host object. - chromoting_host_ = remoting::ChromotingHost::Create(chromoting_context_.get(), - chromoting_config_); - - // Then start the chromoting host. - // When ChromotingHost is shutdown because of failure or a request that - // we made OnChromotingShutdown() is calls. - chromoting_host_->Start( - NewRunnableMethod(this, &ServiceProcess::OnChromotingHostShutdown)); - OnServiceEnabled(); - return true; -} - -bool ServiceProcess::ShutdownChromotingHost() { - // Chromoting host doesn't exist so return true. - if (!chromoting_host_) - return true; - - // Shutdown the chromoting host asynchronously. This will signal the host to - // shutdown, we'll actually wait for all threads to stop when we destroy - // the chromoting context. - chromoting_host_->Shutdown(); - chromoting_host_ = NULL; - - chromoting_context_->Stop(); - chromoting_context_ .reset(); - - return true; -} - -void ServiceProcess::OnRemotingHostAdded() { - // Save configuration for chromoting. - SaveChromotingConfig(remoting_login_, - talk_token_, - remoting_directory_->host_id(), - remoting_directory_->host_name(), - remoting_directory_->host_key_pair()); - remoting_directory_.reset(); - remoting_login_ = ""; - remoting_token_ = ""; - talk_token_ = ""; - - // Save the preference that we have enabled the remoting host. - service_prefs_->SetBoolean(prefs::kRemotingHostEnabled, true); - - // Force writing prefs to the disk. - service_prefs_->WritePrefs(); - - // TODO(hclam): If we have a problem we need to send an IPC message back - // to the client that started this. - bool ret = StartChromotingHost(); - DCHECK(ret); -} - -void ServiceProcess::OnRemotingDirectoryError() { - remoting_directory_.reset(); - remoting_login_ = ""; - remoting_token_ = ""; - talk_token_ = ""; - - // TODO(hclam): If we have a problem we need to send an IPC message back - // to the client that started this. -} - -void ServiceProcess::SaveChromotingConfig( - const std::string& login, - const std::string& token, - const std::string& host_id, - const std::string& host_name, - remoting::HostKeyPair* host_key_pair) { - // First we need to load the config first. - LoadChromotingConfig(); - - // And then do the update. - chromoting_config_->SetString(remoting::kXmppLoginConfigPath, login); - chromoting_config_->SetString(remoting::kXmppAuthTokenConfigPath, token); - chromoting_config_->SetString(remoting::kHostIdConfigPath, host_id); - chromoting_config_->SetString(remoting::kHostNameConfigPath, host_name); - chromoting_config_->Save(); - - // And then save the key pair. - host_key_pair->Save(chromoting_config_); -} - -void ServiceProcess::LoadChromotingConfig() { - // TODO(hclam): We really should be doing this on IO thread so we are not - // blocked on file IOs. - if (chromoting_config_) - return; - - FilePath user_data_dir; - PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); - FilePath chromoting_config_path = - user_data_dir.Append(FILE_PATH_LITERAL(".ChromotingConfig.json")); - chromoting_config_ = new remoting::JsonHostConfig( - chromoting_config_path, file_thread_->message_loop_proxy()); - if (!chromoting_config_->Read()) - VLOG(1) << "Failed to read chromoting config file."; -} - -void ServiceProcess::OnChromotingHostShutdown() { - // TODO(hclam): Implement. -} -#endif - ServiceProcess::~ServiceProcess() { Teardown(); g_service_process = NULL; diff --git a/chrome/service/service_process.h b/chrome/service/service_process.h index 230cf77..66ee79f 100644 --- a/chrome/service/service_process.h +++ b/chrome/service/service_process.h @@ -14,7 +14,7 @@ #include "base/thread.h" #include "base/waitable_event.h" #include "chrome/service/cloud_print/cloud_print_proxy.h" -#include "chrome/service/remoting/remoting_directory_service.h" +#include "chrome/service/remoting/chromoting_host_manager.h" class ServiceProcessPrefs; class ServiceIPCServer; @@ -23,19 +23,12 @@ namespace net { class NetworkChangeNotifier; } -namespace remoting { -class ChromotingHost; -class ChromotingHostContext; -class HostKeyPair; -class JsonHostConfig; -} - class CommandLine; // The ServiceProcess does not inherit from ChildProcess because this // process can live independently of the browser process. -class ServiceProcess : public RemotingDirectoryService::Client, - public CloudPrintProxy::Client { +class ServiceProcess : public CloudPrintProxy::Client, + public remoting::ChromotingHostManager::Observer { public: ServiceProcess(); ~ServiceProcess(); @@ -92,27 +85,15 @@ class ServiceProcess : public RemotingDirectoryService::Client, virtual void OnCloudPrintProxyEnabled(); virtual void OnCloudPrintProxyDisabled(); + // ChromotingHostManager::Observer interface. + virtual void OnRemotingHostEnabled(); + virtual void OnRemotingHostDisabled(); + #if defined(ENABLE_REMOTING) // Return the reference to the chromoting host only if it has started. - remoting::ChromotingHost* GetChromotingHost() { return chromoting_host_; } - - // Enable chromoting host with the tokens. - // Return true if successful. - bool EnableChromotingHostWithTokens(const std::string& login, - const std::string& remoting_token, - const std::string& talk_token); - - // Start running the chromoting host asynchronously. - // Return true if chromoting host has started. - bool StartChromotingHost(); - - // Shutdown chromoting host. Return true if chromoting host was shutdown. - // The shutdown process will happen asynchronously. - bool ShutdownChromotingHost(); - - // RemotingDirectoryService::Client implementation. - virtual void OnRemotingHostAdded(); - virtual void OnRemotingDirectoryError(); + remoting::ChromotingHostManager* remoting_host_manager() { + return remoting_host_manager_; + } #endif private: @@ -128,26 +109,6 @@ class ServiceProcess : public RemotingDirectoryService::Client, // disabled in this process (note that shutdown != disabled). void OnServiceDisabled(); -#if defined(ENABLE_REMOTING) - FRIEND_TEST_ALL_PREFIXES(ServiceProcessTest, RunChromoting); - FRIEND_TEST_ALL_PREFIXES(ServiceProcessTest, RunChromotingUntilShutdown); - - // Save authenication token to the json config file. - void SaveChromotingConfig( - const std::string& login, - const std::string& token, - const std::string& host_id, - const std::string& host_name, - remoting::HostKeyPair* host_key_pair); - - // Load settings for chromoting from json file. - void LoadChromotingConfig(); - - // This method is called when chromoting is shutting down. This is virtual - // for used in the test. - virtual void OnChromotingHostShutdown(); -#endif - scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; scoped_ptr<base::Thread> io_thread_; scoped_ptr<base::Thread> file_thread_; @@ -155,19 +116,6 @@ class ServiceProcess : public RemotingDirectoryService::Client, scoped_ptr<ServiceProcessPrefs> service_prefs_; scoped_ptr<ServiceIPCServer> ipc_server_; -#if defined(ENABLE_REMOTING) - scoped_refptr<remoting::JsonHostConfig> chromoting_config_; - scoped_ptr<remoting::ChromotingHostContext> chromoting_context_; - scoped_refptr<remoting::ChromotingHost> chromoting_host_; - scoped_ptr<RemotingDirectoryService> remoting_directory_; - - // Temporary storage for remoting credentials. The content is cleared - // after it is saved. - std::string remoting_login_; - std::string remoting_token_; - std::string talk_token_; -#endif - // An event that will be signalled when we shutdown. base::WaitableEvent shutdown_event_; @@ -180,6 +128,10 @@ class ServiceProcess : public RemotingDirectoryService::Client, // Speficies whether a product update is available. bool update_available_; +#if defined(ENABLE_REMOTING) + scoped_refptr<remoting::ChromotingHostManager> remoting_host_manager_; +#endif + DISALLOW_COPY_AND_ASSIGN(ServiceProcess); }; diff --git a/chrome/service/service_process_unittest.cc b/chrome/service/service_process_unittest.cc index 1de1492..7b8fff1 100644 --- a/chrome/service/service_process_unittest.cc +++ b/chrome/service/service_process_unittest.cc @@ -31,11 +31,9 @@ TEST(ServiceProcessTest, DISABLED_RunChromoting) { EXPECT_TRUE(process.Initialize(&main_message_loop, command_line)); // Then config the chromoting host and start it. - remoting::HostKeyPair key; - key.Generate(); - process.SaveChromotingConfig("hello", "world", "it's a", "good day", &key); - EXPECT_TRUE(process.StartChromotingHost()); - EXPECT_TRUE(process.ShutdownChromotingHost()); + process.remoting_host_manager()->SetCredentials("email", "token"); + process.remoting_host_manager()->Enable(); + process.remoting_host_manager()->Disable(); EXPECT_TRUE(process.Teardown()); } @@ -60,10 +58,8 @@ TEST(ServiceProcessTest, DISABLED_RunChromotingUntilShutdown) { .WillOnce(QuitMessageLoop(&main_message_loop)); // Then config the chromoting host and start it. - remoting::HostKeyPair key; - key.Generate(); - process.SaveChromotingConfig("hello", "world", "it's a", "good day", &key); - EXPECT_TRUE(process.StartChromotingHost()); + process.remoting_host_manager()->SetCredentials("email", "token"); + process.remoting_host_manager()->Enable(); MessageLoop::current()->Run(); EXPECT_TRUE(process.Teardown()); |