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

Unified Diff: remoting/protocol/pairing_registry.h

Issue 21128006: Refactored PairingRegistry::Delegate such that it can retrieve/modify for a single client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 7 years, 5 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.h
diff --git a/remoting/protocol/pairing_registry.h b/remoting/protocol/pairing_registry.h
index fc63e84c91079577cb71a532184029a7b0b03fdf..3e5aa9698809f22a84a5e2b5ca3c5246557f6210 100644
--- a/remoting/protocol/pairing_registry.h
+++ b/remoting/protocol/pairing_registry.h
@@ -14,13 +14,18 @@
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "base/threading/non_thread_safe.h"
#include "base/time/time.h"
namespace base {
class ListValue;
+class Value;
+class SingleThreadTaskRunner;
} // namespace base
+namespace tracked_objects {
+class Location;
+} // namespace tracked_objects
+
namespace remoting {
namespace protocol {
@@ -33,8 +38,7 @@ namespace protocol {
// class and sent in plain-text by the client during authentication.
// * The shared secret for the client. This is generated on-demand by this
// class and used in the SPAKE2 exchange to mutually verify identity.
-class PairingRegistry : public base::RefCountedThreadSafe<PairingRegistry>,
- public base::NonThreadSafe {
+class PairingRegistry : public base::RefCountedThreadSafe<PairingRegistry> {
public:
struct Pairing {
Pairing();
@@ -45,6 +49,9 @@ class PairingRegistry : public base::RefCountedThreadSafe<PairingRegistry>,
~Pairing();
static Pairing Create(const std::string& client_name);
+ static Pairing CreateFromValue(const base::Value& pairing_json);
+
+ scoped_ptr<base::Value> ToValue() const;
bool operator==(const Pairing& other) const;
@@ -66,11 +73,10 @@ class PairingRegistry : public base::RefCountedThreadSafe<PairingRegistry>,
typedef std::map<std::string, Pairing> PairedClients;
// Delegate callbacks.
- typedef base::Callback<void(const std::string& pairings_json)> LoadCallback;
- typedef base::Callback<void(bool success)> SaveCallback;
- typedef base::Callback<void(Pairing pairing)> GetPairingCallback;
+ typedef base::Callback<void(bool success)> DoneCallback;
typedef base::Callback<void(scoped_ptr<base::ListValue> pairings)>
GetAllPairingsCallback;
+ typedef base::Callback<void(Pairing pairing)> GetPairingCallback;
static const char kCreatedTimeKey[];
static const char kClientIdKey[];
@@ -82,18 +88,25 @@ class PairingRegistry : public base::RefCountedThreadSafe<PairingRegistry>,
public:
virtual ~Delegate() {}
- // Save JSON-encoded pairing information to persistent storage. If
- // a non-NULL callback is provided, invoke it on completion to
- // indicate success or failure. Must not block.
- virtual void Save(const std::string& pairings_json,
- const SaveCallback& callback) = 0;
+ // Retrieves all JSON-encoded pairings from persistent storage.
+ virtual scoped_ptr<base::ListValue> LoadAll() = 0;
+
+ // Deletes all pairings in persistent storage. Must not block.
Jamie 2013/08/01 22:44:04 I think these are all allowed to block now, correc
alexeypa (please no reviews) 2013/08/01 23:07:42 Done.
+ virtual bool DeleteAll() = 0;
- // Retrieve the JSON-encoded pairing information from persistent
- // storage. Must not block.
- virtual void Load(const LoadCallback& callback) = 0;
+ // Retrieves the pairing identified by |client_id|.
+ virtual Pairing Load(const std::string& client_id) = 0;
+
+ // Saves |pairing| to persistent storage.
+ virtual bool Save(const Pairing& pairing) = 0;
+
+ // Deletes the pairing identified by |client_id|.
+ virtual bool Delete(const std::string& client_id) = 0;
};
- explicit PairingRegistry(scoped_ptr<Delegate> delegate);
+ PairingRegistry(
+ scoped_refptr<base::SingleThreadTaskRunner> delegate_task_runner,
+ scoped_ptr<Delegate> delegate);
// Creates a pairing for a new client and saves it to disk.
//
@@ -115,58 +128,68 @@ class PairingRegistry : public base::RefCountedThreadSafe<PairingRegistry>,
// the result of saving the new config, which occurs even if the client ID
// did not match any pairing.
void DeletePairing(const std::string& client_id,
- const SaveCallback& callback);
+ const DoneCallback& callback);
// Clear all pairings from the registry.
- void ClearAllPairings(const SaveCallback& callback);
+ void ClearAllPairings(const DoneCallback& callback);
+
+ protected:
+ friend class base::RefCountedThreadSafe<PairingRegistry>;
+ virtual ~PairingRegistry();
+
+ // Lets the tests to override task posting to make all callbacks synchronous.
Jamie 2013/08/01 22:44:04 Nit: Either "Allows the tests to override..." or "
alexeypa (please no reviews) 2013/08/01 23:07:42 Done.
+ virtual void PostTask(
+ const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
+ const tracked_objects::Location& from_here,
+ const base::Closure& task);
private:
FRIEND_TEST_ALL_PREFIXES(PairingRegistryTest, AddPairing);
- FRIEND_TEST_ALL_PREFIXES(PairingRegistryTest, GetAllPairingsJSON);
friend class NegotiatingAuthenticatorTest;
- friend class base::RefCountedThreadSafe<PairingRegistry>;
-
- virtual ~PairingRegistry();
// Helper method for unit tests.
void AddPairing(const Pairing& pairing);
- // Worker functions for each of the public methods, passed as a callback to
- // the delegate.
- void MergePairingAndSave(const Pairing& pairing,
- const SaveCallback& callback,
- const std::string& pairings_json);
- void DoGetPairing(const std::string& client_id,
- const GetPairingCallback& callback,
- const std::string& pairings_json);
- void SanitizePairings(const GetAllPairingsCallback& callback,
- const std::string& pairings_json);
- void DoDeletePairing(const std::string& client_id,
- const SaveCallback& callback,
- const std::string& pairings_json);
+ // Blocking helper methods used to call the delegate.
+ void DoLoadAll(
+ const protocol::PairingRegistry::GetAllPairingsCallback& callback);
+ void DoDeleteAll(
+ const protocol::PairingRegistry::DoneCallback& callback);
+ void DoLoad(
+ const std::string& client_id,
+ const protocol::PairingRegistry::GetPairingCallback& callback);
+ void DoSave(
+ const protocol::PairingRegistry::Pairing& pairing,
+ const protocol::PairingRegistry::DoneCallback& callback);
+ void DoDelete(
+ const std::string& client_id,
+ const protocol::PairingRegistry::DoneCallback& callback);
// "Trampoline" callbacks that schedule the next pending request and then
// invoke the original caller-supplied callback.
- void InvokeLoadCallbackAndScheduleNext(
- const LoadCallback& callback, const std::string& pairings_json);
- void InvokeSaveCallbackAndScheduleNext(
- const SaveCallback& callback, bool success);
+ void InvokeDoneCallbackAndScheduleNext(
+ const DoneCallback& callback, bool success);
void InvokeGetPairingCallbackAndScheduleNext(
const GetPairingCallback& callback, Pairing pairing);
void InvokeGetAllPairingsCallbackAndScheduleNext(
const GetAllPairingsCallback& callback,
scoped_ptr<base::ListValue> pairings);
+ // Sanitize |pairings| by parsing each entry and removing the secret from it.
+ void SanitizePairings(const GetAllPairingsCallback& callback,
+ scoped_ptr<base::ListValue> pairings);
+
// Queue management methods.
void ServiceOrQueueRequest(const base::Closure& request);
void ServiceNextRequest();
- // Translate between the structured and serialized forms of the pairing data.
- static PairedClients DecodeJson(const std::string& pairings_json);
- static std::string EncodeJson(const PairedClients& clients);
- static scoped_ptr<base::ListValue> ConvertToListValue(
- const PairedClients& clients,
- bool include_shared_secrets);
+ // Task runner on which all public methods of this class should be called.
+ scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_;
+
+ // Task runner used to run blocking calls to the delegate. A single thread
+ // task runner is used to guarantee that one one method of the delegate is
+ // called at a time.
+ scoped_refptr<base::SingleThreadTaskRunner> delegate_task_runner_;
scoped_ptr<Delegate> delegate_;

Powered by Google App Engine
This is Rietveld 408576698