summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--remoting/host/register_support_host_request.cc10
-rw-r--r--remoting/host/register_support_host_request.h8
-rw-r--r--remoting/host/register_support_host_request_unittest.cc4
-rw-r--r--remoting/host/simple_host_process.cc37
-rw-r--r--remoting/host/support_access_verifier.cc7
5 files changed, 34 insertions, 32 deletions
diff --git a/remoting/host/register_support_host_request.cc b/remoting/host/register_support_host_request.cc
index 64172fa..ccc7c36 100644
--- a/remoting/host/register_support_host_request.cc
+++ b/remoting/host/register_support_host_request.cc
@@ -41,9 +41,8 @@ RegisterSupportHostRequest::~RegisterSupportHostRequest() {
}
bool RegisterSupportHostRequest::Init(HostConfig* config,
- RegisterCallback* callback) {
- DCHECK(!callback_.get());
- callback_.reset(callback);
+ const RegisterCallback& callback) {
+ callback_ = callback;
if (!key_pair_.Load(config)) {
return false;
@@ -54,7 +53,7 @@ bool RegisterSupportHostRequest::Init(HostConfig* config,
void RegisterSupportHostRequest::OnSignallingConnected(
SignalStrategy* signal_strategy,
const std::string& jid) {
- DCHECK(callback_.get()); // Expect that the object has been initialized.
+ DCHECK(!callback_.is_null());
message_loop_ = MessageLoop::current();
@@ -140,8 +139,7 @@ void RegisterSupportHostRequest::ProcessResponse(const XmlElement* response) {
DCHECK_EQ(message_loop_, MessageLoop::current());
std::string support_id;
bool result = ParseResponse(response, &support_id);
- callback_->Run(result, support_id);
- callback_.reset();
+ callback_.Run(result, support_id);
}
} // namespace remoting
diff --git a/remoting/host/register_support_host_request.h b/remoting/host/register_support_host_request.h
index b8f904e..c9b1e60 100644
--- a/remoting/host/register_support_host_request.h
+++ b/remoting/host/register_support_host_request.h
@@ -7,7 +7,7 @@
#include <string>
-#include "base/callback_old.h"
+#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "remoting/host/host_key_pair.h"
@@ -34,7 +34,7 @@ class RegisterSupportHostRequest : public HostStatusObserver {
public:
// First parameter is set to true on success. Second parameter is
// the new SessionID received from the bot.
- typedef Callback2<bool, const std::string&>::Type RegisterCallback;
+ typedef base::Callback<void(bool, const std::string&)> RegisterCallback;
RegisterSupportHostRequest();
virtual ~RegisterSupportHostRequest();
@@ -47,7 +47,7 @@ class RegisterSupportHostRequest : public HostStatusObserver {
// while signalling connection exists. Returns false on falure
// (e.g. config is invalid). Callback is never called if the bot
// malfunctions and doesn't respond to the request.
- bool Init(HostConfig* config, RegisterCallback* callback);
+ bool Init(HostConfig* config, const RegisterCallback& callback);
// HostStatusObserver implementation.
virtual void OnSignallingConnected(SignalStrategy* signal_strategy,
@@ -67,7 +67,7 @@ class RegisterSupportHostRequest : public HostStatusObserver {
void InvokeCallback(bool result, const std::string& support_id);
MessageLoop* message_loop_;
- scoped_ptr<RegisterCallback> callback_;
+ RegisterCallback callback_;
scoped_ptr<IqRequest> request_;
HostKeyPair key_pair_;
diff --git a/remoting/host/register_support_host_request_unittest.cc b/remoting/host/register_support_host_request_unittest.cc
index 5c11fdc..53761fa 100644
--- a/remoting/host/register_support_host_request_unittest.cc
+++ b/remoting/host/register_support_host_request_unittest.cc
@@ -4,6 +4,7 @@
#include "remoting/host/register_support_host_request.h"
+#include "base/bind.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop.h"
#include "base/string_number_conversions.h"
@@ -63,7 +64,8 @@ TEST_F(RegisterSupportHostRequestTest, Send) {
scoped_refptr<RegisterSupportHostRequest> request(
new RegisterSupportHostRequest());
ASSERT_TRUE(request->Init(
- config_, NewCallback(&callback_, &MockCallback::OnResponse)));
+ config_, base::Bind(&MockCallback::OnResponse,
+ base::Unretained(&callback_))));
MockIqRequest* iq_request = new MockIqRequest();
iq_request->Init();
diff --git a/remoting/host/simple_host_process.cc b/remoting/host/simple_host_process.cc
index 691e5b8..7684348 100644
--- a/remoting/host/simple_host_process.cc
+++ b/remoting/host/simple_host_process.cc
@@ -12,13 +12,15 @@
// 3. Receive mouse / keyboard events through libjingle.
// 4. Sends screen capture through libjingle.
+#include <stdlib.h>
+
#include <iostream>
#include <string>
-#include <stdlib.h>
#include "build/build_config.h"
#include "base/at_exit.h"
+#include "base/bind.h"
#include "base/callback.h"
#include "base/command_line.h"
#include "base/environment.h"
@@ -80,6 +82,16 @@ const char kVideoSwitchValueZip[] = "zip";
const char kVideoSwitchValueVp8[] = "vp8";
const char kVideoSwitchValueVp8Rtp[] = "vp8rtp";
+// Glue class to print out the access code for Me2Mom.
+void SetMe2MomAccessCode(remoting::SupportAccessVerifier* access_verifier,
+ bool successful, const std::string& support_id) {
+ if (successful) {
+ std::cout << "Support id: " << support_id << "-"
+ << access_verifier->host_secret() << std::endl;
+ }
+ access_verifier->OnMe2MomHostRegistered(successful, support_id);
+}
+
class SimpleHost {
public:
SimpleHost()
@@ -110,20 +122,22 @@ class SimpleHost {
// Initialize AccessVerifier.
// TODO(jamiewalch): For the Me2Mom case, the access verifier is passed to
// RegisterSupportHostRequest::Init, so transferring ownership of it to the
- // ChromotingHost could cause a crash condition at shut-down. Fix this.
+ // ChromotingHost could cause a crash condition if SetMe2MomAccessCode is
+ // called after the ChromotingHost is destroyed (for example, at shutdown).
+ // Fix this.
scoped_ptr<remoting::AccessVerifier> access_verifier;
- remoting::RegisterSupportHostRequest::RegisterCallback*
- register_callback = NULL;
+ scoped_refptr<remoting::RegisterSupportHostRequest> register_request;
if (me2mom_) {
scoped_ptr<remoting::SupportAccessVerifier> support_access_verifier(
new remoting::SupportAccessVerifier());
if (!support_access_verifier->Init())
return 1;
- std::cout << "Host secret: "
- << support_access_verifier->host_secret() << std::endl;
- register_callback = NewCallback(
- support_access_verifier.get(),
- &remoting::SupportAccessVerifier::OnMe2MomHostRegistered);
+ register_request = new remoting::RegisterSupportHostRequest();
+ if (!register_request->Init(
+ config, base::Bind(&SetMe2MomAccessCode,
+ support_access_verifier.get()))) {
+ return 1;
+ }
access_verifier.reset(support_access_verifier.release());
} else {
scoped_ptr<remoting::SelfAccessVerifier> self_access_verifier(
@@ -155,11 +169,6 @@ class SimpleHost {
}
if (me2mom_) {
- scoped_refptr<remoting::RegisterSupportHostRequest> register_request =
- new remoting::RegisterSupportHostRequest();
- if (!register_request->Init(config, register_callback)) {
- return 1;
- }
host->AddStatusObserver(register_request);
} else {
// Initialize HeartbeatSender.
diff --git a/remoting/host/support_access_verifier.cc b/remoting/host/support_access_verifier.cc
index 30ad662..5d1c019 100644
--- a/remoting/host/support_access_verifier.cc
+++ b/remoting/host/support_access_verifier.cc
@@ -6,7 +6,6 @@
#include <stdlib.h>
#include <vector>
-#include <iostream>
#include "base/logging.h"
#include "base/rand_util.h"
@@ -63,8 +62,6 @@ bool SupportAccessVerifier::VerifyPermissions(
CHECK(initialized_);
if (support_id_.empty())
return false;
- // TODO(jamiewalch): This needs to compose the support id with the host
- // secret before verification.
std::string access_code = support_id_ + "-" + host_secret_;
return protocol::VerifySupportAuthToken(
client_jid, access_code, encoded_access_token);
@@ -73,10 +70,6 @@ bool SupportAccessVerifier::VerifyPermissions(
void SupportAccessVerifier::OnMe2MomHostRegistered(
bool successful, const std::string& support_id) {
if (successful) {
- // TODO(jamiewalch): cout is only needed so that remoting_simple_host can
- // report the support id to the user. Find a better way (issue 82651).
- std::cout << "Support id: "
- << support_id << std::endl;
support_id_ = support_id;
} else {
LOG(ERROR) << "Failed to register support host";