summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-02 04:27:49 +0000
committeralexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-02 04:27:49 +0000
commit9cfb0c35a8ee5bb7f1ee22063e4b5d4bc2b62d3d (patch)
tree419e5567d6e33222e350438cc20809274a77d480
parent6efcdcd281eac224b621474f4a82bece49e94ba9 (diff)
downloadchromium_src-9cfb0c35a8ee5bb7f1ee22063e4b5d4bc2b62d3d.zip
chromium_src-9cfb0c35a8ee5bb7f1ee22063e4b5d4bc2b62d3d.tar.gz
chromium_src-9cfb0c35a8ee5bb7f1ee22063e4b5d4bc2b62d3d.tar.bz2
Moving host status events monitoring to a separate interface (HostStatusMonitor).
This CL unbinds the host status event observers from ChromotingHost. This is useful when, for instance, an observer resides in a different process where ChromotingHost is not available. Additionally, observers get HostStatusMonitor as a weak pointer, making sure that they do not need to worry about HostStatusMonitor's life time. BUG=178873 Review URL: https://chromiumcodereview.appspot.com/12386035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@185684 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--remoting/host/chromoting_host.cc5
-rw-r--r--remoting/host/chromoting_host.h16
-rw-r--r--remoting/host/curtaining_host_observer.cc11
-rw-r--r--remoting/host/curtaining_host_observer.h8
-rw-r--r--remoting/host/host_event_logger.h6
-rw-r--r--remoting/host/host_event_logger_posix.cc25
-rw-r--r--remoting/host/host_event_logger_win.cc23
-rw-r--r--remoting/host/host_status_monitor.h24
-rw-r--r--remoting/host/host_status_monitor_fake.h27
-rw-r--r--remoting/host/log_to_server.cc15
-rw-r--r--remoting/host/log_to_server.h8
-rw-r--r--remoting/host/log_to_server_unittest.cc10
-rw-r--r--remoting/host/plugin/host_script_object.cc7
-rw-r--r--remoting/host/remoting_me2me_host.cc11
-rw-r--r--remoting/host/resizing_host_observer.cc17
-rw-r--r--remoting/host/resizing_host_observer.h11
-rw-r--r--remoting/host/resizing_host_observer_unittest.cc12
-rw-r--r--remoting/remoting.gyp2
18 files changed, 158 insertions, 80 deletions
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc
index 848b926..68009d4 100644
--- a/remoting/host/chromoting_host.cc
+++ b/remoting/host/chromoting_host.cc
@@ -78,7 +78,8 @@ ChromotingHost::ChromotingHost(
protocol_config_(protocol::CandidateSessionConfig::CreateDefault()),
login_backoff_(&kDefaultBackoffPolicy),
authenticating_client_(false),
- reject_authenticating_client_(false) {
+ reject_authenticating_client_(false),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
DCHECK(signal_strategy);
DCHECK(network_task_runner_->BelongsToCurrentThread());
@@ -409,6 +410,8 @@ void ChromotingHost::ShutdownFinish() {
it->Run();
}
shutdown_tasks_.clear();
+
+ weak_factory_.InvalidateWeakPtrs();
}
} // namespace remoting
diff --git a/remoting/host/chromoting_host.h b/remoting/host/chromoting_host.h
index bfd4dca..d755744 100644
--- a/remoting/host/chromoting_host.h
+++ b/remoting/host/chromoting_host.h
@@ -10,11 +10,13 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/threading/thread.h"
#include "net/base/backoff_entry.h"
#include "remoting/host/client_session.h"
#include "remoting/host/host_key_pair.h"
+#include "remoting/host/host_status_monitor.h"
#include "remoting/host/host_status_observer.h"
#include "remoting/host/mouse_move_observer.h"
#include "remoting/protocol/authenticator.h"
@@ -62,6 +64,7 @@ class DesktopEnvironmentFactory;
class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
public ClientSession::EventHandler,
public protocol::SessionManager::Listener,
+ public HostStatusMonitor,
public MouseMoveObserver {
public:
// The caller must ensure that |signal_strategy| and
@@ -90,10 +93,9 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
// called after shutdown is completed.
void Shutdown(const base::Closure& shutdown_task);
- // Add/Remove |observer| to/from the list of status observers. Both
- // methods can be called on the network thread only.
- void AddStatusObserver(HostStatusObserver* observer);
- void RemoveStatusObserver(HostStatusObserver* observer);
+ // HostStatusMonitor interface.
+ virtual void AddStatusObserver(HostStatusObserver* observer) OVERRIDE;
+ virtual void RemoveStatusObserver(HostStatusObserver* observer) OVERRIDE;
// This method may be called only from
// HostStatusObserver::OnClientAuthenticated() to reject the new
@@ -151,6 +153,10 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
// clients that were not connected when this method is called.
void DisconnectAllClients();
+ base::WeakPtr<ChromotingHost> AsWeakPtr() {
+ return weak_factory_.GetWeakPtr();
+ }
+
private:
friend class base::RefCountedThreadSafe<ChromotingHost>;
friend class ChromotingHostTest;
@@ -211,6 +217,8 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
// The maximum duration of any session.
base::TimeDelta max_session_duration_;
+ base::WeakPtrFactory<ChromotingHost> weak_factory_;
+
DISALLOW_COPY_AND_ASSIGN(ChromotingHost);
};
diff --git a/remoting/host/curtaining_host_observer.cc b/remoting/host/curtaining_host_observer.cc
index 6eacabe..31bb411 100644
--- a/remoting/host/curtaining_host_observer.cc
+++ b/remoting/host/curtaining_host_observer.cc
@@ -6,18 +6,19 @@
#include "base/logging.h"
#include "remoting/host/curtain_mode.h"
-#include "remoting/host/chromoting_host.h"
+#include "remoting/host/host_status_monitor.h"
namespace remoting {
CurtainingHostObserver::CurtainingHostObserver(
- CurtainMode *curtain, scoped_refptr<ChromotingHost> host)
- : curtain_(curtain), host_(host) {
- host_->AddStatusObserver(this);
+ CurtainMode *curtain, base::WeakPtr<HostStatusMonitor> monitor)
+ : curtain_(curtain), monitor_(monitor) {
+ monitor_->AddStatusObserver(this);
}
CurtainingHostObserver::~CurtainingHostObserver() {
- host_->RemoveStatusObserver(this);
+ if (monitor_)
+ monitor_->RemoveStatusObserver(this);
curtain_->SetActivated(false);
}
diff --git a/remoting/host/curtaining_host_observer.h b/remoting/host/curtaining_host_observer.h
index a952344..20771f4 100644
--- a/remoting/host/curtaining_host_observer.h
+++ b/remoting/host/curtaining_host_observer.h
@@ -10,19 +10,19 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
-#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "remoting/host/host_status_observer.h"
namespace remoting {
class CurtainMode;
-class ChromotingHost;
+class HostStatusMonitor;
class CurtainingHostObserver : public HostStatusObserver {
public:
CurtainingHostObserver(CurtainMode *curtain,
- scoped_refptr<ChromotingHost> host);
+ base::WeakPtr<HostStatusMonitor> monitor);
virtual ~CurtainingHostObserver();
// Enables/disables curtaining when one or more clients are connected.
@@ -35,7 +35,7 @@ class CurtainingHostObserver : public HostStatusObserver {
private:
CurtainMode* curtain_;
- scoped_refptr<ChromotingHost> host_;
+ base::WeakPtr<HostStatusMonitor> monitor_;
std::set<std::string> active_clients_;
bool enable_curtaining_;
};
diff --git a/remoting/host/host_event_logger.h b/remoting/host/host_event_logger.h
index b039b3b..92dd81e 100644
--- a/remoting/host/host_event_logger.h
+++ b/remoting/host/host_event_logger.h
@@ -10,10 +10,11 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
namespace remoting {
-class ChromotingHost;
+class HostStatusMonitor;
class HostEventLogger {
public:
@@ -22,7 +23,8 @@ class HostEventLogger {
// Creates an event-logger that monitors host status changes and logs
// corresponding events to the OS-specific log (syslog/EventLog).
static scoped_ptr<HostEventLogger> Create(
- ChromotingHost* host, const std::string& application_name);
+ base::WeakPtr<HostStatusMonitor> monitor,
+ const std::string& application_name);
protected:
HostEventLogger() {}
diff --git a/remoting/host/host_event_logger_posix.cc b/remoting/host/host_event_logger_posix.cc
index fed6203..6cd7412 100644
--- a/remoting/host/host_event_logger_posix.cc
+++ b/remoting/host/host_event_logger_posix.cc
@@ -4,11 +4,11 @@
#include "remoting/host/host_event_logger.h"
-#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/stringprintf.h"
#include "net/base/ip_endpoint.h"
-#include "remoting/host/chromoting_host.h"
+#include "remoting/host/host_status_monitor.h"
#include "remoting/host/host_status_observer.h"
#include "remoting/protocol/transport.h"
@@ -23,7 +23,7 @@ namespace {
class HostEventLoggerPosix : public HostEventLogger, public HostStatusObserver {
public:
- HostEventLoggerPosix(ChromotingHost* host,
+ HostEventLoggerPosix(base::WeakPtr<HostStatusMonitor> monitor,
const std::string& application_name);
virtual ~HostEventLoggerPosix();
@@ -43,7 +43,7 @@ class HostEventLoggerPosix : public HostEventLogger, public HostStatusObserver {
private:
void Log(const std::string& message);
- scoped_refptr<ChromotingHost> host_;
+ base::WeakPtr<HostStatusMonitor> monitor_;
std::string application_name_;
DISALLOW_COPY_AND_ASSIGN(HostEventLoggerPosix);
@@ -51,16 +51,18 @@ class HostEventLoggerPosix : public HostEventLogger, public HostStatusObserver {
} //namespace
-HostEventLoggerPosix::HostEventLoggerPosix(ChromotingHost* host,
- const std::string& application_name)
- : host_(host),
+HostEventLoggerPosix::HostEventLoggerPosix(
+ base::WeakPtr<HostStatusMonitor> monitor,
+ const std::string& application_name)
+ : monitor_(monitor),
application_name_(application_name) {
openlog(application_name_.c_str(), 0, LOG_USER);
- host_->AddStatusObserver(this);
+ monitor_->AddStatusObserver(this);
}
HostEventLoggerPosix::~HostEventLoggerPosix() {
- host_->RemoveStatusObserver(this);
+ if (monitor_)
+ monitor_->RemoveStatusObserver(this);
closelog();
}
@@ -102,9 +104,10 @@ void HostEventLoggerPosix::Log(const std::string& message) {
// static
scoped_ptr<HostEventLogger> HostEventLogger::Create(
- ChromotingHost* host, const std::string& application_name) {
+ base::WeakPtr<HostStatusMonitor> monitor,
+ const std::string& application_name) {
return scoped_ptr<HostEventLogger>(
- new HostEventLoggerPosix(host, application_name));
+ new HostEventLoggerPosix(monitor, application_name));
}
} // namespace remoting
diff --git a/remoting/host/host_event_logger_win.cc b/remoting/host/host_event_logger_win.cc
index 7e13a40..a0a30c9 100644
--- a/remoting/host/host_event_logger_win.cc
+++ b/remoting/host/host_event_logger_win.cc
@@ -8,12 +8,12 @@
#include <string>
#include <vector>
-#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "net/base/ip_endpoint.h"
-#include "remoting/host/chromoting_host.h"
+#include "remoting/host/host_status_monitor.h"
#include "remoting/host/host_status_observer.h"
#include "remoting/protocol/transport.h"
@@ -25,7 +25,8 @@ namespace {
class HostEventLoggerWin : public HostEventLogger, public HostStatusObserver {
public:
- HostEventLoggerWin(ChromotingHost* host, const std::string& application_name);
+ HostEventLoggerWin(base::WeakPtr<HostStatusMonitor> monitor,
+ const std::string& application_name);
virtual ~HostEventLoggerWin();
@@ -45,7 +46,7 @@ class HostEventLoggerWin : public HostEventLogger, public HostStatusObserver {
void LogString(WORD type, DWORD event_id, const std::string& string);
void Log(WORD type, DWORD event_id, const std::vector<std::string>& strings);
- scoped_refptr<ChromotingHost> host_;
+ base::WeakPtr<HostStatusMonitor> monitor_;
// The handle of the application event log.
HANDLE event_log_;
@@ -55,14 +56,14 @@ class HostEventLoggerWin : public HostEventLogger, public HostStatusObserver {
} //namespace
-HostEventLoggerWin::HostEventLoggerWin(ChromotingHost* host,
+HostEventLoggerWin::HostEventLoggerWin(base::WeakPtr<HostStatusMonitor> monitor,
const std::string& application_name)
- : host_(host),
+ : monitor_(monitor),
event_log_(NULL) {
event_log_ = RegisterEventSourceW(NULL,
UTF8ToUTF16(application_name).c_str());
if (event_log_ != NULL) {
- host_->AddStatusObserver(this);
+ monitor_->AddStatusObserver(this);
} else {
LOG_GETLASTERROR(ERROR) << "Failed to register the event source: "
<< application_name;
@@ -71,7 +72,8 @@ HostEventLoggerWin::HostEventLoggerWin(ChromotingHost* host,
HostEventLoggerWin::~HostEventLoggerWin() {
if (event_log_ != NULL) {
- host_->RemoveStatusObserver(this);
+ if (monitor_)
+ monitor_->RemoveStatusObserver(this);
DeregisterEventSource(event_log_);
}
}
@@ -147,9 +149,10 @@ void HostEventLoggerWin::LogString(WORD type,
// static
scoped_ptr<HostEventLogger> HostEventLogger::Create(
- ChromotingHost* host, const std::string& application_name) {
+ base::WeakPtr<HostStatusMonitor> monitor,
+ const std::string& application_name) {
return scoped_ptr<HostEventLogger>(
- new HostEventLoggerWin(host, application_name));
+ new HostEventLoggerWin(monitor, application_name));
}
} // namespace remoting
diff --git a/remoting/host/host_status_monitor.h b/remoting/host/host_status_monitor.h
new file mode 100644
index 0000000..6cc80cb
--- /dev/null
+++ b/remoting/host/host_status_monitor.h
@@ -0,0 +1,24 @@
+// Copyright (c) 2013 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_STATUS_MONITOR_H_
+#define REMOTING_HOST_HOST_STATUS_MONITOR_H_
+
+namespace remoting {
+
+class HostStatusObserver;
+
+// Interface for registering host status observers.
+class HostStatusMonitor {
+ public:
+ virtual ~HostStatusMonitor() {}
+
+ // Add/Remove |observer| to/from the list of status observers.
+ virtual void AddStatusObserver(HostStatusObserver* observer) = 0;
+ virtual void RemoveStatusObserver(HostStatusObserver* observer) = 0;
+};
+
+} // namespace remoting
+
+#endif // REMOTING_HOST_HOST_STATUS_MONITOR_H_
diff --git a/remoting/host/host_status_monitor_fake.h b/remoting/host/host_status_monitor_fake.h
new file mode 100644
index 0000000..f989ce3
--- /dev/null
+++ b/remoting/host/host_status_monitor_fake.h
@@ -0,0 +1,27 @@
+// Copyright (c) 2013 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_STATUS_MONITOR_FAKE_H_
+#define REMOTING_HOST_HOST_STATUS_MONITOR_FAKE_H_
+
+#include "base/memory/weak_ptr.h"
+#include "remoting/host/host_status_monitor.h"
+
+namespace remoting {
+
+// An implementation of HostStatusMonitor that does nothing.
+class HostStatusMonitorFake
+ : public base::SupportsWeakPtr<HostStatusMonitorFake>,
+ public HostStatusMonitor {
+ public:
+ virtual ~HostStatusMonitorFake() {}
+
+ // HostStatusMonitor interface.
+ virtual void AddStatusObserver(HostStatusObserver* observer) OVERRIDE {}
+ virtual void RemoveStatusObserver(HostStatusObserver* observer) OVERRIDE {}
+};
+
+} // namespace remoting
+
+#endif // REMOTING_HOST_HOST_STATUS_MONITOR_FAKE_H_
diff --git a/remoting/host/log_to_server.cc b/remoting/host/log_to_server.cc
index f4830f6..ce2aa64 100644
--- a/remoting/host/log_to_server.cc
+++ b/remoting/host/log_to_server.cc
@@ -7,7 +7,7 @@
#include "base/bind.h"
#include "base/message_loop_proxy.h"
#include "remoting/base/constants.h"
-#include "remoting/host/chromoting_host.h"
+#include "remoting/host/host_status_monitor.h"
#include "remoting/host/server_log_entry.h"
#include "remoting/jingle_glue/iq_sender.h"
#include "remoting/jingle_glue/signal_strategy.h"
@@ -20,25 +20,22 @@ using buzz::XmlElement;
namespace remoting {
-LogToServer::LogToServer(ChromotingHost* host,
+LogToServer::LogToServer(base::WeakPtr<HostStatusMonitor> monitor,
ServerLogEntry::Mode mode,
SignalStrategy* signal_strategy,
const std::string& directory_bot_jid)
- : host_(host),
+ : monitor_(monitor),
mode_(mode),
signal_strategy_(signal_strategy),
directory_bot_jid_(directory_bot_jid) {
+ monitor_->AddStatusObserver(this);
signal_strategy_->AddListener(this);
-
- // |host| may be NULL in tests.
- if (host_)
- host_->AddStatusObserver(this);
}
LogToServer::~LogToServer() {
signal_strategy_->RemoveListener(this);
- if (host_)
- host_->RemoveStatusObserver(this);
+ if (monitor_)
+ monitor_->RemoveStatusObserver(this);
}
void LogToServer::LogSessionStateChange(const std::string& jid,
diff --git a/remoting/host/log_to_server.h b/remoting/host/log_to_server.h
index e65adae..bbd920c 100644
--- a/remoting/host/log_to_server.h
+++ b/remoting/host/log_to_server.h
@@ -9,8 +9,8 @@
#include <map>
#include <string>
-#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "base/threading/non_thread_safe.h"
#include "remoting/host/host_status_observer.h"
#include "remoting/host/server_log_entry.h"
@@ -27,7 +27,7 @@ class XmlElement;
namespace remoting {
-class ChromotingHost;
+class HostStatusMonitor;
class IqSender;
// LogToServer sends log entries to a server.
@@ -37,7 +37,7 @@ class LogToServer : public base::NonThreadSafe,
public HostStatusObserver,
public SignalStrategy::Listener {
public:
- explicit LogToServer(ChromotingHost* host,
+ explicit LogToServer(base::WeakPtr<HostStatusMonitor> monitor,
ServerLogEntry::Mode mode,
SignalStrategy* signal_strategy,
const std::string& directory_bot_jid);
@@ -65,7 +65,7 @@ class LogToServer : public base::NonThreadSafe,
void Log(const ServerLogEntry& entry);
void SendPendingEntries();
- scoped_refptr<ChromotingHost> host_;
+ base::WeakPtr<HostStatusMonitor> monitor_;
ServerLogEntry::Mode mode_;
SignalStrategy* signal_strategy_;
scoped_ptr<IqSender> iq_sender_;
diff --git a/remoting/host/log_to_server_unittest.cc b/remoting/host/log_to_server_unittest.cc
index 4277e49..1fb0500 100644
--- a/remoting/host/log_to_server_unittest.cc
+++ b/remoting/host/log_to_server_unittest.cc
@@ -4,10 +4,11 @@
#include "base/message_loop.h"
#include "base/message_loop_proxy.h"
-#include "remoting/jingle_glue/mock_objects.h"
+#include "remoting/host/host_status_monitor_fake.h"
#include "remoting/host/log_to_server.h"
-#include "testing/gmock_mutant.h"
+#include "remoting/jingle_glue/mock_objects.h"
#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gmock_mutant.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
@@ -126,7 +127,9 @@ class LogToServerTest : public testing::Test {
message_loop_proxy_ = base::MessageLoopProxy::current();
EXPECT_CALL(signal_strategy_, AddListener(_));
log_to_server_.reset(
- new LogToServer(NULL, ServerLogEntry::ME2ME, &signal_strategy_,
+ new LogToServer(host_status_monitor_.AsWeakPtr(),
+ ServerLogEntry::ME2ME,
+ &signal_strategy_,
kTestBotJid));
EXPECT_CALL(signal_strategy_, RemoveListener(_));
}
@@ -136,6 +139,7 @@ class LogToServerTest : public testing::Test {
scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
MockSignalStrategy signal_strategy_;
scoped_ptr<LogToServer> log_to_server_;
+ HostStatusMonitorFake host_status_monitor_;
};
TEST_F(LogToServerTest, SendNow) {
diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc
index 02ade7b..1346bce 100644
--- a/remoting/host/plugin/host_script_object.cc
+++ b/remoting/host/plugin/host_script_object.cc
@@ -388,8 +388,8 @@ void HostNPScriptObject::It2MeImpl::FinishConnect(
host_context_->ui_task_runner());
host_->AddStatusObserver(this);
log_to_server_.reset(
- new LogToServer(host_, ServerLogEntry::IT2ME, signal_strategy_.get(),
- directory_bot_jid_));
+ new LogToServer(host_->AsWeakPtr(), ServerLogEntry::IT2ME,
+ signal_strategy_.get(), directory_bot_jid_));
// Disable audio by default.
// TODO(sergeyu): Add UI to enable it.
@@ -403,7 +403,8 @@ void HostNPScriptObject::It2MeImpl::FinishConnect(
base::Bind(&It2MeImpl::Disconnect, this));
// Create event logger.
- host_event_logger_ = HostEventLogger::Create(host_, kApplicationName);
+ host_event_logger_ =
+ HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName);
// Connect signaling and start the host.
signal_strategy_->Connect();
diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc
index e645f81..2d1a3b7 100644
--- a/remoting/host/remoting_me2me_host.cc
+++ b/remoting/host/remoting_me2me_host.cc
@@ -935,17 +935,18 @@ void HostProcess::StartHost() {
this, host_id_, signal_strategy_.get(), directory_bot_jid_));
log_to_server_.reset(
- new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get(),
- directory_bot_jid_));
- host_event_logger_ = HostEventLogger::Create(host_, kApplicationName);
+ new LogToServer(host_->AsWeakPtr(), ServerLogEntry::ME2ME,
+ signal_strategy_.get(), directory_bot_jid_));
+ host_event_logger_ =
+ HostEventLogger::Create(host_->AsWeakPtr(), kApplicationName);
resizing_host_observer_.reset(
- new ResizingHostObserver(desktop_resizer_.get(), host_));
+ new ResizingHostObserver(desktop_resizer_.get(), host_->AsWeakPtr()));
// Create a host observer to enable/disable curtain mode as clients connect
// and disconnect.
curtaining_host_observer_.reset(new CurtainingHostObserver(
- curtain_.get(), host_));
+ curtain_.get(), host_->AsWeakPtr()));
curtaining_host_observer_->SetEnableCurtaining(curtain_required_);
if (host_user_interface_.get()) {
diff --git a/remoting/host/resizing_host_observer.cc b/remoting/host/resizing_host_observer.cc
index 48742ca..e1c96b5 100644
--- a/remoting/host/resizing_host_observer.cc
+++ b/remoting/host/resizing_host_observer.cc
@@ -3,28 +3,27 @@
// found in the LICENSE file.
#include "remoting/host/resizing_host_observer.h"
-#include "remoting/host/desktop_resizer.h"
#include <set>
#include "base/logging.h"
+#include "remoting/host/desktop_resizer.h"
+#include "remoting/host/host_status_monitor.h"
namespace remoting {
ResizingHostObserver::ResizingHostObserver(
- DesktopResizer* desktop_resizer, ChromotingHost* host)
+ DesktopResizer* desktop_resizer,
+ base::WeakPtr<HostStatusMonitor> monitor)
: desktop_resizer_(desktop_resizer),
- host_(host),
+ monitor_(monitor),
original_size_(SkISize::Make(0, 0)) {
- if (host_ != NULL) {
- host_->AddStatusObserver(this);
- }
+ monitor_->AddStatusObserver(this);
}
ResizingHostObserver::~ResizingHostObserver() {
- if (host_ != NULL) {
- host_->RemoveStatusObserver(this);
- }
+ if (monitor_)
+ monitor_->RemoveStatusObserver(this);
}
void ResizingHostObserver::OnClientAuthenticated(const std::string& jid) {
diff --git a/remoting/host/resizing_host_observer.h b/remoting/host/resizing_host_observer.h
index 1c23b75..85c23f1 100644
--- a/remoting/host/resizing_host_observer.h
+++ b/remoting/host/resizing_host_observer.h
@@ -7,23 +7,24 @@
#include <string>
-#include "remoting/host/host_status_observer.h"
-#include "remoting/host/chromoting_host.h"
-
#include "base/basictypes.h"
#include "base/compiler_specific.h"
+#include "base/memory/weak_ptr.h"
+#include "remoting/host/host_status_observer.h"
#include "third_party/skia/include/core/SkSize.h"
namespace remoting {
class DesktopResizer;
+class HostStatusMonitor;
// Use the specified DesktopResizer to match host desktop size to the client
// view size as closely as is possible. When the connection closes, restore
// the original desktop size.
class ResizingHostObserver : public HostStatusObserver {
public:
- ResizingHostObserver(DesktopResizer* desktop_resizer, ChromotingHost* host);
+ ResizingHostObserver(DesktopResizer* desktop_resizer,
+ base::WeakPtr<HostStatusMonitor> monitor);
virtual ~ResizingHostObserver();
// HostStatusObserver interface
@@ -35,7 +36,7 @@ class ResizingHostObserver : public HostStatusObserver {
private:
DesktopResizer* const desktop_resizer_;
- scoped_refptr<ChromotingHost> host_;
+ base::WeakPtr<HostStatusMonitor> monitor_;
SkISize original_size_;
std::string client_jid_;
diff --git a/remoting/host/resizing_host_observer_unittest.cc b/remoting/host/resizing_host_observer_unittest.cc
index 3d5d1e0..ec0ae10 100644
--- a/remoting/host/resizing_host_observer_unittest.cc
+++ b/remoting/host/resizing_host_observer_unittest.cc
@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "remoting/host/resizing_host_observer.h"
-#include "remoting/host/desktop_resizer.h"
-
#include <list>
#include "base/compiler_specific.h"
#include "base/logging.h"
+#include "remoting/host/desktop_resizer.h"
+#include "remoting/host/host_status_monitor_fake.h"
+#include "remoting/host/resizing_host_observer.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkSize.h"
@@ -67,8 +67,9 @@ class ResizingHostObserverTest : public testing::Test {
public:
void SetDesktopResizer(FakeDesktopResizer* desktop_resizer) {
CHECK(!desktop_resizer_.get()) << "Call SetDeskopResizer once per test";
- resizing_host_observer_.reset(new ResizingHostObserver(desktop_resizer,
- NULL));
+ resizing_host_observer_.reset(
+ new ResizingHostObserver(desktop_resizer,
+ host_status_monitor_.AsWeakPtr()));
desktop_resizer_.reset(desktop_resizer);
resizing_host_observer_->OnClientAuthenticated("");
}
@@ -103,6 +104,7 @@ class ResizingHostObserverTest : public testing::Test {
private:
scoped_ptr<ResizingHostObserver> resizing_host_observer_;
scoped_ptr<FakeDesktopResizer> desktop_resizer_;
+ HostStatusMonitorFake host_status_monitor_;
};
// Check that the host is not resized if GetSupportedSizes returns an empty
diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp
index 0c2472d..71999b5 100644
--- a/remoting/remoting.gyp
+++ b/remoting/remoting.gyp
@@ -359,6 +359,7 @@
'host/host_port_allocator.h',
'host/host_secret.cc',
'host/host_secret.h',
+ 'host/host_status_monitor.h',
'host/host_status_observer.h',
'host/host_user_interface.cc',
'host/host_user_interface.h',
@@ -2485,6 +2486,7 @@
'host/host_key_pair_unittest.cc',
'host/host_mock_objects.cc',
'host/host_mock_objects.h',
+ 'host/host_status_monitor_fake.h',
'host/ipc_desktop_environment_unittest.cc',
'host/json_host_config_unittest.cc',
'host/linux/x_server_clipboard_unittest.cc',