forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Chromoting] Implement HostExperimentSessionPlugin
HostExperimentSessionPlugin is a host side SessionPlugin to send host attributes to, and receive configuration from the client side. A host can attach this plugin to the Session and use its configuration to initialize a HostSessionOptions. This is part of host experiment framework. BUG=650926 Review-Url: https://codereview.chromium.org/2586133002 Cr-Commit-Position: refs/heads/master@{#441850}
- Loading branch information
zijiehe
authored and
Commit bot
committed
Jan 6, 2017
1 parent
5d47305
commit 8e659c5
Showing
5 changed files
with
158 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2016 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/host_experiment_session_plugin.h" | ||
|
||
#include "remoting/base/constants.h" | ||
#include "remoting/host/host_attributes.h" | ||
|
||
namespace remoting { | ||
|
||
using buzz::QName; | ||
using buzz::XmlElement; | ||
|
||
std::unique_ptr<XmlElement> HostExperimentSessionPlugin::GetNextMessage() { | ||
if (attributes_sent_) { | ||
return nullptr; | ||
} | ||
attributes_sent_ = true; | ||
std::unique_ptr<XmlElement> attributes( | ||
new XmlElement(QName(kChromotingXmlNamespace, "host-attributes"))); | ||
attributes->SetBodyText(GetHostAttributes()); | ||
return attributes; | ||
} | ||
|
||
void HostExperimentSessionPlugin::OnIncomingMessage( | ||
const XmlElement& attachments) { | ||
if (configuration_received_) { | ||
return; | ||
} | ||
|
||
const XmlElement* configuration = attachments.FirstNamed( | ||
QName(kChromotingXmlNamespace, "host-configuration")); | ||
if (!configuration) { | ||
return; | ||
} | ||
|
||
configuration_received_ = true; | ||
configuration_ = configuration->BodyText(); | ||
} | ||
|
||
bool HostExperimentSessionPlugin::configuration_received() const { | ||
return configuration_received_; | ||
} | ||
|
||
const std::string& HostExperimentSessionPlugin::configuration() const { | ||
return configuration_; | ||
} | ||
|
||
} // namespace remoting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2016 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_EXPERIMENT_SESSION_PLUGIN_H_ | ||
#define REMOTING_HOST_HOST_EXPERIMENT_SESSION_PLUGIN_H_ | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include "remoting/protocol/session_plugin.h" | ||
#include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | ||
|
||
namespace remoting { | ||
|
||
// A SessionPlugin implementation to send host attributes to client, and | ||
// receives experiment settings. | ||
class HostExperimentSessionPlugin : public protocol::SessionPlugin { | ||
public: | ||
using SessionPlugin::SessionPlugin; | ||
|
||
// protocol::SessionPlug implementation. | ||
std::unique_ptr<buzz::XmlElement> GetNextMessage() override; | ||
|
||
void OnIncomingMessage(const buzz::XmlElement& attachments) override; | ||
|
||
// Whether we have received configuration from client. | ||
bool configuration_received() const; | ||
|
||
// The configuration sent from client, may be empty. | ||
const std::string& configuration() const; | ||
|
||
private: | ||
bool attributes_sent_ = false; | ||
bool configuration_received_ = false; | ||
std::string configuration_; | ||
}; | ||
|
||
} // namespace remoting | ||
|
||
#endif // REMOTING_HOST_HOST_EXPERIMENT_SESSION_PLUGIN_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2016 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/host_experiment_session_plugin.h" | ||
|
||
#include <memory> | ||
|
||
#include "base/bind.h" | ||
#include "remoting/base/constants.h" | ||
#include "remoting/host/host_attributes.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
#include "third_party/webrtc/libjingle/xmllite/xmlelement.h" | ||
|
||
using buzz::QName; | ||
using buzz::XmlElement; | ||
|
||
namespace remoting { | ||
|
||
TEST(HostExperimentSessionPluginTest, AttachAttributes) { | ||
HostExperimentSessionPlugin plugin; | ||
std::unique_ptr<XmlElement> attachments = plugin.GetNextMessage(); | ||
ASSERT_TRUE(attachments); | ||
ASSERT_EQ(attachments->Name(), | ||
QName(kChromotingXmlNamespace, "host-attributes")); | ||
ASSERT_EQ(attachments->BodyText(), GetHostAttributes()); | ||
|
||
attachments.reset(); | ||
attachments = plugin.GetNextMessage(); | ||
ASSERT_FALSE(attachments); | ||
} | ||
|
||
TEST(HostExperimentSessionPluginTest, LoadConfiguration) { | ||
std::unique_ptr<XmlElement> attachment( | ||
new XmlElement(QName(kChromotingXmlNamespace, "attachments"))); | ||
XmlElement* configuration = | ||
new XmlElement(QName(kChromotingXmlNamespace, "host-configuration")); | ||
configuration->SetBodyText("This Is A Test Configuration"); | ||
attachment->AddElement(configuration); | ||
HostExperimentSessionPlugin plugin; | ||
plugin.OnIncomingMessage(*attachment); | ||
ASSERT_TRUE(plugin.configuration_received()); | ||
ASSERT_EQ(plugin.configuration(), "This Is A Test Configuration"); | ||
} | ||
|
||
TEST(HostExperimentSessionPluginTest, IgnoreSecondConfiguration) { | ||
std::unique_ptr<XmlElement> attachment( | ||
new XmlElement(QName(kChromotingXmlNamespace, "attachments"))); | ||
XmlElement* configuration = | ||
new XmlElement(QName(kChromotingXmlNamespace, "host-configuration")); | ||
attachment->AddElement(configuration); | ||
configuration->SetBodyText("config1"); | ||
HostExperimentSessionPlugin plugin; | ||
plugin.OnIncomingMessage(*attachment); | ||
ASSERT_TRUE(plugin.configuration_received()); | ||
ASSERT_EQ(plugin.configuration(), "config1"); | ||
|
||
configuration->SetBodyText("config2"); | ||
plugin.OnIncomingMessage(*attachment); | ||
ASSERT_TRUE(plugin.configuration_received()); | ||
ASSERT_EQ(plugin.configuration(), "config1"); | ||
} | ||
|
||
} // namespace remoting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters