diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-07 19:20:06 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-07 19:20:06 +0000 |
commit | 30224c162fbe39aa325248d116e2f02427ac7c8c (patch) | |
tree | 5fdca261c47f1e86a764e2ce6f8a661ac076ff7d /remoting | |
parent | b5457c7d515524938eafd6f0040f5a9bca7ddbbe (diff) | |
download | chromium_src-30224c162fbe39aa325248d116e2f02427ac7c8c.zip chromium_src-30224c162fbe39aa325248d116e2f02427ac7c8c.tar.gz chromium_src-30224c162fbe39aa325248d116e2f02427ac7c8c.tar.bz2 |
Cleanup and simplify HostConfig and JsonHostConfig.
These classes were previously overdesigned. Simplifying them.
- Config doesn't need to be ref-counted.
- Save() is synchronous now.
- Config is NonThreadSafe now.
BUG=120950
Review URL: http://codereview.chromium.org/10007048
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131288 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/host/chromoting_host_unittest.cc | 3 | ||||
-rw-r--r-- | remoting/host/host_config.h | 14 | ||||
-rw-r--r-- | remoting/host/host_key_pair.cc | 4 | ||||
-rw-r--r-- | remoting/host/host_key_pair.h | 2 | ||||
-rw-r--r-- | remoting/host/host_key_pair_unittest.cc | 14 | ||||
-rw-r--r-- | remoting/host/in_memory_host_config.cc | 22 | ||||
-rw-r--r-- | remoting/host/in_memory_host_config.h | 19 | ||||
-rw-r--r-- | remoting/host/json_host_config.cc | 27 | ||||
-rw-r--r-- | remoting/host/json_host_config.h | 12 | ||||
-rw-r--r-- | remoting/host/json_host_config_unittest.cc | 60 | ||||
-rw-r--r-- | remoting/host/plugin/daemon_controller_mac.cc | 25 | ||||
-rw-r--r-- | remoting/host/remoting_me2me_host.cc | 28 | ||||
-rw-r--r-- | remoting/host/simple_host_process.cc | 17 |
13 files changed, 109 insertions, 138 deletions
diff --git a/remoting/host/chromoting_host_unittest.cc b/remoting/host/chromoting_host_unittest.cc index 13d80b1..c17a9ce 100644 --- a/remoting/host/chromoting_host_unittest.cc +++ b/remoting/host/chromoting_host_unittest.cc @@ -10,7 +10,6 @@ #include "remoting/host/chromoting_host.h" #include "remoting/host/chromoting_host_context.h" #include "remoting/host/host_mock_objects.h" -#include "remoting/host/in_memory_host_config.h" #include "remoting/host/it2me_host_user_interface.h" #include "remoting/proto/video.pb.h" #include "remoting/protocol/protocol_mock_objects.h" @@ -70,7 +69,6 @@ class ChromotingHostTest : public testing::Test { virtual void SetUp() OVERRIDE { message_loop_proxy_ = base::MessageLoopProxy::current(); - config_ = new InMemoryHostConfig(); ON_CALL(context_, main_message_loop()) .WillByDefault(Return(&message_loop_)); ON_CALL(context_, encode_message_loop()) @@ -233,7 +231,6 @@ class ChromotingHostTest : public testing::Test { scoped_ptr<DesktopEnvironment> desktop_environment_; scoped_ptr<It2MeHostUserInterface> it2me_host_user_interface_; scoped_refptr<ChromotingHost> host_; - scoped_refptr<InMemoryHostConfig> config_; MockChromotingHostContext context_; MockConnectionToClient* connection_; scoped_ptr<MockConnectionToClient> owned_connection_; diff --git a/remoting/host/host_config.h b/remoting/host/host_config.h index 4c7ed77..6124598 100644 --- a/remoting/host/host_config.h +++ b/remoting/host/host_config.h @@ -7,7 +7,7 @@ #include <string> -#include "base/memory/ref_counted.h" +#include "base/basictypes.h" namespace remoting { @@ -34,14 +34,16 @@ extern const char kHostSecretHashConfigPath[]; extern const char kPrivateKeyConfigPath[]; // HostConfig interace provides read-only access to host configuration. -class HostConfig : public base::RefCountedThreadSafe<HostConfig> { +class HostConfig { public: HostConfig() {} virtual ~HostConfig() {} - virtual bool GetString(const std::string& path, std::string* out_value) = 0; - virtual bool GetBoolean(const std::string& path, bool* out_value) = 0; + virtual bool GetString(const std::string& path, + std::string* out_value) const = 0; + virtual bool GetBoolean(const std::string& path, bool* out_value) const = 0; + private: DISALLOW_COPY_AND_ASSIGN(HostConfig); }; @@ -56,8 +58,8 @@ class MutableHostConfig : public HostConfig { const std::string& in_value) = 0; virtual void SetBoolean(const std::string& path, bool in_value) = 0; - // Save's changes. - virtual void Save() = 0; + // Saves changes. + virtual bool Save() = 0; DISALLOW_COPY_AND_ASSIGN(MutableHostConfig); }; diff --git a/remoting/host/host_key_pair.cc b/remoting/host/host_key_pair.cc index 7bf1e84..704f8f8 100644 --- a/remoting/host/host_key_pair.cc +++ b/remoting/host/host_key_pair.cc @@ -44,9 +44,9 @@ bool HostKeyPair::LoadFromString(const std::string& key_base64) { return true; } -bool HostKeyPair::Load(HostConfig* host_config) { +bool HostKeyPair::Load(const HostConfig& host_config) { std::string key_base64; - if (!host_config->GetString(kPrivateKeyConfigPath, &key_base64)) { + if (!host_config.GetString(kPrivateKeyConfigPath, &key_base64)) { LOG(ERROR) << "Private key wasn't found in the config file."; return false; } diff --git a/remoting/host/host_key_pair.h b/remoting/host/host_key_pair.h index a2b9d5d..8af41d9 100644 --- a/remoting/host/host_key_pair.h +++ b/remoting/host/host_key_pair.h @@ -26,7 +26,7 @@ class HostKeyPair { void Generate(); bool LoadFromString(const std::string& key_base64); - bool Load(HostConfig* host_config); + bool Load(const HostConfig& host_config); void Save(MutableHostConfig* host_config); crypto::RSAPrivateKey* private_key() { return key_.get(); } diff --git a/remoting/host/host_key_pair_unittest.cc b/remoting/host/host_key_pair_unittest.cc index ec4fc38..06aae2b 100644 --- a/remoting/host/host_key_pair_unittest.cc +++ b/remoting/host/host_key_pair_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -27,21 +27,19 @@ const char kExpectedSignature[] = "gDcvyW8QiGuKLopGj/4c5CQT4yE8JjsyU3Qqo2ZPK4neJYQhOmAlg+Q5dAPLpzWMj5HQyOVHJaSXZ" "Y8vl/LiKvbdofYLeYNVKAE4q5mfpQMrsysPYpbxBV60AhFyrvtC040MFGcflKQRZNiZwMXVb7DclC" "BPgvK7rI5Y0ERtVm+yNmH7vCivfyAnDUYA=="; -} - +} // namespace class HostKeyPairTest : public testing::Test { protected: virtual void SetUp() { ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); FilePath config_path = test_dir_.path().AppendASCII("test_config.json"); - config_ = new JsonHostConfig( - config_path, base::MessageLoopProxy::current()); + config_.reset(new JsonHostConfig(config_path)); } MessageLoop message_loop_; ScopedTempDir test_dir_; - scoped_refptr<JsonHostConfig> config_; + scoped_ptr<JsonHostConfig> config_; }; TEST_F(HostKeyPairTest, SaveLoad) { @@ -49,12 +47,12 @@ TEST_F(HostKeyPairTest, SaveLoad) { // generate the same signature with both keys. HostKeyPair exported_key; exported_key.LoadFromString(kTestHostKeyPair); - exported_key.Save(config_); + exported_key.Save(config_.get()); message_loop_.RunAllPending(); HostKeyPair imported_key; - imported_key.Load(config_); + imported_key.Load(*config_); ASSERT_EQ(exported_key.GetSignature(kTestMessage), imported_key.GetSignature(kTestMessage)); diff --git a/remoting/host/in_memory_host_config.cc b/remoting/host/in_memory_host_config.cc index 4df3ada..5e95127 100644 --- a/remoting/host/in_memory_host_config.cc +++ b/remoting/host/in_memory_host_config.cc @@ -1,9 +1,10 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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 "remoting/host/in_memory_host_config.h" +#include "base/logging.h" #include "base/values.h" namespace remoting { @@ -15,28 +16,31 @@ InMemoryHostConfig::InMemoryHostConfig() InMemoryHostConfig::~InMemoryHostConfig() {} bool InMemoryHostConfig::GetString(const std::string& path, - std::string* out_value) { - base::AutoLock auto_lock(lock_); + std::string* out_value) const { + DCHECK(CalledOnValidThread()); return values_->GetString(path, out_value); } -bool InMemoryHostConfig::GetBoolean(const std::string& path, bool* out_value) { - base::AutoLock auto_lock(lock_); +bool InMemoryHostConfig::GetBoolean(const std::string& path, + bool* out_value) const { + DCHECK(CalledOnValidThread()); return values_->GetBoolean(path, out_value); } -void InMemoryHostConfig::Save() { - // Save is NOP for in-memory host config. +bool InMemoryHostConfig::Save() { + // Saving in-memory host config is not supported. + NOTREACHED(); + return false; } void InMemoryHostConfig::SetString(const std::string& path, const std::string& in_value) { - base::AutoLock auto_lock(lock_); + DCHECK(CalledOnValidThread()); values_->SetString(path, in_value); } void InMemoryHostConfig::SetBoolean(const std::string& path, bool in_value) { - base::AutoLock auto_lock(lock_); + DCHECK(CalledOnValidThread()); values_->SetBoolean(path, in_value); } diff --git a/remoting/host/in_memory_host_config.h b/remoting/host/in_memory_host_config.h index 4043e83..82b9f6f 100644 --- a/remoting/host/in_memory_host_config.h +++ b/remoting/host/in_memory_host_config.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -7,37 +7,36 @@ #include <string> -#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" -#include "base/synchronization/lock.h" +#include "base/threading/non_thread_safe.h" #include "remoting/host/host_config.h" namespace base { class DictionaryValue; -} +} // namespace base namespace remoting { // In-memory host config. Used by unittests. -class InMemoryHostConfig : public MutableHostConfig { +class InMemoryHostConfig : public MutableHostConfig, + public base::NonThreadSafe { public: InMemoryHostConfig(); virtual ~InMemoryHostConfig(); // MutableHostConfig interface. virtual bool GetString(const std::string& path, - std::string* out_value) OVERRIDE; - virtual bool GetBoolean(const std::string& path, bool* out_value) OVERRIDE; + std::string* out_value) const OVERRIDE; + virtual bool GetBoolean(const std::string& path, + bool* out_value) const OVERRIDE; virtual void SetString(const std::string& path, const std::string& in_value) OVERRIDE; virtual void SetBoolean(const std::string& path, bool in_value) OVERRIDE; - virtual void Save() OVERRIDE; + virtual bool Save() OVERRIDE; protected: - // |lock_| must be locked whenever |values_| is used. - base::Lock lock_; scoped_ptr<base::DictionaryValue> values_; private: diff --git a/remoting/host/json_host_config.cc b/remoting/host/json_host_config.cc index 4e8580c..66e518c2 100644 --- a/remoting/host/json_host_config.cc +++ b/remoting/host/json_host_config.cc @@ -9,52 +9,49 @@ #include "base/json/json_reader.h" #include "base/json/json_writer.h" #include "base/location.h" -#include "base/message_loop_proxy.h" -#include "base/synchronization/lock.h" +#include "base/memory/scoped_ptr.h" #include "base/values.h" namespace remoting { -JsonHostConfig::JsonHostConfig( - const FilePath& filename, - base::MessageLoopProxy* file_message_loop_proxy) - : filename_(filename), - message_loop_proxy_(file_message_loop_proxy) { +JsonHostConfig::JsonHostConfig(const FilePath& filename) + : filename_(filename) { } JsonHostConfig::~JsonHostConfig() {} bool JsonHostConfig::Read() { + DCHECK(CalledOnValidThread()); + // TODO(sergeyu): Implement better error handling here. std::string file_content; if (!file_util::ReadFileToString(filename_, &file_content)) { + LOG(WARNING) << "Failed to read " << filename_.value(); return false; } scoped_ptr<Value> value(base::JSONReader::Read(file_content, true)); if (value.get() == NULL || !value->IsType(Value::TYPE_DICTIONARY)) { + LOG(WARNING) << "Failed to parse " << filename_.value(); return false; } DictionaryValue* dictionary = static_cast<DictionaryValue*>(value.release()); - base::AutoLock auto_lock(lock_); values_.reset(dictionary); return true; } -void JsonHostConfig::Save() { - message_loop_proxy_->PostTask( - FROM_HERE, base::Bind(&JsonHostConfig::DoWrite, this)); -} +bool JsonHostConfig::Save() { + DCHECK(CalledOnValidThread()); -void JsonHostConfig::DoWrite() { std::string file_content; - base::AutoLock auto_lock(lock_); base::JSONWriter::WriteWithOptions(values_.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &file_content); // TODO(sergeyu): Move ImportantFileWriter to base and use it here. - file_util::WriteFile(filename_, file_content.c_str(), file_content.size()); + int result = file_util::WriteFile(filename_, file_content.c_str(), + file_content.size()); + return result == static_cast<int>(file_content.size()); } } // namespace remoting diff --git a/remoting/host/json_host_config.h b/remoting/host/json_host_config.h index e04238c..f4db06d 100644 --- a/remoting/host/json_host_config.h +++ b/remoting/host/json_host_config.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -8,8 +8,6 @@ #include <string> #include "base/file_path.h" -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" #include "remoting/host/in_memory_host_config.h" namespace base { @@ -21,20 +19,16 @@ namespace remoting { // JsonHostConfig implements MutableHostConfig for JSON file. class JsonHostConfig : public InMemoryHostConfig { public: - JsonHostConfig(const FilePath& pref_filename, - base::MessageLoopProxy* file_message_loop_proxy); + JsonHostConfig(const FilePath& filename); virtual ~JsonHostConfig(); virtual bool Read(); // MutableHostConfig interface. - virtual void Save() OVERRIDE; + virtual bool Save() OVERRIDE; private: - void DoWrite(); - FilePath filename_; - scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; DISALLOW_COPY_AND_ASSIGN(JsonHostConfig); }; diff --git a/remoting/host/json_host_config_unittest.cc b/remoting/host/json_host_config_unittest.cc index 3184f75..dd318ae 100644 --- a/remoting/host/json_host_config_unittest.cc +++ b/remoting/host/json_host_config_unittest.cc @@ -1,11 +1,9 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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 "base/file_util.h" #include "base/memory/ref_counted.h" -#include "base/message_loop.h" -#include "base/message_loop_proxy.h" #include "base/path_service.h" #include "base/scoped_temp_dir.h" #include "remoting/host/json_host_config.h" @@ -26,51 +24,42 @@ const char* kTestConfig = class JsonHostConfigTest : public testing::Test { protected: - virtual void SetUp() { - message_loop_proxy_ = base::MessageLoopProxy::current(); - } - static void WriteTestFile(const FilePath& filename) { file_util::WriteFile(filename, kTestConfig, std::strlen(kTestConfig)); } // The temporary directory used to contain the test operations. ScopedTempDir test_dir_; - // A message loop that we can use as the file thread message loop. - MessageLoop message_loop_; - scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; }; TEST_F(JsonHostConfigTest, InvalidFile) { ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); FilePath non_existent_file = test_dir_.path().AppendASCII("non_existent.json"); - scoped_refptr<JsonHostConfig> target( - new JsonHostConfig(non_existent_file, message_loop_proxy_.get())); - EXPECT_FALSE(target->Read()); + JsonHostConfig target(non_existent_file); + EXPECT_FALSE(target.Read()); } TEST_F(JsonHostConfigTest, Read) { ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); FilePath test_file = test_dir_.path().AppendASCII("read.json"); WriteTestFile(test_file); - scoped_refptr<JsonHostConfig> target( - new JsonHostConfig(test_file, message_loop_proxy_.get())); - ASSERT_TRUE(target->Read()); + JsonHostConfig target(test_file); + ASSERT_TRUE(target.Read()); std::string value; - EXPECT_TRUE(target->GetString(kXmppLoginConfigPath, &value)); + EXPECT_TRUE(target.GetString(kXmppLoginConfigPath, &value)); EXPECT_EQ("test@gmail.com", value); - EXPECT_TRUE(target->GetString(kXmppAuthTokenConfigPath, &value)); + EXPECT_TRUE(target.GetString(kXmppAuthTokenConfigPath, &value)); EXPECT_EQ("TEST_AUTH_TOKEN", value); - EXPECT_TRUE(target->GetString(kHostIdConfigPath, &value)); + EXPECT_TRUE(target.GetString(kHostIdConfigPath, &value)); EXPECT_EQ("TEST_HOST_ID", value); - EXPECT_TRUE(target->GetString(kHostNameConfigPath, &value)); + EXPECT_TRUE(target.GetString(kHostNameConfigPath, &value)); EXPECT_EQ("TEST_MACHINE_NAME", value); - EXPECT_TRUE(target->GetString(kPrivateKeyConfigPath, &value)); + EXPECT_TRUE(target.GetString(kPrivateKeyConfigPath, &value)); EXPECT_EQ("TEST_PRIVATE_KEY", value); - EXPECT_FALSE(target->GetString("non_existent_value", &value)); + EXPECT_FALSE(target.GetString("non_existent_value", &value)); } TEST_F(JsonHostConfigTest, Write) { @@ -78,32 +67,27 @@ TEST_F(JsonHostConfigTest, Write) { FilePath test_file = test_dir_.path().AppendASCII("write.json"); WriteTestFile(test_file); - scoped_refptr<JsonHostConfig> target( - new JsonHostConfig(test_file, message_loop_proxy_.get())); - ASSERT_TRUE(target->Read()); + JsonHostConfig target(test_file); + ASSERT_TRUE(target.Read()); std::string new_auth_token_value = "NEW_AUTH_TOKEN"; - target->SetString(kXmppAuthTokenConfigPath, new_auth_token_value); - target->Save(); - - message_loop_.RunAllPending(); + target.SetString(kXmppAuthTokenConfigPath, new_auth_token_value); + ASSERT_TRUE(target.Save()); // Now read the file again and check that the value has been written. - scoped_refptr<JsonHostConfig> reader( - new JsonHostConfig(test_file, message_loop_proxy_.get())); - - ASSERT_TRUE(reader->Read()); + JsonHostConfig reader(test_file); + ASSERT_TRUE(reader.Read()); std::string value; - EXPECT_TRUE(reader->GetString(kXmppLoginConfigPath, &value)); + EXPECT_TRUE(reader.GetString(kXmppLoginConfigPath, &value)); EXPECT_EQ("test@gmail.com", value); - EXPECT_TRUE(reader->GetString(kXmppAuthTokenConfigPath, &value)); + EXPECT_TRUE(reader.GetString(kXmppAuthTokenConfigPath, &value)); EXPECT_EQ(new_auth_token_value, value); - EXPECT_TRUE(reader->GetString(kHostIdConfigPath, &value)); + EXPECT_TRUE(reader.GetString(kHostIdConfigPath, &value)); EXPECT_EQ("TEST_HOST_ID", value); - EXPECT_TRUE(reader->GetString(kHostNameConfigPath, &value)); + EXPECT_TRUE(reader.GetString(kHostNameConfigPath, &value)); EXPECT_EQ("TEST_MACHINE_NAME", value); - EXPECT_TRUE(reader->GetString(kPrivateKeyConfigPath, &value)); + EXPECT_TRUE(reader.GetString(kPrivateKeyConfigPath, &value)); EXPECT_EQ("TEST_PRIVATE_KEY", value); } diff --git a/remoting/host/plugin/daemon_controller_mac.cc b/remoting/host/plugin/daemon_controller_mac.cc index 5c2b9f9..be9d66b 100644 --- a/remoting/host/plugin/daemon_controller_mac.cc +++ b/remoting/host/plugin/daemon_controller_mac.cc @@ -136,19 +136,18 @@ void DaemonControllerMac::Stop(const CompletionCallback& done_callback) { } void DaemonControllerMac::DoGetConfig(const GetConfigCallback& callback) { - JsonHostConfig host_config(FilePath(kHostConfigFile), - base::MessageLoopProxy::current()); - host_config.Read(); - - scoped_ptr<base::DictionaryValue> config(new base::DictionaryValue()); - - const char* key = "host_id"; - std::string value; - if (host_config.GetString(key, &value)) - config.get()->SetString(key, value); - key = "xmpp_login"; - if (host_config.GetString(key, &value)) - config.get()->SetString(key, value); + FilePath config_path(kHostConfigFile); + JsonHostConfig host_config(config_path); + scoped_ptr<base::DictionaryValue> config; + + if (host_config.Read()) { + config.reset(new base::DictionaryValue()); + std::string value; + if (host_config.GetString(kHostIdConfigPath, &value)) + config.get()->SetString(kHostIdConfigPath, value); + if (host_config.GetString(kXmppLoginConfigPath, &value)) + config.get()->SetString(kXmppLoginConfigPath, value); + } callback.Run(config.Pass()); } diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc index adb79f9..885f7a0 100644 --- a/remoting/host/remoting_me2me_host.cc +++ b/remoting/host/remoting_me2me_host.cc @@ -155,15 +155,13 @@ class HostProcess : public OAuthClient::Delegate { // Read Host config from disk, returning true if successful. bool LoadConfig(base::MessageLoopProxy* io_message_loop, bool* tokens_pending) { - scoped_refptr<JsonHostConfig> host_config = - new JsonHostConfig(host_config_path_, io_message_loop); - scoped_refptr<JsonHostConfig> auth_config = - new JsonHostConfig(auth_config_path_, io_message_loop); + JsonHostConfig host_config(host_config_path_); + JsonHostConfig auth_config(auth_config_path_); FilePath failed_path; - if (!host_config->Read()) { + if (!host_config.Read()) { failed_path = host_config_path_; - } else if (!auth_config->Read()) { + } else if (!auth_config.Read()) { failed_path = auth_config_path_; } if (!failed_path.empty()) { @@ -171,7 +169,7 @@ class HostProcess : public OAuthClient::Delegate { return false; } - if (!host_config->GetString(kHostIdConfigPath, &host_id_)) { + if (!host_config.GetString(kHostIdConfigPath, &host_id_)) { LOG(ERROR) << "host_id is not defined in the config."; return false; } @@ -181,8 +179,8 @@ class HostProcess : public OAuthClient::Delegate { } std::string host_secret_hash_string; - if (!host_config->GetString(kHostSecretHashConfigPath, - &host_secret_hash_string)) { + if (!host_config.GetString(kHostSecretHashConfigPath, + &host_secret_hash_string)) { host_secret_hash_string = "plain:"; } @@ -192,10 +190,10 @@ class HostProcess : public OAuthClient::Delegate { } // Use an XMPP connection to the Talk network for session signalling. - if (!auth_config->GetString(kXmppLoginConfigPath, &xmpp_login_) || - !(auth_config->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token_) || - auth_config->GetString(kOAuthRefreshTokenConfigPath, - &oauth_refresh_token_))) { + if (!auth_config.GetString(kXmppLoginConfigPath, &xmpp_login_) || + !(auth_config.GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token_) || + auth_config.GetString(kOAuthRefreshTokenConfigPath, + &oauth_refresh_token_))) { LOG(ERROR) << "XMPP credentials are not defined in the config."; return false; } @@ -204,8 +202,8 @@ class HostProcess : public OAuthClient::Delegate { if (*tokens_pending) { xmpp_auth_token_ = ""; // This will be set to the access token later. xmpp_auth_service_ = "oauth2"; - } else if (!auth_config->GetString(kXmppAuthServiceConfigPath, - &xmpp_auth_service_)) { + } else if (!auth_config.GetString(kXmppAuthServiceConfigPath, + &xmpp_auth_service_)) { // For the me2me host, we default to ClientLogin token for chromiumsync // because earlier versions of the host had no HTTP stack with which to // request an OAuth2 access token. diff --git a/remoting/host/simple_host_process.cc b/remoting/host/simple_host_process.cc index 2818eea..f37d7a9 100644 --- a/remoting/host/simple_host_process.cc +++ b/remoting/host/simple_host_process.cc @@ -104,15 +104,14 @@ class SimpleHost { int Run() { FilePath config_path = GetConfigPath(); - scoped_refptr<JsonHostConfig> config = new JsonHostConfig( - config_path, file_io_thread_.message_loop_proxy()); - if (!config->Read()) { + JsonHostConfig config(config_path); + if (!config.Read()) { LOG(ERROR) << "Failed to read configuration file " << config_path.value(); return 1; } - if (!config->GetString(kHostIdConfigPath, &host_id_)) { + if (!config.GetString(kHostIdConfigPath, &host_id_)) { LOG(ERROR) << "host_id is not defined in the config."; return 1; } @@ -122,8 +121,8 @@ class SimpleHost { } std::string host_secret_hash_string; - if (!config->GetString(kHostSecretHashConfigPath, - &host_secret_hash_string)) { + if (!config.GetString(kHostSecretHashConfigPath, + &host_secret_hash_string)) { host_secret_hash_string = "plain:"; } @@ -133,12 +132,12 @@ class SimpleHost { } // Use an XMPP connection to the Talk network for session signalling. - if (!config->GetString(kXmppLoginConfigPath, &xmpp_login_) || - !config->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token_)) { + if (!config.GetString(kXmppLoginConfigPath, &xmpp_login_) || + !config.GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token_)) { LOG(ERROR) << "XMPP credentials are not defined in the config."; return 1; } - if (!config->GetString(kXmppAuthServiceConfigPath, &xmpp_auth_service_)) { + if (!config.GetString(kXmppAuthServiceConfigPath, &xmpp_auth_service_)) { // For the simple host, we assume we always use the ClientLogin token for // chromiumsync because we do not have an HTTP stack with which we can // easily request an OAuth2 access token even if we had a RefreshToken for |