Index: remoting/protocol/pairing_registry.h |
diff --git a/remoting/protocol/pairing_registry.h b/remoting/protocol/pairing_registry.h |
index fc63e84c91079577cb71a532184029a7b0b03fdf..56181a07026b19b88a6a17ec183ebbfe13accca4 100644 |
--- a/remoting/protocol/pairing_registry.h |
+++ b/remoting/protocol/pairing_registry.h |
@@ -19,6 +19,7 @@ |
namespace base { |
class ListValue; |
+class Value; |
} // namespace base |
namespace remoting { |
@@ -45,6 +46,9 @@ class PairingRegistry : public base::RefCountedThreadSafe<PairingRegistry>, |
~Pairing(); |
static Pairing Create(const std::string& client_name); |
+ static Pairing CreateFromJson(const base::Value& pairing_json); |
+ |
+ scoped_ptr<base::Value> EncodeJson() const; |
Jamie
2013/07/30 21:35:07
These methods don't deal with JSON. It might make
alexeypa (please no reviews)
2013/07/31 21:31:24
Done.
|
bool operator==(const Pairing& other) const; |
@@ -66,11 +70,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,15 +85,24 @@ 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. Must not |
+ // block. |
Jamie
2013/07/30 21:35:07
Since you've removed the SanitizePairings method,
alexeypa (please no reviews)
2013/07/31 21:31:24
I resurrected SanitizePairings().
|
+ virtual void LoadAll(const GetAllPairingsCallback& callback) = 0; |
+ |
+ // Deletes all pairings in persistent storage. Must not block. |
+ virtual void DeleteAll(const DoneCallback& callback) = 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|. Must not block. |
+ virtual void Load(const std::string& client_id, |
+ const GetPairingCallback& callback) = 0; |
+ |
+ // Saves |pairing| to persistent storage. Must not block. |
+ virtual void Save(const Pairing& pairing, |
+ const DoneCallback& callback) = 0; |
+ |
+ // Deletes the pairing identified by |client_id|. Must not block. |
+ virtual void Delete(const std::string& client_id, |
+ const DoneCallback& callback) = 0; |
}; |
explicit PairingRegistry(scoped_ptr<Delegate> delegate); |
@@ -115,10 +127,10 @@ 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); |
private: |
FRIEND_TEST_ALL_PREFIXES(PairingRegistryTest, AddPairing); |
@@ -131,26 +143,10 @@ class PairingRegistry : public base::RefCountedThreadSafe<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); |
- |
// "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( |
@@ -162,7 +158,7 @@ class PairingRegistry : public base::RefCountedThreadSafe<PairingRegistry>, |
void ServiceNextRequest(); |
// Translate between the structured and serialized forms of the pairing data. |
- static PairedClients DecodeJson(const std::string& pairings_json); |
+ static Pairing DecodeJson(const std::string& pairing_json); |
static std::string EncodeJson(const PairedClients& clients); |
static scoped_ptr<base::ListValue> ConvertToListValue( |
const PairedClients& clients, |