diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-15 23:00:26 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-15 23:00:26 +0000 |
commit | 34f09f1a76bcb5391a602928269272a4ba9aa1c0 (patch) | |
tree | 2aae553ab047d74263b6f89b62fc0a4eb0750dfa /remoting | |
parent | 565669351555e4183fbdf23c97842aa3c5841805 (diff) | |
download | chromium_src-34f09f1a76bcb5391a602928269272a4ba9aa1c0.zip chromium_src-34f09f1a76bcb5391a602928269272a4ba9aa1c0.tar.gz chromium_src-34f09f1a76bcb5391a602928269272a4ba9aa1c0.tar.bz2 |
Added HostConfig class. Changed SimpleHost to use it.
BUG=none
TEST=unittests
Review URL: http://codereview.chromium.org/2810002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49852 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/host/chromoting_host.cc | 19 | ||||
-rw-r--r-- | remoting/host/chromoting_host.h | 10 | ||||
-rw-r--r-- | remoting/host/heartbeat_sender.cc | 8 | ||||
-rw-r--r-- | remoting/host/heartbeat_sender.h | 5 | ||||
-rw-r--r-- | remoting/host/host_config.h | 79 | ||||
-rw-r--r-- | remoting/host/simple_host_process.cc | 21 | ||||
-rw-r--r-- | remoting/remoting.gyp | 1 |
7 files changed, 115 insertions, 28 deletions
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc index f8abdb6..9679442 100644 --- a/remoting/host/chromoting_host.cc +++ b/remoting/host/chromoting_host.cc @@ -9,22 +9,21 @@ #include "build/build_config.h" #include "remoting/base/constants.h" #include "remoting/base/protocol_decoder.h" +#include "remoting/host/host_config.h" #include "remoting/host/session_manager.h" #include "remoting/jingle_glue/jingle_channel.h" namespace remoting { -ChromotingHost::ChromotingHost(const std::string& username, - const std::string& auth_token, - Capturer* capturer, - Encoder* encoder, - EventExecutor* executor, - base::WaitableEvent* host_done) +ChromotingHost::ChromotingHost(HostConfig* config, + Capturer* capturer, + Encoder* encoder, + EventExecutor* executor, + base::WaitableEvent* host_done) : main_thread_("MainThread"), capture_thread_("CaptureThread"), encode_thread_("EncodeThread"), - username_(username), - auth_token_(auth_token), + config_(config), capturer_(capturer), encoder_(encoder), executor_(executor), @@ -83,7 +82,7 @@ void ChromotingHost::RegisterHost() { // Connect to the talk network with a JingleClient. jingle_client_ = new JingleClient(&network_thread_); - jingle_client_->Init(username_, auth_token_, + jingle_client_->Init(config_->xmpp_login(), config_->xmpp_auth_token(), kChromotingTokenServiceName, this); } @@ -186,7 +185,7 @@ void ChromotingHost::OnStateChange(JingleClient* jingle_client, // Start heartbeating after we connected heartbeat_sender_ = new HeartbeatSender(); // TODO(sergeyu): where do we get host id? - heartbeat_sender_->Start(jingle_client_.get(), "HostID"); + heartbeat_sender_->Start(config_, jingle_client_.get()); } else if (state == JingleClient::CLOSED) { LOG(INFO) << "Host disconnected from talk network." << std::endl; heartbeat_sender_ = NULL; diff --git a/remoting/host/chromoting_host.h b/remoting/host/chromoting_host.h index 463d03c..6b00b2e 100644 --- a/remoting/host/chromoting_host.h +++ b/remoting/host/chromoting_host.h @@ -23,6 +23,8 @@ class WaitableEvent; namespace remoting { +class HostConfig; + // A class to implement the functionality of a host process. // // Here's the work flow of this class: @@ -52,9 +54,8 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, public ClientConnection::EventHandler, public JingleClient::Callback { public: - ChromotingHost(const std::string& username, const std::string& auth_token, - Capturer* capturer, Encoder* encoder, EventExecutor* executor, - base::WaitableEvent* host_done); + ChromotingHost(HostConfig* config, Capturer* capturer, Encoder* encoder, + EventExecutor* executor, base::WaitableEvent* host_done); virtual ~ChromotingHost(); // Run the host porcess. This method returns only after the message loop @@ -108,8 +109,7 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, // A thread that hosts encode operations. base::Thread encode_thread_; - std::string username_; - std::string auth_token_; + scoped_refptr<HostConfig> config_; // Capturer to be used by SessionManager. Once the SessionManager is // constructed this is set to NULL. diff --git a/remoting/host/heartbeat_sender.cc b/remoting/host/heartbeat_sender.cc index 10fb3aa..4ce45b6 100644 --- a/remoting/host/heartbeat_sender.cc +++ b/remoting/host/heartbeat_sender.cc @@ -7,6 +7,7 @@ #include "base/logging.h" #include "base/message_loop.h" #include "remoting/base/constants.h" +#include "remoting/host/host_config.h" #include "remoting/jingle_glue/iq_request.h" #include "remoting/jingle_glue/jingle_client.h" #include "remoting/jingle_glue/jingle_thread.h" @@ -28,15 +29,14 @@ HeartbeatSender::HeartbeatSender() : started_(false) { } -void HeartbeatSender::Start(JingleClient* jingle_client, - const std::string& host_id) { +void HeartbeatSender::Start(HostConfig* config, JingleClient* jingle_client) { DCHECK(jingle_client); DCHECK(!started_); started_ = true; jingle_client_ = jingle_client; - host_id_ = host_id; + config_ = config; jingle_client_->message_loop()->PostTask( FROM_HERE, NewRunnableMethod(this, &HeartbeatSender::DoStart)); @@ -58,7 +58,7 @@ void HeartbeatSender::DoSendStanza() { LOG(INFO) << "Sending heartbeat stanza to " << kChromotingBotJid; buzz::XmlElement* stanza = new buzz::XmlElement(kHeartbeatQuery); - stanza->AddAttr(kHostIdAttr, host_id_); + stanza->AddAttr(kHostIdAttr, config_->host_id()); request_->SendIq(buzz::STR_SET, kChromotingBotJid, stanza); // Schedule next heartbeat. diff --git a/remoting/host/heartbeat_sender.h b/remoting/host/heartbeat_sender.h index 6521654..f11d21d 100644 --- a/remoting/host/heartbeat_sender.h +++ b/remoting/host/heartbeat_sender.h @@ -15,6 +15,7 @@ namespace remoting { class IqRequest; class JingleClient; +class HostConfig; // HeartbeatSender periodically sends hertbeats to the chromoting bot. // TODO(sergeyu): Write unittest for this class. @@ -23,7 +24,7 @@ class HeartbeatSender : public base::RefCountedThreadSafe<HeartbeatSender> { HeartbeatSender(); // Starts heart-beating for |jingle_client|. - void Start(JingleClient* jingle_client, const std::string& host_id); + void Start(HostConfig* config, JingleClient* jingle_client); private: void DoStart(); @@ -32,8 +33,8 @@ class HeartbeatSender : public base::RefCountedThreadSafe<HeartbeatSender> { void ProcessResponse(const buzz::XmlElement* response); bool started_; + scoped_refptr<HostConfig> config_; JingleClient* jingle_client_; - std::string host_id_; scoped_ptr<IqRequest> request_; }; diff --git a/remoting/host/host_config.h b/remoting/host/host_config.h new file mode 100644 index 0000000..b0eb382 --- /dev/null +++ b/remoting/host/host_config.h @@ -0,0 +1,79 @@ +// 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 REMOTING_HOST_HOST_CONFIG_H_ +#define REMOTING_HOST_HOST_CONFIG_H_ + +#include <string> + +#include "base/ref_counted.h" + +namespace remoting { + +// HostConfig class implements container for all host settings. +class HostConfig : public base::RefCountedThreadSafe<HostConfig> { + public: + HostConfig() { } + + // Login used to authenticate in XMPP network. + const std::string& xmpp_login() const { + return xmpp_login_; + } + void set_xmpp_login(const std::string& xmpp_login) { + xmpp_login_ = xmpp_login; + } + + // Auth token used to authenticate in XMPP network. + const std::string& xmpp_auth_token() const { + return xmpp_auth_token_; + } + void set_xmpp_auth_token(const std::string& xmpp_auth_token) { + xmpp_auth_token_ = xmpp_auth_token; + } + + // Unique identifier of the host used to register the host in directory. + // Normally a random UUID. + const std::string& host_id() const { + return host_id_; + } + void set_host_id(const std::string& host_id) { + host_id_ = host_id; + } + + // Public key used by the host for authentication. + // TODO(sergeyu): Do we need to use other type to store public key? E.g. + // DataBuffer? Revisit this when public key generation is implemented. + const std::string& public_key() const { + return public_key_; + } + void set_public_key(const std::string& public_key) { + public_key_ = public_key; + } + + // TODO(sergeyu): Add a property for private key. + + private: + std::string xmpp_login_; + std::string xmpp_auth_token_; + std::string host_id_; + std::string public_key_; + + DISALLOW_COPY_AND_ASSIGN(HostConfig); +}; + +// Interface for host configuration storage provider. +class HostConfigStorage { + // Load() and Save() are used to load/save settings to/from permanent + // storage. For example FileHostConfig stores all settings in a file. + // Simularly RegistryHostConfig stores settings in windows registry. + // Both methods return false if operation has failed, true otherwise. + virtual bool Load(HostConfig* config) = 0; + virtual bool Save(const HostConfig& config) = 0; + + DISALLOW_COPY_AND_ASSIGN(HostConfigStorage); +}; + +} // namespace remoting + +#endif // REMOTING_HOST_HOST_CONFIG_H_ diff --git a/remoting/host/simple_host_process.cc b/remoting/host/simple_host_process.cc index d32547f..86890f7 100644 --- a/remoting/host/simple_host_process.cc +++ b/remoting/host/simple_host_process.cc @@ -25,6 +25,7 @@ #include "base/waitable_event.h" #include "remoting/host/capturer_fake.h" #include "remoting/host/encoder_verbatim.h" +#include "remoting/host/host_config.h" #include "remoting/host/chromoting_host.h" #if defined(OS_WIN) @@ -102,15 +103,21 @@ int main(int argc, char** argv) { capturer.reset(new remoting::CapturerFake()); } + // TODO(sergeyu): Implement HostConfigStorage and use it here to load + // settings. + scoped_refptr<remoting::HostConfig> config(new remoting::HostConfig()); + config->set_xmpp_login(username); + config->set_xmpp_auth_token(auth_token); + config->set_host_id("foo"); + // Construct a chromoting host with username and auth_token. - // TODO(hclam): Allow the host to load saved credentials. base::WaitableEvent host_done(false, false); - scoped_refptr<remoting::ChromotingHost> host - = new remoting::ChromotingHost(username, auth_token, - capturer.release(), - encoder.release(), - executor.release(), - &host_done); + scoped_refptr<remoting::ChromotingHost> host = + new remoting::ChromotingHost(config, + capturer.release(), + encoder.release(), + executor.release(), + &host_done); host->Run(); host_done.Wait(); return 0; diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index 49bab0b..101680f 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -188,6 +188,7 @@ 'host/session_manager.h', 'host/heartbeat_sender.cc', 'host/heartbeat_sender.h', + 'host/host_config.h', ], 'conditions': [ ['OS=="win"', { |