Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1630)

Unified Diff: remoting/protocol/pairing_registry.cc

Issue 17063003: Changes to PairingRegistry to facilitate per-platform implementions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed spacing. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/protocol/pairing_registry.cc
diff --git a/remoting/protocol/pairing_registry.cc b/remoting/protocol/pairing_registry.cc
index 10098b03ed74850a820670e1f9b5646a2d68caec..a6ab4fa421560fbc343e5fe516687673ac11f20e 100644
--- a/remoting/protocol/pairing_registry.cc
+++ b/remoting/protocol/pairing_registry.cc
@@ -12,35 +12,59 @@
namespace remoting {
namespace protocol {
-// How many bytes of random data to use for the client id and shared secret.
+// How many bytes of random data to use for the shared secret.
const int kKeySize = 16;
-PairingRegistry::PairingRegistry(scoped_ptr<Delegate> delegate)
- : delegate_(delegate.Pass()) {
- DCHECK(delegate_);
+PairingRegistry::Pairing::Pairing() {
}
-PairingRegistry::~PairingRegistry() {
+PairingRegistry::Pairing::Pairing(const base::Time& created_time,
+ const std::string& client_name,
+ const std::string& client_id,
+ const std::string& shared_secret)
+ : created_time_(created_time),
+ client_name_(client_name),
+ client_id_(client_id),
+ shared_secret_(shared_secret) {
}
-PairingRegistry::Pairing PairingRegistry::CreatePairing(
+PairingRegistry::Pairing PairingRegistry::Pairing::Create(
const std::string& client_name) {
- DCHECK(CalledOnValidThread());
-
- Pairing result;
- result.client_name = client_name;
- result.client_id = base::GenerateGUID();
-
- // Create a random shared secret to authenticate this client.
+ base::Time created_time = base::Time::Now();
+ std::string client_id = base::GenerateGUID();
+ std::string shared_secret;
char buffer[kKeySize];
crypto::RandBytes(buffer, arraysize(buffer));
if (!base::Base64Encode(base::StringPiece(buffer, arraysize(buffer)),
- &result.shared_secret)) {
+ &shared_secret)) {
LOG(FATAL) << "Base64Encode failed.";
}
+ return Pairing(created_time, client_name, client_id, shared_secret);
+}
+
+PairingRegistry::Pairing::~Pairing() {
+}
+
+bool PairingRegistry::Pairing::operator==(const Pairing& other) const {
+ return created_time_ == other.created_time_ &&
+ client_id_ == other.client_id_ &&
+ client_name_ == other.client_name_ &&
+ shared_secret_ == other.shared_secret_;
+}
- // Save the result via the Delegate and return it to the caller.
- delegate_->AddPairing(result);
+PairingRegistry::PairingRegistry(scoped_ptr<Delegate> delegate)
+ : delegate_(delegate.Pass()) {
+ DCHECK(delegate_);
+}
+
+PairingRegistry::~PairingRegistry() {
+}
+
+PairingRegistry::Pairing PairingRegistry::CreatePairing(
+ const std::string& client_name) {
+ DCHECK(CalledOnValidThread());
+ Pairing result = Pairing::Create(client_name);
+ delegate_->AddPairing(result, AddPairingCallback());
return result;
}
@@ -51,17 +75,20 @@ void PairingRegistry::GetPairing(const std::string& client_id,
}
void NotImplementedPairingRegistryDelegate::AddPairing(
- const PairingRegistry::Pairing& new_paired_client) {
+ const PairingRegistry::Pairing& new_paired_client,
+ const PairingRegistry::AddPairingCallback& callback) {
NOTIMPLEMENTED();
+ if (!callback.is_null()) {
+ callback.Run(false);
+ }
}
void NotImplementedPairingRegistryDelegate::GetPairing(
const std::string& client_id,
const PairingRegistry::GetPairingCallback& callback) {
NOTIMPLEMENTED();
- callback.Run(PairingRegistry::Pairing());
+ callback.Run(PairingRegistry::Pairing(base::Time(), "", "", ""));
}
-
} // namespace protocol
} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698