Commit 1c085a63 authored by ajwong@chromium.org's avatar ajwong@chromium.org

Change ClientConfig to be a struct since it's just a dumb data carrier.

Also, the old method of passing around a pointer was not safe due to
object lifetime issues.

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53851 0039d316-1c4b-4281-b951-d872f2087c98
parent 9e7fbfea
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "base/message_loop.h" #include "base/message_loop.h"
#include "remoting/client/chromoting_view.h" #include "remoting/client/chromoting_view.h"
#include "remoting/client/client_config.h"
#include "remoting/client/client_context.h" #include "remoting/client/client_context.h"
#include "remoting/client/host_connection.h" #include "remoting/client/host_connection.h"
#include "remoting/client/input_handler.h" #include "remoting/client/input_handler.h"
...@@ -17,7 +16,7 @@ static const uint32 kFailedColor = 0xffcc00ff; ...@@ -17,7 +16,7 @@ static const uint32 kFailedColor = 0xffcc00ff;
namespace remoting { namespace remoting {
ChromotingClient::ChromotingClient(ClientConfig* config, ChromotingClient::ChromotingClient(const ClientConfig& config,
ClientContext* context, ClientContext* context,
HostConnection* connection, HostConnection* connection,
ChromotingView* view, ChromotingView* view,
......
...@@ -9,20 +9,20 @@ ...@@ -9,20 +9,20 @@
#include "base/task.h" #include "base/task.h"
#include "remoting/client/host_connection.h" #include "remoting/client/host_connection.h"
#include "remoting/client/client_config.h"
class MessageLoop; class MessageLoop;
namespace remoting { namespace remoting {
class ChromotingView; class ChromotingView;
class ClientConfig;
class ClientContext; class ClientContext;
class InputHandler; class InputHandler;
class ChromotingClient : public HostConnection::HostEventCallback { class ChromotingClient : public HostConnection::HostEventCallback {
public: public:
// Objects passed in are not owned by this class. // Objects passed in are not owned by this class.
ChromotingClient(ClientConfig* config, ChromotingClient(const ClientConfig& config,
ClientContext* context, ClientContext* context,
HostConnection* connection, HostConnection* connection,
ChromotingView* view, ChromotingView* view,
...@@ -71,7 +71,7 @@ class ChromotingClient : public HostConnection::HostEventCallback { ...@@ -71,7 +71,7 @@ class ChromotingClient : public HostConnection::HostEventCallback {
void EndUpdate(HostMessage* msg); void EndUpdate(HostMessage* msg);
// The following are not owned by this class. // The following are not owned by this class.
ClientConfig* config_; ClientConfig config_;
ClientContext* context_; ClientContext* context_;
HostConnection* connection_; HostConnection* connection_;
ChromotingView* view_; ChromotingView* view_;
......
...@@ -11,24 +11,10 @@ ...@@ -11,24 +11,10 @@
namespace remoting { namespace remoting {
class ClientConfig { struct ClientConfig {
public: std::string host_jid;
ClientConfig() { } std::string username;
std::string auth_token;
const std::string host_jid() { return host_jid_; }
const std::string username() { return username_; }
const std::string auth_token() { return auth_token_; }
void set_host_jid(std::string val) { host_jid_ = val; }
void set_username(std::string val) { username_ = val; }
void set_auth_token(std::string val) { auth_token_ = val; }
private:
std::string host_jid_;
std::string username_;
std::string auth_token_;
DISALLOW_COPY_AND_ASSIGN(ClientConfig);
}; };
} // namespace remoting } // namespace remoting
......
...@@ -72,9 +72,9 @@ bool GetLoginInfoFromArgs(int argc, char** argv, ClientConfig* config) { ...@@ -72,9 +72,9 @@ bool GetLoginInfoFromArgs(int argc, char** argv, ClientConfig* config) {
return false; return false;
} }
config->set_host_jid(host_jid); config->host_jid = host_jid;
config->set_username(username); config->username = username;
config->set_auth_token(auth_token); config->auth_token = auth_token;
return true; return true;
} }
...@@ -110,9 +110,9 @@ bool GetLoginInfoFromUrlParams(const std::string& url, ClientConfig* config) { ...@@ -110,9 +110,9 @@ bool GetLoginInfoFromUrlParams(const std::string& url, ClientConfig* config) {
} }
std::string host_jid = parts[2].substr(pos + 1); std::string host_jid = parts[2].substr(pos + 1);
config->set_host_jid(host_jid); config->host_jid = host_jid;
config->set_username(username); config->username = username;
config->set_auth_token(auth_token); config->auth_token = auth_token;
return true; return true;
} }
......
...@@ -25,12 +25,11 @@ TEST_F(ClientUtilTest, GetLoginInfoFromUrlParams) { ...@@ -25,12 +25,11 @@ TEST_F(ClientUtilTest, GetLoginInfoFromUrlParams) {
std::string host_jid; std::string host_jid;
ClientConfig config; ClientConfig config;
ASSERT_TRUE( ASSERT_TRUE(GetLoginInfoFromUrlParams(url, &config));
GetLoginInfoFromUrlParams(url, &config));
EXPECT_EQ("auser", config.username()); EXPECT_EQ("auser", config.username);
EXPECT_EQ("someauth", config.auth_token()); EXPECT_EQ("someauth", config.auth_token);
EXPECT_EQ("ajid", config.host_jid()); EXPECT_EQ("ajid", config.host_jid);
} }
} // namespace remoting } // namespace remoting
...@@ -39,7 +39,7 @@ class HostConnection { ...@@ -39,7 +39,7 @@ class HostConnection {
virtual ~HostConnection() {} virtual ~HostConnection() {}
// TODO(ajwong): We need to generalize this API. // TODO(ajwong): We need to generalize this API.
virtual void Connect(ClientConfig* config, virtual void Connect(const ClientConfig& config,
HostEventCallback* event_callback) = 0; HostEventCallback* event_callback) = 0;
virtual void Disconnect() = 0; virtual void Disconnect() = 0;
......
...@@ -18,7 +18,7 @@ JingleHostConnection::JingleHostConnection(ClientContext* context) ...@@ -18,7 +18,7 @@ JingleHostConnection::JingleHostConnection(ClientContext* context)
JingleHostConnection::~JingleHostConnection() { JingleHostConnection::~JingleHostConnection() {
} }
void JingleHostConnection::Connect(ClientConfig* config, void JingleHostConnection::Connect(const ClientConfig& config,
HostEventCallback* event_callback) { HostEventCallback* event_callback) {
message_loop()->PostTask( message_loop()->PostTask(
FROM_HERE, FROM_HERE,
...@@ -106,16 +106,16 @@ MessageLoop* JingleHostConnection::message_loop() { ...@@ -106,16 +106,16 @@ MessageLoop* JingleHostConnection::message_loop() {
return context_->jingle_thread()->message_loop(); return context_->jingle_thread()->message_loop();
} }
void JingleHostConnection::DoConnect(ClientConfig* config, void JingleHostConnection::DoConnect(const ClientConfig& config,
HostEventCallback* event_callback) { HostEventCallback* event_callback) {
DCHECK_EQ(message_loop(), MessageLoop::current()); DCHECK_EQ(message_loop(), MessageLoop::current());
event_callback_ = event_callback; event_callback_ = event_callback;
jingle_client_ = new JingleClient(context_->jingle_thread()); jingle_client_ = new JingleClient(context_->jingle_thread());
jingle_client_->Init(config->username(), config->auth_token(), jingle_client_->Init(config.username, config.auth_token,
kChromotingTokenServiceName, this); kChromotingTokenServiceName, this);
jingle_channel_ = jingle_client_->Connect(config->host_jid(), this); jingle_channel_ = jingle_client_->Connect(config.host_jid, this);
} }
void JingleHostConnection::DoDisconnect() { void JingleHostConnection::DoDisconnect() {
......
...@@ -41,7 +41,7 @@ class JingleHostConnection : public HostConnection, ...@@ -41,7 +41,7 @@ class JingleHostConnection : public HostConnection,
explicit JingleHostConnection(ClientContext* context); explicit JingleHostConnection(ClientContext* context);
virtual ~JingleHostConnection(); virtual ~JingleHostConnection();
virtual void Connect(ClientConfig* config, virtual void Connect(const ClientConfig& config,
HostEventCallback* event_callback); HostEventCallback* event_callback);
virtual void Disconnect(); virtual void Disconnect();
...@@ -61,7 +61,7 @@ class JingleHostConnection : public HostConnection, ...@@ -61,7 +61,7 @@ class JingleHostConnection : public HostConnection,
private: private:
MessageLoop* message_loop(); MessageLoop* message_loop();
void DoConnect(ClientConfig* config, void DoConnect(const ClientConfig& config,
HostEventCallback* event_callback); HostEventCallback* event_callback);
void DoDisconnect(); void DoDisconnect();
......
...@@ -86,7 +86,7 @@ bool ChromotingPlugin::Init(uint32_t argc, ...@@ -86,7 +86,7 @@ bool ChromotingPlugin::Init(uint32_t argc,
host_connection_.reset(new JingleHostConnection(context_.get())); host_connection_.reset(new JingleHostConnection(context_.get()));
view_.reset(new PepperView(this)); view_.reset(new PepperView(this));
input_handler_.reset(new PepperInputHandler()); input_handler_.reset(new PepperInputHandler());
client_.reset(new ChromotingClient(&config, client_.reset(new ChromotingClient(config,
context_.get(), context_.get(),
host_connection_.get(), host_connection_.get(),
view_.get(), view_.get(),
......
...@@ -32,7 +32,7 @@ int main(int argc, char** argv) { ...@@ -32,7 +32,7 @@ int main(int argc, char** argv) {
remoting::JingleHostConnection connection(&context); remoting::JingleHostConnection connection(&context);
remoting::X11View view; remoting::X11View view;
remoting::X11InputHandler input_handler(&context, &view); remoting::X11InputHandler input_handler(&context, &view);
remoting::ChromotingClient client(&config, &context, &connection, &view, remoting::ChromotingClient client(config, &context, &connection, &view,
&input_handler, NewRunnableFunction(&ClientQuit, &ui_loop)); &input_handler, NewRunnableFunction(&ClientQuit, &ui_loop));
// Run the client on a new MessageLoop until // Run the client on a new MessageLoop until
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment