diff options
author | jamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-23 02:58:17 +0000 |
---|---|---|
committer | jamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-23 02:58:17 +0000 |
commit | f292f1719c54a79e83eedd44154f1259093d909e (patch) | |
tree | ec212236e51540388efecb63807d0b8aa4bf7b4a /remoting | |
parent | ccb067e65dfc79d5e336c84736fe66e76f5f585a (diff) | |
download | chromium_src-f292f1719c54a79e83eedd44154f1259093d909e.zip chromium_src-f292f1719c54a79e83eedd44154f1259093d909e.tar.gz chromium_src-f292f1719c54a79e83eedd44154f1259093d909e.tar.bz2 |
Get the timeout period from the cloud instead of hard-coding it (b/5049410).
BUG=
TEST=
Review URL: http://codereview.chromium.org/7466012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93767 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/host/plugin/host_script_object.cc | 10 | ||||
-rw-r--r-- | remoting/host/plugin/host_script_object.h | 5 | ||||
-rw-r--r-- | remoting/host/register_support_host_request.cc | 39 | ||||
-rw-r--r-- | remoting/host/register_support_host_request.h | 16 | ||||
-rw-r--r-- | remoting/host/register_support_host_request_unittest.cc | 12 | ||||
-rw-r--r-- | remoting/host/simple_host_process.cc | 3 | ||||
-rw-r--r-- | remoting/webapp/me2mom/remoting.js | 5 |
7 files changed, 70 insertions, 20 deletions
diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc index 226df03..afbf232 100644 --- a/remoting/host/plugin/host_script_object.cc +++ b/remoting/host/plugin/host_script_object.cc @@ -22,6 +22,7 @@ namespace remoting { // Supported Javascript interface: // readonly attribute string accessCode; +// readonly attribute int accessCodeLifetime; // readonly attribute int state; // // state: { @@ -44,6 +45,7 @@ namespace remoting { namespace { const char* kAttrNameAccessCode = "accessCode"; +const char* kAttrNameAccessCodeLifetime = "accessCodeLifetime"; const char* kAttrNameState = "state"; const char* kAttrNameLogDebugInfo = "logDebugInfo"; const char* kAttrNameOnStateChanged = "onStateChanged"; @@ -141,6 +143,7 @@ bool HostNPScriptObject::HasProperty(const std::string& property_name) { logger_->VLog(2, "HasProperty %s", property_name.c_str()); CHECK_EQ(base::PlatformThread::CurrentId(), np_thread_id_); return (property_name == kAttrNameAccessCode || + property_name == kAttrNameAccessCodeLifetime || property_name == kAttrNameState || property_name == kAttrNameLogDebugInfo || property_name == kAttrNameOnStateChanged || @@ -173,6 +176,9 @@ bool HostNPScriptObject::GetProperty(const std::string& property_name, } else if (property_name == kAttrNameAccessCode) { *result = NPVariantFromString(access_code_); return true; + } else if (property_name == kAttrNameAccessCodeLifetime) { + INT32_TO_NPVARIANT(access_code_lifetime_.InSeconds(), *result); + return true; } else if (property_name == kAttrNameDisconnected) { INT32_TO_NPVARIANT(kDisconnected, *result); return true; @@ -430,7 +436,8 @@ void HostNPScriptObject::OnShutdownFinished() { void HostNPScriptObject::OnReceivedSupportID( SupportAccessVerifier* access_verifier, bool success, - const std::string& support_id) { + const std::string& support_id, + const base::TimeDelta& lifetime) { CHECK_NE(base::PlatformThread::CurrentId(), np_thread_id_); if (!success) { @@ -445,6 +452,7 @@ void HostNPScriptObject::OnReceivedSupportID( // Combine the Support Id with the Host Id to make the Access Code. // TODO(wez): Locking, anyone? access_code_ = support_id + access_verifier->host_secret(); + access_code_lifetime_ = lifetime; // Let the caller know that life is good. OnStateChanged(kReceivedAccessCode); diff --git a/remoting/host/plugin/host_script_object.h b/remoting/host/plugin/host_script_object.h index d623c32..5a759ce 100644 --- a/remoting/host/plugin/host_script_object.h +++ b/remoting/host/plugin/host_script_object.h @@ -14,6 +14,7 @@ #include "base/synchronization/cancellation_flag.h" #include "base/synchronization/waitable_event.h" #include "base/threading/platform_thread.h" +#include "base/time.h" #include "remoting/host/chromoting_host_context.h" #include "remoting/host/host_status_observer.h" #include "remoting/host/plugin/host_plugin_logger.h" @@ -95,7 +96,8 @@ class HostNPScriptObject : public HostStatusObserver { // Callbacks invoked during session setup. void OnReceivedSupportID(remoting::SupportAccessVerifier* access_verifier, bool success, - const std::string& support_id); + const std::string& support_id, + const base::TimeDelta& lifetime); // Helper functions that run on main thread. Can be called on any // other thread. @@ -127,6 +129,7 @@ class HostNPScriptObject : public HostStatusObserver { NPObject* parent_; int state_; std::string access_code_; + base::TimeDelta access_code_lifetime_; NPObject* log_debug_info_func_; NPObject* on_state_changed_func_; base::PlatformThreadId np_thread_id_; diff --git a/remoting/host/register_support_host_request.cc b/remoting/host/register_support_host_request.cc index bd16b6b..b5a3500 100644 --- a/remoting/host/register_support_host_request.cc +++ b/remoting/host/register_support_host_request.cc @@ -31,6 +31,7 @@ const char kSignatureTimeAttr[] = "time"; // Strings used to parse responses received from the bot. const char kRegisterQueryResultTag[] = "register-support-host-result"; const char kSupportIdTag[] = "support-id"; +const char kSupportIdLifetimeTag[] = "support-id-lifetime"; } RegisterSupportHostRequest::RegisterSupportHostRequest() @@ -71,7 +72,7 @@ void RegisterSupportHostRequest::OnSignallingDisconnected() { // XMPP connection attempt fails. CHECK(!callback_.is_null()); DCHECK(!request_.get()); - callback_.Run(false, std::string()); + callback_.Run(false, std::string(), base::TimeDelta()); return; } DCHECK_EQ(message_loop_, MessageLoop::current()); @@ -114,7 +115,8 @@ XmlElement* RegisterSupportHostRequest::CreateSignature( } bool RegisterSupportHostRequest::ParseResponse(const XmlElement* response, - std::string* support_id) { + std::string* support_id, + base::TimeDelta* lifetime) { std::string type = response->Attr(buzz::QN_TYPE); if (type == buzz::STR_ERROR) { LOG(ERROR) << "Received error in response to heartbeat: " @@ -128,20 +130,42 @@ bool RegisterSupportHostRequest::ParseResponse(const XmlElement* response, const XmlElement* result_element = response->FirstNamed(QName( kChromotingXmlNamespace, kRegisterQueryResultTag)); if (!result_element) { - LOG(ERROR) << "<register-support-host-result> is missing in the " - "host registration response: " << response->Str(); + LOG(ERROR) << "<" << kRegisterQueryResultTag + << "> is missing in the host registration response: " + << response->Str(); return false; } const XmlElement* support_id_element = result_element->FirstNamed(QName(kChromotingXmlNamespace, kSupportIdTag)); if (!support_id_element) { - LOG(ERROR) << "<support-id> is missing in the host registration response: " + LOG(ERROR) << "<" << kSupportIdTag + << "> is missing in the host registration response: " + << response->Str(); + return false; + } + + const XmlElement* lifetime_element = + result_element->FirstNamed(QName(kChromotingXmlNamespace, + kSupportIdLifetimeTag)); + if (!lifetime_element) { + LOG(ERROR) << "<" << kSupportIdLifetimeTag + << "> is missing in the host registration response: " + << response->Str(); + return false; + } + + int lifetime_int; + if (!base::StringToInt(lifetime_element->BodyText().c_str(), &lifetime_int) || + lifetime_int <= 0) { + LOG(ERROR) << "<" << kSupportIdLifetimeTag + << "> is malformed in the host registration response: " << response->Str(); return false; } *support_id = support_id_element->BodyText(); + *lifetime = base::TimeDelta::FromSeconds(lifetime_int); return true; } @@ -149,8 +173,9 @@ bool RegisterSupportHostRequest::ParseResponse(const XmlElement* response, 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); + base::TimeDelta lifetime; + bool success = ParseResponse(response, &support_id, &lifetime); + callback_.Run(success, support_id, lifetime); } } // namespace remoting diff --git a/remoting/host/register_support_host_request.h b/remoting/host/register_support_host_request.h index efe3d48..7d7c4d0 100644 --- a/remoting/host/register_support_host_request.h +++ b/remoting/host/register_support_host_request.h @@ -20,21 +20,27 @@ namespace buzz { class XmlElement; } // namespace buzz +namespace base { +class TimeDelta; +} // namespace base + namespace remoting { class IqRequest; class MutableHostConfig; // RegisterSupportHostRequest sends support host registeration request -// to the Chromoting Bot. It listents to the status of the host using +// to the Chromoting Bot. It listens to the status of the host using // HostStatusObserver interface and sends the request when signalling // channel is connected. When a response is received from the bot, it // calls the callback specified in the Init() method. class RegisterSupportHostRequest : public HostStatusObserver { public: // First parameter is set to true on success. Second parameter is - // the new SessionID received from the bot. - typedef base::Callback<void(bool, const std::string&)> RegisterCallback; + // the new SessionID received from the bot. Third parameter is the + // amount of time until that id expires. + typedef base::Callback<void(bool, const std::string&, + const base::TimeDelta&)> RegisterCallback; RegisterSupportHostRequest(); virtual ~RegisterSupportHostRequest(); @@ -65,8 +71,8 @@ class RegisterSupportHostRequest : public HostStatusObserver { buzz::XmlElement* CreateSignature(const std::string& jid); void ProcessResponse(const buzz::XmlElement* response); - bool ParseResponse(const buzz::XmlElement* response, std::string* support_id); - void InvokeCallback(bool result, const std::string& support_id); + bool ParseResponse(const buzz::XmlElement* response, + std::string* support_id, base::TimeDelta* lifetime); MessageLoop* message_loop_; RegisterCallback callback_; diff --git a/remoting/host/register_support_host_request_unittest.cc b/remoting/host/register_support_host_request_unittest.cc index c290581..e08b99d 100644 --- a/remoting/host/register_support_host_request_unittest.cc +++ b/remoting/host/register_support_host_request_unittest.cc @@ -34,10 +34,12 @@ namespace { const char kTestJid[] = "user@gmail.com/chromoting123"; const int64 kTestTime = 123123123; const char kSupportId[] = "AB4RF3"; +const char kSupportIdLifetime[] = "300"; class MockCallback { public: - MOCK_METHOD2(OnResponse, void(bool result, const std::string& support_id)); + MOCK_METHOD3(OnResponse, void(bool result, const std::string& support_id, + const base::TimeDelta& lifetime)); }; } // namespace @@ -107,7 +109,8 @@ TEST_F(RegisterSupportHostRequestTest, Send) { EXPECT_EQ(expected_signature, signature->BodyText()); // Generate response and verify that callback is called. - EXPECT_CALL(callback_, OnResponse(true, kSupportId)); + EXPECT_CALL(callback_, OnResponse(true, kSupportId, + base::TimeDelta::FromSeconds(300))); scoped_ptr<XmlElement> response(new XmlElement(QName("", "iq"))); response->AddAttr(QName("", "type"), "result"); @@ -121,6 +124,11 @@ TEST_F(RegisterSupportHostRequestTest, Send) { support_id->AddText(kSupportId); result->AddElement(support_id); + XmlElement* support_id_lifetime = new XmlElement( + QName(kChromotingXmlNamespace, "support-id-lifetime")); + support_id_lifetime->AddText(kSupportIdLifetime); + result->AddElement(support_id_lifetime); + iq_request->callback()->Run(response.get()); message_loop_.RunAllPending(); } diff --git a/remoting/host/simple_host_process.cc b/remoting/host/simple_host_process.cc index e8c1f32..a5664dd 100644 --- a/remoting/host/simple_host_process.cc +++ b/remoting/host/simple_host_process.cc @@ -94,7 +94,8 @@ const char kVideoSwitchValueVp8Rtp[] = "vp8rtp"; // Glue class to print out the access code for IT2Me. void SetIT2MeAccessCode(remoting::SupportAccessVerifier* access_verifier, - bool successful, const std::string& support_id) { + bool successful, const std::string& support_id, + const base::TimeDelta& lifetime) { access_verifier->OnIT2MeHostRegistered(successful, support_id); if (successful) { std::cout << "Support id: " << support_id diff --git a/remoting/webapp/me2mom/remoting.js b/remoting/webapp/me2mom/remoting.js index 6bbb67a..8433a90 100644 --- a/remoting/webapp/me2mom/remoting.js +++ b/remoting/webapp/me2mom/remoting.js @@ -309,7 +309,7 @@ function updateTimeoutStyles_() { } } document.getElementById('access-code-countdown').hidden = - (remoting.accessCodeExpiresIn > ACCESS_CODE_TIMER_DISPLAY_THRESHOLD ) || + (remoting.accessCodeExpiresIn > ACCESS_CODE_TIMER_DISPLAY_THRESHOLD) || !remoting.timerRunning; return true; } @@ -345,8 +345,7 @@ function onStateChanged_() { nextFourDigits.innerText = accessCode.substring(i, i + kDigitsPerGroup); accessCodeDisplay.appendChild(nextFourDigits); } - // TODO(jamiewalch): Get the validity period from the cloud. - remoting.accessCodeExpiresIn = 300; + remoting.accessCodeExpiresIn = plugin.accessCodeLifetime; if (remoting.accessCodeExpiresIn > 0) { // Check it hasn't expired. remoting.accessCodeTimerId = setInterval( 'remoting.decrementAccessCodeTimeout_()', 1000); |